cli: simplify option model per pike review
- appendList: one home for the List newline-join rule (was duplicated across accumulate and set) - fold the redundant Int64 getter into Int; drop the truthy helper for the shared boolWord vocabulary - add Opt.Metavar so help derives the value placeholder from data instead of branching on the option name (seed-time) No behavior change; --help output is byte-identical.
This commit is contained in:
43
cli/help.go
43
cli/help.go
@@ -89,24 +89,31 @@ func flagLabel(o *Opt) string {
|
||||
b.WriteString(" ")
|
||||
}
|
||||
b.WriteString("--" + o.Long)
|
||||
switch o.Kind {
|
||||
case Bool:
|
||||
// no argument shown
|
||||
case Size:
|
||||
b.WriteString("=SIZE")
|
||||
case Int:
|
||||
b.WriteString("=N")
|
||||
case Float:
|
||||
// seed-time is a count of minutes; only seed-ratio is an actual ratio.
|
||||
if o.Long == "seed-time" {
|
||||
b.WriteString("=MIN")
|
||||
} else {
|
||||
b.WriteString("=RATIO")
|
||||
}
|
||||
case Enum:
|
||||
b.WriteString("=" + strings.Join(o.Enum, "|"))
|
||||
default:
|
||||
b.WriteString("=VAL")
|
||||
if m := metavar(o); m != "" {
|
||||
b.WriteString("=" + m)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// metavar is the placeholder shown after a value-taking flag, e.g. the "N" in
|
||||
// "--split=N". An explicit Opt.Metavar wins; otherwise it derives from the Kind.
|
||||
// Bool takes no value, so its metavar is empty and no "=ARG" is printed.
|
||||
func metavar(o *Opt) string {
|
||||
if o.Metavar != "" {
|
||||
return o.Metavar
|
||||
}
|
||||
switch o.Kind {
|
||||
case Bool:
|
||||
return ""
|
||||
case Size:
|
||||
return "SIZE"
|
||||
case Int:
|
||||
return "N"
|
||||
case Float:
|
||||
return "RATIO"
|
||||
case Enum:
|
||||
return strings.Join(o.Enum, "|")
|
||||
default:
|
||||
return "VAL"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user