Skip to content
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

Incorrect PrintHelpMessage return code #187

Closed
pgreze opened this issue May 30, 2020 · 3 comments · Fixed by #188
Closed

Incorrect PrintHelpMessage return code #187

pgreze opened this issue May 30, 2020 · 3 comments · Fixed by #188

Comments

@pgreze
Copy link

pgreze commented May 30, 2020

Facing a similar issue than #41 I tried to display the help message + return an error code, as it's specified in PrintHelpMessage javadoc:

* Execution should be immediately halted with an error.

Sadly the current behavior is returning the return code 0:

Considering help message is the expected output when using -h or --help which is already implemented by clikt, user usage of PrintHelpMessage would probably always means that help message is the consequence of an error.
If you agree with previous sentence, I would encourage enforcing javadoc behavior by fixing the code but still provide a way to show help message without failing (like Abort logic?).

In any case, thanks for your this nice project, always useful when trying to create Kotlin CLI 👍

@ajalt
Copy link
Owner

ajalt commented May 30, 2020

$ for i in git man ls cat bash grep awk cloc rg; do $i --help >/dev/null; echo $i : $?; done
git : 0
man : 0
ls : 0
cat : 0
bash : 0
grep : 0
awk : 0
cloc : 0
rg : 0

Every command line tool I looked at exits with status code 0 when they print their help message, so I think the current behavior is correct, and this is a bug in the documentation.

@ajalt ajalt closed this as completed in 34ff1e8 May 30, 2020
@pgreze
Copy link
Author

pgreze commented Jun 1, 2020

@ajalt I agree, but you always tried with "--help", which of course should return 0.

But if you're trying:

$ git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
...
$ echo $?
1

Even if output is similar to --help, this is still an error. That's what I was talking about, and that's why it's not obvious for me that show usage output should always finish without error.

@ajalt
Copy link
Owner

ajalt commented Jun 1, 2020

I see. That's different than the --help case mentioned in the initial issue. I agree it makes sense to use an error code when the printHelpOnEmptyArgs or invokeWithoutSubcommand cases are triggered.

I'll add an error : Boolean parameter to PrintHelpMessage and PrintMessage and use it for those cases. The --help case will continue to exit with 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants