Skip to content

Commit c12711c

Browse files
committed
unify and simplify
1 parent a70fcdc commit c12711c

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

docs.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ func (tt tabularTemplate) PrepareFlags(flags []cli.Flag) []cliTabularFlagTemplat
411411
} else if value != "" {
412412
defaultValue = fmt.Sprintf("`%s`", value)
413413
}
414-
if boolFlag, isBool := appFlag.(*cli.BoolFlag); isBool && defaultText == "" {
415-
defaultValue = fmt.Sprintf("`%s`", strconv.FormatBool(boolFlag.Value))
416-
}
417414

418415
f := cliTabularFlagTemplate{
419416
Usage: tt.PrepareMultilineString(flag.GetUsage()),
@@ -577,35 +574,18 @@ func getFlagDefaultValue(f cli.DocGenerationFlag) (value, text string) {
577574
return "", ""
578575
}
579576

580-
if _, ok := f.(interface{ GetDefaultText() string }); ok {
581-
// GetDefaultText also returns GetValue so we have to use reflection
582-
if ref := reflect.ValueOf(f); ref.Kind() == reflect.Ptr && ref.Elem().Kind() == reflect.Struct {
583-
if val := ref.Elem().FieldByName("DefaultText"); val.IsValid() && val.Type().Kind() == reflect.String {
584-
if defaultText := val.Interface().(string); defaultText != "" {
585-
return "", defaultText
586-
}
577+
// GetDefaultText also returns GetValue so we have to use reflection
578+
if ref := reflect.ValueOf(f); ref.Kind() == reflect.Ptr && ref.Elem().Kind() == reflect.Struct {
579+
if val := ref.Elem().FieldByName("DefaultText"); val.IsValid() && val.Type().Kind() == reflect.String {
580+
if defaultText := val.Interface().(string); defaultText != "" {
581+
return "", defaultText
587582
}
588583
}
589584
}
590585

591-
if v, ok := f.(interface{ GetValue() string }); ok {
592-
return v.GetValue(), ""
593-
}
594-
595-
ref := reflect.ValueOf(f)
596-
if ref.Kind() != reflect.Ptr {
597-
return "", ""
598-
} else {
599-
ref = ref.Elem()
600-
}
601-
602-
if ref.Kind() != reflect.Struct {
603-
return "", ""
604-
}
605-
606-
if val := ref.FieldByName("Value"); val.IsValid() && val.Type().Kind() != reflect.Bool {
607-
return fmt.Sprintf("%v", val.Interface()), ""
586+
if boolFlag, isBool := f.(*cli.BoolFlag); isBool {
587+
return strconv.FormatBool(boolFlag.Value), ""
608588
}
609589

610-
return "", ""
590+
return f.GetValue(), ""
611591
}

0 commit comments

Comments
 (0)