diff --git a/main.go b/main.go index 7a51f222..d09fb7af 100644 --- a/main.go +++ b/main.go @@ -86,7 +86,6 @@ func main() { // of the arguments for the subcommand. func ParseArgs() (string, []string) { // Print usage if no arguments are provided. - // Terminate with non-zero exit status. if len(os.Args) < 2 { _ = Help("help") os.Exit(1) @@ -96,7 +95,7 @@ func ParseArgs() (string, []string) { case "version", "-v", "-version", "--version": if len(os.Args) != 2 { _ = Help("version") - os.Exit(1) + os.Exit(0) } return "version", os.Args @@ -119,11 +118,12 @@ func ParseArgs() (string, []string) { } else { subcommand = "help" } - - if Help(subcommand) == nil { - os.Exit(0) + // If the subcommand is not recognized, we exit with status 1 + err := Help(subcommand) + if err != nil { + os.Exit(1) } - os.Exit(1) + os.Exit(0) } @@ -162,10 +162,14 @@ func Help(command string) error { fmt.Fprint(os.Stderr, subcommandUsage) } fmt.Fprintf(os.Stderr, - "Use '%s help ' to get help with subcommand flags.\n", + "use '%s help ' to get help with subcommand flags.\n", os.Args[0]) - return fmt.Errorf("Unknown command: %s", command) + if command == "help" { + return nil + } + + return fmt.Errorf("unknown command: %s", command) } // print subcommand help