Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

yargs-cn

bcoe6MIT4.0.2

Light-weight option parsing with an argv hash. No optstrings attached.

argument, args, option, parser, parsing, cli, command

readme

yargs

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

With yargs, ye be havin' a map that leads straight to yer treasure! Treasure of course, being a simple option hash.

No need wrap any more, will auto wrap for your terminal.

Build Status Dependency Status Coverage Status NPM version Windows Tests

Yargs is the official successor to optimist. Please feel free to submit issues and pull requests. If you'd like to contribute and don't know where to start, have a look at the issue list :)

examples

With yargs, the options be just a hash!

plunder.js:

#!/usr/bin/env node
var 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!

Joe was one optimistic pirate.

But don't walk the plank just yet! There be more! You can do short options:

short.js:

#!/usr/bin/env node
var argv = require('yargs').argv;
console.log('(%d,%d)', argv.x, argv.y);

$ ./short.js -x 10 -y 21
(10,21)

And booleans, both long, short, and even grouped:

bool.js:

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

if (argv.s) {
    process.stdout.write(argv.fr ? 'Le perroquet dit: ' : 'The parrot says: ');
}
console.log(
    (argv.fr ? 'couac' : 'squawk') + (argv.p ? '!' : '')
);

$ ./bool.js -s
The parrot says: squawk

$ ./bool.js -sp
The parrot says: squawk!

$ ./bool.js -sp --fr
Le perroquet dit: couac!

And non-hyphenated options too! Just use argv._!

nonopt.js:

#!/usr/bin/env node
var argv = require('yargs').argv;
console.log('(%d,%d)', argv.x, argv.y);
console.log(argv._);

$ ./nonopt.js -x 6.82 -y 3.35 rum
(6.82,3.35)
[ 'rum' ]

$ ./nonopt.js "me hearties" -x 0.54 yo -y 1.12 ho
(0.54,1.12)
[ 'me hearties', 'yo', 'ho' ]

Yargs even counts your booleans!

count.js:

#!/usr/bin/env node
var argv = require('yargs')
    .count('verbose')
    .alias('v', 'verbose')
    .argv;

VERBOSE_LEVEL = argv.verbose;

function WARN()  { VERBOSE_LEVEL >= 0 && console.log.apply(console, arguments); }
function INFO()  { VERBOSE_LEVEL >= 1 && console.log.apply(console, arguments); }
function DEBUG() { VERBOSE_LEVEL >= 2 && console.log.apply(console, arguments); }

WARN("Showing only important stuff");
INFO("Showing semi-important stuff too");
DEBUG("Extra chatty mode");

$ node count.js
Showing only important stuff

$ node count.js -v
Showing only important stuff
Showing semi-important stuff too

$ node count.js -vv
Showing only important stuff
Showing semi-important stuff too
Extra chatty mode

$ node count.js -v --verbose
Showing only important stuff
Showing semi-important stuff too
Extra chatty mode

Tell users how to use yer options and make demands.

area.js:

#!/usr/bin/env node
var argv = require('yargs')
    .usage('Usage: $0 -w [num] -h [num]')
    .demand(['w','h'])
    .argv;

console.log("The area is:", argv.w * argv.h);

$ ./area.js -w 55 -h 11
The area is: 605

$ node ./area.js -w 4.91 -w 2.51
Usage: area.js -w [num] -h [num]

Options:
  -w  [required]
  -h  [required]

Missing required arguments: h

After yer demands have been met, demand more! Ask for non-hyphenated arguments!

demand_count.js:

#!/usr/bin/env node
var argv = require('yargs')
    .demand(2)
    .argv;
console.dir(argv);

$ ./demand_count.js a

Not enough non-option arguments: got 1, need at least 2

$ ./demand_count.js a b
{ _: [ 'a', 'b' ], '$0': 'demand_count.js' }

$ ./demand_count.js a b c
{ _: [ 'a', 'b', 'c' ], '$0': 'demand_count.js' }

EVEN MORE SHIVER ME TIMBERS!

default_singles.js:

#!/usr/bin/env node
var argv = require('yargs')
    .default('x', 10)
    .default('y', 10)
    .argv
;
console.log(argv.x + argv.y);

$ ./default_singles.js -x 5
15

default_hash.js:

#!/usr/bin/env node
var argv = require('yargs')
    .default({ x : 10, y : 10 })
    .argv
;
console.log(argv.x + argv.y);

$ ./default_hash.js -y 7
17

And if you really want to get all descriptive about it...

boolean_single.js:

#!/usr/bin/env node
var argv = require('yargs')
    .boolean('v')
    .argv
;
console.dir(argv.v);
console.dir(argv._);

$ ./boolean_single.js -v "me hearties" yo ho
true
[ 'me hearties', 'yo', 'ho' ]

boolean_double.js:

#!/usr/bin/env node
var argv = require('yargs')
    .boolean(['x','y','z'])
    .argv
;
console.dir([ argv.x, argv.y, argv.z ]);
console.dir(argv._);

$ ./boolean_double.js -x -z one two three
[ true, false, true ]
[ 'one', 'two', 'three' ]

Yargs is here to help you...

Ye can describe parameters fer help messages and set aliases. Yargs figures out how ter format a handy help string automatically.

line_count.js:

#!/usr/bin/env node
var argv = require('yargs')
    .usage('Usage: $0 <command> [options]')
    .command('count', 'Count the lines in a file')
    .demand(1)
    .example('$0 count -f foo.js', 'count the lines in the given file')
    .demand('f')
    .alias('f', 'file')
    .nargs('f', 1)
    .describe('f', 'Load a file')
    .help('h')
    .alias('h', 'help')
    .epilog('copyright 2015')
    .argv;

var fs = require('fs');
var s = fs.createReadStream(argv.file);

var lines = 0;
s.on('data', function (buf) {
    lines += buf.toString().match(/\n/g).length;
});

s.on('end', function () {
    console.log(lines);
});

$ node line_count.js count
Usage: line_count.js <command> [options]

