diff --git a/app/app.go b/app/app.go index 5e9ff86..8fa8165 100644 --- a/app/app.go +++ b/app/app.go @@ -244,7 +244,8 @@ offers several options for fine-grained control over the renaming process.`, flagTargetDir, flagVerbose, }, - UseShortOptionHandling: true, + UseShortOptionHandling: true, + DisableSliceFlagSeparator: true, OnUsageError: func(_ *cli.Context, err error, _ bool) error { return err }, diff --git a/app/app_test/app_test.go b/app/app_test/app_test.go index d7f2adc..df68c56 100644 --- a/app/app_test/app_test.go +++ b/app/app_test/app_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/stretchr/testify/assert" "github.com/urfave/cli/v2" "github.com/ayoisaiah/f2/v2/app" @@ -207,3 +208,45 @@ func TestDefaultEnv(t *testing.T) { }) } } + +func TestStringSliceFlag(t *testing.T) { + cases := []*testutil.TestCase{ + { + Name: "commas should not be interpreted as a separator", + Args: []string{ + "f2_test", + "--replace", + "Windows, Linux Episode {%d}{ext}", + }, + Want: []string{"Windows, Linux Episode {%d}{ext}"}, + }, + { + Name: "multiple flags should add a separate value to the slice", + Args: []string{ + "f2_test", + "--replace", + "Windows", + "--replace", + "Linux Episode {%d}{ext}", + }, + Want: []string{"Windows", "Linux Episode {%d}{ext}"}, + }, + } + + for _, tc := range cases { + var stdout bytes.Buffer + + renamer, err := app.Get(os.Stdin, &stdout) + if err != nil { + t.Fatal(err) + } + + renamer.Action = func(ctx *cli.Context) error { + assert.Equal(t, tc.Want, ctx.StringSlice("replace")) + + return nil + } + + _ = renamer.Run(tc.Args) + } +}