mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Initial commit
This commit is contained in:
3
node_modules/yargs/.npmignore
generated
vendored
Normal file
3
node_modules/yargs/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
node_modules/
|
||||
*.swp
|
3
node_modules/yargs/.travis.yml
generated
vendored
Normal file
3
node_modules/yargs/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
21
node_modules/yargs/LICENSE
generated
vendored
Normal file
21
node_modules/yargs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
Copyright 2010 James Halliday (mail@substack.net)
|
||||
|
||||
This project is free software released under the MIT/X11 license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
681
node_modules/yargs/README.md
generated
vendored
Normal file
681
node_modules/yargs/README.md
generated
vendored
Normal file
@@ -0,0 +1,681 @@
|
||||
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.
|
||||
|
||||
[](https://travis-ci.org/chevex/yargs)
|
||||
[](https://gemnasium.com/chevex/yargs)
|
||||
[](http://badge.fury.io/js/yargs)
|
||||
|
||||
> ~~NOTE: Yargs is a fork of [optimist](https://github.com/substack/node-optimist) by [substack (James Halliday)](https://github.com/substack). It is obvious that substack is stretched pretty thin maintaining over 300 modules on npm at the time of this writing. So rather than complain in the project issue tracker I thought I'd just pick up the torch and maintain a proper fork. Currently the project is totally backward compatible with optimist but this may change in the future (if it does I will update this notice to inform you of this). For now though, enjoy optimist with about 5 months worth of fixes and updates rolled in, most of them pulled from optimist's own [stale pull requests](https://github.com/substack/node-optimist/pulls).~~
|
||||
|
||||
> UPDATE: Yargs is now the official successor to optimist. Please feel free to submit issues and pull requests. While I personally don't have the time to pore over all the issues and fix all of them on a regular basis, I'm more than happy to look over pull requests, test them, and merge them in. If you'd like to contribute and don't know where to start, have a look at [the issue list](https://github.com/chevex/yargs/issues) :)
|
||||
|
||||
examples
|
||||
========
|
||||
|
||||
With yargs, the options be just a hash!
|
||||
-------------------------------------------------------------------
|
||||
|
||||
xup.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
if (argv.rif - 5 * argv.xup > 7.138) {
|
||||
console.log('Plunder more riffiwobbles!');
|
||||
}
|
||||
else {
|
||||
console.log('Drop the xupptumblers!');
|
||||
}
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./xup.js --rif=55 --xup=9.52
|
||||
Plunder more riffiwobbles!
|
||||
|
||||
$ ./xup.js --rif 12 --xup 8.1
|
||||
Drop the xupptumblers!
|
||||
|
||||

|
||||
|
||||
But don't walk the plank just yet! There be more! You can do short options:
|
||||
-------------------------------------------------
|
||||
|
||||
short.js:
|
||||
|
||||
````javascript
|
||||
#!/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:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var util = require('util');
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
if (argv.s) {
|
||||
util.print(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:
|
||||
|
||||
````javascript
|
||||
#!/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
|
||||
|
||||
````javascript
|
||||
#!/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-mportant 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.
|
||||
-------------------------------------------------
|
||||
|
||||
divide.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Usage: $0 -x [num] -y [num]')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
|
||||
console.log(argv.x / argv.y);
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./divide.js -x 55 -y 11
|
||||
5
|
||||
|
||||
$ node ./divide.js -x 4.91 -z 2.51
|
||||
Usage: node ./divide.js -x [num] -y [num]
|
||||
|
||||
Options:
|
||||
-x [required]
|
||||
-y [required]
|
||||
|
||||
Missing required arguments: y
|
||||
|
||||
After yer demands have been met, demand more! Ask for non-hypenated arguments!
|
||||
-----------------------------------------
|
||||
|
||||
demand_count.js:
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.demand(2)
|
||||
.argv;
|
||||
console.dir(argv)
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ ./demand_count.js a
|
||||
Not enough arguments, expected 2, but only found 1
|
||||
$ ./demand_count.js a b
|
||||
{ _: [ 'a', 'b' ], '$0': 'node ./demand_count.js' }
|
||||
$ ./demand_count.js a b c
|
||||
{ _: [ 'a', 'b', 'c' ], '$0': 'node ./demand_count.js' }
|
||||
|
||||
EVEN MORE SHIVER ME TIMBERS!
|
||||
------------------
|
||||
|
||||
default_singles.js:
|
||||
|
||||
````javascript
|
||||
#!/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:
|
||||
|
||||
````javascript
|
||||
#!/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
|
||||
|
||||
````javascript
|
||||
#!/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
|
||||
|
||||
````javascript
|
||||
#!/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
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.example('$0 -f', 'count the lines in the given file')
|
||||
.demand('f')
|
||||
.alias('f', 'file')
|
||||
.describe('f', 'Load a file')
|
||||
.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 the lines in a file.
|
||||
Usage: node ./line_count.js
|
||||
|
||||
Examples:
|
||||
node ./line_count.js -f count the lines in the given file
|
||||
|
||||
Options:
|
||||
-f, --file Load a file [required]
|
||||
|
||||
Missing required arguments: f
|
||||
|
||||
$ node line_count.js --file line_count.js
|
||||
20
|
||||
|
||||
$ node line_count.js -f line_count.js
|
||||
20
|
||||
|
||||
methods
|
||||
=======
|
||||
|
||||
By itself,
|
||||
|
||||
````javascript
|
||||
require('yargs').argv
|
||||
`````
|
||||
|
||||
will use `process.argv` array to construct the `argv` object.
|
||||
|
||||
You can pass in the `process.argv` yourself:
|
||||
|
||||
````javascript
|
||||
require('yargs')([ '-x', '1', '-y', '2' ]).argv
|
||||
````
|
||||
|
||||
or use .parse() to do the same thing:
|
||||
|
||||
````javascript
|
||||
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.
|
||||
|
||||
.default(key, value)
|
||||
--------------------
|
||||
|
||||
Set `argv[key]` to `value` if no option was specified on `process.argv`.
|
||||
|
||||
Optionally `.default()` can take an object that maps keys to default values.
|
||||
|
||||
.demand(key, [msg | boolean])
|
||||
-----------------------------
|
||||
.require(key, [msg | boolean])
|
||||
------------------------------
|
||||
.required(key, [msg | boolean])
|
||||
-------------------------------
|
||||
|
||||
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._`.
|
||||
|
||||
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.
|
||||
|
||||
.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 behaviour is to set the value of any key not followed by an
|
||||
option value to `true`.
|
||||
|
||||
.describe(key, desc)
|
||||
--------------------
|
||||
|
||||
Describe a `key` for the generated usage information.
|
||||
|
||||
Optionally `.describe()` can take an object that maps keys to descriptions.
|
||||
|
||||
.options(key, opt)
|
||||
------------------
|
||||
|
||||
Instead of chaining together `.alias().demand().default()`, you can specify
|
||||
keys in `opt` for each of the chainable methods.
|
||||
|
||||
For example:
|
||||
|
||||
````javascript
|
||||
var argv = require('yargs')
|
||||
.options('f', {
|
||||
alias : 'file',
|
||||
default : '/etc/passwd',
|
||||
})
|
||||
.argv
|
||||
;
|
||||
````
|
||||
|
||||
is the same as
|
||||
|
||||
````javascript
|
||||
var argv = require('yargs')
|
||||
.alias('f', 'file')
|
||||
.default('f', '/etc/passwd')
|
||||
.argv
|
||||
;
|
||||
````
|
||||
|
||||
Optionally `.options()` can take an object that maps keys to `opt` parameters.
|
||||
|
||||
.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)`.
|
||||
|
||||
.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.
|
||||
|
||||
.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 `false`, show the thrown error, usage information, and
|
||||
exit.
|
||||
|
||||
.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`.
|
||||
|
||||
If `key` never shows up as a flag in `process.arguments`, `argv[key]` will be
|
||||
`false`.
|
||||
|
||||
If `key` is an Array, interpret all the elements as booleans.
|
||||
|
||||
.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.
|
||||
|
||||
.config(key)
|
||||
------------
|
||||
|
||||
Tells the parser to interpret `key` as a path to a JSON config file. The file
|
||||
is loaded and parsed, and its properties are set as arguments.
|
||||
|
||||
.wrap(columns)
|
||||
--------------
|
||||
|
||||
Format usage output to wrap at `columns` many columns.
|
||||
|
||||
.strict()
|
||||
---------
|
||||
|
||||
Any command-line argument given that is not demanded, or does not have a
|
||||
corresponding description, will be reported as an error.
|
||||
|
||||
.help([option, [description]])
|
||||
------------------------------
|
||||
|
||||
Add an option (e.g., `--help`) that displays the usage string and exits the
|
||||
process. If present, the `description` parameter customises 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 retrived with ```yargs.argv```
|
||||
|
||||
.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 customises the description of the version option in the usage string.
|
||||
|
||||
.showHelpOnFail(enable, [message])
|
||||
----------------------------------
|
||||
|
||||
By default, yargs outputs a usage string if any error is detected. Use the
|
||||
`.showHelpOnFail` method to customize this behaviour. 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
|
||||
|
||||
````javascript
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.demand('f')
|
||||
.alias('f', 'file')
|
||||
.describe('f', 'Load a file')
|
||||
.showHelpOnFail(false, "Specify --help for available options")
|
||||
.argv;
|
||||
|
||||
// etc.
|
||||
````
|
||||
|
||||
***
|
||||
|
||||
$ node line_count.js --file
|
||||
Missing argument value: f
|
||||
|
||||
Specify --help for available options
|
||||
|
||||
.showHelp(fn=console.error)
|
||||
---------------------------
|
||||
|
||||
Print the usage data using `fn` for printing.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
var yargs = require("yargs")
|
||||
.usage("$0 -operand1 number -operand2 number -operation [add|subtract]");
|
||||
yargs.showHelp();
|
||||
```
|
||||
|
||||
Later on, ```argv``` can be retrived with ```yargs.argv```
|
||||
|
||||
.parse(args)
|
||||
------------
|
||||
|
||||
Parse `args` instead of `process.argv`. Returns the `argv` object.
|
||||
|
||||
.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.
|
||||
|
||||
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' ],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
a: 1,
|
||||
b: 2 }
|
||||
|
||||
negate fields
|
||||
-------------
|
||||
|
||||
If you want to explicity 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
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
a: true,
|
||||
b: false }
|
||||
|
||||
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
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
x: [ 5, 8, 0 ] }
|
||||
|
||||
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
|
||||
{ _: [],
|
||||
'$0': 'node ./examples/reflect.js',
|
||||
foo: { bar: { baz: 33 }, quux: 5 } }
|
||||
|
||||
short numbers
|
||||
-------------
|
||||
|
||||
Short numeric `head -n5` style argument work too:
|
||||
|
||||
$ node reflect.js -n123 -m456
|
||||
{ '3': true,
|
||||
'6': true,
|
||||
_: [],
|
||||
'$0': 'node ./reflect.js',
|
||||
n: 123,
|
||||
m: 456 }
|
||||
|
||||
installation
|
||||
============
|
||||
|
||||
With [npm](http://github.com/isaacs/npm), just do:
|
||||
|
||||
npm install yargs
|
||||
|
||||
or clone this project on github:
|
||||
|
||||
git clone http://github.com/chevex/yargs.git
|
||||
|
||||
To run the tests with [expresso](http://github.com/visionmedia/expresso),
|
||||
just do:
|
||||
|
||||
expresso
|
||||
|
||||
inspired By
|
||||
===========
|
||||
|
||||
This module is loosely inspired by Perl's
|
||||
[Getopt::Casual](http://search.cpan.org/~photo/Getopt-Casual-0.13.1/Casual.pm).
|
10
node_modules/yargs/example/bool.js
generated
vendored
Normal file
10
node_modules/yargs/example/bool.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
var util = require('util');
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
if (argv.s) {
|
||||
util.print(argv.fr ? 'Le chat dit: ' : 'The cat says: ');
|
||||
}
|
||||
console.log(
|
||||
(argv.fr ? 'miaou' : 'meow') + (argv.p ? '.' : '')
|
||||
);
|
7
node_modules/yargs/example/boolean_double.js
generated
vendored
Normal file
7
node_modules/yargs/example/boolean_double.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.boolean(['x','y','z'])
|
||||
.argv
|
||||
;
|
||||
console.dir([ argv.x, argv.y, argv.z ]);
|
||||
console.dir(argv._);
|
7
node_modules/yargs/example/boolean_single.js
generated
vendored
Normal file
7
node_modules/yargs/example/boolean_single.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.boolean('v')
|
||||
.argv
|
||||
;
|
||||
console.dir(argv.v);
|
||||
console.dir(argv._);
|
15
node_modules/yargs/example/count.js
generated
vendored
Normal file
15
node_modules/yargs/example/count.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/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");
|
8
node_modules/yargs/example/default_hash.js
generated
vendored
Normal file
8
node_modules/yargs/example/default_hash.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('yargs')
|
||||
.default({ x : 10, y : 10 })
|
||||
.argv
|
||||
;
|
||||
|
||||
console.log(argv.x + argv.y);
|
7
node_modules/yargs/example/default_singles.js
generated
vendored
Normal file
7
node_modules/yargs/example/default_singles.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.default('x', 10)
|
||||
.default('y', 10)
|
||||
.argv
|
||||
;
|
||||
console.log(argv.x + argv.y);
|
5
node_modules/yargs/example/demand_count.js
generated
vendored
Normal file
5
node_modules/yargs/example/demand_count.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.demand(2)
|
||||
.argv;
|
||||
console.dir(argv)
|
8
node_modules/yargs/example/divide.js
generated
vendored
Normal file
8
node_modules/yargs/example/divide.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('yargs')
|
||||
.usage('Usage: $0 -x [num] -y [num]')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
|
||||
console.log(argv.x / argv.y);
|
27
node_modules/yargs/example/help.js
generated
vendored
Normal file
27
node_modules/yargs/example/help.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var yargs = require('../index');
|
||||
|
||||
var argv = yargs
|
||||
.usage('This is my awesome program\n\nUsage: $0 [options]')
|
||||
.help('help').alias('help', 'h')
|
||||
.version('1.0.1', 'version').alias('version', 'V')
|
||||
.options({
|
||||
input: {
|
||||
alias: 'i',
|
||||
description: "<filename> Input file name",
|
||||
requiresArg: true,
|
||||
required: true
|
||||
},
|
||||
output: {
|
||||
alias: 'o',
|
||||
description: "<filename> output file name",
|
||||
requiresArg: true,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
.argv;
|
||||
|
||||
console.log('Inspecting options');
|
||||
console.dir(argv);
|
||||
|
||||
console.log("input:", argv.input);
|
||||
console.log("output:", argv.output);
|
10
node_modules/yargs/example/implies.js
generated
vendored
Normal file
10
node_modules/yargs/example/implies.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('yargs')
|
||||
.usage('Usage: $0 -x [num] -y [num]')
|
||||
.implies('x', 'y')
|
||||
.argv;
|
||||
|
||||
if (argv.x) {
|
||||
console.log(argv.x / argv.y);
|
||||
}
|
26
node_modules/yargs/example/implies_hash.js
generated
vendored
Normal file
26
node_modules/yargs/example/implies_hash.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var argv = require('yargs')
|
||||
.usage('Usage: $0 -x [num] -y [num] -w [msg] -h [msg]')
|
||||
.implies({
|
||||
x: 'y',
|
||||
w: '--no-h',
|
||||
1: 'h'
|
||||
})
|
||||
.argv;
|
||||
|
||||
if (argv.x) {
|
||||
console.log('x / y : ' + (argv.x / argv.y));
|
||||
}
|
||||
|
||||
if (argv.y) {
|
||||
console.log('y: ' + argv.y);
|
||||
}
|
||||
|
||||
if (argv.w) {
|
||||
console.log('w: ' +argv.w);
|
||||
}
|
||||
|
||||
if (argv.h) {
|
||||
console.log('h: ' +argv.h);
|
||||
}
|
20
node_modules/yargs/example/line_count.js
generated
vendored
Normal file
20
node_modules/yargs/example/line_count.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.demand('f')
|
||||
.alias('f', 'file')
|
||||
.describe('f', 'Load a file')
|
||||
.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);
|
||||
});
|
29
node_modules/yargs/example/line_count_options.js
generated
vendored
Normal file
29
node_modules/yargs/example/line_count_options.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.options({
|
||||
file : {
|
||||
demand : true,
|
||||
alias : 'f',
|
||||
description : 'Load a file'
|
||||
},
|
||||
base : {
|
||||
alias : 'b',
|
||||
description : 'Numeric base to use for output',
|
||||
default : 10,
|
||||
},
|
||||
})
|
||||
.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.toString(argv.base));
|
||||
});
|
29
node_modules/yargs/example/line_count_wrap.js
generated
vendored
Normal file
29
node_modules/yargs/example/line_count_wrap.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.usage('Count the lines in a file.\nUsage: $0')
|
||||
.wrap(80)
|
||||
.demand('f')
|
||||
.alias('f', [ 'file', 'filename' ])
|
||||
.describe('f',
|
||||
"Load a file. It's pretty important."
|
||||
+ " Required even. So you'd better specify it."
|
||||
)
|
||||
.alias('b', 'base')
|
||||
.describe('b', 'Numeric base to display the number of lines in')
|
||||
.default('b', 10)
|
||||
.describe('x', 'Super-secret optional parameter which is secret')
|
||||
.default('x', '')
|
||||
.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.toString(argv.base));
|
||||
});
|
4
node_modules/yargs/example/nonopt.js
generated
vendored
Normal file
4
node_modules/yargs/example/nonopt.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
||||
console.log(argv._);
|
19
node_modules/yargs/example/requires_arg.js
generated
vendored
Normal file
19
node_modules/yargs/example/requires_arg.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var yargs = require('yargs');
|
||||
|
||||
var argv = yargs.usage('This is my awesome program', {
|
||||
'input': {
|
||||
description: 'Input file name',
|
||||
requiresArg: true,
|
||||
short: 'i',
|
||||
},
|
||||
'output': {
|
||||
description: 'Output file name',
|
||||
requiresArg: true,
|
||||
short: 'o'
|
||||
}
|
||||
}).argv;
|
||||
|
||||
yargs.showHelp();
|
||||
|
||||
console.log('\n\nInspecting options');
|
||||
console.dir(argv);
|
3
node_modules/yargs/example/short.js
generated
vendored
Normal file
3
node_modules/yargs/example/short.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs').argv;
|
||||
console.log('(%d,%d)', argv.x, argv.y);
|
19
node_modules/yargs/example/strict.js
generated
vendored
Normal file
19
node_modules/yargs/example/strict.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var yargs = require('yargs');
|
||||
|
||||
var argv = yargs.usage('This is my awesome program', {
|
||||
'about': {
|
||||
description: 'Provide some details about the author of this program',
|
||||
boolean: true,
|
||||
short: 'a',
|
||||
},
|
||||
'info': {
|
||||
description: 'Provide some information about this program',
|
||||
boolean: true,
|
||||
short: 'i'
|
||||
}
|
||||
}).strict().argv;
|
||||
|
||||
yargs.showHelp();
|
||||
|
||||
console.log('\n\nInspecting options');
|
||||
console.dir(argv);
|
11
node_modules/yargs/example/string.js
generated
vendored
Normal file
11
node_modules/yargs/example/string.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs')
|
||||
.string('x', 'y')
|
||||
.argv
|
||||
;
|
||||
console.dir([ argv.x, argv.y ]);
|
||||
|
||||
/* Turns off numeric coercion:
|
||||
./node string.js -x 000123 -y 9876
|
||||
[ '000123', '9876' ]
|
||||
*/
|
19
node_modules/yargs/example/usage-options.js
generated
vendored
Normal file
19
node_modules/yargs/example/usage-options.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var yargs = require('yargs');
|
||||
|
||||
var argv = yargs.usage('This is my awesome program', {
|
||||
'about': {
|
||||
description: 'Provide some details about the author of this program',
|
||||
required: true,
|
||||
alias: 'a',
|
||||
},
|
||||
'info': {
|
||||
description: 'Provide some information about the node.js agains!!!!!!',
|
||||
boolean: true,
|
||||
alias: 'i'
|
||||
}
|
||||
}).argv;
|
||||
|
||||
yargs.showHelp();
|
||||
|
||||
console.log('\n\nInspecting options');
|
||||
console.dir(argv);
|
9
node_modules/yargs/example/xup.js
generated
vendored
Normal file
9
node_modules/yargs/example/xup.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('yargs').argv;
|
||||
|
||||
if (argv.rif - 5 * argv.xup > 7.138) {
|
||||
console.log('Buy more riffiwobbles');
|
||||
}
|
||||
else {
|
||||
console.log('Sell the xupptumblers');
|
||||
}
|
638
node_modules/yargs/index.js
generated
vendored
Normal file
638
node_modules/yargs/index.js
generated
vendored
Normal file
@@ -0,0 +1,638 @@
|
||||
var path = require('path');
|
||||
var minimist = require('./lib/minimist');
|
||||
var wordwrap = require('./lib/wordwrap');
|
||||
|
||||
/* Hack an instance of Argv with process.argv into Argv
|
||||
so people can do
|
||||
require('yargs')(['--beeble=1','-z','zizzle']).argv
|
||||
to parse a list of args and
|
||||
require('yargs').argv
|
||||
to get a parsed version of process.argv.
|
||||
*/
|
||||
|
||||
var inst = Argv(process.argv.slice(2));
|
||||
Object.keys(inst).forEach(function (key) {
|
||||
Argv[key] = typeof inst[key] == 'function'
|
||||
? inst[key].bind(inst)
|
||||
: inst[key];
|
||||
});
|
||||
|
||||
var exports = module.exports = Argv;
|
||||
function Argv (processArgs, cwd) {
|
||||
var self = {};
|
||||
if (!cwd) cwd = process.cwd();
|
||||
|
||||
self.$0 = process.argv
|
||||
.slice(0,2)
|
||||
.map(function (x) {
|
||||
var b = rebase(cwd, x);
|
||||
return x.match(/^\//) && b.length < x.length
|
||||
? b : x
|
||||
})
|
||||
.join(' ')
|
||||
;
|
||||
|
||||
if (process.env._ != undefined && process.argv[1] == process.env._) {
|
||||
self.$0 = process.env._.replace(
|
||||
path.dirname(process.execPath) + '/', ''
|
||||
);
|
||||
}
|
||||
|
||||
var options;
|
||||
self.resetOptions = function () {
|
||||
options = {
|
||||
boolean: [],
|
||||
string: [],
|
||||
alias: {},
|
||||
default: [],
|
||||
requiresArg: [],
|
||||
count: [],
|
||||
normalize: [],
|
||||
config: []
|
||||
};
|
||||
return self;
|
||||
};
|
||||
self.resetOptions();
|
||||
|
||||
self.boolean = function (bools) {
|
||||
options.boolean.push.apply(options.boolean, [].concat(bools));
|
||||
return self;
|
||||
};
|
||||
|
||||
self.normalize = function (strings) {
|
||||
options.normalize.push.apply(options.normalize, [].concat(strings));
|
||||
return self;
|
||||
};
|
||||
|
||||
self.config = function (configs) {
|
||||
options.config.push.apply(options.config, [].concat(configs));
|
||||
return self;
|
||||
};
|
||||
|
||||
var examples = [];
|
||||
self.example = function (cmd, description) {
|
||||
examples.push([cmd, description]);
|
||||
return self;
|
||||
};
|
||||
|
||||
self.string = function (strings) {
|
||||
options.string.push.apply(options.string, [].concat(strings));
|
||||
return self;
|
||||
};
|
||||
|
||||
self.default = function (key, value) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.default(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
options.default[key] = value;
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
self.alias = function (x, y) {
|
||||
if (typeof x === 'object') {
|
||||
Object.keys(x).forEach(function (key) {
|
||||
self.alias(key, x[key]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
options.alias[x] = (options.alias[x] || []).concat(y);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
self.count = function(counts) {
|
||||
options.count.push.apply(options.count, [].concat(counts));
|
||||
return self;
|
||||
};
|
||||
|
||||
var demanded = {};
|
||||
self.demand = self.required = self.require = function (keys, msg) {
|
||||
if (typeof keys == 'number') {
|
||||
if (!demanded._) demanded._ = { count: 0, msg: null };
|
||||
demanded._.count += keys;
|
||||
demanded._.msg = msg;
|
||||
}
|
||||
else if (Array.isArray(keys)) {
|
||||
keys.forEach(function (key) {
|
||||
self.demand(key, msg);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (typeof msg === 'string') {
|
||||
demanded[keys] = { msg: msg };
|
||||
}
|
||||
else if (msg === true || typeof msg === 'undefined') {
|
||||
demanded[keys] = { msg: null };
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
self.requiresArg = function (requiresArgs) {
|
||||
options.requiresArg.push.apply(options.requiresArg, [].concat(requiresArgs));
|
||||
return self;
|
||||
};
|
||||
|
||||
var implied = {};
|
||||
self.implies = function (key, value) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.implies(k, key[k]);
|
||||
});
|
||||
} else {
|
||||
implied[key] = value;
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
var usage;
|
||||
self.usage = function (msg, opts) {
|
||||
if (!opts && typeof msg === 'object') {
|
||||
opts = msg;
|
||||
msg = null;
|
||||
}
|
||||
|
||||
usage = msg;
|
||||
|
||||
if (opts) self.options(opts);
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
var fails = [];
|
||||
self.fail = function (f) {
|
||||
fails.push(f);
|
||||
return self;
|
||||
};
|
||||
|
||||
function fail (msg) {
|
||||
if (fails.length) {
|
||||
fails.forEach(function (f) {
|
||||
f(msg);
|
||||
});
|
||||
} else {
|
||||
if (showHelpOnFail) {
|
||||
self.showHelp();
|
||||
}
|
||||
if (msg) console.error(msg);
|
||||
if (failMessage) {
|
||||
if (msg) {
|
||||
console.error("");
|
||||
}
|
||||
console.error(failMessage);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
var checks = [];
|
||||
self.check = function (f) {
|
||||
checks.push(f);
|
||||
return self;
|
||||
};
|
||||
|
||||
self.defaults = self.default;
|
||||
|
||||
var descriptions = {};
|
||||
self.describe = function (key, desc) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.describe(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
descriptions[key] = desc;
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
self.parse = function (args) {
|
||||
return parseArgs(args);
|
||||
};
|
||||
|
||||
self.option = self.options = function (key, opt) {
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(function (k) {
|
||||
self.options(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (opt.alias) self.alias(key, opt.alias);
|
||||
|
||||
var demand = opt.demand || opt.required || opt.require;
|
||||
if (demand) {
|
||||
self.demand(key, demand);
|
||||
}
|
||||
|
||||
if (typeof opt.default !== 'undefined') {
|
||||
self.default(key, opt.default);
|
||||
}
|
||||
|
||||
if (opt.boolean || opt.type === 'boolean') {
|
||||
self.boolean(key);
|
||||
if (opt.alias) self.boolean(opt.alias);
|
||||
}
|
||||
if (opt.string || opt.type === 'string') {
|
||||
self.string(key);
|
||||
if (opt.alias) self.string(opt.alias);
|
||||
}
|
||||
if (opt.count || opt.type === 'count') {
|
||||
self.count(key);
|
||||
}
|
||||
|
||||
var desc = opt.describe || opt.description || opt.desc;
|
||||
if (desc) {
|
||||
self.describe(key, desc);
|
||||
}
|
||||
|
||||
if (opt.requiresArg) {
|
||||
self.requiresArg(key);
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
var wrap = null;
|
||||
self.wrap = function (cols) {
|
||||
wrap = cols;
|
||||
return self;
|
||||
};
|
||||
|
||||
var strict = false;
|
||||
self.strict = function () {
|
||||
strict = true;
|
||||
return self;
|
||||
};
|
||||
|
||||
self.showHelp = function (fn) {
|
||||
if (!fn) fn = console.error.bind(console);
|
||||
fn(self.help());
|
||||
return self;
|
||||
};
|
||||
|
||||
var version = null;
|
||||
var versionOpt = null;
|
||||
self.version = function (ver, opt, msg) {
|
||||
version = ver;
|
||||
versionOpt = opt;
|
||||
self.describe(opt, msg || 'Show version number');
|
||||
return self;
|
||||
};
|
||||
|
||||
var helpOpt = null;
|
||||
self.addHelpOpt = function (opt, msg) {
|
||||
helpOpt = opt;
|
||||
self.describe(opt, msg || 'Show help');
|
||||
return self;
|
||||
};
|
||||
|
||||
var failMessage = null;
|
||||
var showHelpOnFail = true;
|
||||
self.showHelpOnFail = function (enabled, message) {
|
||||
if (typeof enabled === 'string') {
|
||||
enabled = true;
|
||||
message = enabled;
|
||||
}
|
||||
else if (typeof enabled === 'undefined') {
|
||||
enabled = true;
|
||||
}
|
||||
failMessage = message;
|
||||
showHelpOnFail = enabled;
|
||||
return self;
|
||||
};
|
||||
|
||||
|
||||
self.help = function () {
|
||||
if (arguments.length > 0) {
|
||||
return self.addHelpOpt.apply(self, arguments);
|
||||
}
|
||||
|
||||
var keys = Object.keys(
|
||||
Object.keys(descriptions)
|
||||
.concat(Object.keys(demanded))
|
||||
.concat(Object.keys(options.default))
|
||||
.reduce(function (acc, key) {
|
||||
if (key !== '_') acc[key] = true;
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
var help = keys.length ? [ 'Options:' ] : [];
|
||||
|
||||
if (examples.length) {
|
||||
help.unshift('');
|
||||
examples.forEach(function (example) {
|
||||
example[0] = example[0].replace(/\$0/g, self.$0);
|
||||
});
|
||||
|
||||
var commandlen = longest(examples.map(function (a) {
|
||||
return a[0];
|
||||
}));
|
||||
|
||||
var exampleLines = examples.map(function(example) {
|
||||
var command = example[0];
|
||||
var description = example[1];
|
||||
command += Array(commandlen + 5 - command.length).join(' ');
|
||||
return ' ' + command + description;
|
||||
});
|
||||
|
||||
exampleLines.push('');
|
||||
help = exampleLines.concat(help);
|
||||
help.unshift('Examples:');
|
||||
}
|
||||
|
||||
if (usage) {
|
||||
help.unshift(usage.replace(/\$0/g, self.$0), '');
|
||||
}
|
||||
|
||||
var aliasKeys = (Object.keys(options.alias) || [])
|
||||
.concat(Object.keys(self.parsed.newAliases) || []);
|
||||
|
||||
keys = keys.filter(function(key) {
|
||||
return !self.parsed.newAliases[key] && aliasKeys.every(function(alias) {
|
||||
return -1 == (options.alias[alias] || []).indexOf(key);
|
||||
});
|
||||
});
|
||||
var switches = keys.reduce(function (acc, key) {
|
||||
acc[key] = [ key ].concat(options.alias[key] || [])
|
||||
.map(function (sw) {
|
||||
return (sw.length > 1 ? '--' : '-') + sw
|
||||
})
|
||||
.join(', ')
|
||||
;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
var switchlen = longest(Object.keys(switches).map(function (s) {
|
||||
return switches[s] || '';
|
||||
}));
|
||||
|
||||
var desclen = longest(Object.keys(descriptions).map(function (d) {
|
||||
return descriptions[d] || '';
|
||||
}));
|
||||
|
||||
keys.forEach(function (key) {
|
||||
var kswitch = switches[key];
|
||||
var desc = descriptions[key] || '';
|
||||
|
||||
if (wrap) {
|
||||
desc = wordwrap(switchlen + 4, wrap)(desc)
|
||||
.slice(switchlen + 4)
|
||||
;
|
||||
}
|
||||
|
||||
var spadding = new Array(
|
||||
Math.max(switchlen - kswitch.length + 3, 0)
|
||||
).join(' ');
|
||||
|
||||
var dpadding = new Array(
|
||||
Math.max(desclen - desc.length + 1, 0)
|
||||
).join(' ');
|
||||
|
||||
var type = null;
|
||||
|
||||
if (options.boolean[key]) type = '[boolean]';
|
||||
if (options.count[key]) type = '[count]';
|
||||
if (options.string[key]) type = '[string]';
|
||||
if (options.normalize[key]) type = '[string]';
|
||||
|
||||
if (!wrap && dpadding.length > 0) {
|
||||
desc += dpadding;
|
||||
}
|
||||
|
||||
var prelude = ' ' + kswitch + spadding;
|
||||
var extra = [
|
||||
type,
|
||||
demanded[key]
|
||||
? '[required]'
|
||||
: null
|
||||
,
|
||||
options.default[key] !== undefined
|
||||
? '[default: ' + (typeof options.default[key] === 'string' ?
|
||||
JSON.stringify : String)(options.default[key]) + ']'
|
||||
: null
|
||||
].filter(Boolean).join(' ');
|
||||
|
||||
var body = [ desc, extra ].filter(Boolean).join(' ');
|
||||
|
||||
if (wrap) {
|
||||
var dlines = desc.split('\n');
|
||||
var dlen = dlines.slice(-1)[0].length
|
||||
+ (dlines.length === 1 ? prelude.length : 0)
|
||||
|
||||
body = desc + (dlen + extra.length > wrap - 2
|
||||
? '\n'
|
||||
+ new Array(wrap - extra.length + 1).join(' ')
|
||||
+ extra
|
||||
: new Array(wrap - extra.length - dlen + 1).join(' ')
|
||||
+ extra
|
||||
);
|
||||
}
|
||||
|
||||
help.push(prelude + body);
|
||||
});
|
||||
|
||||
if (keys.length) help.push('');
|
||||
return help.join('\n');
|
||||
};
|
||||
|
||||
Object.defineProperty(self, 'argv', {
|
||||
get : function () { return parseArgs(processArgs) },
|
||||
enumerable : true
|
||||
});
|
||||
|
||||
function parseArgs (args) {
|
||||
var parsed = minimist(args, options),
|
||||
argv = parsed.argv,
|
||||
aliases = parsed.aliases;
|
||||
|
||||
argv.$0 = self.$0;
|
||||
|
||||
self.parsed = parsed;
|
||||
|
||||
Object.keys(argv).forEach(function(key) {
|
||||
if (key === helpOpt) {
|
||||
self.showHelp(console.log);
|
||||
process.exit(0);
|
||||
}
|
||||
else if (key === versionOpt) {
|
||||
process.stdout.write(version);
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
if (demanded._ && argv._.length < demanded._.count) {
|
||||
if (demanded._.msg) {
|
||||
fail(demanded._.msg);
|
||||
} else {
|
||||
fail('Not enough non-option arguments: got '
|
||||
+ argv._.length + ', need at least ' + demanded._.count
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.requiresArg.length > 0) {
|
||||
var missingRequiredArgs = [];
|
||||
|
||||
options.requiresArg.forEach(function(key) {
|
||||
var value = argv[key];
|
||||
|
||||
// minimist sets --foo value to true / --no-foo to false
|
||||
if (value === true || value === false) {
|
||||
missingRequiredArgs.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequiredArgs.length == 1) {
|
||||
fail("Missing argument value: " + missingRequiredArgs[0]);
|
||||
}
|
||||
else if (missingRequiredArgs.length > 1) {
|
||||
message = "Missing argument values: " + missingRequiredArgs.join(", ");
|
||||
fail(message);
|
||||
}
|
||||
}
|
||||
|
||||
var missing = null;
|
||||
Object.keys(demanded).forEach(function (key) {
|
||||
if (!argv.hasOwnProperty(key)) {
|
||||
missing = missing || {};
|
||||
missing[key] = demanded[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (missing) {
|
||||
var customMsgs = [];
|
||||
Object.keys(missing).forEach(function(key) {
|
||||
var msg = missing[key].msg;
|
||||
if (msg && customMsgs.indexOf(msg) < 0) {
|
||||
customMsgs.push(msg);
|
||||
}
|
||||
});
|
||||
var customMsg = customMsgs.length ? '\n' + customMsgs.join('\n') : '';
|
||||
|
||||
fail('Missing required arguments: ' + Object.keys(missing).join(', ') + customMsg);
|
||||
}
|
||||
|
||||
if (strict) {
|
||||
var unknown = [];
|
||||
|
||||
var aliases = {};
|
||||
|
||||
Object.keys(parsed.aliases).forEach(function (key) {
|
||||
parsed.aliases[key].forEach(function (alias) {
|
||||
aliases[alias] = key;
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(argv).forEach(function (key) {
|
||||
if (key !== "$0" && key !== "_" &&
|
||||
!descriptions.hasOwnProperty(key) &&
|
||||
!demanded.hasOwnProperty(key) &&
|
||||
!aliases.hasOwnProperty(key)) {
|
||||
unknown.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
if (unknown.length == 1) {
|
||||
fail("Unknown argument: " + unknown[0]);
|
||||
}
|
||||
else if (unknown.length > 1) {
|
||||
fail("Unknown arguments: " + unknown.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
checks.forEach(function (f) {
|
||||
try {
|
||||
var result = f(argv, aliases);
|
||||
if (result === false) {
|
||||
fail('Argument check failed: ' + f.toString());
|
||||
} else if (typeof result === 'string') {
|
||||
fail(result);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
fail(err)
|
||||
}
|
||||
});
|
||||
|
||||
var implyFail = [];
|
||||
Object.keys(implied).forEach(function (key) {
|
||||
var num, origKey = key, value = implied[key];
|
||||
|
||||
// convert string '1' to number 1
|
||||
var num = Number(key);
|
||||
key = isNaN(num) ? key : num;
|
||||
|
||||
if (typeof key === 'number') {
|
||||
// check length of argv._
|
||||
key = argv._.length >= key;
|
||||
} else if (key.match(/^--no-.+/)) {
|
||||
// check if key doesn't exist
|
||||
key = key.match(/^--no-(.+)/)[1];
|
||||
key = !argv[key];
|
||||
} else {
|
||||
// check if key exists
|
||||
key = argv[key];
|
||||
}
|
||||
|
||||
num = Number(value);
|
||||
value = isNaN(num) ? value : num;
|
||||
|
||||
if (typeof value === 'number') {
|
||||
value = argv._.length >= value;
|
||||
} else if (value.match(/^--no-.+/)) {
|
||||
value = value.match(/^--no-(.+)/)[1];
|
||||
value = !argv[value];
|
||||
} else {
|
||||
value = argv[value];
|
||||
}
|
||||
|
||||
if (key && !value) {
|
||||
implyFail.push(origKey);
|
||||
}
|
||||
});
|
||||
|
||||
if (implyFail.length) {
|
||||
var msg = 'Implications failed:\n';
|
||||
|
||||
implyFail.forEach(function (key) {
|
||||
msg += (' ' + key + ' -> ' + implied[key] + '\n');
|
||||
});
|
||||
|
||||
fail(msg);
|
||||
}
|
||||
|
||||
return argv;
|
||||
}
|
||||
|
||||
function longest (xs) {
|
||||
return Math.max.apply(
|
||||
null,
|
||||
xs.map(function (x) { return x.length })
|
||||
);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
// rebase an absolute path to a relative one with respect to a base directory
|
||||
// exported for tests
|
||||
exports.rebase = rebase;
|
||||
function rebase (base, dir) {
|
||||
var ds = path.normalize(dir).split('/').slice(1);
|
||||
var bs = path.normalize(base).split('/').slice(1);
|
||||
|
||||
for (var i = 0; ds[i] && ds[i] == bs[i]; i++);
|
||||
ds.splice(0, i); bs.splice(0, i);
|
||||
|
||||
var p = path.normalize(
|
||||
bs.map(function () { return '..' }).concat(ds).join('/')
|
||||
).replace(/\/$/,'').replace(/^$/, '.');
|
||||
return p.match(/^[.\/]/) ? p : './' + p;
|
||||
};
|
288
node_modules/yargs/lib/minimist.js
generated
vendored
Normal file
288
node_modules/yargs/lib/minimist.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function (args, opts) {
|
||||
if (!opts) opts = {};
|
||||
|
||||
var flags = { bools : {}, strings : {}, counts: {}, normalize: {}, configs: {} };
|
||||
|
||||
[].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
|
||||
flags.bools[key] = true;
|
||||
});
|
||||
|
||||
[].concat(opts.string).filter(Boolean).forEach(function (key) {
|
||||
flags.strings[key] = true;
|
||||
});
|
||||
|
||||
[].concat(opts.count).filter(Boolean).forEach(function (key) {
|
||||
flags.counts[key] = true;
|
||||
});
|
||||
|
||||
[].concat(opts.normalize).filter(Boolean).forEach(function (key) {
|
||||
flags.normalize[key] = true;
|
||||
});
|
||||
|
||||
[].concat(opts.config).filter(Boolean).forEach(function (key) {
|
||||
flags.configs[key] = true;
|
||||
});
|
||||
|
||||
function toCamelCase(str) {
|
||||
return str.split('-').map(function(word, i) {
|
||||
return (i ? word[0].toUpperCase() + word.slice(1) : word);
|
||||
}).join('');
|
||||
}
|
||||
|
||||
var aliases = {},
|
||||
newAliases = {};
|
||||
|
||||
Object.keys(opts.alias || {}).forEach(function (key) {
|
||||
aliases[key] = [].concat(opts.alias[key]);
|
||||
// For "--option-name", also set argv.optionName
|
||||
aliases[key].concat(key).forEach(function (x) {
|
||||
if (/-/.test(x)) {
|
||||
var c = toCamelCase(x);
|
||||
aliases[key].push(c);
|
||||
newAliases[c] = true;
|
||||
}
|
||||
});
|
||||
aliases[key].forEach(function (x) {
|
||||
aliases[x] = [key].concat(aliases[key].filter(function (y) {
|
||||
return x !== y;
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
var defaults = opts['default'] || {};
|
||||
|
||||
Object.keys(defaults || {}).forEach(function (key) {
|
||||
if (/-/.test(key) && !opts.alias[key]) {
|
||||
var c = toCamelCase(key);
|
||||
aliases[key] = aliases[key] || [];
|
||||
// don't allow the same key to be added multiple times.
|
||||
if (aliases[key].indexOf(c) === -1) {
|
||||
aliases[key] = (aliases[key] || []).concat(c);
|
||||
newAliases[c] = true;
|
||||
}
|
||||
}
|
||||
(aliases[key] || []).forEach(function (alias) {
|
||||
defaults[alias] = defaults[key];
|
||||
});
|
||||
});
|
||||
|
||||
var argv = { _ : [] };
|
||||
Object.keys(flags.bools).forEach(function (key) {
|
||||
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
||||
});
|
||||
|
||||
var notFlags = [];
|
||||
if (args.indexOf('--') !== -1) {
|
||||
notFlags = args.slice(args.indexOf('--')+1);
|
||||
args = args.slice(0, args.indexOf('--'));
|
||||
}
|
||||
|
||||
function setArg (key, val) {
|
||||
if (/-/.test(key) && !(aliases[key] && aliases[key].length)) {
|
||||
var c = toCamelCase(key);
|
||||
aliases[key] = [c];
|
||||
newAliases[c] = true;
|
||||
}
|
||||
|
||||
var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
|
||||
|
||||
if (flags.counts[key] || flags.counts[aliases[key]]) {
|
||||
value = function(orig) { return orig !== undefined ? orig + 1 : 0; };
|
||||
}
|
||||
|
||||
if (flags.configs[key]) {
|
||||
try {
|
||||
var config = JSON.parse(fs.readFileSync(val, 'utf8'));
|
||||
Object.keys(config).forEach(function (key) {
|
||||
setArg(key, config[key]);
|
||||
});
|
||||
} catch (ex) {
|
||||
console.error('Invalid JSON config file: ' + val);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
setKey(argv, key.split('.'), value);
|
||||
|
||||
(aliases[key] || []).forEach(function (x) {
|
||||
setKey(argv, x.split('.'), value);
|
||||
});
|
||||
|
||||
var keys = [key].concat(aliases[key] || []);
|
||||
for (var i = 0, l = keys.length; i < l; i++) {
|
||||
if (flags.normalize[keys[i]]) {
|
||||
keys.forEach(function(key) {
|
||||
argv.__defineSetter__(key, function(v) {
|
||||
val = path.normalize(v);
|
||||
});
|
||||
|
||||
argv.__defineGetter__(key, function () {
|
||||
return typeof val === 'string' ?
|
||||
path.normalize(val) : val;
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
|
||||
if (arg.match(/^--.+=/)) {
|
||||
// Using [\s\S] instead of . because js doesn't support the
|
||||
// 'dotall' regex modifier. See:
|
||||
// http://stackoverflow.com/a/1068308/13216
|
||||
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
||||
setArg(m[1], m[2]);
|
||||
}
|
||||
else if (arg.match(/^--no-.+/)) {
|
||||
var key = arg.match(/^--no-(.+)/)[1];
|
||||
setArg(key, false);
|
||||
}
|
||||
else if (arg.match(/^--.+/)) {
|
||||
var key = arg.match(/^--(.+)/)[1];
|
||||
var next = args[i + 1];
|
||||
if (next !== undefined && !next.match(/^-/)
|
||||
&& !flags.bools[key]
|
||||
&& (aliases[key] ? !flags.bools[aliases[key]] : true)) {
|
||||
setArg(key, next);
|
||||
i++;
|
||||
}
|
||||
else if (/^(true|false)$/.test(next)) {
|
||||
setArg(key, next === 'true');
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
setArg(key, true);
|
||||
}
|
||||
}
|
||||
else if (arg.match(/^-[^-]+/)) {
|
||||
var letters = arg.slice(1,-1).split('');
|
||||
|
||||
var broken = false;
|
||||
for (var j = 0; j < letters.length; j++) {
|
||||
var next = arg.slice(j+2);
|
||||
|
||||
if (letters[j+1] && letters[j+1] === '=') {
|
||||
setArg(letters[j], arg.slice(j+3));
|
||||
broken = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (next === '-') {
|
||||
setArg(letters[j], next)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/[A-Za-z]/.test(letters[j])
|
||||
&& /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
||||
setArg(letters[j], next);
|
||||
broken = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (letters[j+1] && letters[j+1].match(/\W/)) {
|
||||
setArg(letters[j], arg.slice(j+2));
|
||||
broken = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
setArg(letters[j], true);
|
||||
}
|
||||
}
|
||||
|
||||
var key = arg.slice(-1)[0];
|
||||
if (!broken && key !== '-') {
|
||||
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
|
||||
&& !flags.bools[key]
|
||||
&& (aliases[key] ? !flags.bools[aliases[key]] : true)) {
|
||||
setArg(key, args[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (args[i+1] && /true|false/.test(args[i+1])) {
|
||||
setArg(key, args[i+1] === 'true');
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
setArg(key, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
argv._.push(
|
||||
flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
if (!hasKey(argv, key.split('.'))) {
|
||||
setKey(argv, key.split('.'), defaults[key]);
|
||||
|
||||
(aliases[key] || []).forEach(function (x) {
|
||||
setKey(argv, x.split('.'), defaults[key]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(flags.counts).forEach(function (key) {
|
||||
setArg(key, defaults[key]);
|
||||
});
|
||||
|
||||
notFlags.forEach(function(key) {
|
||||
argv._.push(key);
|
||||
});
|
||||
|
||||
return {
|
||||
argv: argv,
|
||||
aliases: aliases,
|
||||
newAliases: newAliases
|
||||
};
|
||||
};
|
||||
|
||||
function hasKey (obj, keys) {
|
||||
var o = obj;
|
||||
keys.slice(0,-1).forEach(function (key) {
|
||||
o = (o[key] || {});
|
||||
});
|
||||
|
||||
var key = keys[keys.length - 1];
|
||||
return key in o;
|
||||
}
|
||||
|
||||
function setKey (obj, keys, value) {
|
||||
var o = obj;
|
||||
keys.slice(0,-1).forEach(function (key) {
|
||||
if (o[key] === undefined) o[key] = {};
|
||||
o = o[key];
|
||||
});
|
||||
|
||||
|
||||
var key = keys[keys.length - 1];
|
||||
if (typeof value === 'function') {
|
||||
o[key] = value(o[key]);
|
||||
}
|
||||
else if (o[key] === undefined || typeof o[key] === 'boolean') {
|
||||
o[key] = value;
|
||||
}
|
||||
else if (Array.isArray(o[key])) {
|
||||
o[key].push(value);
|
||||
}
|
||||
else {
|
||||
o[key] = [ o[key], value ];
|
||||
}
|
||||
}
|
||||
|
||||
function isNumber (x) {
|
||||
if (typeof x === 'number') return true;
|
||||
if (/^0x[0-9a-f]+$/i.test(x)) return true;
|
||||
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
||||
}
|
||||
|
||||
function longest (xs) {
|
||||
return Math.max.apply(null, xs.map(function (x) { return x.length }));
|
||||
}
|
50
node_modules/yargs/lib/wordwrap.js
generated
vendored
Normal file
50
node_modules/yargs/lib/wordwrap.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// Simplified version of https://github.com/substack/node-wordwrap
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function (start, stop) {
|
||||
|
||||
if (!stop) {
|
||||
stop = start;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
var re = /(\S+\s+)/;
|
||||
|
||||
return function (text) {
|
||||
var chunks = text.toString().split(re);
|
||||
|
||||
return chunks.reduce(function (lines, rawChunk) {
|
||||
if (rawChunk === '') return lines;
|
||||
|
||||
var chunk = rawChunk.replace(/\t/g, ' ');
|
||||
|
||||
var i = lines.length - 1;
|
||||
if (lines[i].length + chunk.length > stop) {
|
||||
lines[i] = lines[i].replace(/\s+$/, '');
|
||||
|
||||
chunk.split(/\n/).forEach(function (c) {
|
||||
lines.push(
|
||||
new Array(start + 1).join(' ')
|
||||
+ c.replace(/^\s+/, '')
|
||||
);
|
||||
});
|
||||
}
|
||||
else if (chunk.match(/\n/)) {
|
||||
var xs = chunk.split(/\n/);
|
||||
lines[i] += xs.shift();
|
||||
xs.forEach(function (c) {
|
||||
lines.push(
|
||||
new Array(start + 1).join(' ')
|
||||
+ c.replace(/^\s+/, '')
|
||||
);
|
||||
});
|
||||
}
|
||||
else {
|
||||
lines[i] += chunk;
|
||||
}
|
||||
|
||||
return lines;
|
||||
}, [ new Array(start + 1).join(' ') ]).join('\n');
|
||||
};
|
||||
};
|
105
node_modules/yargs/package.json
generated
vendored
Normal file
105
node_modules/yargs/package.json
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"yargs@^1.2.6",
|
||||
"/Users/pmarsceill/_projects/just-the-docs/node_modules/colorguard"
|
||||
]
|
||||
],
|
||||
"_from": "yargs@>=1.2.6 <2.0.0",
|
||||
"_id": "yargs@1.3.3",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/yargs",
|
||||
"_nodeVersion": "0.10.33",
|
||||
"_npmUser": {
|
||||
"email": "alex.ford@codetunnel.com",
|
||||
"name": "chevex"
|
||||
},
|
||||
"_npmVersion": "2.1.7",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "yargs",
|
||||
"raw": "yargs@^1.2.6",
|
||||
"rawSpec": "^1.2.6",
|
||||
"scope": null,
|
||||
"spec": ">=1.2.6 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/colorguard"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/yargs/-/yargs-1.3.3.tgz",
|
||||
"_shasum": "054de8b61f22eefdb7207059eaef9d6b83fb931a",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "yargs@^1.2.6",
|
||||
"_where": "/Users/pmarsceill/_projects/just-the-docs/node_modules/colorguard",
|
||||
"author": {
|
||||
"email": "Alex.Ford@CodeTunnel.com",
|
||||
"name": "Alex Ford",
|
||||
"url": "http://CodeTunnel.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/chevex/yargs/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Chris Needham",
|
||||
"email": "chris@chrisneedham.com",
|
||||
"url": "http://chrisneedham.com"
|
||||
},
|
||||
{
|
||||
"name": "James Nylen",
|
||||
"email": "jnylen@gmail.com",
|
||||
"url": "https://github.com/nylen"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Horsleben",
|
||||
"url": "https://github.com/fizker"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",
|
||||
"devDependencies": {
|
||||
"chai": "*",
|
||||
"hashish": "*",
|
||||
"mocha": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "054de8b61f22eefdb7207059eaef9d6b83fb931a",
|
||||
"tarball": "https://registry.npmjs.org/yargs/-/yargs-1.3.3.tgz"
|
||||
},
|
||||
"engine": {
|
||||
"node": ">=0.4"
|
||||
},
|
||||
"gitHead": "e6807327c06dd6a311c63e124ff6a50e38b23804",
|
||||
"homepage": "https://github.com/chevex/yargs",
|
||||
"keywords": [
|
||||
"args",
|
||||
"argument",
|
||||
"cli",
|
||||
"command",
|
||||
"option",
|
||||
"parser",
|
||||
"parsing"
|
||||
],
|
||||
"license": "MIT/X11",
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "chevex",
|
||||
"email": "alex.ford@codetunnel.com"
|
||||
}
|
||||
],
|
||||
"name": "yargs",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/chevex/yargs.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R nyan"
|
||||
},
|
||||
"version": "1.3.3"
|
||||
}
|
64
node_modules/yargs/test/_.js
generated
vendored
Normal file
64
node_modules/yargs/test/_.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
var spawn = require('child_process').spawn,
|
||||
should = require('chai').should();
|
||||
|
||||
describe('bin script', function () {
|
||||
|
||||
it('should run as a shell script with no arguments', function (done) {
|
||||
testCmd('./bin.js', [], done);
|
||||
});
|
||||
|
||||
it('should run as a shell script with arguments', function (done) {
|
||||
testCmd('./bin.js', [ 'a', 'b', 'c' ], done);
|
||||
});
|
||||
|
||||
it('should run as a node script with no arguments', function (done) {
|
||||
testCmd('node bin.js', [], done);
|
||||
});
|
||||
|
||||
it('should run as a node script with arguments', function (done) {
|
||||
testCmd('node bin.js', [ 'x', 'y', 'z' ], done);
|
||||
});
|
||||
|
||||
describe('path returned by "which"', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.which = spawn('which', ['node']);
|
||||
});
|
||||
|
||||
it('should match the actual path to the script file', function (done) {
|
||||
this.which.stdout.on('data', function (buf) {
|
||||
testCmd(buf.toString().trim() + ' bin.js', [], done);
|
||||
});
|
||||
this.which.stderr.on('data', done);
|
||||
});
|
||||
|
||||
it('should match the actual path to the script file, with arguments', function (done) {
|
||||
this.which.stdout.on('data', function (buf) {
|
||||
testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ], done);
|
||||
});
|
||||
this.which.stderr.on('data', done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function testCmd(cmd, args, done) {
|
||||
|
||||
var oldDir = process.cwd();
|
||||
process.chdir(__dirname + '/_');
|
||||
|
||||
var cmds = cmd.split(' ');
|
||||
|
||||
var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));
|
||||
process.chdir(oldDir);
|
||||
|
||||
bin.stderr.on('data', done);
|
||||
|
||||
bin.stdout.on('data', function (buf) {
|
||||
var _ = JSON.parse(buf.toString());
|
||||
_.map(String).should.deep.equal(args.map(String));
|
||||
done();
|
||||
});
|
||||
|
||||
}
|
3
node_modules/yargs/test/_/bin.js
generated
vendored
Executable file
3
node_modules/yargs/test/_/bin.js
generated
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
var argv = require('../../index').argv
|
||||
console.log(JSON.stringify(argv._));
|
5
node_modules/yargs/test/config.json
generated
vendored
Normal file
5
node_modules/yargs/test/config.json
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"herp": "derp",
|
||||
"z": 55,
|
||||
"foo": "baz"
|
||||
}
|
28
node_modules/yargs/test/count.js
generated
vendored
Normal file
28
node_modules/yargs/test/count.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var should = require('chai').should()
|
||||
yargs = require('../index');
|
||||
|
||||
describe('count', function () {
|
||||
|
||||
it('should count the number of times a boolean is present', function () {
|
||||
var parsed;
|
||||
|
||||
parsed = yargs(['-x']).count('verbose').argv;
|
||||
parsed.verbose.should.equal(0);
|
||||
|
||||
parsed = yargs(['--verbose']).count('verbose').argv;
|
||||
parsed.verbose.should.equal(1);
|
||||
|
||||
parsed = yargs(['--verbose', '--verbose']).count('verbose').argv;
|
||||
parsed.verbose.should.equal(2);
|
||||
|
||||
parsed = yargs(['-vvv']).alias('v', 'verbose').count('verbose').argv;
|
||||
parsed.verbose.should.equal(3);
|
||||
|
||||
parsed = yargs(['--verbose', '--verbose', '-v', '--verbose']).count('verbose').alias('v', 'verbose').argv;
|
||||
parsed.verbose.should.equal(4);
|
||||
|
||||
parsed = yargs(['--verbose', '--verbose', '-v', '-vv']).count('verbose').alias('v', 'verbose').argv;
|
||||
parsed.verbose.should.equal(5);
|
||||
});
|
||||
|
||||
});
|
35
node_modules/yargs/test/dash.js
generated
vendored
Normal file
35
node_modules/yargs/test/dash.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../index');
|
||||
|
||||
describe('-', function () {
|
||||
|
||||
it('should set - as value of n', function () {
|
||||
var argv = yargs.parse(['-n', '-']);
|
||||
argv.should.have.property('n', '-');
|
||||
argv.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set - as a non-hyphenated value', function () {
|
||||
var argv = yargs.parse(['-']);
|
||||
argv.should.have.property('_').and.deep.equal(['-']);
|
||||
});
|
||||
|
||||
it('should set - as a value of f', function () {
|
||||
var argv = yargs.parse(['-f-']);
|
||||
argv.should.have.property('f', '-');
|
||||
argv.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set b to true and set - as a non-hyphenated value when b is set as a boolean', function () {
|
||||
var argv = yargs(['-b', '-']).boolean('b').argv;
|
||||
argv.should.have.property('b', true);
|
||||
argv.should.have.property('_').and.deep.equal(['-']);
|
||||
});
|
||||
|
||||
it('should set - as the value of s when s is set as a string', function () {
|
||||
var argv = yargs([ '-s', '-' ]).string('s').argv;
|
||||
argv.should.have.property('s', '-');
|
||||
argv.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
});
|
1
node_modules/yargs/test/mocha.opts
generated
vendored
Normal file
1
node_modules/yargs/test/mocha.opts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
-R nyan
|
389
node_modules/yargs/test/parse.js
generated
vendored
Normal file
389
node_modules/yargs/test/parse.js
generated
vendored
Normal file
@@ -0,0 +1,389 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../'),
|
||||
path = require('path');
|
||||
|
||||
describe('parse', function () {
|
||||
|
||||
it('should pass when specifying a "short boolean"', function () {
|
||||
var parse = yargs.parse([ '-b' ]);
|
||||
parse.should.have.property('b').to.be.ok.and.be.a('boolean');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should pass when specifying a "long boolean"', function () {
|
||||
var parse = yargs.parse(['--bool']);
|
||||
parse.should.have.property('bool', true);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should place bare options in the _ array', function () {
|
||||
var parse = yargs.parse(['foo', 'bar', 'baz']);
|
||||
parse.should.have.property('_').and.deep.equal(['foo','bar','baz']);
|
||||
});
|
||||
|
||||
it('should expand grouped short options to a hash with a key for each', function () {
|
||||
var parse = yargs.parse(['-cats']);
|
||||
parse.should.have.property('c', true);
|
||||
parse.should.have.property('a', true);
|
||||
parse.should.have.property('t', true);
|
||||
parse.should.have.property('s', true);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of the final option in a group to the next supplied value', function () {
|
||||
var parse = yargs.parse(['-cats', 'meow']);
|
||||
parse.should.have.property('c', true);
|
||||
parse.should.have.property('a', true);
|
||||
parse.should.have.property('t', true);
|
||||
parse.should.have.property('s', 'meow');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of a single short option to the next supplied value', function () {
|
||||
var parse = yargs.parse(['-h', 'localhost']);
|
||||
parse.should.have.property('h', 'localhost');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of multiple single short options to the next supplied values relative to each', function () {
|
||||
var parse = yargs.parse(['-h', 'localhost', '-p', '555']);
|
||||
parse.should.have.property('h', 'localhost');
|
||||
parse.should.have.property('p', 555);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of a single long option to the next supplied value', function () {
|
||||
var parse = yargs.parse(['--pow', 'xixxle']);
|
||||
parse.should.have.property('pow', 'xixxle');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of a single long option if an = was used', function () {
|
||||
var parse = yargs.parse(['--pow=xixxle']);
|
||||
parse.should.have.property('pow', 'xixxle');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of multiple long options to the next supplied values relative to each', function () {
|
||||
var parse = yargs.parse(['--host', 'localhost', '--port', '555']);
|
||||
parse.should.have.property('host', 'localhost');
|
||||
parse.should.have.property('port', 555);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set the value of multiple long options if = signs were used', function () {
|
||||
var parse = yargs.parse(['--host=localhost', '--port=555']);
|
||||
parse.should.have.property('host', 'localhost');
|
||||
parse.should.have.property('port', 555);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should still set values appropriately if a mix of short, long, and grouped short options are specified', function () {
|
||||
var parse = yargs.parse(['-h', 'localhost', '-fp', '555', 'script.js']);
|
||||
parse.should.have.property('f', true);
|
||||
parse.should.have.property('p', 555);
|
||||
parse.should.have.property('h', 'localhost');
|
||||
parse.should.have.property('_').and.deep.equal(['script.js']);
|
||||
});
|
||||
|
||||
it('should still set values appropriately if a mix of short and long options are specified', function () {
|
||||
var parse = yargs.parse(['-h', 'localhost', '--port', '555']);
|
||||
parse.should.have.property('h', 'localhost');
|
||||
parse.should.have.property('port', 555);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should explicitly set a boolean option to false if preceeded by "--no-"', function () {
|
||||
var parse = yargs.parse(['--no-moo']);
|
||||
parse.should.have.property('moo', false);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should group values into an array if the same option is specified multiple times', function () {
|
||||
var parse = yargs.parse(['-v', 'a', '-v', 'b', '-v', 'c' ]);
|
||||
parse.should.have.property('v').and.deep.equal(['a','b','c']);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should still set values appropriately if we supply a comprehensive list of various types of options', function () {
|
||||
var parse = yargs.parse([
|
||||
'--name=meowmers', 'bare', '-cats', 'woo',
|
||||
'-h', 'awesome', '--multi=quux',
|
||||
'--key', 'value',
|
||||
'-b', '--bool', '--no-meep', '--multi=baz',
|
||||
'--', '--not-a-flag', 'eek'
|
||||
]);
|
||||
parse.should.have.property('c', true);
|
||||
parse.should.have.property('a', true);
|
||||
parse.should.have.property('t', true);
|
||||
parse.should.have.property('s', 'woo');
|
||||
parse.should.have.property('h', 'awesome');
|
||||
parse.should.have.property('b', true);
|
||||
parse.should.have.property('bool', true);
|
||||
parse.should.have.property('key', 'value');
|
||||
parse.should.have.property('multi').and.deep.equal(['quux', 'baz']);
|
||||
parse.should.have.property('meep', false);
|
||||
parse.should.have.property('name', 'meowmers');
|
||||
parse.should.have.property('_').and.deep.equal(['bare', '--not-a-flag', 'eek']);
|
||||
});
|
||||
|
||||
it('should parse numbers appropriately', function () {
|
||||
var argv = yargs.parse([
|
||||
'-x', '1234',
|
||||
'-y', '5.67',
|
||||
'-z', '1e7',
|
||||
'-w', '10f',
|
||||
'--hex', '0xdeadbeef',
|
||||
'789',
|
||||
]);
|
||||
argv.should.have.property('x', 1234).and.be.a('number');
|
||||
argv.should.have.property('y', 5.67).and.be.a('number');
|
||||
argv.should.have.property('z', 1e7).and.be.a('number');
|
||||
argv.should.have.property('w', '10f').and.be.a('string');
|
||||
argv.should.have.property('hex', 0xdeadbeef).and.be.a('number');
|
||||
argv.should.have.property('_').and.deep.equal([789]);
|
||||
argv._[0].should.be.a('number');
|
||||
});
|
||||
|
||||
it('should not set the next value as the value of a short option if that option is explicitly defined as a boolean', function () {
|
||||
var parse = yargs([ '-t', 'moo' ]).boolean(['t']).argv;
|
||||
parse.should.have.property('t', true).and.be.a('boolean');
|
||||
parse.should.have.property('_').and.deep.equal(['moo']);
|
||||
});
|
||||
|
||||
it('should set boolean options values if the next value is "true" or "false"', function () {
|
||||
var parse = yargs(['--verbose', 'false', 'moo', '-t', 'true'])
|
||||
.boolean(['t', 'verbose']).default('verbose', true).argv;
|
||||
parse.should.have.property('verbose', false).and.be.a('boolean');
|
||||
parse.should.have.property('t', true).and.be.a('boolean');
|
||||
parse.should.have.property('_').and.deep.equal(['moo']);
|
||||
});
|
||||
|
||||
it('should set boolean options to false by default', function () {
|
||||
var parse = yargs(['moo'])
|
||||
.boolean(['t', 'verbose'])
|
||||
.default('verbose', false)
|
||||
.default('t', false).argv;
|
||||
parse.should.have.property('verbose', false).and.be.a('boolean');
|
||||
parse.should.have.property('t', false).and.be.a('boolean');
|
||||
parse.should.have.property('_').and.deep.equal(['moo']);
|
||||
});
|
||||
|
||||
it('should allow defining options as boolean in groups', function () {
|
||||
var parse = yargs([ '-x', '-z', 'one', 'two', 'three' ])
|
||||
.boolean(['x','y','z']).argv;
|
||||
parse.should.have.property('x', true).and.be.a('boolean');
|
||||
parse.should.have.property('y', false).and.be.a('boolean');
|
||||
parse.should.have.property('z', true).and.be.a('boolean');
|
||||
parse.should.have.property('_').and.deep.equal(['one','two','three']);
|
||||
});
|
||||
|
||||
it('should preserve newlines in option values' , function () {
|
||||
var args = yargs.parse(['-s', "X\nX"]);
|
||||
args.should.have.property('_').with.length(0);
|
||||
args.should.have.property('s', 'X\nX');
|
||||
// reproduce in bash:
|
||||
// VALUE="new
|
||||
// line"
|
||||
// node program.js --s="$VALUE"
|
||||
args = yargs.parse(["--s=X\nX"]);
|
||||
args.should.have.property('_').with.length(0);
|
||||
args.should.have.property('s', 'X\nX');
|
||||
});
|
||||
|
||||
it('should not convert numbers to type number if explicitly defined as strings' , function () {
|
||||
var s = yargs([ '-s', '0001234' ]).string('s').argv.s;
|
||||
s.should.be.a('string').and.equal('0001234');
|
||||
var x = yargs([ '-x', '56' ]).string('x').argv.x;
|
||||
x.should.be.a('string').and.equal('56');
|
||||
});
|
||||
|
||||
it('should leave all non-hyphenated values as strings if _ is defined as a string', function () {
|
||||
var s = yargs([ ' ', ' ' ]).string('_').argv._;
|
||||
s.should.have.length(2);
|
||||
s[0].should.be.a('string').and.equal(' ');
|
||||
s[1].should.be.a('string').and.equal(' ');
|
||||
});
|
||||
|
||||
it('should normalize redundant paths', function () {
|
||||
var a = yargs([ '-s', '/tmp/../' ]).alias('s', 'save').normalize('s').argv;
|
||||
a.should.have.property('s', '/');
|
||||
a.should.have.property('save', '/');
|
||||
});
|
||||
|
||||
it('should normalize redundant paths when a value is later assigned', function () {
|
||||
var a = yargs(['-s']).normalize('s').argv;
|
||||
a.should.have.property('s', true);
|
||||
a.s = '/path/to/new/dir/../../';
|
||||
a.s.should.equal('/path/to/');
|
||||
});
|
||||
|
||||
it('should assign data after forward slash to the option before the slash', function () {
|
||||
var parse = yargs.parse(['-I/foo/bar/baz']);
|
||||
parse.should.have.property('_').with.length(0);
|
||||
parse.should.have.property('I', '/foo/bar/baz');
|
||||
parse = yargs.parse(['-xyz/foo/bar/baz']);
|
||||
parse.should.have.property('x', true);
|
||||
parse.should.have.property('y', true);
|
||||
parse.should.have.property('z', '/foo/bar/baz');
|
||||
parse.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should set alias value to the same value as the full option', function () {
|
||||
var argv = yargs([ '-f', '11', '--zoom', '55' ])
|
||||
.alias('z', 'zoom')
|
||||
.argv;
|
||||
argv.should.have.property('zoom', 55);
|
||||
argv.should.have.property('z', 55);
|
||||
argv.should.have.property('f', 11);
|
||||
});
|
||||
|
||||
/*
|
||||
*it('should load options and values from a file when config is used', function () {
|
||||
* var argv = yargs([ '--settings', '../test/config.json', '--foo', 'bar' ])
|
||||
* .alias('z', 'zoom')
|
||||
* .config('settings')
|
||||
* .argv;
|
||||
* argv.should.have.property('herp', 'derp');
|
||||
* argv.should.have.property('zoom', 55);
|
||||
* argv.should.have.property('foo').and.deep.equal(['baz','bar']);
|
||||
*});
|
||||
*/
|
||||
|
||||
it('should allow multiple aliases to be specified', function () {
|
||||
var argv = yargs([ '-f', '11', '--zoom', '55' ])
|
||||
.alias('z', [ 'zm', 'zoom' ])
|
||||
.argv;
|
||||
argv.should.have.property('zoom', 55);
|
||||
argv.should.have.property('z', 55);
|
||||
argv.should.have.property('zm', 55);
|
||||
argv.should.have.property('f', 11);
|
||||
});
|
||||
|
||||
it('should define option as boolean and set default to true', function () {
|
||||
var argv = yargs.options({
|
||||
sometrue: {
|
||||
boolean: true,
|
||||
default: true
|
||||
}
|
||||
}).argv;
|
||||
argv.should.have.property('sometrue', true);
|
||||
});
|
||||
|
||||
it('should define option as boolean and set default to false', function () {
|
||||
var argv = yargs.options({
|
||||
somefalse: {
|
||||
boolean: true,
|
||||
default: false
|
||||
}
|
||||
}).argv;
|
||||
argv.should.have.property('somefalse', false);
|
||||
});
|
||||
|
||||
it('should allow object graph traversal via dot notation', function () {
|
||||
var argv = yargs([
|
||||
'--foo.bar', '3', '--foo.baz', '4',
|
||||
'--foo.quux.quibble', '5', '--foo.quux.o_O',
|
||||
'--beep.boop'
|
||||
]).argv;
|
||||
argv.should.have.property('foo').and.deep.equal({
|
||||
bar: 3,
|
||||
baz: 4,
|
||||
quux: {
|
||||
quibble: 5,
|
||||
o_O: true
|
||||
}
|
||||
});
|
||||
argv.should.have.property('beep').and.deep.equal({ boop: true });
|
||||
});
|
||||
|
||||
it('should allow booleans and aliases to be defined with chainable api', function () {
|
||||
var aliased = [ '-h', 'derp' ],
|
||||
regular = [ '--herp', 'derp' ],
|
||||
opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
},
|
||||
aliasedArgv = yargs(aliased).boolean('herp').alias('h', 'herp').argv,
|
||||
propertyArgv = yargs(regular).boolean('herp').alias('h', 'herp').argv;
|
||||
aliasedArgv.should.have.property('herp', true);
|
||||
aliasedArgv.should.have.property('h', true);
|
||||
aliasedArgv.should.have.property('_').and.deep.equal(['derp']);
|
||||
propertyArgv.should.have.property('herp', true);
|
||||
propertyArgv.should.have.property('h', true);
|
||||
propertyArgv.should.have.property('_').and.deep.equal(['derp']);
|
||||
});
|
||||
|
||||
it('should allow booleans and aliases to be defined with options hash', function () {
|
||||
var aliased = [ '-h', 'derp' ],
|
||||
regular = [ '--herp', 'derp' ],
|
||||
opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
},
|
||||
aliasedArgv = yargs(aliased).options(opts).argv,
|
||||
propertyArgv = yargs(regular).options(opts).argv;
|
||||
aliasedArgv.should.have.property('herp', true);
|
||||
aliasedArgv.should.have.property('h', true);
|
||||
aliasedArgv.should.have.property('_').and.deep.equal(['derp']);
|
||||
propertyArgv.should.have.property('herp', true);
|
||||
propertyArgv.should.have.property('h', true);
|
||||
propertyArgv.should.have.property('_').and.deep.equal(['derp']);
|
||||
});
|
||||
|
||||
it('should set boolean and alias using explicit true', function () {
|
||||
var aliased = [ '-h', 'true' ],
|
||||
regular = [ '--herp', 'true' ],
|
||||
opts = {
|
||||
herp: { alias: 'h', boolean: true }
|
||||
},
|
||||
aliasedArgv = yargs(aliased).boolean('h').alias('h', 'herp').argv,
|
||||
propertyArgv = yargs(regular).boolean('h').alias('h', 'herp').argv;
|
||||
aliasedArgv.should.have.property('herp', true);
|
||||
aliasedArgv.should.have.property('h', true);
|
||||
aliasedArgv.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
// regression, see https://github.com/substack/node-optimist/issues/71
|
||||
it('should set boolean and --x=true', function() {
|
||||
var parsed = yargs(['--boool', '--other=true']).boolean('boool').argv;
|
||||
parsed.should.have.property('boool', true);
|
||||
parsed.should.have.property('other', 'true');
|
||||
parsed = yargs(['--boool', '--other=false']).boolean('boool').argv;
|
||||
parsed.should.have.property('boool', true);
|
||||
parsed.should.have.property('other', 'false');
|
||||
});
|
||||
|
||||
// regression, see https://github.com/chevex/yargs/issues/63
|
||||
it('should not add the same key to argv multiple times, when creating camel-case aliases', function() {
|
||||
var yargs = require('../')(['--health-check=banana', '--second-key', 'apple', '-t=blarg'])
|
||||
.options('h', {
|
||||
alias: 'health-check',
|
||||
description: 'health check',
|
||||
default: 'apple'
|
||||
})
|
||||
.options('second-key', {
|
||||
alias: 's',
|
||||
description: 'second key',
|
||||
default: 'banana'
|
||||
})
|
||||
.options('third-key', {
|
||||
alias: 't',
|
||||
description: 'third key',
|
||||
default: 'third'
|
||||
})
|
||||
|
||||
// before this fix, yargs failed parsing
|
||||
// one but not all forms of an arg.
|
||||
yargs.argv.secondKey.should.eql('apple');
|
||||
yargs.argv.s.should.eql('apple');
|
||||
yargs.argv['second-key'].should.eql('apple');
|
||||
|
||||
yargs.argv.healthCheck.should.eql('banana');
|
||||
yargs.argv.h.should.eql('banana');
|
||||
yargs.argv['health-check'].should.eql('banana');
|
||||
|
||||
yargs.argv.thirdKey.should.eql('blarg');
|
||||
yargs.argv.t.should.eql('blarg');
|
||||
yargs.argv['third-key'].should.eql('blarg');
|
||||
});
|
||||
|
||||
});
|
129
node_modules/yargs/test/parse_camelCase.js
generated
vendored
Normal file
129
node_modules/yargs/test/parse_camelCase.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../');
|
||||
|
||||
describe('parse', function () {
|
||||
|
||||
function runTests (yargs, strict) {
|
||||
|
||||
if (!strict) {
|
||||
// Skip this test in strict mode because this option is not specified
|
||||
it('should provide options with dashes as camelCase properties', function () {
|
||||
var result = yargs()
|
||||
.parse([ '--some-option' ]);
|
||||
|
||||
result.should.have.property('some-option').that.is.a('boolean').and.is.true;
|
||||
result.should.have.property('someOption' ).that.is.a('boolean').and.is.true;
|
||||
});
|
||||
}
|
||||
|
||||
it('should provide count options with dashes as camelCase properties', function () {
|
||||
var result = yargs()
|
||||
.option('some-option', {
|
||||
describe : 'some option',
|
||||
type : 'count'
|
||||
})
|
||||
.parse([ '--some-option', '--some-option', '--some-option' ]);
|
||||
|
||||
result.should.have.property('some-option', 3);
|
||||
result.should.have.property('someOption' , 3);
|
||||
});
|
||||
|
||||
it('should provide options with dashes and aliases as camelCase properties', function () {
|
||||
var result = yargs()
|
||||
.option('some-option', {
|
||||
alias : 'o',
|
||||
describe : 'some option'
|
||||
})
|
||||
.parse([ '--some-option' ]);
|
||||
|
||||
result.should.have.property('some-option').that.is.a('boolean').and.is.true;
|
||||
result.should.have.property('someOption' ).that.is.a('boolean').and.is.true;
|
||||
});
|
||||
|
||||
it('should provide defaults of options with dashes as camelCase properties', function() {
|
||||
var result = yargs()
|
||||
.option('some-option', {
|
||||
describe : 'some option',
|
||||
default : 'asdf'
|
||||
})
|
||||
.parse([ ]);
|
||||
|
||||
result.should.have.property('some-option', 'asdf');
|
||||
result.should.have.property('someOption' , 'asdf');
|
||||
});
|
||||
|
||||
it('should provide aliases of options with dashes as camelCase properties', function() {
|
||||
var result = yargs()
|
||||
.option('some-option', {
|
||||
alias : 'o',
|
||||
describe : 'some option',
|
||||
default : 'asdf'
|
||||
})
|
||||
.parse([ ]);
|
||||
|
||||
result.should.have.property('o', 'asdf');
|
||||
result.should.have.property('some-option', 'asdf');
|
||||
result.should.have.property('someOption' , 'asdf');
|
||||
});
|
||||
|
||||
it('should provide aliases of options with dashes as camelCase properties', function() {
|
||||
var result = yargs()
|
||||
.option('o', {
|
||||
alias : 'some-option',
|
||||
describe : 'some option',
|
||||
default : 'asdf'
|
||||
})
|
||||
.parse([ ]);
|
||||
|
||||
result.should.have.property('o', 'asdf');
|
||||
result.should.have.property('some-option', 'asdf');
|
||||
result.should.have.property('someOption' , 'asdf');
|
||||
});
|
||||
|
||||
it('should provide aliases with dashes as camelCase properties', function() {
|
||||
var result = yargs()
|
||||
.option('o', {
|
||||
alias : 'some-option',
|
||||
describe : 'some option'
|
||||
})
|
||||
.parse([ '--some-option', 'val' ]);
|
||||
|
||||
result.should.have.property('o' ).that.is.a('string').and.equals('val');
|
||||
result.should.have.property('some-option').that.is.a('string').and.equals('val');
|
||||
result.should.have.property('someOption' ).that.is.a('string').and.equals('val');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
describe('dashes and camelCase', function () {
|
||||
runTests(function() {
|
||||
return yargs();
|
||||
});
|
||||
});
|
||||
|
||||
describe('dashes and camelCase (strict)', function () {
|
||||
runTests(function() {
|
||||
// Special handling for failure messages, because normally a
|
||||
// failure calls process.exit(1);
|
||||
return yargs().strict().fail(function(msg) {
|
||||
throw new Error(msg);
|
||||
});
|
||||
}, true);
|
||||
|
||||
// See https://github.com/chevex/yargs/issues/31
|
||||
|
||||
it('should not fail when options with defaults are missing', function () {
|
||||
var result = yargs()
|
||||
.fail(function(msg) {
|
||||
throw new Error(msg);
|
||||
})
|
||||
.option('some-option', {
|
||||
describe : 'some option',
|
||||
default : 80
|
||||
})
|
||||
.strict()
|
||||
.parse([ ]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
82
node_modules/yargs/test/parse_defaults.js
generated
vendored
Normal file
82
node_modules/yargs/test/parse_defaults.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../');
|
||||
|
||||
describe('parse', function () {
|
||||
|
||||
describe('defaults', function () {
|
||||
function checkNoArgs(argv, hasAlias) {
|
||||
it('should set defaults if no args', function() {
|
||||
var result = argv.parse([ ]);
|
||||
result.should.have.property('flag', true);
|
||||
if (hasAlias) {
|
||||
result.should.have.property('f', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkExtraArg(argv, hasAlias) {
|
||||
it('should set defaults if one extra arg', function() {
|
||||
var result = argv.parse([ 'extra' ]);
|
||||
result.should.have.property('flag', true);
|
||||
result.should.have.property('_').and.deep.equal(['extra']);
|
||||
if (hasAlias) {
|
||||
result.should.have.property('f', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkStringArg(argv, hasAlias) {
|
||||
it('should set defaults even if arg looks like a string', function() {
|
||||
var result = argv.parse([ '--flag', 'extra' ]);
|
||||
result.should.have.property('flag', true);
|
||||
result.should.have.property('_').and.deep.equal(['extra']);
|
||||
if (hasAlias) {
|
||||
result.should.have.property('f', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe('for options with aliases', function () {
|
||||
var args = yargs().options({
|
||||
flag : {
|
||||
alias : 'f',
|
||||
default : true
|
||||
}
|
||||
});
|
||||
|
||||
checkNoArgs(args, true);
|
||||
checkExtraArg(args, true);
|
||||
// This test case should fail, because we didn't specify that the
|
||||
// option is a boolean
|
||||
// checkStringArg(args, true);
|
||||
});
|
||||
|
||||
describe('for typed options without aliases', function () {
|
||||
var args = yargs().options({
|
||||
flag : {
|
||||
type : 'boolean',
|
||||
default : true
|
||||
}
|
||||
});
|
||||
|
||||
checkNoArgs(args);
|
||||
checkExtraArg(args);
|
||||
checkStringArg(args);
|
||||
});
|
||||
|
||||
describe('for typed options with aliases', function () {
|
||||
var args = yargs().options({
|
||||
flag : {
|
||||
alias : 'f',
|
||||
type : 'boolean',
|
||||
default : true
|
||||
}
|
||||
});
|
||||
|
||||
checkNoArgs(args, true);
|
||||
checkExtraArg(args, true);
|
||||
checkStringArg(args, true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
21
node_modules/yargs/test/parse_modified.js
generated
vendored
Normal file
21
node_modules/yargs/test/parse_modified.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../');
|
||||
|
||||
describe('parse', function () {
|
||||
|
||||
describe('boolean modifier function', function () {
|
||||
|
||||
it('should prevent yargs from sucking in the next option as the value of the first option', function () {
|
||||
|
||||
// Arrange & Act
|
||||
var result = yargs().boolean('b').parse([ '-b', '123' ]);
|
||||
|
||||
// Assert
|
||||
result.should.have.property('b').that.is.a('boolean').and.is.true;
|
||||
result.should.have.property('_').and.deep.equal([123]);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
20
node_modules/yargs/test/short.js
generated
vendored
Normal file
20
node_modules/yargs/test/short.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../');
|
||||
|
||||
describe('short options', function () {
|
||||
|
||||
it ('should set n to the numeric value 123', function () {
|
||||
var argv = yargs.parse([ '-n123' ]);
|
||||
should.exist(argv);
|
||||
argv.should.have.property('n', 123);
|
||||
});
|
||||
|
||||
it ('should set option "1" to true, option "2" to true, and option "3" to numeric value 456', function () {
|
||||
var argv = yargs.parse([ '-123', '456' ]);
|
||||
should.exist(argv);
|
||||
argv.should.have.property('1', true);
|
||||
argv.should.have.property('2', true);
|
||||
argv.should.have.property('3', 456);
|
||||
});
|
||||
|
||||
});
|
773
node_modules/yargs/test/usage.js
generated
vendored
Normal file
773
node_modules/yargs/test/usage.js
generated
vendored
Normal file
@@ -0,0 +1,773 @@
|
||||
var should = require('chai').should(),
|
||||
Hash = require('hashish'),
|
||||
yargs = require('../');
|
||||
|
||||
describe('usage', function () {
|
||||
|
||||
describe('demand options', function () {
|
||||
describe('using .demand()', function () {
|
||||
it ('should show an error along with the missing arguments on demand fail', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'Options:',
|
||||
' -x [required]',
|
||||
' -y [required]',
|
||||
'Missing required arguments: y'
|
||||
]);
|
||||
r.logs.should.have.length(0);
|
||||
r.exit.should.be.ok;
|
||||
});
|
||||
|
||||
describe('using .require()', function() {
|
||||
it ('should show an error along with the missing arguments on demand fail', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.require(['x','y'])
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'Options:',
|
||||
' -x [required]',
|
||||
' -y [required]',
|
||||
'Missing required arguments: y'
|
||||
]);
|
||||
r.logs.should.have.length(0);
|
||||
r.exit.should.be.ok;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should show an error along with a custom message on demand fail', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.demand(['x','y'], 'x and y are both required to multiply all the things')
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'Options:',
|
||||
' -x [required]',
|
||||
' -y [required]',
|
||||
'Missing required arguments: x, y',
|
||||
'x and y are both required to multiply all the things'
|
||||
]);
|
||||
r.logs.should.have.length(0);
|
||||
r.exit.should.be.ok;
|
||||
});
|
||||
|
||||
it('should return valid values when demand passes', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.demand(['x','y'])
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('y', 20)
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit', false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return valid values when check passes', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) throw 'You forgot about -x';
|
||||
if (!('y' in argv)) throw 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('y', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit', false);
|
||||
});
|
||||
|
||||
it('should display missing arguments when check fails with a thrown exception', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) throw 'You forgot about -x';
|
||||
if (!('y' in argv)) throw 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'You forgot about -y'
|
||||
]);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
});
|
||||
|
||||
it('should display missing arguments when check fails with a return value', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) return 'You forgot about -x';
|
||||
if (!('y' in argv)) return 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'You forgot about -y'
|
||||
]);
|
||||
});
|
||||
|
||||
exports.checkFailReturn = function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(function (argv) {
|
||||
if (!('x' in argv)) return 'You forgot about -x';
|
||||
if (!('y' in argv)) return 'You forgot about -y';
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM -y NUM',
|
||||
'You forgot about -y'
|
||||
]);
|
||||
};
|
||||
|
||||
it('should return a valid result when check condition passes', function () {
|
||||
function checker (argv) {
|
||||
return 'x' in argv && 'y' in argv;
|
||||
}
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -y 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(checker)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('y', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit', false);
|
||||
});
|
||||
|
||||
it('should display a failed message when check condition fails', function () {
|
||||
function checker (argv) {
|
||||
return 'x' in argv && 'y' in argv;
|
||||
}
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-x 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM -y NUM')
|
||||
.check(checker)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('x', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).join('\n').should.equal(
|
||||
'Usage: ./usage -x NUM -y NUM\n'
|
||||
+ 'Argument check failed: ' + checker.toString()
|
||||
);
|
||||
});
|
||||
|
||||
it('should return a valid result when demanding a count of non-hyphenated values', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('1 2 3 --moo'.split(' '))
|
||||
.usage('Usage: $0 [x] [y] [z] {OPTIONS}')
|
||||
.demand(3)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit', false);
|
||||
r.result.should.have.property('_').and.deep.equal([1,2,3]);
|
||||
r.result.should.have.property('moo', true);
|
||||
});
|
||||
|
||||
it('should return a failure message when not enough non-hyphenated arguments are found after a demand count', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('1 2 --moo'.split(' '))
|
||||
.usage('Usage: $0 [x] [y] [z] {OPTIONS}')
|
||||
.demand(3)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.result.should.have.property('_').and.deep.equal([1,2]);
|
||||
r.result.should.have.property('moo', true);
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [x] [y] [z] {OPTIONS}',
|
||||
'Not enough non-option arguments: got 2, need at least 3'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return a custom failure message when not enough non-hyphenated arguments are found after a demand count', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('src --moo'.split(' '))
|
||||
.usage('Usage: $0 [x] [y] [z] {OPTIONS} <src> <dest> [extra_files...]')
|
||||
.demand(2, 'src and dest files are both required')
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.result.should.have.property('_').and.deep.equal(['src']);
|
||||
r.result.should.have.property('moo', true);
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [x] [y] [z] {OPTIONS} <src> <dest> [extra_files...]',
|
||||
'src and dest files are both required'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return a valid result when setting defaults for singles', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('--foo 50 --baz 70 --powsy'.split(' '))
|
||||
.default('foo', 5)
|
||||
.default('bar', 6)
|
||||
.default('baz', 7)
|
||||
.argv
|
||||
;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('foo', 50);
|
||||
r.result.should.have.property('bar', 6);
|
||||
r.result.should.have.property('baz', 70);
|
||||
r.result.should.have.property('powsy', true);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should return a valid result when default is set for an alias', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('')
|
||||
.alias('f', 'foo')
|
||||
.default('f', 5)
|
||||
.argv
|
||||
;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('f', 5);
|
||||
r.result.should.have.property('foo', 5);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
});
|
||||
|
||||
it('should print a single line when failing and default is set for an alias', function() {
|
||||
var r = checkUsage(function() {
|
||||
return yargs('')
|
||||
.alias('f', 'foo')
|
||||
.default('f', 5)
|
||||
.demand(1)
|
||||
.argv
|
||||
;
|
||||
});
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Options:',
|
||||
' -f, --foo [default: 5]',
|
||||
'Not enough non-option arguments: got 0, need at least 1',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should allow you to set default values for a hash of options', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('--foo 50 --baz 70'.split(' '))
|
||||
.default({ foo : 10, bar : 20, quux : 30 })
|
||||
.argv
|
||||
;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.result.should.have.property('foo', 50);
|
||||
r.result.should.have.property('baz', 70);
|
||||
r.result.should.have.property('bar', 20);
|
||||
r.result.should.have.property('quux', 30);
|
||||
});
|
||||
|
||||
describe('required arguments', function () {
|
||||
describe('with options object', function () {
|
||||
it('should show a failure message if a required option is missing', function () {
|
||||
var r = checkUsage(function () {
|
||||
var opts = {
|
||||
foo: { description: 'foo option', alias: 'f', requiresArg: true },
|
||||
bar: { description: 'bar option', alias: 'b', requiresArg: true }
|
||||
};
|
||||
|
||||
return yargs('-f --bar 20'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f foo option',
|
||||
' --bar, -b bar option',
|
||||
'Missing argument value: foo',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should show a failure message if more than one required option is missing', function () {
|
||||
var r = checkUsage(function () {
|
||||
var opts = {
|
||||
foo: { description: 'foo option', alias: 'f', requiresArg: true },
|
||||
bar: { description: 'bar option', alias: 'b', requiresArg: true }
|
||||
};
|
||||
|
||||
return yargs('-f --bar'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f foo option',
|
||||
' --bar, -b bar option',
|
||||
'Missing argument values: foo, bar',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with requiresArg method', function () {
|
||||
it('should show a failure message if a required option is missing', function () {
|
||||
var r = checkUsage(function () {
|
||||
var opts = {
|
||||
foo: { description: 'foo option', alias: 'f' },
|
||||
bar: { description: 'bar option', alias: 'b' }
|
||||
};
|
||||
|
||||
return yargs('-f --bar 20'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.requiresArg(['foo', 'bar'])
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f foo option',
|
||||
' --bar, -b bar option',
|
||||
'Missing argument value: foo',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context("with strict() option set", function () {
|
||||
it('should fail given an option argument that is not demanded', function () {
|
||||
var r = checkUsage(function () {
|
||||
opts = {
|
||||
foo: { demand: 'foo option', alias: 'f' },
|
||||
bar: { demand: 'bar option', alias: 'b' }
|
||||
};
|
||||
|
||||
return yargs('-f 10 --bar 20 --baz 30'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.strict()
|
||||
.argv;
|
||||
});
|
||||
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.result.should.have.property('f', 10);
|
||||
r.result.should.have.property('foo', 10);
|
||||
r.result.should.have.property('b', 20);
|
||||
r.result.should.have.property('bar', 20);
|
||||
r.result.should.have.property('baz', 30);
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f [required]',
|
||||
' --bar, -b [required]',
|
||||
'Unknown argument: baz',
|
||||
]);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
});
|
||||
|
||||
it('should fail given an option argument without a corresponding description', function () {
|
||||
var r = checkUsage(function () {
|
||||
opts = {
|
||||
foo: { description: 'foo option', alias: 'f' },
|
||||
bar: { description: 'bar option', alias: 'b' }
|
||||
};
|
||||
|
||||
return yargs('-f 10 --bar 20 --baz 30'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.strict()
|
||||
.argv;
|
||||
});
|
||||
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.result.should.have.property('f', 10);
|
||||
r.result.should.have.property('foo', 10);
|
||||
r.result.should.have.property('b', 20);
|
||||
r.result.should.have.property('bar', 20);
|
||||
r.result.should.have.property('baz', 30);
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f foo option',
|
||||
' --bar, -b bar option',
|
||||
'Unknown argument: baz',
|
||||
]);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
});
|
||||
|
||||
it('should fail given multiple option arguments without corresponding descriptions', function () {
|
||||
var r = checkUsage(function () {
|
||||
opts = {
|
||||
foo: { description: 'foo option', alias: 'f' },
|
||||
bar: { description: 'bar option', alias: 'b' }
|
||||
};
|
||||
|
||||
return yargs('-f 10 --bar 20 --baz 30 -q 40'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.strict()
|
||||
.argv;
|
||||
});
|
||||
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.result.should.have.property('f', 10);
|
||||
r.result.should.have.property('foo', 10);
|
||||
r.result.should.have.property('b', 20);
|
||||
r.result.should.have.property('bar', 20);
|
||||
r.result.should.have.property('baz', 30);
|
||||
r.result.should.have.property('q', 40);
|
||||
r.should.have.property('errors');
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage [options]',
|
||||
'Options:',
|
||||
' --foo, -f foo option',
|
||||
' --bar, -b bar option',
|
||||
'Unknown arguments: baz, q',
|
||||
]);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
});
|
||||
|
||||
it('should pass given option arguments with corresponding descriptions', function () {
|
||||
var r = checkUsage(function () {
|
||||
opts = {
|
||||
foo: { description: 'foo option' },
|
||||
bar: { description: 'bar option' }
|
||||
};
|
||||
|
||||
return yargs('--foo 10 --bar 20'.split(' '))
|
||||
.usage('Usage: $0 [options]', opts)
|
||||
.strict()
|
||||
.argv;
|
||||
});
|
||||
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('foo', 10);
|
||||
r.result.should.have.property('bar', 20)
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit', false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should display example on fail', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('')
|
||||
.example("$0 something", "description")
|
||||
.example("$0 something else", "other description")
|
||||
.demand(['y'])
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.errors.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Examples:',
|
||||
' ./usage something description',
|
||||
' ./usage something else other description',
|
||||
'Options:',
|
||||
' -y [required]',
|
||||
'Missing required arguments: y'
|
||||
]);
|
||||
});
|
||||
|
||||
describe('demand option with boolean flag', function () {
|
||||
describe('with demand option', function () {
|
||||
it('should report missing required arguments', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-y 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM [-y NUM]')
|
||||
.options({
|
||||
'x': { description: 'an option', demand: true },
|
||||
'y': { description: 'another option', demand: false }
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('y', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM [-y NUM]',
|
||||
'',
|
||||
'Options:',
|
||||
' -x an option [required]',
|
||||
' -y another option',
|
||||
'',
|
||||
'Missing required arguments: x'
|
||||
]);
|
||||
r.logs.should.have.length(0);
|
||||
r.exit.should.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe('with required option', function () {
|
||||
it('should report missing required arguments', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-y 10 -z 20'.split(' '))
|
||||
.usage('Usage: $0 -x NUM [-y NUM]')
|
||||
.options({
|
||||
'x': { description: 'an option', required: true },
|
||||
'y': { description: 'another option', required: false }
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('y', 10);
|
||||
r.result.should.have.property('z', 20);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.errors.join('\n').split(/\n/).should.deep.equal([
|
||||
'Usage: ./usage -x NUM [-y NUM]',
|
||||
'',
|
||||
'Options:',
|
||||
' -x an option [required]',
|
||||
' -y another option',
|
||||
'',
|
||||
'Missing required arguments: x'
|
||||
]);
|
||||
r.logs.should.have.length(0);
|
||||
r.exit.should.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it('should not report missing required arguments when given an alias', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs('-w 10'.split(' '))
|
||||
.usage('Usage: $0 --width NUM [--height NUM]')
|
||||
.options({
|
||||
'width': { description: 'Width', alias: 'w', demand: true },
|
||||
'height': { description: 'Height', alias: 'h', demand: false }
|
||||
})
|
||||
.argv;
|
||||
});
|
||||
r.result.should.have.property('w', 10);
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.logs.should.have.length(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('help option', function () {
|
||||
it('should display usage', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs(['--help'])
|
||||
.demand(['y'])
|
||||
.help('help')
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(1);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.logs.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Options:',
|
||||
' --help Show help',
|
||||
' -y [required]',
|
||||
''
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not show both dashed and camelCase aliases', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs(['--help'])
|
||||
.usage('Usage: $0 options')
|
||||
.help('help')
|
||||
.describe('some-opt', 'Some option')
|
||||
.default('some-opt', 2)
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.should.have.property('errors').with.length(0);
|
||||
r.should.have.property('logs');
|
||||
r.logs.join('\n').split(/\n+/).should.deep.equal([
|
||||
'Usage: ./usage options',
|
||||
'Options:',
|
||||
' --help Show help ',
|
||||
' --some-opt Some option [default: 2]',
|
||||
''
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('version option', function () {
|
||||
it('should display version', function () {
|
||||
var r = checkUsage(function () {
|
||||
return yargs(['--version'])
|
||||
.version('1.0.1', 'version', 'Show version number')
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(1);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.logs.join('\n').split(/\n+/).should.deep.equal([
|
||||
'1.0.1'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('showHelpOnFail', function () {
|
||||
it('should display user supplied message', function () {
|
||||
var opts = {
|
||||
foo: { desc: 'foo option', alias: 'f' },
|
||||
bar: { desc: 'bar option', alias: 'b' }
|
||||
};
|
||||
|
||||
var r = checkUsage(function () {
|
||||
return yargs(['--foo'])
|
||||
.usage('Usage: $0 [options]')
|
||||
.options(opts)
|
||||
.demand(['foo', 'bar'])
|
||||
.showHelpOnFail(false, "Specify --help for available options")
|
||||
.argv;
|
||||
});
|
||||
r.should.have.property('result');
|
||||
r.result.should.have.property('_').with.length(0);
|
||||
r.should.have.property('errors');
|
||||
r.should.have.property('logs').with.length(0);
|
||||
r.should.have.property('exit').and.be.ok;
|
||||
r.errors.join('\n').split(/\n/).should.deep.equal([
|
||||
'Missing required arguments: bar',
|
||||
'',
|
||||
'Specify --help for available options'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should succeed when rebase', function () {
|
||||
yargs.rebase('/home/chevex', '/home/chevex/foo/bar/baz').should.equal('./foo/bar/baz');
|
||||
yargs.rebase('/home/chevex/foo/bar/baz', '/home/chevex').should.equal('../../..');
|
||||
yargs.rebase('/home/chevex/foo', '/home/chevex/pow/zoom.txt').should.equal('../pow/zoom.txt');
|
||||
});
|
||||
|
||||
function checkUsage (f) {
|
||||
|
||||
var exit = false;
|
||||
|
||||
process._exit = process.exit;
|
||||
process._env = process.env;
|
||||
process._argv = process.argv;
|
||||
process.stdout._write = process.stdout.write;
|
||||
|
||||
process.exit = function () { exit = true };
|
||||
process.env = Hash.merge(process.env, { _ : 'node' });
|
||||
process.argv = [ './usage' ];
|
||||
process.stdout.write = function (msg) { logs.push(msg) };
|
||||
|
||||
var errors = [];
|
||||
var logs = [];
|
||||
|
||||
console._error = console.error;
|
||||
console.error = function (msg) { errors.push(msg) };
|
||||
console._log = console.log;
|
||||
console.log = function (msg) { logs.push(msg) };
|
||||
|
||||
var result = f();
|
||||
|
||||
process.exit = process._exit;
|
||||
process.env = process._env;
|
||||
process.argv = process._argv;
|
||||
process.stdout.write = process.stdout._write;
|
||||
|
||||
console.error = console._error;
|
||||
console.log = console._log;
|
||||
|
||||
return {
|
||||
errors : errors,
|
||||
logs : logs,
|
||||
exit : exit,
|
||||
result : result
|
||||
};
|
||||
};
|
||||
|
||||
});
|
12
node_modules/yargs/test/whitespace.js
generated
vendored
Normal file
12
node_modules/yargs/test/whitespace.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var should = require('chai').should(),
|
||||
yargs = require('../');
|
||||
|
||||
describe('whitespace', function () {
|
||||
|
||||
it('should be whitespace', function () {
|
||||
var argv = yargs.parse([ '-x', '\t' ]);
|
||||
should.exist(argv);
|
||||
argv.should.have.property('x', '\t');
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user