Call actions on flags set from env#2221
Merged
dearchap merged 1 commit intourfave:mainfrom Nov 9, 2025
Merged
Conversation
malclocke
commented
Nov 8, 2025
malclocke
commented
Nov 8, 2025
Contributor
|
@malclocke revieweing |
dearchap
reviewed
Nov 8, 2025
Ensures flag actions are called when flags are set via env vars.
e188e9f to
9e5f598
Compare
dearchap
approved these changes
Nov 9, 2025
dearchap
added a commit
to dearchap/cli
that referenced
this pull request
Nov 16, 2025
…gs-from-env Call actions on flags set from env Signed-off-by: Naveen Gogineni <dear.chap@gmail.com>
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:
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