feat: add bootcamp completion command for bash/zsh/fish#54
Merged
Conversation
Adds `bootcamp completion <shell>` which prints a tab-completion script for bash, zsh, or fish. The completion spec (subcommands, aliases, and option flags) is collected from the live Commander `program` at runtime, so the scripts always match the real CLI surface and never drift as commands are added or changed. - src/completion.ts: pure, fully-testable spec collection + per-shell renderers - src/commands/completion-command.ts: validation, exit codes, injectable IO - Generated bash script validated with `bash -n` and a functional COMPREPLY check Tests: 17 unit (spec + renderers), 4 wrapper unit (validation/DI), 4 E2E spawning the real CLI for each shell + the unsupported-shell error path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4a6e777 to
cfd04ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
bootcamp completion <shell>command that prints a shell completion script for bash, zsh, or fish, enabling tab-completion of subcommands, their aliases, and option flags.Why this approach
The completion spec — every subcommand, its aliases, and its option flags — is collected from the live Commander
programat runtime rather than hardcoded. This means the generated scripts can never drift from the real CLI: when a new command or flag is added (like the recenthealth,init,doctor, orstylescommands), completions pick it up automatically with zero extra maintenance.Implementation
src/completion.ts— pure, fully-testable building blocks:collectCompletionSpec(program)walks the command tree (skipping commander's auto-generatedhelp), andrenderBash/renderZsh/renderFishturn the spec into shell scripts. Column/quoting concerns per shell are handled (e.g. zshname:desccolon sanitization, fish__fish_seen_subcommand_fromguards).src/commands/completion-command.ts— thin wrapper handling shell validation (case-insensitive), exit codes, and injectable IO, matching thedoctor/cache listDI pattern.The generated bash script was validated with
bash -nand a functionalCOMPREPLYcheck (top-level suggests subcommands;bootcamp health --<TAB>suggests--min-score,--json, etc.).Testing
test/completion.test.ts).test/completion-command.test.ts).test/e2e/completion-command.e2e.test.ts).npm test→ 1079 passing; typecheck + lint + build clean.🤖 Generated with Claude Code