Merge branch 'master' into refactor-tests-drop-buffer-writer

This commit is contained in:
lynn [they] 2019-12-29 16:55:36 -08:00 committed by GitHub
commit 9b991ba730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 16 additions and 30 deletions

16
flag.go
View File

@ -203,12 +203,9 @@ func withEnvHint(envVars []string, str string) string {
return str + envText return str + envText
} }
func flagNames(f Flag) []string { func flagNames(name string, aliases []string) []string {
var ret []string var ret []string
name := flagStringField(f, "Name")
aliases := flagStringSliceField(f, "Aliases")
for _, part := range append([]string{name}, aliases...) { for _, part := range append([]string{name}, aliases...) {
// v1 -> v2 migration warning zone: // v1 -> v2 migration warning zone:
// Strip off anything after the first found comma or space, which // Strip off anything after the first found comma or space, which
@ -231,17 +228,6 @@ func flagStringSliceField(f Flag, name string) []string {
return []string{} return []string{}
} }
func flagStringField(f Flag, name string) string {
fv := flagValue(f)
field := fv.FieldByName(name)
if field.IsValid() {
return field.String()
}
return ""
}
func withFileHint(filePath, str string) string { func withFileHint(filePath, str string) string {
fileText := "" fileText := ""
if filePath != "" { if filePath != "" {

View File

@ -34,7 +34,7 @@ func (f *BoolFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *BoolFlag) Names() []string { func (f *BoolFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *DurationFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *DurationFlag) Names() []string { func (f *DurationFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *Float64Flag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *Float64Flag) Names() []string { func (f *Float64Flag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -90,7 +90,7 @@ func (f *Float64SliceFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *Float64SliceFlag) Names() []string { func (f *Float64SliceFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -39,7 +39,7 @@ func (f *GenericFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *GenericFlag) Names() []string { func (f *GenericFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *IntFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *IntFlag) Names() []string { func (f *IntFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *Int64Flag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *Int64Flag) Names() []string { func (f *Int64Flag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -91,7 +91,7 @@ func (f *Int64SliceFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *Int64SliceFlag) Names() []string { func (f *Int64SliceFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -102,7 +102,7 @@ func (f *IntSliceFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *IntSliceFlag) Names() []string { func (f *IntSliceFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -30,7 +30,7 @@ func (f *PathFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *PathFlag) Names() []string { func (f *PathFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -31,7 +31,7 @@ func (f *StringFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *StringFlag) Names() []string { func (f *StringFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -86,7 +86,7 @@ func (f *StringSliceFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *StringSliceFlag) Names() []string { func (f *StringSliceFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -86,7 +86,7 @@ func (f *TimestampFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *TimestampFlag) Names() []string { func (f *TimestampFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *UintFlag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *UintFlag) Names() []string { func (f *UintFlag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required

View File

@ -34,7 +34,7 @@ func (f *Uint64Flag) String() string {
// Names returns the names of the flag // Names returns the names of the flag
func (f *Uint64Flag) Names() []string { func (f *Uint64Flag) Names() []string {
return flagNames(f) return flagNames(f.Name, f.Aliases)
} }
// IsRequired returns whether or not the flag is required // IsRequired returns whether or not the flag is required