Initial commit

This commit is contained in:
Patrick Marsceill
2017-03-09 13:16:08 -05:00
commit b7b0d0d7bf
4147 changed files with 401224 additions and 0 deletions

64
node_modules/yargs/test/_.js generated vendored Normal file
View 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
View 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
View File

@@ -0,0 +1,5 @@
{
"herp": "derp",
"z": 55,
"foo": "baz"
}

28
node_modules/yargs/test/count.js generated vendored Normal file
View 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
View 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
View File

@@ -0,0 +1 @@
-R nyan

389
node_modules/yargs/test/parse.js generated vendored Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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');
});
});