Commands:
  count    Count the lines in a file

Options:
  -f, --file  Load a file        [required]
  -h, --help  Show help           [boolean]

Examples:
  line_count.js count -f foo.js  count the lines in the given file

copyright 2015

Missing required arguments: f

$ node line_count.js count --file line_count.js
26

$ node line_count.js count -f line_count.js
26

methods

By itself,

require('yargs').argv

will use the process.argv array to construct the argv object.

You can pass in the process.argv yourself:

require('yargs')([ '-x', '1', '-y', '2' ]).argv

or use .parse() to do the same thing:

require('yargs').parse([ '-x', '1', '-y', '2' ])

The rest of these methods below come in just before the terminating .argv.

.alias(key, alias)

Set key names as equivalent such that updates to a key will propagate to aliases and vice-versa.

Optionally .alias() can take an object that maps keys to aliases. Each key of this object should be the canonical version of the option, and each value should be a string or an array of strings.

.argv

Get the arguments as a plain old object.

Arguments without a corresponding flag show up in the argv._ array.

The script name or node command is available at argv.$0 similarly to how $0 works in bash or perl.

If yargs is executed in an environment that embeds node and there's no script name (e.g. Electron or nw.js), it will ignore the first parameter since it expects it to be the script name. In order to override this behavior, use .parse(process.argv.slice(1)) instead of .argv and the first parameter won't be ignored.

.array(key)

Tell the parser to interpret key as an array. If .array('foo') is set, --foo foo bar will be parsed as ['foo', 'bar'] rather than as 'foo'.

.boolean(key)

Interpret key as a boolean. If a non-flag option follows key in process.argv, that string won't get set as the value of key.

key will default to false, unless a default(key, undefined) is explicitly set.

If key is an array, interpret all the elements as booleans.

.check(fn)

Check that certain conditions are met in the provided arguments.

fn is called with two arguments, the parsed argv hash and an array of options and their aliases.

If fn throws or returns a non-truthy value, show the thrown error, usage information, and exit.

.choices(key, choices)

Limit valid values for key to a predefined set of choices, given as an array or as an individual value.

var argv = require('yargs')
  .alias('i', 'ingredient')
  .describe('i', 'choose your sandwich ingredients')
  .choices('i', ['peanut-butter', 'jelly', 'banana', 'pickles'])
  .help('help')
  .argv

If this method is called multiple times, all enumerated values will be merged together. Choices are generally strings or numbers, and value matching is case-sensitive.

Optionally .choices() can take an object that maps multiple keys to their choices.

Choices can also be specified as choices in the object given to option().

var argv = require('yargs')
  .option('size', {
    alias: 's',
    describe: 'choose a size',
    choices: ['xs', 's', 'm', 'l', 'xl']
  })
  .argv

.command(cmd, desc, [fn])

Document the commands exposed by your application.

Use desc to provide a description for each command your application accepts (the values stored in argv._). Set desc to false to create a hidden command. Hidden commands don't show up in the help output and aren't available for completion.

Optionally, you can provide a handler fn which will be executed when a given command is provided. The handler will be executed with an instance of yargs, which can be used to compose nested commands.

Here's an example of top-level and nested commands in action:

var argv = require('yargs')
  .usage('npm <command>')
  .command('install', 'tis a mighty fine package to install')
  .command('publish', 'shiver me timbers, should you be sharing all that', function (yargs) {
    argv = yargs.option('f', {
      alias: 'force',
      description: 'yar, it usually be a bad idea'
    })
    .help('help')
    .argv
  })
  .help('help')
  .argv;

.completion(cmd, [description], [fn]);

Enable bash-completion shortcuts for commands and options.

cmd: When present in argv._, will result in the .bashrc completion script being outputted. To enable bash completions, concat the generated script to your .bashrc or .bash_profile.

description: Provide a description in your usage instructions for the command that generates bash completion scripts.

fn: Rather than relying on yargs' default completion functionality, which shiver me timbers is pretty awesome, you can provide your own completion method.

var argv = require('yargs')
  .completion('completion', function(current, argv) {
    // 'current' is the current command being completed.
    // 'argv' is the parsed arguments so far.
    // simply return an array of completions.
    return [
      'foo',
      'bar'
    ];
  })
  .argv;

But wait, there's more! You can provide asynchronous completions.

var argv = require('yargs')
  .completion('completion', function(current, argv, done) {
    setTimeout(function() {
      done([
        'apple',
        'banana'
      ]);
    }, 500);
  })
  .argv;

.config(key, [description])

Tells the parser that if the option specified by key is passed in, it should be interpreted as a path to a JSON config file. The file is loaded and parsed, and its properties are set as arguments. If present, the description parameter customizes the description of the config (key) option in the usage string.

.count(key)

Interpret key as a boolean flag, but set its parsed value to the number of flag occurrences rather than true or false. Default value is thus 0.

.default(key, value, [description])

Set argv[key] to value if no option was specified in process.argv.

Optionally .default() can take an object that maps keys to default values.

But wait, there's more! The default value can be a function which returns a value. The name of the function will be used in the usage string:

var argv = require('yargs')
  .default('random', function randomValue() {
    return Math.random() * 256;
  }).argv;

Optionally, description can also be provided and will take precedence over displaying the value in the usage instructions:

.default('timeout', 60000, '(one-minute)')

.demand(key, [msg | boolean])

.demand(count, [max], [msg])

If key is a string, show the usage information and exit if key wasn't specified in process.argv.

If key is a number, demand at least as many non-option arguments, which show up in argv._. A second number can also optionally be provided, which indicates the maximum number of non-option arguments.

If key is an array, demand each element.

If a msg string is given, it will be printed when the argument is missing, instead of the standard error message. This is especially helpful for the non-option arguments in argv._.

If a boolean value is given, it controls whether the option is demanded; this is useful when using .options() to specify command line parameters.

.describe(key, desc)

Describe a key for the generated usage information.

Optionally .describe() can take an object that maps keys to descriptions.

