reduce diff???
This commit is contained in:
parent
138dbaafec
commit
ce1630141e
111
flag.go
111
flag.go
@ -115,22 +115,6 @@ type Generic interface {
|
|||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericFlag is the flag type for types implementing Generic
|
|
||||||
type GenericFlag struct {
|
|
||||||
Name string
|
|
||||||
Value Generic
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns the string representation of the generic flag to display the
|
|
||||||
// help text to the user (uses the String() method of the generic flag to show
|
|
||||||
// the value)
|
|
||||||
func (f GenericFlag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s%s \"%v\"\t%v", prefixFor(f.Name), f.Name, f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply takes the flagset and calls Set on the generic flag with the value
|
// Apply takes the flagset and calls Set on the generic flag with the value
|
||||||
// provided by the user for parsing by the flag
|
// provided by the user for parsing by the flag
|
||||||
// Ignores parsing errors
|
// Ignores parsing errors
|
||||||
@ -178,20 +162,6 @@ func (f *StringSlice) Value() []string {
|
|||||||
return *f
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringSliceFlag struct {
|
|
||||||
Name string
|
|
||||||
Value *StringSlice
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f StringSliceFlag) String() string {
|
|
||||||
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
||||||
pref := prefixFor(firstName)
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get returns the slice of strings set by this flag
|
// Get returns the slice of strings set by this flag
|
||||||
func (f *StringSlice) Get() interface{} {
|
func (f *StringSlice) Get() interface{} {
|
||||||
return *f
|
return *f
|
||||||
@ -257,20 +227,6 @@ func (f *IntSlice) Value() []int {
|
|||||||
return *f
|
return *f
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntSliceFlag struct {
|
|
||||||
Name string
|
|
||||||
Value *IntSlice
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f IntSliceFlag) String() string {
|
|
||||||
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
||||||
pref := prefixFor(firstName)
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get returns the slice of ints set by this flag
|
// Get returns the slice of ints set by this flag
|
||||||
func (f *IntSlice) Get() interface{} {
|
func (f *IntSlice) Get() interface{} {
|
||||||
return *f
|
return *f
|
||||||
@ -331,17 +287,6 @@ func (f IntSliceFlag) IsRequired() bool {
|
|||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoolFlag struct {
|
|
||||||
Name string
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f BoolFlag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value returns the slice of ints set by this flag
|
// Value returns the slice of ints set by this flag
|
||||||
func (f *Int64Slice) Value() []int64 {
|
func (f *Int64Slice) Value() []int64 {
|
||||||
return *f
|
return *f
|
||||||
@ -394,17 +339,6 @@ func (f BoolFlag) IsRequired() bool {
|
|||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoolTFlag struct {
|
|
||||||
Name string
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f BoolTFlag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
|
func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
val := false
|
val := false
|
||||||
@ -468,14 +402,6 @@ func (f BoolTFlag) IsRequired() bool {
|
|||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringFlag struct {
|
|
||||||
Name string
|
|
||||||
Value string
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f StringFlag) Apply(set *flag.FlagSet) {
|
func (f StringFlag) Apply(set *flag.FlagSet) {
|
||||||
@ -536,18 +462,6 @@ func (f StringFlag) IsRequired() bool {
|
|||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntFlag struct {
|
|
||||||
Name string
|
|
||||||
Value int
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f IntFlag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
|
func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok {
|
if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok {
|
||||||
@ -602,18 +516,6 @@ func (f IntFlag) IsRequired() bool {
|
|||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type DurationFlag struct {
|
|
||||||
Name string
|
|
||||||
Value time.Duration
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f DurationFlag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Uint64Flag) Apply(set *flag.FlagSet) {
|
func (f Uint64Flag) Apply(set *flag.FlagSet) {
|
||||||
@ -667,24 +569,13 @@ func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
set.Duration(name, f.Value, f.Usage)
|
set.Duration(name, f.Value, f.Usage)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f DurationFlag) IsRequired() bool {
|
func (f DurationFlag) IsRequired() bool {
|
||||||
return f.Required
|
return f.Required
|
||||||
}
|
}
|
||||||
|
|
||||||
type Float64Flag struct {
|
|
||||||
Name string
|
|
||||||
Value float64
|
|
||||||
Usage string
|
|
||||||
EnvVar string
|
|
||||||
Required bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Float64Flag) String() string {
|
|
||||||
return withHints(f.EnvVar, f.Required, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
||||||
|
Loading…
Reference in New Issue
Block a user