Link Search Menu Expand Document

Cook

Default Hash

var argv = require('yargs')
    .default({ x : 10, y : 10 })
    .argv
;

Boolean args

argv
    .boolean({booleanop})

Multipel commands

argv
    .command('*', 'default cmd', ()=> {}, (argv) => {
        // will be run by default
    })
  • more complicated
#!/usr/bin/env node
require('yargs')
  .command(['start [app]', 'run', 'up'], 'Start up an app', {}, (argv) => {
    console.log('starting up the', argv.app || 'default', 'app')
  })
  .command({
    command: 'configure <key> [value]',
    aliases: ['config', 'cfg'],
    desc: 'Set a config variable',
    builder: (yargs) => yargs.default('value', 'true'),
    handler: (argv) => {
      console.log(`setting ${argv.key} to ${argv.value}`)
    }
  })
  .demandCommand()
  .help()
  .wrap(72)
  .argv


Table of contents


Copyright © 2020 Thence LLC