.detectLocale(boolean)

Should yargs attempt to detect the os' locale? Defaults to true.

.epilog(str)

.epilogue(str)

A message to print at the end of the usage instructions, e.g.

var argv = require('yargs')
  .epilogue('for more information, find our manual at http://example.com');

.example(cmd, desc)

Give some example invocations of your program. Inside cmd, the string $0 will get interpolated to the current script name or node command for the present script similar to how $0 works in bash or perl. Examples will be printed out as part of the help message.

.exitProcess(enable)

By default, yargs exits the process when the user passes a help flag, uses the .version functionality, or when validation fails. Calling .exitProcess(false) disables this behavior, enabling further actions after yargs have been validated.

.fail(fn)

Method to execute when a failure occurs, rather than printing the failure message.

fn is called with the failure message that would have been printed.

.help([option, [description]])

Add an option (e.g. --help) that displays the usage string and exits the process. If present, the description parameter customizes the description of the help option in the usage string.

If invoked without parameters, .help() returns the generated usage string.

Example:

var yargs = require("yargs")
  .usage("$0 -operand1 number -operand2 number -operation [add|subtract]");
console.log(yargs.help());

Later on, argv can be retrieved with yargs.argv.

.implies(x, y)

Given the key x is set, it is required that the key y is set.

Optionally .implies() can accept an object specifying multiple implications.

.locale()

Return the locale that yargs is currently using.

By default, yargs will auto-detect the operating system's locale so that yargs-generated help content will display in the user's language.

To override this behavior with a static locale, pass the desired locale as a string to this method (see below).

.locale(locale)

Override the auto-detected locale from the user's operating system with a static locale. Note that the OS locale can be modified by setting/exporting the LC_ALL environment variable.

var argv = require('yargs')
  .usage('./$0 - follow ye instructions true')
  .option('option', {
    alias: 'o',
    describe: "'tis a mighty fine option",
    demand: true
  })
  .command('run', "Arrr, ya best be knowin' what yer doin'")
  .example('$0 run foo', "shiver me timbers, here's an example for ye")
  .help('help')
  .wrap(70)
  .locale('pirate')
  .argv

./test.js - follow ye instructions true

Choose yer command:
  run  Arrr, ya best be knowin' what yer doin'

Options for me hearties!
  --option, -o  'tis a mighty fine option               [requi-yar-ed]
  --help        Parlay this here code of conduct             [boolean]

Ex. marks the spot:
  test.js run foo  shiver me timbers, here's an example for ye

Ye be havin' to set the followin' argument land lubber: option

Locales currently supported:

  • de: German.
  • en: American English.
  • es: Spanish.
  • fr: French.
  • ja: Japanese.
  • pt: Portuguese.
  • zh: Chinese.
  • pirate: American Pirate.

To submit a new translation for yargs:

  1. use ./locales/en.json as a starting point.
  2. submit a pull request with the new locale file.

.nargs(key, count)

The number of arguments that should be consumed after a key. This can be a useful hint to prevent parsing ambiguity. For example:

var argv = require('yargs')
  .nargs('token', 1)
  .parse(['--token', '-my-token']);

parses as:

{ _: [], token: '-my-token', '$0': 'node test' }

Optionally .nargs() can take an object of key/narg pairs.

.option(key, opt)

.options(key, opt)

Instead of chaining together .alias().demand().default().describe().string(), you can specify keys in opt for each of the chainable methods.

For example:

var argv = require('yargs')
    .option('f', {
        alias: 'file',
        demand: true,
        default: '/etc/passwd',
        describe: 'x marks the spot',
        type: 'string'
    })
    .argv
;

is the same as

var argv = require('yargs')
    .alias('f', 'file')
    .demand('f')
    .default('f', '/etc/passwd')
    .describe('f', 'x marks the spot')
    .string('f')
    .argv
;

Optionally .options() can take an object that maps keys to opt parameters.

var argv = require('yargs')
    .options({
      'f': {
        alias: 'file',
        demand: true,
        default: '/etc/passwd',
        describe: 'x marks the spot',
        type: 'string'
      }
    })
    .argv
;

Valid opt keys include:

  • alias: string or array of strings, alias(es) for the canonical option key, see alias()
  • array: boolean, interpret option as an array, see array()
  • boolean: boolean, interpret option as a boolean flag, see boolean()
  • choices: value or array of values, limit valid option arguments to a predefined set, see choices()
  • config: boolean, interpret option as a path to a JSON config file, see config()
  • count: boolean, interpret option as a count of boolean flags, see count()
  • default: value, set a default value for the option, see default()
  • defaultDescription: string, use this description for the default value in help content, see default()
  • demand/require/required: boolean or string, demand the option be given, with optional error message, see demand()
  • desc/describe/description: string, the option description for help content, see describe()
  • nargs: number, specify how many arguments should be consumed for the option, see nargs()
  • requiresArg: boolean, require the option be specified with a value, see requiresArg()
  • string: boolean, interpret option as a string, see string()
  • type: one of the following strings
    • 'array': synonymous for array: true, see array()
    • 'boolean': synonymous for boolean: true, see boolean()
    • 'count': synonymous for count: true, see count()
    • 'string': synonymous for string: true, see string()

.parse(args)

Parse args instead of process.argv. Returns the argv object.

.require(key, [msg | boolean])

.required(key, [msg | boolean])

An alias for demand(). See docs there.

.requiresArg(key)

Specifies either a single option key (string), or an array of options that must be followed by option values. If any option value is missing, show the usage information and exit.

The default behavior is to set the value of any key not followed by an option value to true.

.reset()

Reset the argument object built up so far. This is useful for creating nested command line interfaces.

var yargs = require('yargs')
  .usage('$0 command')
  .command('hello', 'hello command')
  .command('world', 'world command')
  .demand(1, 'must provide a valid command'),
  argv = yargs.argv,
  command = argv._[0];

