Repository navigation
Conversation
This branch has not been deployed
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:
With
PrefixMatchCommands: true,app depl --region westrejects a flag declared ondeploy, even thoughapp deploy --region westworks. If the root also declares--region, the abbreviated invocation succeeds but sets the root flag instead; the child action receives its default value.parseFlagsonly recognizes exact command names and explicit aliases. It parses the remaining flags on the parent beforerunresolves the shorthand throughSuggestCommandFunc.Resolve the first positional argument while locating the child command, then let that child parse the remaining flags. Parsing and dispatch share the result, so a custom matcher is called once per invocation. An unmatched name still leaves subsequent flags for the parent, and the cached match is local to each run.
The regression tests cover full names, aliases, shorthand with long and short flags, a custom matcher with a shadowed parent flag, an unmatched name, repeated runs, and preserving the existing shell-completion path.
Which issue(s) this PR fixes:
No existing issue found. Searches for
PrefixMatchCommands,SuggestCommandFunc, and shorthand command flags found no competing fix.Special notes for your reviewer:
A custom matcher now runs when parsing reaches the first positional argument, before flags following it are parsed. This is necessary to choose which command owns those flags.
#2534 addresses command names following
--; this change addresses flags following a shorthand command name. Both touch dispatch, so I will reconcile them if either merges first.Testing
On macOS arm64 with Go 1.26.5:
d5c06cb, pass with the fix, and fail again with only the production fix stashed.--regionflags printschild region=child-default; root region=westbefore the fix andchild region=west; root region=root-defaultafterward.make ensure-goimports lint vet testmake test GFLAGS='--tags urfave_cli_no_template'make check-binary-size generate v3diff diffcheckgolangci-lint run: 0 issues.make gfmrun FLAGS='--walk docs/v3/examples': 42 examples, 0 errors.The local tests use the race detector. Linux, Windows, and the other Go version in the CI matrix have not been run locally.
Release Notes