diff --git a/command_parse.go b/command_parse.go index aa95ae1677..d221a84898 100644 --- a/command_parse.go +++ b/command_parse.go @@ -36,7 +36,7 @@ func (cmd *Command) parseFlags(args Args) (Args, error) { pCmd.Name, cmd.Name, ) - for _, fl := range pCmd.Flags { + for _, fl := range pCmd.allFlags() { flNames := fl.Names() pfl, ok := fl.(LocalFlag) diff --git a/command_test.go b/command_test.go index efc64e9b56..b6021c4c2f 100644 --- a/command_test.go +++ b/command_test.go @@ -5417,3 +5417,40 @@ func TestCommand_ParallelRun(t *testing.T) { }) } } + +func TestCommand_ExclusiveFlagsPersistentPropagation(t *testing.T) { + var subCmdAlphaValue string + + cmd := &Command{ + Name: "root", + MutuallyExclusiveFlags: []MutuallyExclusiveFlags{ + { + Flags: [][]Flag{ + { + &StringFlag{ + Name: "alpha", + }, + }, + { + &StringFlag{ + Name: "beta", + }, + }, + }, + }, + }, + Commands: []*Command{ + { + Name: "sub", + Action: func(_ context.Context, cmd *Command) error { + subCmdAlphaValue = cmd.String("alpha") + return nil + }, + }, + }, + } + + err := cmd.Run(buildTestContext(t), []string{"root", "sub", "--alpha", "hello"}) + require.NoError(t, err) + assert.Equal(t, "hello", subCmdAlphaValue) +} diff --git a/docs/go.mod b/docs/go.mod index 08fbe8bbed..80ac54b0c4 100644 --- a/docs/go.mod +++ b/docs/go.mod @@ -11,6 +11,6 @@ require ( require ( github.com/BurntSushi/toml v1.5.0 // indirect - github.com/stretchr/testify v1.10.0 // indirect + github.com/stretchr/testify v1.11.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/docs/go.sum b/docs/go.sum index a36c208bb8..8127db6371 100644 --- a/docs/go.sum +++ b/docs/go.sum @@ -9,6 +9,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2 h1:j4SaBpPB8++L0c0KuTnz/Yus3UQoWJ54hQjhIMW8rCM= github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2/go.mod h1:Q79oyIY/z4jtzIrKEK6MUeWC7/szGr46x4QdOaOAIWc= github.com/urfave/cli-altsrc/v3 v3.0.1 h1:v+gHk59syLk8ao9rYybZs43+D5ut/gzj0omqQ1XYl8k=