Repository navigation
fix: complete subcommand flags after positional arguments - #2426
Merged
dearchap merged 1 commit intoSep 14, 2026
Merged
Conversation
dearchap
approved these changes
Sep 13, 2026
dearchap
left a comment
Contributor
There was a problem hiding this comment.
LGTM
Approve. Small, targeted fix for the remaining partial-flag completion case after a positional argument in child/nested commands.
Verified locally
- Confirmed the bug on base
50812189: new tests fail for all four child/nested positional cases (output suggests commands/help instead of flags). - Fix passes:
TestPartialFlagCompletion*all green on head816e14f1. - No regressions: full
go test -count=1 .,go vet ./...,goimports -lall clean.
Minor non-blocking notes
TestPartialFlagCustomCompletionArgsasserts current behavior wherecmd.Args()holds the partial--paas positional — good to keep explicit.- No issues found with root-vs-child args asymmetry handling.
Contributor
Author
|
Thanks, @dearchap, for the detailed review and the base/head regression check. I’ll keep the fix and the explicit custom-completion argument test as reviewed. |
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:
Fix the remaining partial-flag completion case after a positional argument in a child command. For example, current main completes
app sub --pa, butapp sub value --pasuggests child commands instead of matching flags.DefaultCompleteWithFlagsreads rawos.Argsfor the root command and parsed arguments for a child. Only the raw arguments still contain the trailing completion marker, so always selecting the penultimate argument skips the flag being completed in the child case.help.go: start with the final argument and step back only when that argument is the completion marker.completion_partial_regression_test.go: cover root, child, and nested commands with zero, one, and two positional arguments, plus hidden flags, custom-completer arguments, disabled completion, and requests after--.The completion request format, flag parsing, and custom completion handlers are unchanged.
Which issue(s) this PR fixes:
Fixes #2248.
Testing
5081218and passes with this change. The already-working root and no-positional cases stay unchanged.make all,make lint,make v3diff, and post-commitmake diffcheckpass.make vet test check-binary-sizepasses.--.The README
gfmruntarget found zero executable blocks; the compiled CLI probe supplies the execution check above. macOS and Windows are left to CI.Release Notes