Skip to content

Commit e330487

Browse files
committed
Use reflections for GetDefaultText
1 parent b2ca258 commit e330487

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

docs.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,21 +578,19 @@ func getFlagDefaultValue(f cli.DocGenerationFlag) (value, text string) {
578578
return "", ""
579579
}
580580

581-
var defaultText string
582-
if v, ok := f.(interface{ GetDefaultText() string }); ok {
583-
defaultText = v.GetDefaultText()
581+
if _, ok := f.(interface{ GetDefaultText() string }); ok {
582+
// GetDefaultText also returns GetValue so we have to use reflection
583+
if ref := reflect.ValueOf(f); ref.Kind() == reflect.Ptr && ref.Elem().Kind() == reflect.Struct {
584+
if val := ref.Elem().FieldByName("DefaultText"); val.IsValid() && val.Type().Kind() == reflect.String {
585+
if defaultText := val.Interface().(string); defaultText != "" {
586+
return "", defaultText
587+
}
588+
}
589+
}
584590
}
585591

586592
if v, ok := f.(interface{ GetValue() string }); ok {
587-
value = v.GetValue()
588-
589-
// GetDefaultText also returns GetValue if default text not set
590-
// but quotes it
591-
if strings.Trim(defaultText, "\"") == value {
592-
return value, ""
593-
} else if defaultText != "" {
594-
return "", defaultText
595-
}
593+
return v.GetValue(), ""
596594
}
597595

598596
var ref = reflect.ValueOf(f)

0 commit comments

Comments
 (0)