Conversation
With UseShortOptionHandling, a flag that is not found as a whole is split into single-rune flags, and each of those was looked up with lookupFlag, which walks the whole command lineage and ignores Local. The normal path uses lookupAppliedFlag, which only sees the command's own flags plus the persistent ones inherited from its ancestors. So `app sub -xd` (and `app sub -d`) silently set a parent's `-d` flag marked Local: true, while `app sub --debug` is rejected with "flag provided but not defined". Use lookupAppliedFlag for the split flags as well.
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
UseShortOptionHandling, a flag that is not found as a whole is split into single-rune flags. Each of those was looked up withlookupFlag, which walks the wholeLineage()and ignoresLocal. The normal parse path useslookupAppliedFlag, which only sees the command's own flags plus the persistent ones inherited from its ancestors.So with
app sub -xdandapp sub -dare accepted and set the parent'sdebugflag (itsActionnever runs either, since it is not among the child's applied flags), whileapp sub --debugis rejected withflag provided but not defined, asTestLocalFlagErrorasserts.FlagBase.Localdocuments that a Local flag is not applied to subcommands.command_parse.go: uselookupAppliedFlagfor the split single-rune flags, same as the whole-flag path.command_test.go:TestCommand_UseShortOptionHandling_LocalFlagNotInheritedcovers-xd,-dx,-d(all rejected) and checks the subcommand's own short flags still work in a group. It fails onmainand passes with this change; the full suite passes.Note: #2443 also touches this loop (pre-checking every flag of a group). The two changes are independent; if that lands first this is a one-identifier rebase.
Release Notes