diff options
| author | Eric Paris <[email protected]> | 2015-08-15 12:46:47 -0500 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-08-15 12:46:47 -0500 |
| commit | 1ad164813157ed6d752ca39b5ac46eb3ae99093b (patch) | |
| tree | dcec07ee60fccf49e2454705a2ff67c8c7a4d2d1 | |
| parent | 580b9be06c33d8ba9dcc8757ea56b7642472c2f5 (diff) | |
| parent | a5c4bbf178a40a1f2a7ecf410f5496f103ab1a2c (diff) | |
Merge pull request #44 from eparis/optional-flag-display
Display which flags are 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) }) |
