Skip to content

Commit d71794d

Browse files
committed
Make ApplyWithError a public method on errorableFlag
Add to altsrc flags. Otherwise, flagSet() was bypassing altsrc's attempt at shadowing.
1 parent 8500a4c commit d71794d

File tree

3 files changed

+139
-41
lines changed

3 files changed

+139
-41
lines changed

altsrc/flag_generated.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) {
2727
f.BoolFlag.Apply(set)
2828
}
2929

30+
// ApplyWithError saves the flagSet for later usage calls, then calls the
31+
// wrapped BoolFlag.ApplyWithError
32+
func (f *BoolFlag) ApplyWithError(set *flag.FlagSet) error {
33+
f.set = set
34+
return f.BoolFlag.ApplyWithError(set)
35+
}
36+
3037
// BoolTFlag is the flag type that wraps cli.BoolTFlag to allow
3138
// for other values to be specified
3239
type BoolTFlag struct {
@@ -46,6 +53,13 @@ func (f *BoolTFlag) Apply(set *flag.FlagSet) {
4653
f.BoolTFlag.Apply(set)
4754
}
4855

56+
// ApplyWithError saves the flagSet for later usage calls, then calls the
57+
// wrapped BoolTFlag.ApplyWithError
58+
func (f *BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
59+
f.set = set
60+
return f.BoolTFlag.ApplyWithError(set)
61+
}
62+
4963
// DurationFlag is the flag type that wraps cli.DurationFlag to allow
5064
// for other values to be specified
5165
type DurationFlag struct {
@@ -65,6 +79,13 @@ func (f *DurationFlag) Apply(set *flag.FlagSet) {
6579
f.DurationFlag.Apply(set)
6680
}
6781

82+
// ApplyWithError saves the flagSet for later usage calls, then calls the
83+
// wrapped DurationFlag.ApplyWithError
84+
func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error {
85+
f.set = set
86+
return f.DurationFlag.ApplyWithError(set)
87+
}
88+
6889
// Float64Flag is the flag type that wraps cli.Float64Flag to allow
6990
// for other values to be specified
7091
type Float64Flag struct {
@@ -84,6 +105,13 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) {
84105
f.Float64Flag.Apply(set)
85106
}
86107

108+
// ApplyWithError saves the flagSet for later usage calls, then calls the
109+
// wrapped Float64Flag.ApplyWithError
110+
func (f *Float64Flag) ApplyWithError(set *flag.FlagSet) error {
111+
f.set = set
112+
return f.Float64Flag.ApplyWithError(set)
113+
}
114+
87115
// GenericFlag is the flag type that wraps cli.GenericFlag to allow
88116
// for other values to be specified
89117
type GenericFlag struct {
@@ -103,6 +131,13 @@ func (f *GenericFlag) Apply(set *flag.FlagSet) {
103131
f.GenericFlag.Apply(set)
104132
}
105133

134+
// ApplyWithError saves the flagSet for later usage calls, then calls the
135+
// wrapped GenericFlag.ApplyWithError
136+
func (f *GenericFlag) ApplyWithError(set *flag.FlagSet) error {
137+
f.set = set
138+
return f.GenericFlag.ApplyWithError(set)
139+
}
140+
106141
// Int64Flag is the flag type that wraps cli.Int64Flag to allow
107142
// for other values to be specified
108143
type Int64Flag struct {
@@ -122,6 +157,13 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) {
122157
f.Int64Flag.Apply(set)
123158
}
124159

160+
// ApplyWithError saves the flagSet for later usage calls, then calls the
161+
// wrapped Int64Flag.ApplyWithError
162+
func (f *Int64Flag) ApplyWithError(set *flag.FlagSet) error {
163+
f.set = set
164+
return f.Int64Flag.ApplyWithError(set)
165+
}
166+
125167
// IntFlag is the flag type that wraps cli.IntFlag to allow
126168
// for other values to be specified
127169
type IntFlag struct {
@@ -141,6 +183,13 @@ func (f *IntFlag) Apply(set *flag.FlagSet) {
141183
f.IntFlag.Apply(set)
142184
}
143185

186+
// ApplyWithError saves the flagSet for later usage calls, then calls the
187+
// wrapped IntFlag.ApplyWithError
188+
func (f *IntFlag) ApplyWithError(set *flag.FlagSet) error {
189+
f.set = set
190+
return f.IntFlag.ApplyWithError(set)
191+
}
192+
144193
// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow
145194
// for other values to be specified
146195
type IntSliceFlag struct {
@@ -160,6 +209,13 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) {
160209
f.IntSliceFlag.Apply(set)
161210
}
162211

212+
// ApplyWithError saves the flagSet for later usage calls, then calls the
213+
// wrapped IntSliceFlag.ApplyWithError
214+
func (f *IntSliceFlag) ApplyWithError(set *flag.FlagSet) error {
215+
f.set = set
216+
return f.IntSliceFlag.ApplyWithError(set)
217+
}
218+
163219
// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow
164220
// for other values to be specified
165221
type Int64SliceFlag struct {
@@ -179,6 +235,13 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) {
179235
f.Int64SliceFlag.Apply(set)
180236
}
181237

238+
// ApplyWithError saves the flagSet for later usage calls, then calls the
239+
// wrapped Int64SliceFlag.ApplyWithError
240+
func (f *Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
241+
f.set = set
242+
return f.Int64SliceFlag.ApplyWithError(set)
243+
}
244+
182245
// StringFlag is the flag type that wraps cli.StringFlag to allow
183246
// for other values to be specified
184247
type StringFlag struct {
@@ -198,6 +261,13 @@ func (f *StringFlag) Apply(set *flag.FlagSet) {
198261
f.StringFlag.Apply(set)
199262
}
200263

264+
// ApplyWithError saves the flagSet for later usage calls, then calls the
265+
// wrapped StringFlag.ApplyWithError
266+
func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error {
267+
f.set = set
268+
return f.StringFlag.ApplyWithError(set)
269+
}
270+
201271
// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow
202272
// for other values to be specified
203273
type StringSliceFlag struct {
@@ -217,6 +287,13 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) {
217287
f.StringSliceFlag.Apply(set)
218288
}
219289

290+
// ApplyWithError saves the flagSet for later usage calls, then calls the
291+
// wrapped StringSliceFlag.ApplyWithError
292+
func (f *StringSliceFlag) ApplyWithError(set *flag.FlagSet) error {
293+
f.set = set
294+
return f.StringSliceFlag.ApplyWithError(set)
295+
}
296+
220297
// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow
221298
// for other values to be specified
222299
type Uint64Flag struct {
@@ -236,6 +313,13 @@ func (f *Uint64Flag) Apply(set *flag.FlagSet) {
236313
f.Uint64Flag.Apply(set)
237314
}
238315

316+
// ApplyWithError saves the flagSet for later usage calls, then calls the
317+
// wrapped Uint64Flag.ApplyWithError
318+
func (f *Uint64Flag) ApplyWithError(set *flag.FlagSet) error {
319+
f.set = set
320+
return f.Uint64Flag.ApplyWithError(set)
321+
}
322+
239323
// UintFlag is the flag type that wraps cli.UintFlag to allow
240324
// for other values to be specified
241325
type UintFlag struct {
@@ -254,3 +338,10 @@ func (f *UintFlag) Apply(set *flag.FlagSet) {
254338
f.set = set
255339
f.UintFlag.Apply(set)
256340
}
341+
342+
// ApplyWithError saves the flagSet for later usage calls, then calls the
343+
// wrapped UintFlag.ApplyWithError
344+
func (f *UintFlag) ApplyWithError(set *flag.FlagSet) error {
345+
f.set = set
346+
return f.UintFlag.ApplyWithError(set)
347+
}

flag.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Flag interface {
6868
type errorableFlag interface {
6969
Flag
7070

71-
applyWithError(*flag.FlagSet) error
71+
ApplyWithError(*flag.FlagSet) error
7272
}
7373

7474
func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
@@ -77,7 +77,7 @@ func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
7777
for _, f := range flags {
7878
//TODO remove in v2 when errorableFlag is removed
7979
if ef, ok := f.(errorableFlag); ok {
80-
if err := ef.applyWithError(set); err != nil {
80+
if err := ef.ApplyWithError(set); err != nil {
8181
return nil, err
8282
}
8383
} else {
@@ -105,12 +105,12 @@ type Generic interface {
105105
// provided by the user for parsing by the flag
106106
// Ignores parsing errors
107107
func (f GenericFlag) Apply(set *flag.FlagSet) {
108-
f.applyWithError(set)
108+
f.ApplyWithError(set)
109109
}
110110

111-
// applyWithError takes the flagset and calls Set on the generic flag with the value
111+
// ApplyWithError takes the flagset and calls Set on the generic flag with the value
112112
// provided by the user for parsing by the flag
113-
func (f GenericFlag) applyWithError(set *flag.FlagSet) error {
113+
func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error {
114114
val := f.Value
115115
if f.EnvVar != "" {
116116
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -158,11 +158,11 @@ func (f *StringSlice) Get() interface{} {
158158
// Apply populates the flag given the flag set and environment
159159
// Ignores errors
160160
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
161-
f.applyWithError(set)
161+
f.ApplyWithError(set)
162162
}
163163

164-
// applyWithError populates the flag given the flag set and environment
165-
func (f StringSliceFlag) applyWithError(set *flag.FlagSet) error {
164+
// ApplyWithError populates the flag given the flag set and environment
165+
func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error {
166166
if f.EnvVar != "" {
167167
for _, envVar := range strings.Split(f.EnvVar, ",") {
168168
envVar = strings.TrimSpace(envVar)
@@ -221,11 +221,11 @@ func (f *IntSlice) Get() interface{} {
221221
// Apply populates the flag given the flag set and environment
222222
// Ignores errors
223223
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
224-
f.applyWithError(set)
224+
f.ApplyWithError(set)
225225
}
226226

227-
// applyWithError populates the flag given the flag set and environment
228-
func (f IntSliceFlag) applyWithError(set *flag.FlagSet) error {
227+
// ApplyWithError populates the flag given the flag set and environment
228+
func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error {
229229
if f.EnvVar != "" {
230230
for _, envVar := range strings.Split(f.EnvVar, ",") {
231231
envVar = strings.TrimSpace(envVar)
@@ -284,11 +284,11 @@ func (f *Int64Slice) Get() interface{} {
284284
// Apply populates the flag given the flag set and environment
285285
// Ignores errors
286286
func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
287-
f.applyWithError(set)
287+
f.ApplyWithError(set)
288288
}
289289

290-
// applyWithError populates the flag given the flag set and environment
291-
func (f Int64SliceFlag) applyWithError(set *flag.FlagSet) error {
290+
// ApplyWithError populates the flag given the flag set and environment
291+
func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
292292
if f.EnvVar != "" {
293293
for _, envVar := range strings.Split(f.EnvVar, ",") {
294294
envVar = strings.TrimSpace(envVar)
@@ -318,11 +318,11 @@ func (f Int64SliceFlag) applyWithError(set *flag.FlagSet) error {
318318
// Apply populates the flag given the flag set and environment
319319
// Ignores errors
320320
func (f BoolFlag) Apply(set *flag.FlagSet) {
321-
f.applyWithError(set)
321+
f.ApplyWithError(set)
322322
}
323323

324-
// applyWithError populates the flag given the flag set and environment
325-
func (f BoolFlag) applyWithError(set *flag.FlagSet) error {
324+
// ApplyWithError populates the flag given the flag set and environment
325+
func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
326326
val := false
327327
if f.EnvVar != "" {
328328
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -358,11 +358,11 @@ func (f BoolFlag) applyWithError(set *flag.FlagSet) error {
358358
// Apply populates the flag given the flag set and environment
359359
// Ignores errors
360360
func (f BoolTFlag) Apply(set *flag.FlagSet) {
361-
f.applyWithError(set)
361+
f.ApplyWithError(set)
362362
}
363363

364-
// applyWithError populates the flag given the flag set and environment
365-
func (f BoolTFlag) applyWithError(set *flag.FlagSet) error {
364+
// ApplyWithError populates the flag given the flag set and environment
365+
func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
366366
val := true
367367
if f.EnvVar != "" {
368368
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -398,11 +398,11 @@ func (f BoolTFlag) applyWithError(set *flag.FlagSet) error {
398398
// Apply populates the flag given the flag set and environment
399399
// Ignores errors
400400
func (f StringFlag) Apply(set *flag.FlagSet) {
401-
f.applyWithError(set)
401+
f.ApplyWithError(set)
402402
}
403403

404-
// applyWithError populates the flag given the flag set and environment
405-
func (f StringFlag) applyWithError(set *flag.FlagSet) error {
404+
// ApplyWithError populates the flag given the flag set and environment
405+
func (f StringFlag) ApplyWithError(set *flag.FlagSet) error {
406406
if f.EnvVar != "" {
407407
for _, envVar := range strings.Split(f.EnvVar, ",") {
408408
envVar = strings.TrimSpace(envVar)
@@ -427,11 +427,11 @@ func (f StringFlag) applyWithError(set *flag.FlagSet) error {
427427
// Apply populates the flag given the flag set and environment
428428
// Ignores errors
429429
func (f IntFlag) Apply(set *flag.FlagSet) {
430-
f.applyWithError(set)
430+
f.ApplyWithError(set)
431431
}
432432

433-
// applyWithError populates the flag given the flag set and environment
434-
func (f IntFlag) applyWithError(set *flag.FlagSet) error {
433+
// ApplyWithError populates the flag given the flag set and environment
434+
func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
435435
if f.EnvVar != "" {
436436
for _, envVar := range strings.Split(f.EnvVar, ",") {
437437
envVar = strings.TrimSpace(envVar)
@@ -460,11 +460,11 @@ func (f IntFlag) applyWithError(set *flag.FlagSet) error {
460460
// Apply populates the flag given the flag set and environment
461461
// Ignores errors
462462
func (f Int64Flag) Apply(set *flag.FlagSet) {
463-
f.applyWithError(set)
463+
f.ApplyWithError(set)
464464
}
465465

466-
// applyWithError populates the flag given the flag set and environment
467-
func (f Int64Flag) applyWithError(set *flag.FlagSet) error {
466+
// ApplyWithError populates the flag given the flag set and environment
467+
func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
468468
if f.EnvVar != "" {
469469
for _, envVar := range strings.Split(f.EnvVar, ",") {
470470
envVar = strings.TrimSpace(envVar)
@@ -494,11 +494,11 @@ func (f Int64Flag) applyWithError(set *flag.FlagSet) error {
494494
// Apply populates the flag given the flag set and environment
495495
// Ignores errors
496496
func (f UintFlag) Apply(set *flag.FlagSet) {
497-
f.applyWithError(set)
497+
f.ApplyWithError(set)
498498
}
499499

500-
// applyWithError populates the flag given the flag set and environment
501-
func (f UintFlag) applyWithError(set *flag.FlagSet) error {
500+
// ApplyWithError populates the flag given the flag set and environment
501+
func (f UintFlag) ApplyWithError(set *flag.FlagSet) error {
502502
if f.EnvVar != "" {
503503
for _, envVar := range strings.Split(f.EnvVar, ",") {
504504
envVar = strings.TrimSpace(envVar)
@@ -528,11 +528,11 @@ func (f UintFlag) applyWithError(set *flag.FlagSet) error {
528528
// Apply populates the flag given the flag set and environment
529529
// Ignores errors
530530
func (f Uint64Flag) Apply(set *flag.FlagSet) {
531-
f.applyWithError(set)
531+
f.ApplyWithError(set)
532532
}
533533

534-
// applyWithError populates the flag given the flag set and environment
535-
func (f Uint64Flag) applyWithError(set *flag.FlagSet) error {
534+
// ApplyWithError populates the flag given the flag set and environment
535+
func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error {
536536
if f.EnvVar != "" {
537537
for _, envVar := range strings.Split(f.EnvVar, ",") {
538538
envVar = strings.TrimSpace(envVar)
@@ -562,11 +562,11 @@ func (f Uint64Flag) applyWithError(set *flag.FlagSet) error {
562562
// Apply populates the flag given the flag set and environment
563563
// Ignores errors
564564
func (f DurationFlag) Apply(set *flag.FlagSet) {
565-
f.applyWithError(set)
565+
f.ApplyWithError(set)
566566
}
567567

568-
// applyWithError populates the flag given the flag set and environment
569-
func (f DurationFlag) applyWithError(set *flag.FlagSet) error {
568+
// ApplyWithError populates the flag given the flag set and environment
569+
func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error {
570570
if f.EnvVar != "" {
571571
for _, envVar := range strings.Split(f.EnvVar, ",") {
572572
envVar = strings.TrimSpace(envVar)
@@ -596,11 +596,11 @@ func (f DurationFlag) applyWithError(set *flag.FlagSet) error {
596596
// Apply populates the flag given the flag set and environment
597597
// Ignores errors
598598
func (f Float64Flag) Apply(set *flag.FlagSet) {
599-
f.applyWithError(set)
599+
f.ApplyWithError(set)
600600
}
601601

602-
// applyWithError populates the flag given the flag set and environment
603-
func (f Float64Flag) applyWithError(set *flag.FlagSet) error {
602+
// ApplyWithError populates the flag given the flag set and environment
603+
func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error {
604604
if f.EnvVar != "" {
605605
for _, envVar := range strings.Split(f.EnvVar, ",") {
606606
envVar = strings.TrimSpace(envVar)

0 commit comments

Comments
 (0)