if (command === 'hello') {
  yargs.reset()
    .usage('$0 hello')
    .help('h')
    .example('$0 hello', 'print the hello message!')
    .argv

  console.log('hello!');
} else if (command === 'world'){
  yargs.reset()
    .usage('$0 world')
    .help('h')
    .example('$0 world', 'print the world message!')
    .argv

  console.log('world!');
} else {
  yargs.showHelp();
}

.showCompletionScript()

Generate a bash completion script. Users of your application can install this script in their .bashrc, and yargs will provide completion shortcuts for commands and options.

.showHelp(consoleLevel='error')

Print the usage data using the console function consoleLevel for printing.

Example:

var yargs = require("yargs")
  .usage("$0 -operand1 number -operand2 number -operation [add|subtract]");
yargs.showHelp(); //prints to stderr using console.error()

Or, to print the usage data to stdout instead, you can specify the use of console.log:

yargs.showHelp("log"); //prints to stdout using console.log()

Later on, argv can be retrieved with yargs.argv.

.showHelpOnFail(enable, [message])

By default, yargs outputs a usage string if any error is detected. Use the .showHelpOnFail() method to customize this behavior. If enable is false, the usage string is not output. If the message parameter is present, this message is output after the error message.

line_count.js:

#!/usr/bin/env node
var argv = require('yargs')
    .usage('Count the lines in a file.\nUsage: $0 -f <file>')
    .demand('f')
    .alias('f', 'file')
    .describe('f', 'Load a file')
    .string('f')
    .showHelpOnFail(false, 'Specify --help for available options')
    .help('help')
    .argv;

// etc.

$ node line_count.js
Missing argument value: f

Specify --help for available options

.strict()

Any command-line argument given that is not demanded, or does not have a corresponding description, will be reported as an error.

.string(key)

Tell the parser logic not to interpret key as a number or boolean. This can be useful if you need to preserve leading zeros in an input.

If key is an array, interpret all the elements as strings.

.string('_') will result in non-hyphenated arguments being interpreted as strings, regardless of whether they resemble numbers.

.updateLocale(obj)

.updateStrings(obj)

Override the default strings used by yargs with the key/value pairs provided in obj:

var argv = require('yargs')
  .command('run', 'the run command')
  .help('help')
  .updateStrings({
    'Commands:': 'My Commands -->\n'
  })
  .wrap(null)
  .argv

My Commands -->

  run  the run command

Options:
  --help  Show help  [boolean]

If you explicitly specify a locale(), you should do so before calling updateStrings().

.usage(message, [opts])

Set a usage message to show which commands to use. Inside message, the string $0 will get interpolated to the current script name or node command for the present script similar to how $0 works in bash or perl.

opts is optional and acts like calling .options(opts).

.version(version, [option], [description])

Add an option (e.g. --version) that displays the version number (given by the version parameter) and exits the process. If present, the description parameter customizes the description of the version option in the usage string.

You can provide a function for version, rather than a string. This is useful if you want to use the version from your package.json:

var argv = require('yargs')
  .version(function() {
    return require('../package').version;
  })
  .argv;

.wrap(columns)

Format usage output to wrap at columns many columns.

By default wrap will be set to Math.min(80, windowWidth). Use .wrap(null) to specify no column limit (no right-align). Use .wrap(yargs.terminalWidth()) to maximize the width of yargs' usage instructions.

parsing tricks

stop parsing

Use -- to stop parsing flags and stuff the remainder into argv._.

$ node examples/reflect.js -a 1 -b 2 -- -c 3 -d 4
{ _: [ '-c', '3', '-d', '4' ],
  a: 1,
  b: 2,
  '$0': 'examples/reflect.js' }

negate fields

If you want to explicitly set a field to false instead of just leaving it undefined or to override a default you can do --no-key.

$ node examples/reflect.js -a --no-b
{ _: [], a: true, b: false, '$0': 'examples/reflect.js' }

numbers

Every argument that looks like a number (!isNaN(Number(arg))) is converted to one. This way you can just net.createConnection(argv.port) and you can add numbers out of argv with + without having that mean concatenation, which is super frustrating.

duplicates

If you specify a flag multiple times it will get turned into an array containing all the values in order.

$ node examples/reflect.js -x 5 -x 8 -x 0
{ _: [], x: [ 5, 8, 0 ], '$0': 'examples/reflect.js' }

dot notation

When you use dots (.s) in argument names, an implicit object path is assumed. This lets you organize arguments into nested objects.

$ node examples/reflect.js --foo.bar.baz=33 --foo.quux=5
{ _: [],
  foo: { bar: { baz: 33 }, quux: 5 },
  '$0': 'examples/reflect.js' }

short numbers

Short numeric -n5 style arguments work too:

$ node examples/reflect.js -n123 -m456
{ _: [], n: 123, m: 456, '$0': 'examples/reflect.js' }

installation

With npm, just do:

npm install yargs

or clone this project on github:

git clone http://github.com/bcoe/yargs.git

To run the tests with npm, just do:

npm test

inspired by

This module is loosely inspired by Perl's Getopt::Casual.

changelog

Change Log

v3.26.0 (2015/09/25 2:14 +00:00)

  • #263 document count() and option() object keys (@nexdrew)
  • #259 remove util in readme (@38elements)
  • #258 node v4 builds, update deps (@nexdrew)
  • #257 fix spelling errors (@dkoleary88)

v3.25.0 (2015/09/13 7:38 -07:00)

  • #254 adds Japanese translation (@oti)
  • #253 fixes for tests on Windows (@bcoe)

v3.24.0 (2015/09/04 12:02 +00:00)

  • #248 reinstate os-locale, no spawning (@nexdrew)
  • #249 use travis container-based infrastructure (@nexdrew)
  • #247 upgrade standard (@nexdrew)

v3.23.0 (2015/08/30 23:00 +00:00)

  • #246 detect locale based only on environment variables (@bcoe)
  • #244 adds Windows CI testing (@bcoe)
  • #245 adds OSX CI testing (@bcoe, @nexdrew)

