Repository navigation
Conversation
A persistent flag is excluded when the current command overrides any of its names. In a deeper descendant, the collision check only looked at that descendant's own flags, so the root flag was added again even when a nearer ancestor had already overridden it. Its old alias then changed the root value instead of the configuration the action read. Check the flags already applied to the command, including those from nearer ancestors, before adding a more distant persistent flag. Cover the rejected alias and the surviving override across command levels.
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:
A persistent flag overridden by an intermediate command becomes available again under its old alias in deeper subcommands. With a root
--config/-cand adeploycommand defining its own--config:The second command silently sets the root flag to
prod, whilecmd.String("config")reads the nearer override. That makes the same alias change behavior depending on the subcommand depth.parseFlagsgathers persistent flags from the nearest ancestor outward, but checks collisions only against flags declared on the current command. The check now includes flags already applied from nearer ancestors, so an overridden root flag stays excluded. The old alias is rejected consistently and the overriding flag still works.Which issue(s) this PR fixes:
None filed; found while exercising nested command flag inheritance. Related completed work: #2421 and #2481.
Testing
On macOS arm64, Go 1.26.5, from upstream
d5c06cb04479eeacbbb9378ea26261b6be516320:TestPersistentFlagOverrideInDescendantsfails on upstream for the old alias on child/grandchild commands and passes with this change. Stashing only the production change makes those cases fail again. The existing rejection ondeployand the surviving--configare also covered.-cinvocations fail before the action runs.make ensure-goimports,make lint,make vet,make test,make test GFLAGS='--tags urfave_cli_no_template',make check-binary-size,make generate,make v3diff, andmake diffcheckpass. Both test targets include-race.golangci-lint run(2.15.0): 0 issues.The Linux/Windows CI matrix and Go stable matrix were not run locally. No exported API changed.
Release Notes