Skip to content

Conversation

@malclocke
Copy link
Contributor

@malclocke malclocke commented Nov 8, 2025

What type of PR is this?

  • bug

What this PR does / why we need it:

Flag actions are invoked in cmd.runFlagActions which is called after the flag values have been set, whether by -x val or from other sources. This method ranges over cmd.setFlags which is a map[Flag]struct{}.

Currently cmd.setFlags is only populated with flags that are set via -x val etc. cmd.setFlags is unchanged when flag values are loaded from the env.

This PR checks if the flag was unset before Flag.PostParse(), but was set after Flag.PostParse() was called. If so, the flag is added to cmd.setFlags and it's Action (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 Local makes no difference, the test fails before the changes whether Local is true or false.

Testing

A regression test is provided.

Release Notes

Fix v3 regression where flag actions were no longer called for flags set from env vars.

@malclocke malclocke requested a review from a team as a code owner November 8, 2025 00:48
@malclocke malclocke changed the title Call actions on env flags from env Call actions on flags set from env Nov 8, 2025
@dearchap
Copy link
Contributor

dearchap commented Nov 8, 2025

@malclocke revieweing

Ensures flag actions are called when flags are set via env vars.
@malclocke malclocke force-pushed the call-actions-on-env-flags-from-env branch from e188e9f to 9e5f598 Compare November 9, 2025 07:23
@malclocke malclocke requested a review from dearchap November 9, 2025 07:31
@dearchap dearchap merged commit 5aca46c into urfave:main Nov 9, 2025
9 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag Action not invoked when the value is supplied from ENV Sources Flag Action should be called when value is set by alternative sources.

2 participants