v3.22.0 (2015/08/28 22:26 +00:00)

  • #242 adds detectLocale config option (@bcoe)

v3.21.1 (2015/08/28 20:58 +00:00)

  • #240 hot-fix for Atom on Windows (@bcoe)

v3.21.0 (2015/08/21 21:20 +00:00)

  • #238 upgrade camelcase, window-size, chai, mocha (@nexdrew)
  • #237 adds defaultDescription to option() (@nexdrew)

v3.20.0 (2015/08/20 01:29 +00:00)

  • #231 Merge pull request #231 from bcoe/detect-locale (@sindresorhus)
  • #235 adds german translation to yargs (@maxrimue)

v3.19.0 (2015/08/14 05:12 +00:00)

  • #224 added Portuguese translation (@codemonkey3045)

v3.18.1 (2015/08/12 05:53 +00:00)

  • #228 notes about embedding yargs in Electron (@etiktin)
  • #223 make booleans work in config files (@sgentle)

v3.18.0 (2015/08/06 20:05 +00:00)

  • #222 updates fr locale (@nexdrew)
  • #221 adds missing locale strings (@nexdrew)
  • #220 adds es locale (@zkat)

v3.17.1 (2015/08/02 19:35 +00:00)

  • #218 upgrades nyc (@bcoe)

v3.17.0 (2015/08/02 18:39 +00:00)

  • #217 sort methods in README.md (@nexdrew)
  • #215 adds fr locale (@LoicMahieu)

v3.16.0 (2015/07/30 04:35 +00:00)

  • #210 adds i18n support to yargs (@bcoe)
  • #209 adds choices type to yargs (@nexdrew)
  • #207 pretty new shields from shields.io (@SimenB)
  • #208 improvements to README.md (@nexdrew)
  • #205 faster build times on Travis (@ChristianMurphy)

v3.15.0 (2015/07/06 06:01 +00:00)

  • #197 tweaks to how errors bubble up from parser.js (@bcoe)
  • #193 upgraded nyc, reporting now happens by default (@bcoe)

v3.14.0 (2015/06/28 02:12 +00:00)

  • #192 standard style nits (@bcoe)
  • #190 allow for hidden commands, e.g., .completion('completion', false) (@tschaub)

v3.13.0 (2015/06/24 04:12 +00:00)

  • #187 completion now behaves differently if it is being run in the context of a command (@tschaub)
  • #186 if no matches are found for a completion default to filename completion (@tschaub)

v3.12.0 (2015/06/19 03:23 +00:00)

  • #183 don't complete commands if they've already been completed (@tschaub)
  • #181 various fixes for completion. (@bcoe, @tschaub)
  • #182 you can now set a maximum # of of required arguments (@bcoe)

v3.11.0 (2015/06/15 05:15 +00:00)

  • #173 update standard, window-size, chai (@bcoe)
  • #171 a description can now be set when providing a config option. (@5c077yP)

v3.10.0 (2015/05/29 04:25 +00:00)

  • #165 expose yargs.terminalWidth() thanks @ensonic (@bcoe)
  • #164 better array handling thanks @getify (@bcoe)

v3.9.1 (2015/05/20 05:14 +00:00)

  • b6662b6 clarify .config() docs (@linclark)
  • 0291360 fixed tests, switched to nyc for coverage, fixed security issue, added Lin as collaborator (@bcoe)

v3.9.0 (2015/05/10 18:32 +00:00)

  • #157 Merge pull request #157 from bcoe/command-yargs. allows handling of command specific arguments. Thanks for the suggestion @ohjames (@bcoe)
  • #158 Merge pull request #158 from kemitchell/spdx-license. Update license format (@kemitchell)

v3.8.0 (2015/04/24 23:10 +00:00)

  • #154 showHelp's method signature was misleading fixes #153 (@bcoe)
  • #151 refactor yargs' table layout logic to use new helper library (@bcoe)
  • #150 Fix README example in argument requirements (@annonymouse)

v3.7.2 (2015/04/13 11:52 -07:00)

v3.7.1 (2015/04/10 11:06 -07:00)

  • 89e1992 detect iojs bin along with node bin. (@bcoe)
  • 755509e improvements to example documentation in README.md (@rstacruz)
  • 0d2dfc8 showHelp() no longer requires that .argv has been called (@bcoe)

v3.7.0 (2015/04/04 02:29 -07:00)

  • 56cbe2d make .requiresArg() work with type hints. (@bcoe).
  • 2f5d562 serialize arrays and objects in usage strings. (@bcoe).
  • 5126304 be more lenient about alias/primary key ordering in chaining API. (@bcoe)

v3.6.0 (2015/03/21 01:00 +00:00)

  • 4e24e22 support for .js configuration files. (@pirxpilot)

v3.5.4 (2015/03/12 05:56 +00:00)

  • c16cc08 message for non-option arguments is now optional, thanks to (@raine)

v3.5.3 (2015/03/09 06:14 +00:00)

  • 870b428 completion script was missing in package.json (@bcoe)

v3.5.2 (2015/03/09 06:11 +00:00)

  • 58a4b24 parse was being called multiple times, resulting in strange behavior (@bcoe)

v3.5.1 (2015/03/09 04:55 +00:00)

  • 4e588e0 accidentally left testing logic in (@bcoe)

v3.5.0 (2015/03/09 04:49 +00:00)

v3.4.7 (2015/03/09 04:09 +00:00)

  • 9845e5c the Argv singleton was not being updated when manually parsing arguments, fixes #114 (@bcoe)

v3.4.6 (2015/03/09 04:01 +00:00)

  • 45b4c80 set placeholders for all keys fixes #115 (@bcoe)

v3.4.5 (2015/03/01 20:31 +00:00)

  • a758e0b fix for count consuming too many arguments (@bcoe)

v3.4.4 (2015/02/28 04:52 +00:00)

  • 0476af7 added nargs feature, allowing you to specify the number of arguments after an option (@bcoe)
  • 092477d updated README with full example of v3.0 API (@bcoe)

