diff --git a/app_test.go b/app_test.go index 6f2115cb72..ccd63b9ef8 100644 --- a/app_test.go +++ b/app_test.go @@ -428,7 +428,7 @@ func ExampleApp_Run_sliceValues() { // 0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 14.4, 15.5, 16.6}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true} // 1-int64Sclice cli.Int64Slice{slice:[]int64{13, 14, 15, 16}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true} // 2-intSclice cli.IntSlice{slice:[]int{13, 14, 15, 16}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true} - // 3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true, noTrimSpace:false} + // 3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true, keepSpace:false} // error: } diff --git a/flag-spec.yaml b/flag-spec.yaml index 92168245f7..03d82e7011 100644 --- a/flag-spec.yaml +++ b/flag-spec.yaml @@ -101,7 +101,7 @@ flag_types: type: bool - name: Action type: "func(*Context, []string) error" - - name: NoTrimSpace + - name: KeepSpace type: bool time.Duration: struct_fields: diff --git a/flag_string_slice.go b/flag_string_slice.go index 4395432b74..28f4798f55 100644 --- a/flag_string_slice.go +++ b/flag_string_slice.go @@ -10,10 +10,10 @@ import ( // StringSlice wraps a []string to satisfy flag.Value type StringSlice struct { - slice []string - separator separatorSpec - hasBeenSet bool - noTrimSpace bool + slice []string + separator separatorSpec + hasBeenSet bool + keepSpace bool } // NewStringSlice creates a *StringSlice with default values @@ -46,7 +46,7 @@ func (s *StringSlice) Set(value string) error { } for _, t := range s.separator.flagSplitMultiValues(value) { - if !s.noTrimSpace { + if !s.keepSpace { t = strings.TrimSpace(t) } s.slice = append(s.slice, t) @@ -153,11 +153,11 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { setValue.WithSeparatorSpec(f.separator) } - setValue.noTrimSpace = f.NoTrimSpace + setValue.keepSpace = f.KeepSpace if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { for _, s := range f.separator.flagSplitMultiValues(val) { - if !f.NoTrimSpace { + if !f.KeepSpace { s = strings.TrimSpace(s) } if err := setValue.Set(s); err != nil { diff --git a/flag_test.go b/flag_test.go index 06813f48c9..60370aceb2 100644 --- a/flag_test.go +++ b/flag_test.go @@ -144,9 +144,9 @@ func TestFlagsFromEnv(t *testing.T) { s.hasBeenSet = false return *s } - newSetStringSliceNoTrimSpace := func(defaults ...string) StringSlice { + newSetStringSliceKeepSpace := func(defaults ...string) StringSlice { s := newSetStringSlice(defaults...) - s.noTrimSpace = true + s.keepSpace = true return s } @@ -203,7 +203,7 @@ func TestFlagsFromEnv(t *testing.T) { {"path", "path", &PathFlag{Name: "path", EnvVars: []string{"PATH"}}, ""}, {"foo,bar", newSetStringSlice("foo", "bar"), &StringSliceFlag{Name: "names", EnvVars: []string{"NAMES"}}, ""}, - {" space ", newSetStringSliceNoTrimSpace(" space "), &StringSliceFlag{Name: "names", NoTrimSpace: true, EnvVars: []string{"NAMES"}}, ""}, + {" space ", newSetStringSliceKeepSpace(" space "), &StringSliceFlag{Name: "names", KeepSpace: true, EnvVars: []string{"NAMES"}}, ""}, {" no space ", newSetStringSlice("no space"), &StringSliceFlag{Name: "names", EnvVars: []string{"NAMES"}}, ""}, {"1", uint(1), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, @@ -781,7 +781,7 @@ func TestStringSliceFlag_MatchStringFlagBehavior(t *testing.T) { app := App{ Flags: []Flag{ &StringFlag{Name: "string"}, - &StringSliceFlag{Name: "slice", NoTrimSpace: true}, + &StringSliceFlag{Name: "slice", KeepSpace: true}, }, Action: func(ctx *Context) error { f1, f2 := ctx.String("string"), ctx.StringSlice("slice") @@ -822,7 +822,7 @@ func TestStringSliceFlag_TrimSpace(t *testing.T) { app := App{ Flags: []Flag{ &StringSliceFlag{Name: "trim"}, - &StringSliceFlag{Name: "no-trim", NoTrimSpace: true}, + &StringSliceFlag{Name: "no-trim", KeepSpace: true}, }, Action: func(ctx *Context) error { flagTrim, flagNoTrim := ctx.StringSlice("trim"), ctx.StringSlice("no-trim") diff --git a/godoc-current.txt b/godoc-current.txt index d6c7a402f9..bd5e1defcd 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -1828,7 +1828,7 @@ type StringSliceFlag struct { Action func(*Context, []string) error - NoTrimSpace bool + KeepSpace bool // Has unexported fields. } StringSliceFlag is a flag with type *StringSlice diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index d6c7a402f9..bd5e1defcd 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -1828,7 +1828,7 @@ type StringSliceFlag struct { Action func(*Context, []string) error - NoTrimSpace bool + KeepSpace bool // Has unexported fields. } StringSliceFlag is a flag with type *StringSlice diff --git a/zz_generated.flags.go b/zz_generated.flags.go index 39813cbe58..73e771451a 100644 --- a/zz_generated.flags.go +++ b/zz_generated.flags.go @@ -271,7 +271,7 @@ type StringSliceFlag struct { Action func(*Context, []string) error - NoTrimSpace bool + KeepSpace bool } // IsSet returns whether or not the flag has been set through env or file