alexflint / go-arg

Struct-based argument parsing in Go
https://pkg.go.dev/github.com/alexflint/go-arg
BSD 2-Clause "Simplified" License
2.04k stars 100 forks source link

Use standard exit status code for usage errors #256

Closed hhromic closed 4 months ago

hhromic commented 4 months ago

The stdlib flag package (specifically ExitOnError) and most command line utilities use status code 2. I tried to find proper sources for common exit status codes, however these are the best I could find:

From: https://stackoverflow.com/a/40484670

Exit status 0: success Exit status 1: "failure", as defined by the program Exit status 2: command line usage error

From: https://tldp.org/LDP/abs/html/exitcodes.html:

2 | Misuse of shell builtins (according to Bash documentation)

More importantly, currently using -1 (which translates to 255) is actually documented as a bad choice in os.Exit:

For portability, the status code should be in the range [0, 125].

Fixes #246