diff options
| author | Eric Paris <[email protected]> | 2015-08-14 20:45:28 -0400 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-08-14 20:49:48 -0400 |
| commit | a5c4bbf178a40a1f2a7ecf410f5496f103ab1a2c (patch) | |
| tree | d7847799298ba89dd58e9281273c2722f46a589a | |
| parent | 4869ec2ae0628354eaac5bf88fccf9a7265ae475 (diff) | |
Annotate optional flags in usageFunc
| -rw-r--r-- | flag.go | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -381,16 +381,25 @@ func (f *FlagSet) FlagUsages() string { if len(flag.Deprecated) > 0 { return } - format := "--%s=%s: %s\n" + format := "" + if len(flag.Shorthand) > 0 { + format = " -%s, --%s" + } else { + format = " %s --%s" + } + if len(flag.NoOptDefVal) > 0 { + format = format + "[" + } if _, ok := flag.Value.(*stringValue); ok { // put quotes on the value - format = "--%s=%q: %s\n" - } - if len(flag.Shorthand) > 0 { - format = " -%s, " + format + format = format + "=%q" } else { - format = " %s " + format + format = format + "=%s" } + if len(flag.NoOptDefVal) > 0 { + format = format + "]" + } + format = format + ": %s\n" fmt.Fprintf(x, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage) }) |
