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')
fork icon13
star icon30
watch icon4

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);
                }
fork icon3
star icon23
watch icon5

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')
fork icon2
star icon20
watch icon5

Other functions in yargs

Sorted by popularity

function icon

yargs.argv is the most popular function in yargs (1012 examples)