Skip to content

Commit

Permalink
feat(cli)!: stop special-casing -h and -v
Browse files Browse the repository at this point in the history
I don't think the approach proved itself.
It is not clear making `-s -h` display help does more good than harm.
  • Loading branch information
dbohdan committed Dec 1, 2024
1 parent 9dc5601 commit 0688fc4
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0688fc4

Please sign in to comment.