jdx / usage

A specification for CLIs
https://usage.jdx.dev
MIT License
151 stars 6 forks source link

wrong exit code if script returns non-zero exit code #149

Closed powerman closed 2 weeks ago

powerman commented 3 weeks ago

It looks like Usage returns exit code 0 if it was able to successfully parse args and 1 otherwise. There are two issues here:

  1. It silently convert failed scripts to successful.
  2. It overwrite script exit code 1 with own meaning.

I propose to use some rarely used exit code for arg parsing issues and return script's actual exit code as is (probably makes sense to do the same as other common tools running other tools do - e.g. nice).

$ usage --version
usage-cli 1.0.1
$ cat >fail <<'EOF'
#!/usr/bin/env -S usage bash
#USAGE about "This script fails"
echo Oops                       
exit 1   
EOF
$ chmod +x fail
$ ./fail; echo $?
Oops
0
$ bash ./fail; echo $?
Oops
1
$ usage bash ./fail; echo $?
Oops
0