Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
setValue = f.Value.clone()
default:
setValue = new(StringSlice)
setValue.WithSeparatorSpec(f.separator)
}
setValue.WithSeparatorSpec(f.separator)

setValue.keepSpace = f.KeepSpace

Expand Down
60 changes: 60 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,66 @@ func TestParseMultiStringSliceWithDestination(t *testing.T) {
}).Run([]string{"run", "-s", "10", "-s", "20"})
}

func TestParseMultiStringSliceDisableSeparator(t *testing.T) {
tests := []struct {
name string
val *StringSlice
dest *StringSlice
disableSep bool
input []string
expected []string
}{
{
name: "Basic",
input: []string{"-s", "10", "-s", "20"},
expected: []string{"10", "20"},
},
{
name: "Basic Sep",
input: []string{"-s", "10,20"},
expected: []string{"10", "20"},
},
{
name: "Basic Disable Sep",
disableSep: true,
input: []string{"-s", "10,20"},
expected: []string{"10,20"},
},
{
name: "Basic Disable Sep dest set",
disableSep: true,
dest: NewStringSlice("11", "22"),
input: []string{"-s", "10,20"},
expected: []string{"10,20"},
},
{
name: "Basic Disable Sep value set",
disableSep: true,
val: NewStringSlice("11", "22"),
input: []string{"-s", "10,201"},
expected: []string{"10,201"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
inputs := []string{"run"}
inputs = append(inputs, test.input...)
_ = (&App{
DisableSliceFlagSeparator: test.disableSep,
Flags: []Flag{
&StringSliceFlag{Name: "serve", Aliases: []string{"s"}, Destination: test.dest, Value: test.val},
},
Action: func(ctx *Context) error {
if !reflect.DeepEqual(ctx.StringSlice("serve"), test.expected) {
t.Errorf("Expected: %v != %v", test.expected, ctx.StringSlice("serve"))
}
return nil
},
}).Run(inputs)
})
}
}

func TestParseMultiStringSliceWithDestinationAndEnv(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
Expand Down
Loading