Print help message if no parameters present
See original GitHub issueIt would be nice if there would be an option that prints the help message, if no parameters are present.
At least I did not find any easy way to check for no parameters?
My request is similar to the sub commands behavior (if non given the help message is printed), but I also want it if no parameter is provided for a sub command, like
"./tool subcommand" -> should print help message
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Bash printing a help message when no arguments are found ...
When no arguments are there and i am using echo it properly displays the help message like it should. What i am TASKED...
Read more >bash - How to check if there are no parameters provided to a ...
To check if there were no arguments provided to the command, check value of $# variable then, if [ $# -eq 0 ];...
Read more >Print Usage and Exit if Arguments are Not Provided - ShellHacks
Print Usage and Exit if Arguments are Not Provided · 1. verify the number of input values · 2. display an error message...
Read more >CS 11: How to write usage statements
To force a program to print its usage message, all you need to do is to type in the program name with no...
Read more >API — Click Documentation (8.1.x)
Add a --help option which immediately prints the help page and exits the ... The current item can be None , such as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the detailed description. I can see that feature being useful. For now, as a workaround, you can check if all of your options are empty, and
throw PrintHelpMessage(this)
yourself in your command’srun
method.CliktCommand.main
will catch that and display the help for your subcommand for you.Sorry if I’m not precise enough. With option/flag I meant a constructor argument, similar to
invokeWithoutSubcommand = false
, for exampleprintHelpOnEmptyArguments = false
.My use-case is that the program needs some input to run successfully and if no input is provided the help message is shown. One example would be
java
itself (it prints the help message if no argument is present).The same is true for subcommands.
My specific use-case: I wrote a CLI to compute scores for Android unlock patterns (and their features) and a user can provide patterns directly and/or in files, some examples:
apc --pattern 1.2.3.4
apc --file /path/to/file1
apc --pattern 1.2.3.4 --file /path/to/file1 --pattern 4.0.8.1.7.2 --file /path/to/file2
Thus I can mark neither
--pattern
nor--file
as required.Now there are certainly more complex scenarios, but since such functionality is—from what I experienced—quite common, my suggestion was to add such an option. However I also can understand if you don’t want to add such functionality.