Backporting flagValue func from v2 branch

This commit is contained in:
Dan Buch 2016-06-08 10:34:44 -04:00
parent 86e4f9526d
commit 7cd5bed6cb
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

12
flag.go
View File

@ -512,7 +512,7 @@ func (f Float64Flag) GetName() string {
func visibleFlags(fl []Flag) []Flag {
visible := []Flag{}
for _, flag := range fl {
if !reflect.Indirect(reflect.ValueOf(flag)).FieldByName("Hidden").Bool() {
if !flagValue(flag).FieldByName("Hidden").Bool() {
visible = append(visible, flag)
}
}
@ -578,8 +578,16 @@ func withEnvHint(envVar, str string) string {
return str + envText
}
func stringifyFlag(f Flag) string {
func flagValue(f Flag) reflect.Value {
fv := reflect.ValueOf(f)
for fv.Kind() == reflect.Ptr {
fv = reflect.Indirect(fv)
}
return fv
}
func stringifyFlag(f Flag) string {
fv := flagValue(f)
switch f.(type) {
case IntSliceFlag: