From 935b2a1bd5710aede269d46752e59fba916abaea Mon Sep 17 00:00:00 2001 From: Fredrik Wallgren Date: Mon, 9 Nov 2015 10:27:15 +0100 Subject: [PATCH] Write usage message to stderr on error When the parsing of parameters/flags fails eg. when a required flag is missing, print the usage statement and error to stderr instead of stdout. --- usage.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usage.go b/usage.go index 4852866..a1ed5a2 100644 --- a/usage.go +++ b/usage.go @@ -9,9 +9,9 @@ import ( "strings" ) -// Fail prints usage information to stdout and exits with non-zero status +// Fail prints usage information to stderr and exits with non-zero status func (p *Parser) Fail(msg string) { - p.WriteUsage(os.Stdout) + p.WriteUsage(os.Stderr) fmt.Println("error:", msg) os.Exit(-1) }