From 0688fc4f97b96cfabcc8d490ece9c3d380462614 Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Sun, 1 Dec 2024 10:55:03 +0000 Subject: [PATCH] feat(cli)!: stop special-casing `-h` and `-v` I don't think the approach proved itself. It is not clear making `-s -h` display help does more good than harm. --- main.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 356def9..23f5948 100644 --- a/main.go +++ b/main.go @@ -201,24 +201,6 @@ func parseArgs() config { wait: defaultWait, } - // Check for a help or version flag first. -loop: - for _, arg := range os.Args[1:] { - if arg == "--" || !strings.HasPrefix(arg, "-") { - break loop - } - - switch arg { - case "-h", "--help": - help() - os.Exit(0) - - case "-v", "--version": - fmt.Println(version) - os.Exit(0) - } - } - usageError := func(message string, badValue interface{}) { usage(os.Stderr) fmt.Fprintf(os.Stderr, "\nError: "+message+"\n", badValue) @@ -257,6 +239,10 @@ loop: case "-d", "--dump": cfg.dumpPath = nextArg(arg) + case "-h", "--help": + help() + os.Exit(0) + case "-l", "--length": value := nextArg(arg) @@ -302,6 +288,10 @@ loop: case "-t", "--time-format": cfg.timeFormat = nextArg(arg) + case "-v", "--version": + fmt.Println(version) + os.Exit(0) + case "-w", "--wait": value := nextArg(arg)