-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default to exit code 2 on help message #47
Conversation
When a command fails because it's mis-used and shows the help message instead of executing normally, it should *never* fail with exit code 0 as that will improperly foul things up if the command is executed in an automated way (i.e. a script or `make`). The convention is code 2, which means "misuse".
@@ -58,7 +58,7 @@ module.exports = (opts, minimistOpts) => { | |||
|
|||
const showHelp = code => { | |||
console.log(help); | |||
process.exit(code || 0); | |||
process.exit(code || 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you need to change it to process.exit(typeof code === 'number' ? code : 2);
Otherwise if the user tries to use 0
it will go to 2
, which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Qix- ⬆️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
You need to update the docs too. |
Hmm, we don't really know what the user is going to use the method for though. |
I would imagine that's an edge case. If anything we could add a third argument for an output stream to write to and have it default to |
@Qix- No, I meant that the user might use With your change here, it also exits with 2 when running |
Right; 2 doesn't always mean misuse but it's used as a human indicator. With |
@Qix- What is "success" though? I would consider showing the help when I asked for it with |
Success means the main functionality of the utility has executed without error*. The main functionality in almost all cases isn't displaying a help message. Put it this way: my-program: main.o
gcc -o $@ $<
main.o: main.c
gcc -v -o $@ -c $< Ignore the fact that GCC doesn't error on version, but this is something I've seen quite a few times. Not only is that flow incorrect (the latter call was not well-formed and thus the linking step shouldn't execute at all) but it makes future error messages quite cryptic. Plus, if this was a huge tree there's the potential for a lot of re-compilation after fixing the error (albeit a bit rarer). All of this can be applied to *Also consider the fact a lot of this is semantics of the concept of "success" and thus is slightly subjective. 💃 |
It seems like the problem here is using short flags, not just misuse. If you would instead use long flags, which are more readable, you wouldn't have this problem. I tried out a lot of different binaries on my Mac and very few exits with other than 0 on I agree it should exit with 2 on |
When a command fails because it's misused and shows the help message instead of executing normally, it should never fail with exit code 0 as that will improperly foul things up if the command is executed in an automated way (i.e. a script or
make
).The convention is code 2, which means "misuse".