Skip to content

feat: add bootcamp completion command for bash/zsh/fish#54

Merged
Arthur742Ramos merged 1 commit into
mainfrom
arthur742ramos/completion-command
Jun 11, 2026
Merged

feat: add bootcamp completion command for bash/zsh/fish#54
Arthur742Ramos merged 1 commit into
mainfrom
arthur742ramos/completion-command

Conversation

@Arthur742Ramos

Copy link
Copy Markdown
Owner

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.

# bash
source <(bootcamp completion bash)
# or persist:
bootcamp completion bash > /etc/bash_completion.d/bootcamp

# zsh
bootcamp completion zsh > "${fpath[1]}/_bootcamp"

# fish
bootcamp completion fish > ~/.config/fish/completions/bootcamp.fish

Why this approach

The completion spec — every subcommand, its aliases, and its option flags — is collected from the live Commander program at 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 recent health, init, doctor, or styles commands), 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-generated help), and renderBash/renderZsh/renderFish turn the spec into shell scripts. Column/quoting concerns per shell are handled (e.g. zsh name:desc colon sanitization, fish __fish_seen_subcommand_from guards).
  • src/commands/completion-command.ts — thin wrapper handling shell validation (case-insensitive), exit codes, and injectable IO, matching the doctor/cache list DI pattern.

The generated bash script was validated with bash -n and a functional COMPREPLY check (top-level suggests subcommands; bootcamp health --<TAB> suggests --min-score, --json, etc.).

Testing

  • 17 unit tests for the spec collector and three renderers (test/completion.test.ts).
  • 4 unit tests for the command wrapper covering valid shells, case-insensitivity, unsupported shell, and missing shell (test/completion-command.test.ts).
  • 4 E2E tests spawning the real CLI for bash/zsh/fish output and the unsupported-shell error path (test/e2e/completion-command.e2e.test.ts).
  • Full suite green: npm test → 1079 passing; typecheck + lint + build clean.

🤖 Generated with Claude Code

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>
@Arthur742Ramos Arthur742Ramos force-pushed the arthur742ramos/completion-command branch from 4a6e777 to cfd04ca Compare June 11, 2026 18:29
@Arthur742Ramos Arthur742Ramos merged commit d6b4c2b into main Jun 11, 2026
13 checks passed
@Arthur742Ramos Arthur742Ramos deleted the arthur742ramos/completion-command branch June 11, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants