diff options
| author | Fredrik Wallgren <[email protected]> | 2015-11-19 14:34:09 +0100 |
|---|---|---|
| committer | Fredrik Wallgren <[email protected]> | 2015-11-22 00:53:29 +0100 |
| commit | b0d37d1fb2b491a861f788a41aabbe66cbf83110 (patch) | |
| tree | 5e80050160892ac7b264be6797e67be199ab3fea /usage.go | |
| parent | 5db9c77fa32bd444360f8376ddfa7bc209813b20 (diff) | |
Add default values to usage
Check if the value isn't it's zero value and if not add a default value
to the usage text.
Diffstat (limited to 'usage.go')
| -rw-r--r-- | usage.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -76,7 +76,6 @@ func (p *Parser) WriteHelp(w io.Writer) { } } - // write the list of options fmt.Fprint(w, "\noptions:\n") for _, spec := range options { printOption(w, spec) @@ -101,6 +100,13 @@ func printOption(w io.Writer, spec *spec) { } fmt.Fprint(w, spec.help) } + // Check if spec.dest is zero value or not + // If it isn't a default value have been added + v := spec.dest + z := reflect.Zero(v.Type()) + if v.Interface() != z.Interface() { + fmt.Fprintf(w, " [default: %v]", v) + } fmt.Fprint(w, "\n") } |
