summaryrefslogtreecommitdiff
path: root/usage.go
diff options
context:
space:
mode:
authorFredrik Wallgren <[email protected]>2015-11-19 14:34:09 +0100
committerFredrik Wallgren <[email protected]>2015-11-22 00:53:29 +0100
commitb0d37d1fb2b491a861f788a41aabbe66cbf83110 (patch)
tree5e80050160892ac7b264be6797e67be199ab3fea /usage.go
parent5db9c77fa32bd444360f8376ddfa7bc209813b20 (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.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/usage.go b/usage.go
index 9404015..64ed901 100644
--- a/usage.go
+++ b/usage.go
@@ -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")
}