Skip to content

feat(cli): add cook completions <shell> for shell completion scripts - #483

Merged
dubadub merged 1 commit into
mainfrom
feat/completions
Sep 3, 2026
Merged

dubadub merged 1 commit into
mainfrom
feat/completions

Conversation

@dubadub

@dubadub dubadub commented Sep 3, 2026

Copy link
Copy Markdown
Member

Closes #467

What

New cook completions <shell> subcommand that prints a completion script for bash, zsh, fish, powershell or elvish to stdout, generated with clap_complete from the existing CliArgs definition.

cook completions bash    > /usr/local/etc/bash_completion.d/cook
cook completions zsh     > "${fpath[1]}/_cook"
cook completions fish    > ~/.config/fish/completions/cook.fish
  • src/completions.rs with CompletionsArgs { shell: clap_complete::Shell } and run()
  • Command::Completions variant plus match arm in main.rs
  • docs/completions.md with per-shell install instructions, linked from docs/README.md and README.md
  • tests/completions_test.rs covering every shell, subcommand/alias/flag coverage, and error cases

Worth knowing

The binary name is passed explicitly rather than taken from cmd.get_name(). That returns the package name cookcli, so the first cut registered complete -F _cookcli cookcli and would never have fired for cook. The tests now assert on the exact registration line so a prefix match can't hide this again.

Generated bash and zsh scripts parse cleanly under bash -n / zsh -n. The help snapshot gained one line for the new subcommand.

Open questions from the issue, and what this PR does about them

  • Feature-gated subcommands: documented in docs/completions.md rather than worked around. The script matches whichever binary generated it.
  • Dynamic completion of recipe names: not included, per the issue's suggestion to ship static first.
  • Bundling scripts in release archives: not included. Most release targets are cross-compiled on a host that cannot run the resulting binary, so generation would need a separate host build. Better as its own change.

https://claude.ai/code/session_013cPWotrjEY4Jac87e6vHsh

Prints a completion script for bash, zsh, fish, PowerShell or elvish to
stdout, generated with clap_complete from the live `CliArgs` definition.
The script therefore matches the binary that produced it, including any
subcommands compiled out by cargo features.

The binary name is passed explicitly: clap's command name is the package
name ("cookcli"), and a script registered under that would never fire
for the `cook` users actually type.

Closes #467

Claude-Session: https://claude.ai/code/session_013cPWotrjEY4Jac87e6vHsh
@claude

claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Review

Clean, well-scoped addition — nice attention to detail catching the cmd.get_name() == "cookcli" vs. binary name "cook" mismatch before it shipped, and locking that down with a test that asserts the exact registration line rather than a loose substring match.

Code quality

  • src/completions.rs is minimal and does exactly one thing. The doc comments explain the why (binary-name mismatch, feature-gated subcommands) rather than restating the code, in line with the repos comment conventions.
  • Wiring into args.rs / lib.rs / main.rs follows the existing per-command module pattern exactly (mirrors update, login, etc.), including that it is not feature-gated, which is correct since completions generation has no external dependencies worth making optional.
  • BIN_NAME is a hardcoded "cook" constant — matches [[bin]] name = "cook" in Cargo.toml, confirmed. Only real nit: a hardcoded name means a renamed binary (e.g. a fork built under a different name) gets a completion script for the wrong command, with no override flag. Given this project ships one binary under one fixed name, this is a reasonable simplicity trade-off, not a bug.

Potential bugs

  • None found. clap_complete::generate is infallible in practice (writes to stdout), so Ok(()) after the call is fine — no swallowed error path.
  • configure_context() in main.rs still runs (and validates the base path is a directory) before dispatching to Completions, same as it does for every other command. That is pre-existing behavior, not something this PR changes, and is very unlikely to ever fail for completions in practice, so not worth flagging as a regression.

Performance

  • Non-issue; this generates a small in-memory script from a static clap definition and writes it once.

Security

  • No user input flows anywhere dangerous — shell is a value_enum restricted to clap_completes Shell variants, and the output is a static script written to stdout, not executed or written to a fixed filesystem path by this code (installation location is left to the user, per the docs). No concerns.

Test coverage

  • tests/completions_test.rs is thorough: covers all five shells with a signal specific enough to catch a regression (e.g. asserting the exact complete -F _cook ... cook line, #compdef cook, etc.), an invalid-shell rejection, missing-arg rejection, and the top-level --help listing. Also good that completions_script_covers_subcommands_and_their_flags checks the shopping-list/sl alias and a flag show up, not just the top-level command names.
  • Cargo.lock/Cargo.toml bump is minimal (clap_complete alone, version-aligned with the existing clap resolution at 4.6.x) and the help-output snapshot update is the expected one-line diff.
  • Docs (docs/completions.md) accurately describe the feature-gating caveat — checked against Cargo.tomls [features] block, and server/import/lsp/self-update are indeed all non-mandatory features, so that note is correct.

Nothing blocking here — this looks ready to merge as-is.

@dubadub
dubadub merged commit 56c5376 into main Sep 3, 2026
6 checks passed
@dubadub
dubadub deleted the feat/completions branch September 3, 2026 12:37
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.

Add a cook completions command for shell completion scripts

1 participant