Call actions on flags set from env #2221
Merged
+27
−0
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:
Flag actions are invoked in
cmd.runFlagActionswhich is called after the flag values have been set, whether by-x valor from other sources. This method ranges overcmd.setFlagswhich is amap[Flag]struct{}.Currently
cmd.setFlagsis only populated with flags that are set via-x valetc.cmd.setFlagsis unchanged when flag values are loaded from the env.This PR checks if the flag was unset before
Flag.PostParse(), but was set afterFlag.PostParse()was called. If so, the flag is added tocmd.setFlagsand it'sAction(if present) is invoked.Which issue(s) this PR fixes:
Fixes #2041
Fixes #2132
Special notes for your reviewer:
@dearchap has raised some concerns over local vs non-local flag actions. I don't fully understand the context of those concerns so a sanity check of this PR would be appreciated. Note that in the regression test added in this PR
Localmakes no difference, the test fails before the changes whetherLocalistrueorfalse.Testing
A regression test is provided.
Release Notes