-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Show help if no command was executed #7
Comments
sometimes you want to accept stdin etc by default, but I'd like some kind of nice option for sure. the best would be probably just to add
or similar |
true about stdin so it would be better off as an option, but aside from that, I think my code also allows for the fact that if people type in spurious commands. BTW, I think your code meant Chris |
yeah sorry I was thinking of |
ahh ok that makes more sense - thx |
This can be closed:
|
In case this helps anyone else out, here's an example of how to do this (with // ...
// Do all the normal things
// ...
// After parsing your commander program....
program.parse(process.argv);
// Check the program.args obj
var NO_COMMAND_SPECIFIED = program.args.length === 0;
// Handle it however you like
if (NO_COMMAND_SPECIFIED) {
// e.g. display usage
program.help();
} |
@mikermcneil thank you! |
Might be worth adding some docs to the README, as it took me a while to figure this out. Would a docs patch PR be accepted? You cannot use Anyway, to get this working, I had to use;
This allows me to do;
|
Docs PR would be fantastic - pull away! |
PR sent, sorry for the delay |
What if I want the argument missing messages and not the help? |
I should leave an example. Given this code: program
.version('1.0.0')
.arguments('<abc> <def> <ghi>')
.parse(process.argv) my experience is:
I was expecting:
Happy to make a pull request if this is anyone else's expected behavior. It could also be activated by a flag. |
+1 for this |
For posterity wondering specifically about the case where a wrong command is given, such as a case where a user gives a bunch of arguments but forgets the command itself, this still isn't handled in the latest commander and the user will get blank unhelpful output. However, the command docs provide a very easy to handle the case explicitly yourself:
|
here is what i have written
|
It is really annoying that there is not flag to automatically display help after parse errors when it crashes. If it will not be added I will just switch to another CLI lib in my next project |
Open a new issue with more details if you want visibility on this @antonkulaga There have been lots of improvements to the error messages and help since this issue was opened and closed in 2011. |
I know this is closed but if anyone finds themselves back here then the best solution is:
|
FYI as recent commenters @jcbdev @antonkulaga : PR opened #1534 |
Related: |
Hi
I wanted my utility to show help if no command was executed.
This was how I monkey patched my code to solve it.
Is this an acceptable solution, or is there something I'm missing in the API?
Chris
The text was updated successfully, but these errors were encountered: