summaryrefslogtreecommitdiff
path: root/usage.go
diff options
context:
space:
mode:
Diffstat (limited to 'usage.go')
-rw-r--r--usage.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/usage.go b/usage.go
index 0c68ee7..f5e4b38 100644
--- a/usage.go
+++ b/usage.go
@@ -9,13 +9,13 @@ import (
// the width of the left column
const colWidth = 25
-// Fail prints usage information to stderr and exits with non-zero status
+// Fail prints usage information to p.Config.Out and exits with status code 2.
func (p *Parser) Fail(msg string) {
p.FailSubcommand(msg)
}
-// FailSubcommand prints usage information for a specified subcommand to stderr,
-// then exits with non-zero status. To write usage information for a top-level
+// FailSubcommand prints usage information for a specified subcommand to p.Config.Out,
+// then exits with status code 2. To write usage information for a top-level
// subcommand, provide just the name of that subcommand. To write usage
// information for a subcommand that is nested under another subcommand, provide
// a sequence of subcommand names starting with the top-level subcommand and so
@@ -27,7 +27,7 @@ func (p *Parser) FailSubcommand(msg string, subcommand ...string) error {
}
fmt.Fprintln(p.config.Out, "error:", msg)
- p.config.Exit(-1)
+ p.config.Exit(2)
return nil
}
@@ -328,7 +328,10 @@ func (p *Parser) printEnvOnlyVar(w io.Writer, spec *spec) {
}
func synopsis(spec *spec, form string) string {
- if spec.cardinality == zero {
+ // if the user omits the placeholder tag then we pick one automatically,
+ // but if the user explicitly specifies an empty placeholder then we
+ // leave out the placeholder in the help message
+ if spec.cardinality == zero || spec.placeholder == "" {
return form
}
return form + " " + spec.placeholder