v3.3.3 (2015/02/28 04:23 +00:00)

  • 0c4b769 remove string dependency, which conflicted with other libraries see #106 (@bcoe)

v3.3.2 (2015/02/28 04:11 +00:00)

  • 2a98906 add $0 to epilog (@schnittstabil)

v3.3.1 (2015/02/24 03:28 +00:00)

  • ad485ce fix for applying defaults to camel-case args (@bcoe)

v3.3.0 (2015/02/24 00:49 +00:00)

  • 8bfe36d fix and document restart() command, as a tool for building nested CLIs (@bcoe)

v3.2.1 (2015/02/22 05:45 +00:00)

  • 49a6d18 you can now provide a function that generates a default value (@bcoe)

v3.2.0 (2015/02/22 05:24 +00:00)

  • 7a55886 improvements to yargs two-column text layout (@bcoe)
  • b6ab513 Tweak NPM version badge (@nylen)

v3.1.0 (2015/02/19 19:37 +00:00)

  • 9bd2379 version now accepts a function, making it easy to load version #s from a package.json (@bcoe)

v3.0.4 (2015/02/14 01:40 +00:00)

  • 0b7c19b various fixes for dot-notation handling (@bcoe)

v3.0.3 (2015/02/14 00:59 +00:00)

  • c3f35e9 make sure dot-notation is applied to aliases (@bcoe)

3.0.2 (2015/02/13 16:50 +00:00)

  • 74c8967 document epilog shorthand of epilogue. (@bcoe)
  • 670110f any non-truthy value now causes check to fail see #76 (@bcoe)
  • 0d8f791 finished implementing my wish-list of fetures for yargs 3.0. see #88 (@bcoe)
  • 5768447 fix coverage. (@bcoe)
  • 82e793f detect console width and perform word-wrapping. (@bcoe)
  • 67476b3 refactor two-column table layout so that we can use it for examples and usage (@bcoe)
  • 4724cdf major refactor of index.js, in prep for 3.x release. (@bcoe)

v2.3.0 (2015/02/08 20:41 +00:00)

  • d824620 allow for undefined boolean defaults (@ashi009)

v2.2.0 (2015/02/08 20:07 +00:00)

  • d6edd98 in-prep for further refactoring, and a 3.x release I've shuffled some things around and gotten test-coverage to 100%. (@bcoe)

v2.1.2 (2015/02/08 06:05 +00:00)

  • d640745 switch to path.relative (@bcoe)
  • 3bfd41f remove mocha.opts. (@bcoe)
  • 47a2f35 document using .string('_') for string ids. see #56 (@bcoe)
  • #57 Merge pull request #57 from eush77/option-readme (@eush77)

v2.1.1 (2015/02/06 08:08 +00:00)

  • 01c6c61 fix for #71, 'newAliases' of undefined (@bcoe)

v2.1.0 (2015/02/06 07:59 +00:00)

  • 6a1a3fa try to guess argument types, and apply sensible defaults see #73 (@bcoe)

v2.0.1 (2015/02/06 07:54 +00:00)

  • 96a06b2 Fix for strange behavior with --sort option, see #51 (@bcoe)

v2.0.0 (2015/02/06 07:45 +00:00)

  • 0250517 - 108fb84 fixed bug with boolean parsing, when bools separated by = see #66 (@bcoe)
  • a465a59 Add files field to the package.json (@shinnn)
  • 31043de fix for yargs.argv having the same keys added multiple times see #63 (@bcoe)
  • 2d68c5b Disable process.exit calls using .exitProcess(false) (@cianclarke)
  • 45da9ec Mention .option in README (@eush77)

v1.3.2 (2014/10/06 21:56 +00:00)

list (2014/08/30 18:41 +00:00)

  • fbc777f Now that yargs is the successor to optimist, I'm changing the README language to be more universal. Pirate speak isn't very accessible to non-native speakers. (@chevex)
  • a54d068 version output will not print extra newline (@boneskull)
  • 1cef5d6 Added contributors section to package.json (@chrisn)
  • cc295c0 Added 'require' and 'required' as synonyms for 'demand' (@chrisn)
  • d0bf951 Updating minimist. (@chevex)
  • c15f8e7 Fix #31 (bad interaction between camelCase options and strict mode) (@nylen)
  • d991b9b Added .help() and .version() methods (@chrisn)
  • e8c8aa4 Added .showHelpOnFail() method (@chrisn)
  • e855af4 Allow boolean flag with .demand() (@chrisn)
  • 14dbec2 Fixes issue #22. Arguments are no longer printed to the console when using .config. (@chevex)
  • bef74fc Informing users that Yargs is the official optimist successor. (@chevex)
  • #24 Merge pull request #24 from chrisn/strict (@chrisn)
  • 889a2b2 Added requiresArg option, for options that require values (@chrisn)
  • eb16369 Added .strict() method, to report error if unknown arguments are given (@chrisn)
  • 0471c3f Changed optimist to yargs in usage-options.js example (@chrisn)
  • 5c88f74 Change optimist to yargs in examples (@chrisn)
  • 66f12c8 Fix a couple of bad interactions between aliases and defaults (@nylen)
  • 8fa1d80 Document second argument of usage(message, opts) (@Gobie)
  • 56e6528 For "--some-option", also set argv.someOption (@nylen)
  • ed5f6d3 Finished porting unit tests to Mocha. (@chevex)

v1.0.15 (2014/02/05 23:18 +00:00)

  • e2b1fc0 1.0.15 update to badges (@chevex)

v1.0.14 (2014/02/05 23:17 +00:00)

  • f33bbb0 Revert "Fixed issue which caused .demand function not to work correctly." (@chevex)

v1.0.13 (2014/02/05 22:13 +00:00)

  • 6509e5e Fixed issue which caused .demand function not to work correctly. (@chevex)

v1.0.12 (2013/12/13 00:09 +00:00)

v1.0.11 (2013/12/13 00:07 +00:00)

v1.0.10 (2013/12/12 23:57 +00:00)

  • dfebf81 Fixed formatting in README (@chevex)

