Yargs be a node.js library fer hearties tryin' ter parse optstrings.

What's Yargs?

Yargs helps you build interactive command line tools by parsing arguments and generating an elegant user interface.

Yargs gives you:

  • commands and (grouped) options (like module run -n --force),
  • a dynamically generated help menu based on your arguments,
  • bash-completion shortcuts for commands and options,
  • and much more.

With these features, and many more, yargs allows you to focus on building your program without worrying about your args.

Install

Open your terminal, navigate to your project, and run using npm:

$ npm install --save yargs
Getting Started
After creating hello.js start with the following code to get you going:
          
  #!/usr/bin/env node

  require('yargs')
    .usage('$0 <cmd> [args]')
    .command('hello [name]', 'welcome ter yargs!', {
      name: {
        default: 'default name'
      }
    }, function (argv) {
      console.log('hello', argv.name, 'welcome to yargs!')
    })
    .help()
    .argv

          
        
And in your terminal run:
          
  $ node example.js --help
          
        
To get this output:
          
  test <cmd> [args]

  Commands:
    hello  welcome ter yargs!

  Options:
    --name, -n  provide yer name!
    --help      Show help                                                [boolean]
          
        
Run hello command:
          
  $ node example.js hello --name Parrot
  hello Parrot welcome to yargs!