fix(cli): replace broken shell completion with full flag+alias support#454
Merged
fix(cli): replace broken shell completion with full flag+alias support#454
Conversation
Coverage Report ✅
Coverage BadgeMerging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
Shell completion was broken for all subcommands. Typing `aicr bundle --<TAB>` executed the command instead of showing flag completions because a custom `commandLister` on the root command overrode urfave/cli's built-in completion and only listed top-level subcommand names — never flags. Three issues are fixed: 1. Remove `commandLister` and replace it with `completeWithAllFlags`, a custom ShellComplete function that lists all flag names including aliases (e.g. both `--accelerator` and `--gpu`). The function is applied recursively to all subcommands via `setShellComplete` so urfave/cli's `setupDefaults` cannot replace it with `DefaultCompleteWithFlags` (which omits aliases). 2. Work around a urfave/cli v3 bug where `--` immediately before `--generate-shell-completion` disables completion mode entirely (`checkShellCompleteFlag` treats `--` as a POSIX flag terminator). This caused `aicr snapshot --<TAB>` to execute the snapshot action — deploying an agent to the cluster. `sanitizeCompletionArgs` replaces the bare `--` with `-` before passing args to `cmd.Run`, keeping completion mode active. 3. Read `os.Args` directly (via `completionLastArg`) instead of `cmd.Args()` to determine what the user was typing. Partial flags like `--form` fail urfave/cli's flag parser and never appear in parsed positional args, so `cmd.Args()` is empty. `os.Args` always has the original command line. Also removes `EnableShellCompletion: true` from 7 subcommands — the field is only meaningful on the root command in urfave/cli v3.
6776c1c to
42ff3e7
Compare
mchmarny
approved these changes
Mar 21, 2026
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
aicr snapshot --<TAB>was executing the actual command (deploying agents) instead of showing flag completions. Root cause: urfave/cli v3 disables completion mode when--precedes--generate-shell-completion.sanitizeCompletionArgsworks around this by replacing bare--with-beforecmd.Run.aicr verify --form<TAB>produced no output because--formfails urfave/cli's flag parser and never appears incmd.Args().completeWithAllFlagsnow readsos.Argsdirectly to see the partial flag.--acceleratorand--gpunow appear in TAB completions. The previouscommandListerfunction (and urfave/cli'sDefaultCompleteWithFlags) only showed primary flag names.EnableShellCompletion: truefrom 7 subcommands — only meaningful on the root command in urfave/cli v3.Test plan
go test -v -run TestCompletion ./pkg/cli/— all 5 completion test suites passgo test -race ./pkg/cli/— no regressionsmake buildthen manual verification:aicr --generate-shell-completion→ lists subcommands ✅aicr bundle - --generate-shell-completion→ lists all flags with aliases ✅aicr snapshot -- --generate-shell-completion→ lists flags (not command execution) ✅aicr verify --form --generate-shell-completion→ shows--format✅