From 1f0c18892598bdc5f17561d6ad13803dba24a81a Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sat, 21 Mar 2026 14:18:04 -0400 Subject: [PATCH] Fix:(issue_2281) Remove incorrect check for local flag for set --- command_test.go | 33 +++++++++++++++++++++++++++++++++ flag_impl.go | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/command_test.go b/command_test.go index 88369cc0fa..47528ac7e7 100644 --- a/command_test.go +++ b/command_test.go @@ -3105,6 +3105,39 @@ func TestFlagAction(t *testing.T) { } } +func TestLocalSliceFlagAccumulation(t *testing.T) { + var got []string + + app := &Command{ + Name: "app", + Commands: []*Command{ + { + Name: "sub", + Flags: []Flag{ + &StringSliceFlag{ + Name: "paths", + Aliases: []string{"p"}, + Local: true, + Destination: &got, + }, + }, + Action: func(_ context.Context, cmd *Command) error { + return nil + }, + }, + }, + } + + err := app.Run(context.Background(), []string{"app", "sub", "-p", "/a", "-p", "/b", "-p", "/c"}) + if err != nil { + t.Fatal(err) + } + + if len(got) != 3 { + t.Errorf("expected 3 values, got %d: %v", len(got), got) + } +} + func TestLocalFlagError(t *testing.T) { var topInt int64 diff --git a/flag_impl.go b/flag_impl.go index c7cc8dffc5..1ca295aaf2 100644 --- a/flag_impl.go +++ b/flag_impl.go @@ -185,7 +185,7 @@ func (f *FlagBase[T, C, V]) Set(_ string, val string) error { // lots of units tests prior to persistent flags assumed that the // flag can be applied to different flag sets multiple times while still // keeping the env set. - if !f.applied || f.Local { + if !f.applied { if err := f.PreParse(); err != nil { return err }