I have read the yargs documetation multiple times, but can't figure out this one. Here are my requirements:
- My CLI should provide two commands:
cmd1
andcmd2
. - The user must specify one of these two commands, otherwise the CLI must print a help message and exit.
This is my attempt:
async function main() {
await yargs(process.argv.slice(2))
.command('cmd1', 'Command 1', {}, () => console.log('Executing command1'))
.command('cmd2', 'Command 2', {}, () => console.log('Executing command2'))
.help().argv;
}
Following commands work as expected:
my-cli cmd1 # prints "Executing command1"
my-cli cmd2 # prints "Executing command2"
However following commands quit silently:
my-cli
my-cli cmd3
What am I missing?