question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Print help message if no parameters present

See original GitHub issue

It 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ajaltcommented, Jan 10, 2019

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’s run method.

CliktCommand.main will catch that and display the help for your subcommand for you.

0reactions
PinkieSwirlcommented, Jan 9, 2019

Sorry if I’m not precise enough. With option/flag I meant a constructor argument, similar to invokeWithoutSubcommand = false, for example printHelpOnEmptyArguments = 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found