manually add FlagsErrRequired field and function to generated flags

This commit is contained in:
Aaron Berns 2019-08-20 08:56:35 -04:00
parent 95f45c1e60
commit a064d9082c
2 changed files with 190 additions and 113 deletions

View File

@ -88,7 +88,7 @@ type RequiredFlag interface {
type RequiredFlagsErr interface { type RequiredFlagsErr interface {
Flag Flag
IsRequired() bool FlagsErrRequired() bool
} }
// DocGenerationFlag is an interface that allows documentation generation for the flag // DocGenerationFlag is an interface that allows documentation generation for the flag

View File

@ -11,14 +11,15 @@ import (
// BoolFlag is a flag with type bool // BoolFlag is a flag with type bool
type BoolFlag struct { type BoolFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Destination *bool TakesFile bool
Destination *bool
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -37,6 +38,11 @@ func (f BoolFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f BoolFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f BoolFlag) TakesValue() bool { func (f BoolFlag) TakesValue() bool {
return false return false
@ -82,14 +88,15 @@ func lookupBool(name string, set *flag.FlagSet) bool {
// BoolTFlag is a flag with type bool that is true by default // BoolTFlag is a flag with type bool that is true by default
type BoolTFlag struct { type BoolTFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Destination *bool TakesFile bool
Destination *bool
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -108,6 +115,11 @@ func (f BoolTFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f BoolTFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f BoolTFlag) TakesValue() bool { func (f BoolTFlag) TakesValue() bool {
return false return false
@ -153,15 +165,16 @@ func lookupBoolT(name string, set *flag.FlagSet) bool {
// DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration)
type DurationFlag struct { type DurationFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value time.Duration TakesFile bool
Destination *time.Duration Value time.Duration
Destination *time.Duration
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -180,6 +193,11 @@ func (f DurationFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f DurationFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f DurationFlag) TakesValue() bool { func (f DurationFlag) TakesValue() bool {
return true return true
@ -225,15 +243,16 @@ func lookupDuration(name string, set *flag.FlagSet) time.Duration {
// Float64Flag is a flag with type float64 // Float64Flag is a flag with type float64
type Float64Flag struct { type Float64Flag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value float64 TakesFile bool
Destination *float64 Value float64
Destination *float64
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -252,6 +271,11 @@ func (f Float64Flag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f Float64Flag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f Float64Flag) TakesValue() bool { func (f Float64Flag) TakesValue() bool {
return true return true
@ -297,14 +321,15 @@ func lookupFloat64(name string, set *flag.FlagSet) float64 {
// GenericFlag is a flag with type Generic // GenericFlag is a flag with type Generic
type GenericFlag struct { type GenericFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value Generic TakesFile bool
Value Generic
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -323,6 +348,11 @@ func (f GenericFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f GenericFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f GenericFlag) TakesValue() bool { func (f GenericFlag) TakesValue() bool {
return true return true
@ -371,15 +401,16 @@ func lookupGeneric(name string, set *flag.FlagSet) interface{} {
// Int64Flag is a flag with type int64 // Int64Flag is a flag with type int64
type Int64Flag struct { type Int64Flag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value int64 TakesFile bool
Destination *int64 Value int64
Destination *int64
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -398,6 +429,11 @@ func (f Int64Flag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f Int64Flag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f Int64Flag) TakesValue() bool { func (f Int64Flag) TakesValue() bool {
return true return true
@ -443,15 +479,16 @@ func lookupInt64(name string, set *flag.FlagSet) int64 {
// IntFlag is a flag with type int // IntFlag is a flag with type int
type IntFlag struct { type IntFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value int TakesFile bool
Destination *int Value int
Destination *int
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -470,6 +507,11 @@ func (f IntFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f IntFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f IntFlag) TakesValue() bool { func (f IntFlag) TakesValue() bool {
return true return true
@ -515,14 +557,15 @@ func lookupInt(name string, set *flag.FlagSet) int {
// IntSliceFlag is a flag with type *IntSlice // IntSliceFlag is a flag with type *IntSlice
type IntSliceFlag struct { type IntSliceFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value *IntSlice TakesFile bool
Value *IntSlice
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -541,6 +584,11 @@ func (f IntSliceFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f IntSliceFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f IntSliceFlag) TakesValue() bool { func (f IntSliceFlag) TakesValue() bool {
return true return true
@ -589,14 +637,15 @@ func lookupIntSlice(name string, set *flag.FlagSet) []int {
// Int64SliceFlag is a flag with type *Int64Slice // Int64SliceFlag is a flag with type *Int64Slice
type Int64SliceFlag struct { type Int64SliceFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value *Int64Slice TakesFile bool
Value *Int64Slice
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -615,6 +664,11 @@ func (f Int64SliceFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f Int64SliceFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f Int64SliceFlag) TakesValue() bool { func (f Int64SliceFlag) TakesValue() bool {
return true return true
@ -663,15 +717,16 @@ func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
// StringFlag is a flag with type string // StringFlag is a flag with type string
type StringFlag struct { type StringFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value string TakesFile bool
Destination *string Value string
Destination *string
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -690,6 +745,11 @@ func (f StringFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f StringFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f StringFlag) TakesValue() bool { func (f StringFlag) TakesValue() bool {
return true return true
@ -735,14 +795,15 @@ func lookupString(name string, set *flag.FlagSet) string {
// StringSliceFlag is a flag with type *StringSlice // StringSliceFlag is a flag with type *StringSlice
type StringSliceFlag struct { type StringSliceFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value *StringSlice TakesFile bool
Value *StringSlice
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -761,6 +822,11 @@ func (f StringSliceFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f StringSliceFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f StringSliceFlag) TakesValue() bool { func (f StringSliceFlag) TakesValue() bool {
return true return true
@ -809,15 +875,16 @@ func lookupStringSlice(name string, set *flag.FlagSet) []string {
// Uint64Flag is a flag with type uint64 // Uint64Flag is a flag with type uint64
type Uint64Flag struct { type Uint64Flag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value uint64 TakesFile bool
Destination *uint64 Value uint64
Destination *uint64
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -836,6 +903,11 @@ func (f Uint64Flag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f Uint64Flag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f Uint64Flag) TakesValue() bool { func (f Uint64Flag) TakesValue() bool {
return true return true
@ -881,15 +953,16 @@ func lookupUint64(name string, set *flag.FlagSet) uint64 {
// UintFlag is a flag with type uint // UintFlag is a flag with type uint
type UintFlag struct { type UintFlag struct {
Name string Name string
Usage string Usage string
EnvVar string EnvVar string
FilePath string FilePath string
Required bool Required bool
Hidden bool RequiredFlagsErr bool
TakesFile bool Hidden bool
Value uint TakesFile bool
Destination *uint Value uint
Destination *uint
} }
// String returns a readable representation of this value // String returns a readable representation of this value
@ -908,6 +981,11 @@ func (f UintFlag) IsRequired() bool {
return f.Required return f.Required
} }
// FlagsErrRequired returns whether or not the flag is required
func (f UintFlag) FlagsErrRequired() bool {
return f.RequiredFlagsErr
}
// TakesValue returns true of the flag takes a value, otherwise false // TakesValue returns true of the flag takes a value, otherwise false
func (f UintFlag) TakesValue() bool { func (f UintFlag) TakesValue() bool {
return true return true
@ -950,4 +1028,3 @@ func lookupUint(name string, set *flag.FlagSet) uint {
} }
return 0 return 0
} }