Repository navigation
Conversation
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:
Calling
cmd.Set("region", "west")inBeforeupdates the flag value and makesIsSet("region")true, but its flag action never runs unless the flag was already set by argv or an environment source. The same hook therefore triggers the action forapp --region eastbut skips it forapp.Command.Setupdates the flag without adding it to the command'ssetFlagsmap. Record successful sets there so the existing flag-action phase sees them. Failed sets return their existing error, and setting a flag before command setup still works with an initially nil map.The regression covers an unset root flag, argv and environment controls, and an inherited flag set through its alias in a child command's
Beforehook.Which issue(s) this PR fixes:
No existing issue found. Related completed work: #2221 made environment-sourced flags participate in the same action phase.
Special notes for your reviewer:
This keeps the existing lifecycle order. It does not invoke actions immediately inside
Setor run actions for untouched defaults. Persistent flag actions retain their existing per-command behavior: if the flag is set in both a parent and a child, its action runs in both contexts. A parent argv value followed by a childBeforecall toSetnow behaves like setting the flag via argv in both contexts.Testing
On macOS arm64 with Go 1.26.5:
d5c06cbfor unset and inherited flags; argv and environment controls pass. All four pass with the fix. Stashing only the production change reproduces the two failures.command action: west (set=true)on upstream. With the fix it first printsflag action: west.make ensure-goimports lint vet testmake test GFLAGS='--tags urfave_cli_no_template'make check-binary-size generate v3diff diffcheckgolangci-lint run: 0 issues.Both local test targets include the race detector. Native Linux/Windows and the other CI Go version have not been run locally.
Release Notes