v1.0.9 (2013/12/12 23:47 +00:00)

  • 0b4e34a Update README.md (@chevex)

v1.0.8 (2013/12/06 16:36 +00:00)

  • #1 fix error caused by check() see #1 (@martinheidegger)

v1.0.7 (2013/11/24 18:01 +00:00)

  • a247d88 Modified Pirate Joe image. (@chevex)

v1.0.6 (2013/11/23 19:21 +00:00)

  • d7f69e1 Updated Pirate Joe image. (@chevex)

v1.0.5 (2013/11/23 19:09 +00:00)

  • ece809c Updated readme notice again. (@chevex)

v1.0.4 (2013/11/23 19:05 +00:00)

  • 9e81e81 Updated README with a notice about yargs being a fork of optimist and what that implies. (@chevex)

v1.0.3 (2013/11/23 17:43 +00:00)

  • 65e7a78 Changed some small wording in README.md. (@chevex)
  • 459e20e Fix a bug in the options function, when string and boolean options weren't applied to aliases. (@shockone)

v1.0.2 (2013/11/23 09:46 +00:00)

v1.0.1 (2013/11/23 09:39 +00:00)

v1.0.0 (2013/11/23 09:33 +00:00)

  • 54e31d5 Rebranded from optimist to yargs in the spirit of the fork :D (@chevex)
  • 4ebb6c5 Added documentation for demandCount(). (@chevex)
  • 4561ce6 Simplified the error messages returned by .check(). (@chevex)
  • 661c678 Fixed an issue with demand not accepting a zero value. (@chevex)
  • 731dd3c Add .fail(fn) so death isn't the only option. Should fix issue #39. (@chevex)
  • fa15417 Added a few missing 'return self' (@chevex)
  • e655e4d Fix showing help in certain JS environments. (@chevex)
  • a746a31 Better string representation of default values. (@chevex)
  • 6134619 Implies: conditional demands (@chevex)
  • 046b93b Added support for JSON config files. (@chevex)
  • a677ec0 Add .example(cmd, desc) feature. (@chevex)
  • 1bd4375 Added 'defaults' as alias to 'default' so as to avoid usage of a reserved keyword. (@chevex)
  • 6b753c1 add .normalize(args..) support for normalizing paths (@chevex)
  • 33d7d59 Customize error messages with demand(key, msg) (@chevex)
  • 647d37f Merge branch 'rewrite-duplicate-test' of github.com:isbadawi/node-optimist (@chevex)
  • 9059d1a Pass aliases object to check functions for greater versatility. (@chevex)
  • 623dc26 Added ability to count boolean options and rolled minimist library back into project. (@chevex)
  • 49f0dce Fixed small typo. (@chevex)
  • 79ec980 Removed dependency on wordwrap module. (@chevex)
  • ea14630 Merge branch 'master' of github.com:chbrown/node-optimist (@chevex)
  • 2b75da2 Merge branch 'master' of github.com:seanzhou1023/node-optimist (@chevex)
  • d9bda11 Merge branch 'patch-1' of github.com:thefourtheye/node-optimist (@chevex)
  • d6cc606 Renamed README. (@chevex)
  • 9498d3f Renamed readme and added .gitignore. (@chevex)
  • bbd1fe3 Included examples for help and showHelp functions and fixed few formatting issues (@thefourtheye)
  • 37fea04 .alias({}) behaves differently based on mapping direction when generating descriptions (@chbrown)
  • 855b20d Documented function signatures are useful for dynamically typed languages. (@chbrown)

0.6.0 (2013/06/25 08:48 +00:00)

  • d37bfe0 all tests passing using minimist (@substack)
  • 76f1352 all parse tests now passing (@substack)
  • a7b6754 using minimist, some tests passing (@substack)
  • 6655688 Give credit where its due (@DeadAlready)
  • 602a2a9 v0.5.3 - Remove wordwrap as dependency (@DeadAlready)

0.5.2 (2013/05/31 03:46 +00:00)

  • 4497ca5 fixed the whitespace bug without breaking anything else (@substack)
  • 5a3dd1a failing test for whitespace arg (@substack)

0.5.1 (2013/05/30 07:17 +00:00)

  • a20228f fix parse() to work with functions before it (@substack)
  • b13bd4c failing test for parse() with modifiers (@substack)

0.5.0 (2013/05/18 21:59 +00:00)

  • c474a64 fixes for dash (@substack)

0.4.0 (2013/04/13 19:03 +00:00)

  • dafe3e1 failing short test (@substack)

0.3.7 (2013/04/04 04:07 +00:00)

  • 6c7a0ec Fix for windows. On windows there is no _ in environment. (@hdf)

0.3.6 (2013/04/04 04:04 +00:00)

  • e72346a Add support for newlines in -a="" arguments (@danielbeardsley)
  • 71e1fb5 drop 0.4, add 0.8 to travis (@substack)

0.3.5 (2012/10/10 11:09 +00:00)

  • ee692b3 Fix parsing booleans (@vojtajina)
  • 5045122 set $0 properly in the tests (@substack)

0.3.4 (2012/04/30 06:54 +00:00)

  • f28c0e6 bump for string "true" params (@substack)
  • 8f44aeb Fix failing test for aliased booleans. (@coderarity)
  • b9f7b61 Add failing test for short aliased booleans. (@coderarity)

0.3.3 (2012/04/30 06:45 +00:00)

0.3.2 (2012/04/12 20:28 +00:00)

  • 3a0f014 travis badge (@substack)
  • 4fb60bf Fix boolean aliases. (@coderarity)
  • f14dda5 Adjusted package.json to use tap (@jfhbrook)
  • 88e5d32 test/usage.js no longer hangs (@jfhbrook)
  • e1e740c two tests for combined boolean/alias opts parsing (@jfhbrook)

0.3.1 (2011/12/31 08:44 +00:00)

  • d09b719 If "default" is set to false it was not passed on, fixed. (@wolframkriesing)

