How to use the demandCommand function from yargs
Find comprehensive JavaScript yargs.demandCommand code examples handpicked from public code repositorys.
70 71 72 73 74 75 76 77 78 79
yargs.command('*', false, () => { yargs.showHelp(); console.error("Non-existing or no command specified."); process.exit(1); }) yargs.demandCommand(1) yargs.help('h') yargs.alias('h', 'help') yargs.alias('v', 'version')
13
30
4
14 15 16 17 18 19 20 21 22 23
export function Command<Args extends Argv>(cmd: Command<Args>) { return { ...cmd, builder(yargs: Yargs<any>) { cmd.builder && cmd.builder(yargs); if(!cmd.handler) yargs.demandCommand(); if(cmd.subCommands) { for(const subCommand of cmd.subCommands) { yargs.command(subCommand); }
3
23
5
32 33 34 35 36 37 38 39 40 41
cli.usage(`Usage: $0 <command> [options]`); this.commands.forEach((command) => { cli.command(command); }); cli.demandCommand(1) .strict() .alias('v', 'version') .help('h') .alias('h', 'help')
2
20
5
yargs.argv is the most popular function in yargs (1012 examples)