yargs 1.3.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -30
- package/index.js +99 -71
- package/lib/{minimist.js → parser.js} +93 -38
- package/package.json +46 -6
- package/.npmignore +0 -3
- package/.travis.yml +0 -3
- package/example/bool.js +0 -10
- package/example/boolean_double.js +0 -7
- package/example/boolean_single.js +0 -7
- package/example/count.js +0 -15
- package/example/default_hash.js +0 -8
- package/example/default_singles.js +0 -7
- package/example/demand_count.js +0 -5
- package/example/divide.js +0 -8
- package/example/help.js +0 -27
- package/example/implies.js +0 -10
- package/example/implies_hash.js +0 -26
- package/example/line_count.js +0 -20
- package/example/line_count_options.js +0 -29
- package/example/line_count_wrap.js +0 -29
- package/example/nonopt.js +0 -4
- package/example/requires_arg.js +0 -19
- package/example/short.js +0 -3
- package/example/strict.js +0 -19
- package/example/string.js +0 -11
- package/example/usage-options.js +0 -19
- package/example/xup.js +0 -9
- package/lib/wordwrap.js +0 -50
- package/test/_/bin.js +0 -3
- package/test/_.js +0 -64
- package/test/config.json +0 -5
- package/test/count.js +0 -28
- package/test/dash.js +0 -35
- package/test/mocha.opts +0 -1
- package/test/parse.js +0 -355
- package/test/parse_camelCase.js +0 -129
- package/test/parse_defaults.js +0 -82
- package/test/parse_modified.js +0 -21
- package/test/short.js +0 -20
- package/test/usage.js +0 -747
- package/test/whitespace.js +0 -12
package/test/parse_defaults.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var should = require('chai').should(),
|
|
2
|
-
yargs = require('../');
|
|
3
|
-
|
|
4
|
-
describe('parse', function () {
|
|
5
|
-
|
|
6
|
-
describe('defaults', function () {
|
|
7
|
-
function checkNoArgs(argv, hasAlias) {
|
|
8
|
-
it('should set defaults if no args', function() {
|
|
9
|
-
var result = argv.parse([ ]);
|
|
10
|
-
result.should.have.property('flag', true);
|
|
11
|
-
if (hasAlias) {
|
|
12
|
-
result.should.have.property('f', true);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function checkExtraArg(argv, hasAlias) {
|
|
18
|
-
it('should set defaults if one extra arg', function() {
|
|
19
|
-
var result = argv.parse([ 'extra' ]);
|
|
20
|
-
result.should.have.property('flag', true);
|
|
21
|
-
result.should.have.property('_').and.deep.equal(['extra']);
|
|
22
|
-
if (hasAlias) {
|
|
23
|
-
result.should.have.property('f', true);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function checkStringArg(argv, hasAlias) {
|
|
29
|
-
it('should set defaults even if arg looks like a string', function() {
|
|
30
|
-
var result = argv.parse([ '--flag', 'extra' ]);
|
|
31
|
-
result.should.have.property('flag', true);
|
|
32
|
-
result.should.have.property('_').and.deep.equal(['extra']);
|
|
33
|
-
if (hasAlias) {
|
|
34
|
-
result.should.have.property('f', true);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
describe('for options with aliases', function () {
|
|
40
|
-
var args = yargs().options({
|
|
41
|
-
flag : {
|
|
42
|
-
alias : 'f',
|
|
43
|
-
default : true
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
checkNoArgs(args, true);
|
|
48
|
-
checkExtraArg(args, true);
|
|
49
|
-
// This test case should fail, because we didn't specify that the
|
|
50
|
-
// option is a boolean
|
|
51
|
-
// checkStringArg(args, true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('for typed options without aliases', function () {
|
|
55
|
-
var args = yargs().options({
|
|
56
|
-
flag : {
|
|
57
|
-
type : 'boolean',
|
|
58
|
-
default : true
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
checkNoArgs(args);
|
|
63
|
-
checkExtraArg(args);
|
|
64
|
-
checkStringArg(args);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('for typed options with aliases', function () {
|
|
68
|
-
var args = yargs().options({
|
|
69
|
-
flag : {
|
|
70
|
-
alias : 'f',
|
|
71
|
-
type : 'boolean',
|
|
72
|
-
default : true
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
checkNoArgs(args, true);
|
|
77
|
-
checkExtraArg(args, true);
|
|
78
|
-
checkStringArg(args, true);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
});
|
package/test/parse_modified.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var should = require('chai').should(),
|
|
2
|
-
yargs = require('../');
|
|
3
|
-
|
|
4
|
-
describe('parse', function () {
|
|
5
|
-
|
|
6
|
-
describe('boolean modifier function', function () {
|
|
7
|
-
|
|
8
|
-
it('should prevent yargs from sucking in the next option as the value of the first option', function () {
|
|
9
|
-
|
|
10
|
-
// Arrange & Act
|
|
11
|
-
var result = yargs().boolean('b').parse([ '-b', '123' ]);
|
|
12
|
-
|
|
13
|
-
// Assert
|
|
14
|
-
result.should.have.property('b').that.is.a('boolean').and.is.true;
|
|
15
|
-
result.should.have.property('_').and.deep.equal([123]);
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
});
|
package/test/short.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var should = require('chai').should(),
|
|
2
|
-
yargs = require('../');
|
|
3
|
-
|
|
4
|
-
describe('short options', function () {
|
|
5
|
-
|
|
6
|
-
it ('should set n to the numeric value 123', function () {
|
|
7
|
-
var argv = yargs.parse([ '-n123' ]);
|
|
8
|
-
should.exist(argv);
|
|
9
|
-
argv.should.have.property('n', 123);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it ('should set option "1" to true, option "2" to true, and option "3" to numeric value 456', function () {
|
|
13
|
-
var argv = yargs.parse([ '-123', '456' ]);
|
|
14
|
-
should.exist(argv);
|
|
15
|
-
argv.should.have.property('1', true);
|
|
16
|
-
argv.should.have.property('2', true);
|
|
17
|
-
argv.should.have.property('3', 456);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
});
|