-
Notifications
You must be signed in to change notification settings - Fork 1k
Invalid command when using commandDir #1306
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
Comments
I've had the same problem. this is not either documented anywhere or maybe not even possible. Any suggestions? |
In my case, I'm using module.exports = {
// ...
builder(yargs) {
yargs.commandDir('my-subcommand')
.check(argv => {
if (argv.command) throw new Error('Command is invalid!!');
return true;
});
}
// ...
} If yargs doesn't supply proper solution, this can be sort of. |
Did you try using demandCommand(1) to force the user to specify a command? Or strict() to forbid the use of unknown commands? |
@mleguen
I figured out why it doesn't show the same error message. They have different command types: |
I couldn't get this to work for deeply nested subcommands even after trying the recommended workarounds and linked issues. I worked around this and a few other issues by using a wrapper function to differentiate leaf commands from commands with registered subcommands when outputting help text and attempting to run command handlers. This issue inspired black flag, a yargs wrapper I built mainly to work around this sort of prickly behavior from |
Uh oh!
There was an error while loading. Please reload this page.
If when using the commandDir() to load subcommands from a directory, the user specifies a command that is not valid i.e. is not in the directory, I am wondering what the best way to inform the user is that an invalid command has been specificed. Currently itit appears that nothing happens and the command simply executes nothing.
Perhaps using the check() with a function that parses the commands available and then checks against the one specified, before then issuing the showHelp()?
After reading the API docs I did try the strict() option, but this only appears to work on the top level command. The sub commands do not seem to honor it, even though I am also explicitly setting it in the builder at this level?
The text was updated successfully, but these errors were encountered: