I have yargs with 2 commands?
yargs
.command('test-all','',handler)
.command('test-file','',handler)
.argv
The user inputs:
node myapp.js other-command
But yargs
don't throw an error. What should I do?
I have yargs with 2 commands?
yargs
.command('test-all','',handler)
.command('test-file','',handler)
.argv
The user inputs:
node myapp.js other-command
But yargs
don't throw an error. What should I do?
You can use .demandCommand()
to do this:
yargs
.command('test-all','',handler)
.command('test-file','',handler)
.demandCommand(1, 'You need at least one command before moving on')
.argv
You just need to define a command on everything else (* wilcard) that shows the help.
yargs
.command('test-all','',handler)
.command('test-file','',handler)
.command('*','', () => { y.showHelp(); })
.argv
Best way to do this now is with:
.demandCommand().recommendCommands().strict()
This also solves the issue wherein you don't enter any command.