Repository navigation
cliflagv2: read each flag from the command that defines it - #453
Merged
Merged
Conversation
Flags were read through the innermost command's context. findFlag only looked at the app and the innermost command, so flags on a middle command were dropped, and a parent flag that shares a name with a child flag got the child's value. Read each flag through its own command's context in the lineage instead.
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.
Follow-up to #451, same problem in the v2 provider.
processFlagsreads every flag throughp.ctx, the innermost command's context, andfindFlagonly looks at the app's flags and the innermost command's flags. Withapp > mid > leaf:master gives:
mid.regionandmid.portare missing, becausefindFlagnever looks atmid.app.nameischild, becausep.ctx.String("name")finds the leaf's flag first.leaf --name child,app.nameis still set tochild.Read()already walks the lineage, and each entry is that command's own*cli.Context. The fix passes that context toprocessFlagsand uses the flag we already hold for the type switch, sofindFlagis gone. Same idea as #451.Added
TestCliFlagParentFlagsInSubcommandwith the three cases above. All three fail on master.go testandgo vetpass inproviders/cliflagv2.