@@ -64,16 +64,14 @@ func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(cCtx *c
64
64
65
65
// ApplyInputSourceValue applies a generic value to the flagSet if required
66
66
func (f * GenericFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
67
- if f .set != nil {
68
- if ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) {
69
- value , err := isc .Generic (f .GenericFlag .Name )
70
- if err != nil {
71
- return err
72
- }
73
- if value != nil {
74
- for _ , name := range f .Names () {
75
- _ = f .set .Set (name , value .String ())
76
- }
67
+ if f .set != nil && ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) && isc .isSet (f .GenericFlag .Name ) {
68
+ value , err := isc .Generic (f .GenericFlag .Name )
69
+ if err != nil {
70
+ return err
71
+ }
72
+ if value != nil {
73
+ for _ , name := range f .Names () {
74
+ _ = f .set .Set (name , value .String ())
77
75
}
78
76
}
79
77
}
@@ -83,19 +81,17 @@ func (f *GenericFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo
83
81
84
82
// ApplyInputSourceValue applies a StringSlice value to the flagSet if required
85
83
func (f * StringSliceFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
86
- if f .set != nil {
87
- if ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) {
88
- value , err := isc .StringSlice (f .StringSliceFlag .Name )
89
- if err != nil {
90
- return err
91
- }
92
- if value != nil {
93
- var sliceValue cli.StringSlice = * (cli .NewStringSlice (value ... ))
94
- for _ , name := range f .Names () {
95
- underlyingFlag := f .set .Lookup (name )
96
- if underlyingFlag != nil {
97
- underlyingFlag .Value = & sliceValue
98
- }
84
+ if f .set != nil && ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) && isc .isSet (f .StringSliceFlag .Name ) {
85
+ value , err := isc .StringSlice (f .StringSliceFlag .Name )
86
+ if err != nil {
87
+ return err
88
+ }
89
+ if value != nil {
90
+ var sliceValue cli.StringSlice = * (cli .NewStringSlice (value ... ))
91
+ for _ , name := range f .Names () {
92
+ underlyingFlag := f .set .Lookup (name )
93
+ if underlyingFlag != nil {
94
+ underlyingFlag .Value = & sliceValue
99
95
}
100
96
}
101
97
}
@@ -105,19 +101,17 @@ func (f *StringSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSour
105
101
106
102
// ApplyInputSourceValue applies a IntSlice value if required
107
103
func (f * IntSliceFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
108
- if f .set != nil {
109
- if ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) {
110
- value , err := isc .IntSlice (f .IntSliceFlag .Name )
111
- if err != nil {
112
- return err
113
- }
114
- if value != nil {
115
- var sliceValue cli.IntSlice = * (cli .NewIntSlice (value ... ))
116
- for _ , name := range f .Names () {
117
- underlyingFlag := f .set .Lookup (name )
118
- if underlyingFlag != nil {
119
- underlyingFlag .Value = & sliceValue
120
- }
104
+ if f .set != nil && ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) && isc .isSet (f .IntSliceFlag .Name ) {
105
+ value , err := isc .IntSlice (f .IntSliceFlag .Name )
106
+ if err != nil {
107
+ return err
108
+ }
109
+ if value != nil {
110
+ var sliceValue cli.IntSlice = * (cli .NewIntSlice (value ... ))
111
+ for _ , name := range f .Names () {
112
+ underlyingFlag := f .set .Lookup (name )
113
+ if underlyingFlag != nil {
114
+ underlyingFlag .Value = & sliceValue
121
115
}
122
116
}
123
117
}
@@ -127,16 +121,14 @@ func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC
127
121
128
122
// ApplyInputSourceValue applies a Bool value to the flagSet if required
129
123
func (f * BoolFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
130
- if f .set != nil {
131
- if ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) {
132
- value , err := isc .Bool (f .BoolFlag .Name )
133
- if err != nil {
134
- return err
135
- }
136
- if value {
137
- for _ , name := range f .Names () {
138
- _ = f .set .Set (name , strconv .FormatBool (value ))
139
- }
124
+ if f .set != nil && ! cCtx .IsSet (f .Name ) && ! isEnvVarSet (f .EnvVars ) && isc .isSet (f .BoolFlag .Name ) {
125
+ value , err := isc .Bool (f .BoolFlag .Name )
126
+ if err != nil {
127
+ return err
128
+ }
129
+ if value {
130
+ for _ , name := range f .Names () {
131
+ _ = f .set .Set (name , strconv .FormatBool (value ))
140
132
}
141
133
}
142
134
}
@@ -145,16 +137,14 @@ func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
145
137
146
138
// ApplyInputSourceValue applies a String value to the flagSet if required
147
139
func (f * StringFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
148
- if f .set != nil {
149
- if ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) {
150
- value , err := isc .String (f .StringFlag .Name )
151
- if err != nil {
152
- return err
153
- }
154
- if value != "" {
155
- for _ , name := range f .Names () {
156
- _ = f .set .Set (name , value )
157
- }
140
+ if f .set != nil && ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) && isc .isSet (f .StringFlag .Name ) {
141
+ value , err := isc .String (f .StringFlag .Name )
142
+ if err != nil {
143
+ return err
144
+ }
145
+ if value != "" {
146
+ for _ , name := range f .Names () {
147
+ _ = f .set .Set (name , value )
158
148
}
159
149
}
160
150
}
@@ -163,26 +153,24 @@ func (f *StringFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCon
163
153
164
154
// ApplyInputSourceValue applies a Path value to the flagSet if required
165
155
func (f * PathFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
166
- if f .set != nil {
167
- if ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) {
168
- value , err := isc .String (f .PathFlag .Name )
169
- if err != nil {
170
- return err
171
- }
172
- if value != "" {
173
- for _ , name := range f .Names () {
174
-
175
- if ! filepath .IsAbs (value ) && isc .Source () != "" {
176
- basePathAbs , err := filepath .Abs (isc .Source ())
177
- if err != nil {
178
- return err
179
- }
156
+ if f .set != nil && ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) && isc .isSet (f .PathFlag .Name ) {
157
+ value , err := isc .String (f .PathFlag .Name )
158
+ if err != nil {
159
+ return err
160
+ }
161
+ if value != "" {
162
+ for _ , name := range f .Names () {
180
163
181
- value = filepath .Join (filepath .Dir (basePathAbs ), value )
164
+ if ! filepath .IsAbs (value ) && isc .Source () != "" {
165
+ basePathAbs , err := filepath .Abs (isc .Source ())
166
+ if err != nil {
167
+ return err
182
168
}
183
169
184
- _ = f . set . Set ( name , value )
170
+ value = filepath . Join ( filepath . Dir ( basePathAbs ) , value )
185
171
}
172
+
173
+ _ = f .set .Set (name , value )
186
174
}
187
175
}
188
176
}
@@ -191,48 +179,42 @@ func (f *PathFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
191
179
192
180
// ApplyInputSourceValue applies a int value to the flagSet if required
193
181
func (f * IntFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
194
- if f .set != nil {
195
- if ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) {
196
- value , err := isc .Int (f .IntFlag .Name )
197
- if err != nil {
198
- return err
199
- }
200
- for _ , name := range f .Names () {
201
- _ = f .set .Set (name , strconv .FormatInt (int64 (value ), 10 ))
202
- }
182
+ if f .set != nil && ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) && isc .isSet (f .IntFlag .Name ) {
183
+ value , err := isc .Int (f .IntFlag .Name )
184
+ if err != nil {
185
+ return err
186
+ }
187
+ for _ , name := range f .Names () {
188
+ _ = f .set .Set (name , strconv .FormatInt (int64 (value ), 10 ))
203
189
}
204
190
}
205
191
return nil
206
192
}
207
193
208
194
// ApplyInputSourceValue applies a Duration value to the flagSet if required
209
195
func (f * DurationFlag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
210
- if f .set != nil {
211
- if ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) {
212
- value , err := isc .Duration (f .DurationFlag .Name )
213
- if err != nil {
214
- return err
215
- }
216
- for _ , name := range f .Names () {
217
- _ = f .set .Set (name , value .String ())
218
- }
196
+ if f .set != nil && ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) && isc .isSet (f .DurationFlag .Name ) {
197
+ value , err := isc .Duration (f .DurationFlag .Name )
198
+ if err != nil {
199
+ return err
200
+ }
201
+ for _ , name := range f .Names () {
202
+ _ = f .set .Set (name , value .String ())
219
203
}
220
204
}
221
205
return nil
222
206
}
223
207
224
208
// ApplyInputSourceValue applies a Float64 value to the flagSet if required
225
209
func (f * Float64Flag ) ApplyInputSourceValue (cCtx * cli.Context , isc InputSourceContext ) error {
226
- if f .set != nil {
227
- if ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) {
228
- value , err := isc .Float64 (f .Float64Flag .Name )
229
- if err != nil {
230
- return err
231
- }
232
- floatStr := float64ToString (value )
233
- for _ , name := range f .Names () {
234
- _ = f .set .Set (name , floatStr )
235
- }
210
+ if f .set != nil && ! (cCtx .IsSet (f .Name ) || isEnvVarSet (f .EnvVars )) && isc .isSet (f .Float64Flag .Name ) {
211
+ value , err := isc .Float64 (f .Float64Flag .Name )
212
+ if err != nil {
213
+ return err
214
+ }
215
+ floatStr := float64ToString (value )
216
+ for _ , name := range f .Names () {
217
+ _ = f .set .Set (name , floatStr )
236
218
}
237
219
}
238
220
return nil
0 commit comments