complete per-command flags in the shell completions#97
Open
Kirananandan wants to merge 1 commit into
Open
Conversation
Past the subcommand the completion scripts only ever offered the five shared flags, so command-specific flags like `restore --clean`, `diff --stat`, `find --ids`, `save -n` or `gc --keep` never showed up on tab. Build a per-command flag map by walking each subparser`s _actions off the argparse parser (the same way `_subcommands()` walks the choices), then inject it into all four completion templates. When the current word starts with `-` each shell now offers that command`s own flags instead of the shared five. Fish also keeps top-level flag completion (`--version`, `--help`) before a subcommand is chosen, derived from the root parser so it stays in sync. Closes qorexdevs#96
5f7c273 to
8145517
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.
Closes #96.
Past the subcommand, the completion scripts only ever offered the five shared flags (
-q --quiet --json --dry-run --help), so command-specific flags likerestore --clean,diff --stat/--name-only,find --ids,save -n, orgc --keepnever showed up on tab.What changed
_flags_for_commands()— a helper next to_subcommands()that walks each subparser's_actionsoff the argparse parser and maps every public subcommand to its option strings, so the map stays in sync as flags are added._bash_flagmap,_zsh_flagmap,_fish_flagmap,_pwsh_flagmap) render that map into each script's native form (bash/zsh associative array, fishcompletelines, PowerShell hashtable), injected via a new__FLAGMAP__placeholder.${command}'s own flags instead of the shared five. Refs and file fallback are unchanged.--version,--help) before a subcommand is chosen — the old unguarded globalcompleteline offered those, and the per-command rewrite would otherwise have dropped them. Derived from the root parser via_root_flags().Scope stayed in
cli.pyas the issue suggested, plus a docs note and a changelog entry.Testing
--keepdoesn't appear underrestore), plus a fish root-flag test.restore --<TAB>→--clean --only-missing ...,gc --<TAB>→--keep --keep-named --keep-within, and the hyphenatedcheck-ignore --<TAB>→--exit-codeall complete correctly. The PowerShell script also parses clean via the PS parser.