0.3.0 (2011/12/09 06:03 +00:00)

  • 6e74aa7 bump and documented dot notation (@substack)

0.2.7 (2011/10/20 02:25 +00:00)

  • 94adee2 argv._ can be told 'Hey! argv._! Don't be messing with my args.', and it WILL obey (@colinta)
  • c46fdd5 optimistic critter image (@substack)
  • 5c95c73 alias options() to option() (@substack)
  • f7692ea [fix] Fix for parsing boolean edge case (@indexzero)
  • d1f92d1
  • b01bda8 [fix test] Update to ensure optimist is aware of default booleans. Associated tests included (@indexzero)
  • aa753e7 [dist test] Update devDependencies in package.json. Update test pathing to be more npm and require.paths future-proof (@indexzero)
  • 7bfce2f s/sys/util/ (@substack)
  • d420a7a update usage output (@substack)
  • cf86eed some sage readme protips about parsing rules (@substack)
  • 5da9f7a documented all the methods finally (@substack)
  • 8ca6879 fenced syntax highlighting (@substack)
  • b72bacf right-alignment of wrapped extra params (@substack)
  • 2b980bf now with .wrap() (@substack)
  • d614f63 don't show 'Options:' when there aren't any (@substack)
  • 691eda3 failing test for multi-aliasing (@substack)
  • 0826c9f "Options:" > "options:" (@substack)
  • 72f7490 [minor] Update formatting for .showHelp() (@indexzero)
  • 75aecce options works again, too lazy to write a proper test right now (@substack)
  • f742e54 line_count_options example, which breaks (@substack)
  • 4ca06b8 line count example (@substack)
  • eeb8423 remove self.argv setting in boolean (@substack)
  • 6903412 removed camel case for now (@substack)
  • 5a0d88b remove dead longest checking code (@substack)
  • d782170 .help() too (@substack)
  • 622ec17 rm old help generator (@substack)
  • 7c8baac nub keys (@substack)
  • 8197785 generate help message based on the previous calls, todo: nub (@substack)
  • 3ffbdc3 stub out new showHelp, better checks (@substack)
  • d4e21f5 let .options() take single options too (@substack)
  • 3c4cf29 .options() is now heaps simpler (@substack)
  • 89f0d04 defaults work again, all tests pass (@substack)
  • dd87333 update test error messages, down to 2 failing tests (@substack)
  • 53f7bc6 fix for bools doubling up, passes the parse test again, others fail (@substack)
  • 2213e2d refactored for an argv getter, failing several tests (@substack)
  • d1e7379 just rescan for now, alias test passes (@substack)
  • b2f8c99 failing alias test (@substack)
  • d0c0174 .alias() (@substack)
  • d85f431 [api] Remove .describe() in favor of building upon the existing .usage() API (@indexzero)
  • edbd527 [doc api] Add .describe(), .options(), and .showHelp() methods along with example. (@indexzero)
  • be4902f updates for coffee since it now does argv the node way (@substack)
  • e24cb23 more general coffeescript detection (@substack)
  • 78ac753 Don't trigger the CoffeeScript hack when running under node_g. (@papandreou)
  • bcfe973 .string() but failing test (@substack)
  • 1987aca test hex strings (@substack)
  • ef36db3 more keywords (@substack)
  • cc53c56 Added camelCase function that converts --multi-word-option to camel case (so it becomes argv.multiWordOption). (@papandreou)
  • 60b57da fixed boolean bug by rescanning (@substack)
  • dff6d07 boolean examples (@substack)
  • 0e380b9 boolean() with passing test (@substack)
  • 62644d4 coffee compatibility with node regex for versions too (@substack)
  • 430fafc argv._ fixed by fixing the coffee detection (@substack)
  • 343b8af whichNodeArgs test fails too (@substack)
  • 63df2f3 replicated mnot's bug in whichNodeEmpty test (@substack)
  • 35473a4 test for ./bin usage (@substack)
  • 13df151 don't coerce booleans to numbers (@substack)
  • 85f8007 package bump for automatic number conversion (@substack)
  • 8f17014 updated readme and examples with new auto-numberification goodness (@substack)
  • 73dc901 auto number conversion works yay (@substack)
  • bcec56b failing test for not-implemented auto numification (@substack)
  • ebd2844 odd that eql doesn't check types careflly (@substack)
  • fd854b0 package author + keywords (@substack)
  • 656a1d5 updated readme with .default() stuff (@substack)
  • cd7f8c5 passing tests for new .default() behavior (@substack)
  • 932725e new default() thing for setting default key/values (@substack)
  • 4e6c7ab test for coffee usage (@substack)
  • d54ffcc new --key value style with passing tests. NOTE: changes existing behavior (@substack)
  • ed2a2d5 package bump for summatix's coffee script fix (@substack)
  • 75a975e Added support for CoffeeScript (@summatix)
  • 56b2b1d test coverage for the falsy check() usage (@substack)
  • a4843a9 check bug fixed plus a handy string (@substack)
  • 857bd2d tests for demandCount, back up to 100% coverage (@substack)
  • 073b776 call demandCount from demand (@substack)
  • 4bd4b7a add demandCount to check for the number of arguments in the _ list (@marshall)
  • b8689ac Rebase checks. That will be its own module eventually. (@substack)
  • e688370 a $0 like in perl (@substack)
  • 2e5e196 usage test hacking around process and console (@substack)
  • fcc3521 description pun (@substack)
  • 87a1fe2 mit/x11 license (@substack)
  • 8d089d2 bool example is more consistent and also shows off short option grouping (@substack)
  • 448d747 start of the readme and examples (@substack)
  • da74dea more tests for long and short captures (@substack)
  • ab6387e silly bug in the tests with s/not/no/, all tests pass now (@substack)
  • 102496a hack an instance for process.argv onto Argv so the export can be called to create an instance or used for argv, which is the most common case (@substack)
  • a01caeb divide example (@substack)
  • 443da55 start of the lib with a package.json (@substack)