The Unix tradition, fading away like all the other Unix traditions, is that
exit code 0 is for success, 1 is for failed execution, and 2 is for
reporting that the usage was incorrect, preventing it from running.
Although one could make the case that "-help" did what it was supposed to
do, tradition says the command didn't run because of the arguments, so the
exit code should be 2.

"grep --help" doesn't grep anything because of what the arguments said. I
just tried this with BSD grep and got exit code 2. For some reason, grep
still obeys the Unix tradition. Someone will fix that soon, no doubt, but
for now let's be consistent.

-rob


On Thu, Jul 20, 2017 at 5:45 AM, Rick <thesuggestednamesareaw...@gmail.com>
wrote:

> It's reasonable to consider calling a command with a flag that is not
> defined an error (whether that flag is -help or -verbose or -whatever). It
> is common to return non 0 on error.
>
>
> On Wednesday, 19 July 2017 11:31:42 UTC-7, Philippe Modard wrote:
>>
>> Hey go-nuts,
>>
>> I realize than running `mybinary --help` returns a nice help message
>> along with a exit status 2.
>> What is the reason it doesn't return 0?
>>
>> I fixed it by manually adding a help flag:
>> ```
>> var help = flag.Bool("help", false, "Print the help message")
>> [...]
>> if *help {
>> flag.PrintDefaults()
>> return
>> }
>> ```
>>
>> But I'm still confused why the default behavior is returning an error
>> along with the right message.
>>
>> Cheers,
>> Philmod
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to