Skip to content

Fix: propagate MutuallyExclusiveFlags persistent flags to subcommands#2266

Open
siutsin wants to merge 1 commit intourfave:mainfrom
siutsin:MutuallyExclusiveFlags-persistent-flags-are-not-propagated-to-subcommands
Open

Fix: propagate MutuallyExclusiveFlags persistent flags to subcommands#2266
siutsin wants to merge 1 commit intourfave:mainfrom
siutsin:MutuallyExclusiveFlags-persistent-flags-are-not-propagated-to-subcommands

Conversation

@siutsin
Copy link

@siutsin siutsin commented Feb 16, 2026

What type of PR is this?

  • bug

What this PR does / why we need it:

  • Fixes persistent flag propagation for flags defined in MutuallyExclusiveFlags groups
  • Changed pCmd.Flags to pCmd.allFlags() in the persistent flag inheritance loop in command_parse.go:39, so that flags from MutuallyExclusiveFlags are included when walking the command lineage
  • Added test TestCommand_ExclusiveFlagsPersistentPropagation to verify the fix

Which issue(s) this PR fixes:

Fixes #2265

Special notes for your reviewer:

allFlags() is already used on line 29 of the same function to populate cmd.appliedFlags for the current command. The ancestor loop on line 39 was the only place still using pCmd.Flags directly, which excluded MutuallyExclusiveFlags groups from propagation.

Testing

  • Added TestCommand_ExclusiveFlagsPersistentPropagation which creates a root command with a MutuallyExclusiveFlags group containing persistent string flags, then verifies a subcommand can receive the flag value
  • All existing tests continue to pass

Release Notes

Fixed persistent flags defined in `MutuallyExclusiveFlags` not being propagated to subcommands

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.

MutuallyExclusiveFlags persistent flags are not propagated to subcommands

1 participant