feat(cli): add completion subcommand for shell completion scripts - #555
Merged
Conversation
Add a `gitu completion <shell>` subcommand that prints a completion script to stdout for bash, elvish, fish, powershell or zsh, generated with clap_complete. It is handled before terminal setup and git repo discovery, so it works from anywhere. Closes altsem#544
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.
Closes #544.
Adds a
completionsubcommand that prints a shell completion script to stdout, generated withclap_complete:Supported shells are bash, elvish, fish, powershell and zsh (whatever
clap_complete::Shelloffers). Since generating a script doesn't need a terminal or a git repository, it's handled early inmain, right alongside--version, and returns before any of that setup runs.Changes
src/cli.rs: newCommands::Completion { shell }variant and a smallcompletions(shell, out)helper that writes the script to anyWrite(keeps the generation testable and letsmainpassstdout).src/main.rs: handle the subcommand before terminal/repo setup.src/app.rs: the completion arm isunreachable!here since it never reaches app construction.docs/installing.mdwith per-shell install paths, plus a one-line pointer from the README.Tests
Added
src/tests/completion.rscovering: the subcommand parses, an unknown shell is rejected, and every supported shell produces a non-empty script that references the binary name.cargo fmt --checkandcargo clippy -- -Dwarningsare clean. (The pre-existingfetch/pull/pushsnapshot tests fail in my sandbox on a cleanmastertoo — they're unrelated to this change.)Happy to adjust the subcommand name or wire the scripts into the release artifacts instead if you'd prefer that approach.