yargs
Light-weight option parsing with an argv hash. No optstrings attached.
Last updated 10 years ago by bcoe .
MIT/X11 · Repository · Bugs · Original npm
$ cnpm install yargs 
SYNC missed versions from official npm registry.

Yargs

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


Build Status NPM version js-standard-style Coverage Conventional Commits Slack

Description :

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

It gives you:

  • commands and (grouped) options (my-program.js serve --port=5000).
  • a dynamically generated help menu based on your arguments.
  • bash-completion shortcuts for commands and options.
  • and tons more.

Installation

Stable version:

npm i yargs

Bleeding edge version with the most recent features:

npm i yargs@next

Usage :

Simple Example

#!/usr/bin/env node
const argv = require('yargs').argv

if (argv.ships > 3 && argv.distance < 53.5) {
  console.log('Plunder more riffiwobbles!')
} else {
  console.log('Retreat from the xupptumblers!')
}
$ ./plunder.js --ships=4 --distance=22
Plunder more riffiwobbles!

$ ./plunder.js --ships 12 --distance 98.7
Retreat from the xupptumblers!

Complex Example

#!/usr/bin/env node
require('yargs') // eslint-disable-line
  .command('serve [port]', 'start the server', (yargs) => {
    yargs
      .positional('port', {
        describe: 'port to bind on',
        default: 5000
      })
  }, (argv) => {
    if (argv.verbose) console.info(`start server on :${argv.port}`)
    serve(argv.port)
  })
  .option('verbose', {
    alias: 'v',
    type: 'boolean',
    description: 'Run with verbose logging'
  })
  .argv

Run the example above with --help to see the help for the application.

TypeScript

yargs has type definitions at @types/yargs.

npm i @types/yargs --save-dev

See usage examples in docs.

Webpack

See usage examples of yargs with webpack in docs.

Community :

Having problems? want to contribute? join our community slack.

Documentation :

Table of Contents

Current Tags

  • 17.7.2                                ...           latest (2 years ago)
  • 11.1.1                                ...           latest-11 (6 years ago)
  • 13.3.2                                ...           latest-13 (5 years ago)
  • 14.2.3                                ...           latest-14 (5 years ago)
  • 7.1.2                                ...           latest-7 (4 years ago)
  • 17.1.1-candidate.0                                ...           next (4 years ago)
  • 14.2.1                                ...           next-14 (6 years ago)

56 Versions

  • 17.7.2                                ...           2 years ago
  • 17.7.1                                ...           3 years ago
  • 17.6.2                                ...           3 years ago
  • 17.6.1                                ...           3 years ago
  • 17.5.1                                ...           3 years ago
  • 17.5.0                                ...           3 years ago
  • 17.4.1                                ...           3 years ago
  • 17.4.0                                ...           3 years ago
  • 17.3.1                                ...           4 years ago
  • 15.0.2                                ...           6 years ago
  • 17.1.1-candidate.0                                ...           4 years ago
  • 17.1.1                                ...           4 years ago
  • 17.1.0-candidate.0                                ...           4 years ago
  • 17.1.0                                ...           4 years ago
  • 3.15.0                                ...           10 years ago
  • 15.5.0-candidate.0                                ...           5 years ago
  • 17.0.0-candidate.13                                ...           4 years ago
  • 7.1.2                                ...           4 years ago
  • 17.0.1                                ...           4 years ago
  • 17.0.0-candidate.0                                ...           5 years ago
  • 16.2.0                                ...           5 years ago
  • 1.2.6                                ...           11 years ago
  • 16.0.4-candidate.0                                ...           5 years ago
  • 16.0.3                                ...           5 years ago
  • 13.2.2                                ...           6 years ago
  • 15.4.1                                ...           5 years ago
  • 15.4.0-beta.1                                ...           5 years ago
  • 15.4.0                                ...           5 years ago
  • 4.7.1                                ...           9 years ago
  • 15.4.0-beta.0                                ...           5 years ago
  • 7.1.1                                ...           5 years ago
  • 3.27.0                                ...           10 years ago
  • 14.2.1                                ...           6 years ago
  • 15.3.2-beta.0                                ...           5 years ago
  • 13.3.0                                ...           6 years ago
  • 15.3.1                                ...           5 years ago
  • 8.0.1                                ...           8 years ago
  • 12.0.2                                ...           7 years ago
  • 9.0.1                                ...           8 years ago
  • 11.1.0                                ...           7 years ago
  • 1.3.3                                ...           11 years ago
  • 10.1.2                                ...           8 years ago
  • 4.3.2                                ...           9 years ago
  • 13.2.4                                ...           6 years ago
  • 11.0.0                                ...           8 years ago
  • 3.5.4                                ...           10 years ago
  • 8.0.2                                ...           8 years ago
  • 11.1.1                                ...           6 years ago
  • 4.8.1                                ...           9 years ago
  • 3.10.0                                ...           10 years ago
  • 6.6.0                                ...           9 years ago
  • 13.3.2                                ...           5 years ago
  • 3.32.0                                ...           10 years ago
  • 7.1.0                                ...           8 years ago
  • 12.0.5                                ...           7 years ago
  • 14.2.3                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org