fix: show flag completions when completing a double-dash prefix#2316
Merged
dearchap merged 1 commit intourfave:mainfrom Apr 18, 2026
Merged
fix: show flag completions when completing a double-dash prefix#2316dearchap merged 1 commit intourfave:mainfrom
dearchap merged 1 commit intourfave:mainfrom
Conversation
dearchap
approved these changes
Apr 18, 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.
What type of PR is this?
What this PR does / why we need it:
When the user types
cmd subcommand --<TAB>orcmd subcommand --prefix<TAB>, the CLI should show available flags. Previously, this produced no completions or malformed output because of four bugs:checkShellCompleteFlag()disabled completion mode when--appeared anywhere in arguments, including when--was the token being completed.DefaultCompleteWithFlags()returned early whenlastArg == "--".parseFlags()stripped--from args during completion, causinglastArgto be empty and triggering command suggestions instead of flag suggestions.parseFlags()dropped unknown or value-less flags fromposArgsand returned an error, so partial prefixes like--prefixwere lost beforeDefaultCompleteWithFlagscould use them to filter flag suggestions.Changes:
checkShellCompleteFlagnow only disables completion if--appears before the token being completed, not when it IS the token being completedDefaultCompleteWithFlagsforlastArg == "--"--inposArgsduring shell completion modeposArgsduring shell completion mode, so partial prefixes reachDefaultCompleteWithFlagsWhich issue(s) this PR fixes:
Fixes #2315
Testing
All changes are covered by new/updated tests that fail without the code changes and pass with them:
TestCommand_Run_CustomShellCompleteAcceptsMalformedFlags: Updated to expect--undefinedand--numberflags preserved in argsTestCompletionSubcommand: Added tests for--<TAB>and--partial<TAB>scenariosTestDefaultCompleteWithFlags: Updatedflag-suggestion-double-dash-shows-all-flagsto expect flag outputTest_checkShellCompleteFlag: Addeddouble dash is the token being completedtest caseRelease Notes