From 474328071db2e8c43e8b913d53959f6ad8c327ba Mon Sep 17 00:00:00 2001 From: Felix Stein Date: Mon, 21 Apr 2025 14:00:41 +0200 Subject: [PATCH] add test for MutuallyExclusiveFlags with After For #2098 --- command_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/command_test.go b/command_test.go index 152a5986ac..3a7978a3d9 100644 --- a/command_test.go +++ b/command_test.go @@ -5011,3 +5011,38 @@ func TestJSONExportCommand(t *testing.T) { ` assert.JSONEq(t, expected, string(out)) } + +func TestCommand_ExclusiveFlagsWithAfter(t *testing.T) { + var called bool + cmd := &Command{ + Name: "bar", + MutuallyExclusiveFlags: []MutuallyExclusiveFlags{ + { + Category: "cat1", + Flags: [][]Flag{ + { + &StringFlag{ + Name: "foo", + }, + }, + { + &StringFlag{ + Name: "foo2", + }, + }, + }, + }, + }, + After: func(ctx context.Context, cmd *Command) error { + called = true + return nil + }, + } + + require.Error(t, cmd.Run(buildTestContext(t), []string{ + "bar", + "--foo", "v1", + "--foo2", "v2", + })) + require.True(t, called) +}