Exit with non-zero code on first argument parsing error

Ignoring return value of ParseFlags leads to exit code 0 if bad
arguments are supplied. This patch makes sure that subcommands exit
with non-zero code in such a case.

Signed-off-by: Michal Minar <miminar@redhat.com>
This commit is contained in:
Michal Minar
2015-01-06 13:46:38 +01:00
parent 08f0f1ee1d
commit 8a785792cd
3 changed files with 85 additions and 142 deletions
+4 -1
View File
@@ -8,7 +8,10 @@ import (
)
// ParseFlags is a utility function that adds a help flag if withHelp is true,
// calls cmd.Parse(args) and prints a relevant error message if there are incorrect number of arguments.
// calls cmd.Parse(args) and prints a relevant error message if there are
// incorrect number of arguments. It returns error only if error handling is
// set to ContinueOnError and parsing fails. If error handling is set to
// ExitOnError, it's safe to ignore the return value.
// TODO: move this to a better package than utils
func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
var help *bool