Skip to content

Commit

Permalink
Rename field for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
palsivertsen committed Jan 31, 2023
1 parent 9998599 commit 30bb798
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: <nil>
}

Expand Down
2 changes: 1 addition & 1 deletion flag-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"}}, ""},
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testdata/godoc-v2.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zz_generated.flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30bb798

Please sign in to comment.