Skip to content

Commit 30bb798

Browse files
committed
Rename field for better readability
Ref: #1675 (comment)
1 parent 9998599 commit 30bb798

7 files changed

+17
-17
lines changed

app_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func ExampleApp_Run_sliceValues() {
428428
// 0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 14.4, 15.5, 16.6}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true}
429429
// 1-int64Sclice cli.Int64Slice{slice:[]int64{13, 14, 15, 16}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true}
430430
// 2-intSclice cli.IntSlice{slice:[]int{13, 14, 15, 16}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true}
431-
// 3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true, noTrimSpace:false}
431+
// 3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, separator:cli.separatorSpec{sep:"", disabled:false, customized:false}, hasBeenSet:true, keepSpace:false}
432432
// error: <nil>
433433
}
434434

flag-spec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ flag_types:
101101
type: bool
102102
- name: Action
103103
type: "func(*Context, []string) error"
104-
- name: NoTrimSpace
104+
- name: KeepSpace
105105
type: bool
106106
time.Duration:
107107
struct_fields:

flag_string_slice.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010

1111
// StringSlice wraps a []string to satisfy flag.Value
1212
type StringSlice struct {
13-
slice []string
14-
separator separatorSpec
15-
hasBeenSet bool
16-
noTrimSpace bool
13+
slice []string
14+
separator separatorSpec
15+
hasBeenSet bool
16+
keepSpace bool
1717
}
1818

1919
// NewStringSlice creates a *StringSlice with default values
@@ -46,7 +46,7 @@ func (s *StringSlice) Set(value string) error {
4646
}
4747

4848
for _, t := range s.separator.flagSplitMultiValues(value) {
49-
if !s.noTrimSpace {
49+
if !s.keepSpace {
5050
t = strings.TrimSpace(t)
5151
}
5252
s.slice = append(s.slice, t)
@@ -153,11 +153,11 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
153153
setValue.WithSeparatorSpec(f.separator)
154154
}
155155

156-
setValue.noTrimSpace = f.NoTrimSpace
156+
setValue.keepSpace = f.KeepSpace
157157

158158
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
159159
for _, s := range f.separator.flagSplitMultiValues(val) {
160-
if !f.NoTrimSpace {
160+
if !f.KeepSpace {
161161
s = strings.TrimSpace(s)
162162
}
163163
if err := setValue.Set(s); err != nil {

flag_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ func TestFlagsFromEnv(t *testing.T) {
144144
s.hasBeenSet = false
145145
return *s
146146
}
147-
newSetStringSliceNoTrimSpace := func(defaults ...string) StringSlice {
147+
newSetStringSliceKeepSpace := func(defaults ...string) StringSlice {
148148
s := newSetStringSlice(defaults...)
149-
s.noTrimSpace = true
149+
s.keepSpace = true
150150
return s
151151
}
152152

@@ -203,7 +203,7 @@ func TestFlagsFromEnv(t *testing.T) {
203203
{"path", "path", &PathFlag{Name: "path", EnvVars: []string{"PATH"}}, ""},
204204

205205
{"foo,bar", newSetStringSlice("foo", "bar"), &StringSliceFlag{Name: "names", EnvVars: []string{"NAMES"}}, ""},
206-
{" space ", newSetStringSliceNoTrimSpace(" space "), &StringSliceFlag{Name: "names", NoTrimSpace: true, EnvVars: []string{"NAMES"}}, ""},
206+
{" space ", newSetStringSliceKeepSpace(" space "), &StringSliceFlag{Name: "names", KeepSpace: true, EnvVars: []string{"NAMES"}}, ""},
207207
{" no space ", newSetStringSlice("no space"), &StringSliceFlag{Name: "names", EnvVars: []string{"NAMES"}}, ""},
208208

209209
{"1", uint(1), &UintFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""},
@@ -781,7 +781,7 @@ func TestStringSliceFlag_MatchStringFlagBehavior(t *testing.T) {
781781
app := App{
782782
Flags: []Flag{
783783
&StringFlag{Name: "string"},
784-
&StringSliceFlag{Name: "slice", NoTrimSpace: true},
784+
&StringSliceFlag{Name: "slice", KeepSpace: true},
785785
},
786786
Action: func(ctx *Context) error {
787787
f1, f2 := ctx.String("string"), ctx.StringSlice("slice")
@@ -822,7 +822,7 @@ func TestStringSliceFlag_TrimSpace(t *testing.T) {
822822
app := App{
823823
Flags: []Flag{
824824
&StringSliceFlag{Name: "trim"},
825-
&StringSliceFlag{Name: "no-trim", NoTrimSpace: true},
825+
&StringSliceFlag{Name: "no-trim", KeepSpace: true},
826826
},
827827
Action: func(ctx *Context) error {
828828
flagTrim, flagNoTrim := ctx.StringSlice("trim"), ctx.StringSlice("no-trim")

godoc-current.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ type StringSliceFlag struct {
18281828

18291829
Action func(*Context, []string) error
18301830

1831-
NoTrimSpace bool
1831+
KeepSpace bool
18321832
// Has unexported fields.
18331833
}
18341834
StringSliceFlag is a flag with type *StringSlice

testdata/godoc-v2.x.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ type StringSliceFlag struct {
18281828

18291829
Action func(*Context, []string) error
18301830

1831-
NoTrimSpace bool
1831+
KeepSpace bool
18321832
// Has unexported fields.
18331833
}
18341834
StringSliceFlag is a flag with type *StringSlice

zz_generated.flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ type StringSliceFlag struct {
271271

272272
Action func(*Context, []string) error
273273

274-
NoTrimSpace bool
274+
KeepSpace bool
275275
}
276276

277277
// IsSet returns whether or not the flag has been set through env or file

0 commit comments

Comments
 (0)