yargs 3.9.1 → 3.10.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/CHANGELOG.md +5 -0
- package/README.md +5 -2
- package/index.js +4 -0
- package/lib/parser.js +50 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
+
### v3.10.0 (2015/05/29 04:25 +00:00)
|
|
4
|
+
|
|
5
|
+
- [#165](https://github.com/bcoe/yargs/pull/165) expose yargs.terminalWidth() thanks @ensonic (@bcoe)
|
|
6
|
+
- [#164](https://github.com/bcoe/yargs/pull/164) better array handling thanks @getify (@bcoe)
|
|
7
|
+
|
|
3
8
|
### v3.9.1 (2015/05/20 05:14 +00:00)
|
|
4
9
|
- [b6662b6](https://github.com/bcoe/yargs/commit/b6662b6774cfeab4876f41ec5e2f67b7698f4e2f) clarify .config() docs (@linclark)
|
|
5
10
|
- [0291360](https://github.com/bcoe/yargs/commit/02913606285ce31ce81d7f12c48d8a3029776ec7) fixed tests, switched to nyc for coverage, fixed security issue, added Lin as collaborator (@bcoe)
|
package/README.md
CHANGED
|
@@ -595,7 +595,7 @@ regardless of whether they resemble numbers.
|
|
|
595
595
|
----------
|
|
596
596
|
|
|
597
597
|
Tell the parser to interpret `key` as an array. If `.array('foo')` is set,
|
|
598
|
-
`--foo bar` will be parsed as `['bar']` rather than as `'bar'`.
|
|
598
|
+
`--foo foo bar` will be parsed as `['foo', 'bar']` rather than as `'bar'`.
|
|
599
599
|
|
|
600
600
|
.nargs(key, count)
|
|
601
601
|
-----------
|
|
@@ -618,7 +618,7 @@ Optionally `.nargs()` can take an object of `key`/`narg` pairs.
|
|
|
618
618
|
.config(key)
|
|
619
619
|
------------
|
|
620
620
|
|
|
621
|
-
Tells the parser that if the option specified by `key` is passed in, it
|
|
621
|
+
Tells the parser that if the option specified by `key` is passed in, it
|
|
622
622
|
should be interpreted as a path to a JSON config file. The file is loaded
|
|
623
623
|
and parsed, and its properties are set as arguments.
|
|
624
624
|
|
|
@@ -630,6 +630,9 @@ Format usage output to wrap at `columns` many columns.
|
|
|
630
630
|
By default wrap will be set to `Math.min(80, windowWidth)`. Use `.wrap(null)` to
|
|
631
631
|
specify no column limit.
|
|
632
632
|
|
|
633
|
+
`yargs.wrap(yargs.terminalWidth())` can be used to maximize the width
|
|
634
|
+
of yargs' usage instructions.
|
|
635
|
+
|
|
633
636
|
.strict()
|
|
634
637
|
---------
|
|
635
638
|
|
package/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -69,7 +69,8 @@ module.exports = function (args, opts) {
|
|
|
69
69
|
key,
|
|
70
70
|
letters,
|
|
71
71
|
m,
|
|
72
|
-
next
|
|
72
|
+
next,
|
|
73
|
+
value
|
|
73
74
|
|
|
74
75
|
// -- seperated by =
|
|
75
76
|
if (arg.match(/^--.+=/)) {
|
|
@@ -77,7 +78,18 @@ module.exports = function (args, opts) {
|
|
|
77
78
|
// 'dotall' regex modifier. See:
|
|
78
79
|
// http://stackoverflow.com/a/1068308/13216
|
|
79
80
|
m = arg.match(/^--([^=]+)=([\s\S]*)$/)
|
|
80
|
-
|
|
81
|
+
|
|
82
|
+
// nargs format = '--f=monkey washing cat'
|
|
83
|
+
if (checkAllAliases(m[1], opts.narg)) {
|
|
84
|
+
args.splice(i + 1, m[1], m[2])
|
|
85
|
+
i = eatNargs(i, m[1], args)
|
|
86
|
+
// arrays format = '--f=a b c'
|
|
87
|
+
} else if (checkAllAliases(m[1], flags.arrays) && args.length > i + 1) {
|
|
88
|
+
args.splice(i + 1, m[1], m[2])
|
|
89
|
+
i = eatArray(i, m[1], args)
|
|
90
|
+
} else {
|
|
91
|
+
setArg(m[1], m[2])
|
|
92
|
+
}
|
|
81
93
|
} else if (arg.match(/^--no-.+/)) {
|
|
82
94
|
key = arg.match(/^--no-(.+)/)[1]
|
|
83
95
|
setArg(key, false)
|
|
@@ -86,8 +98,12 @@ module.exports = function (args, opts) {
|
|
|
86
98
|
} else if (arg.match(/^--.+/)) {
|
|
87
99
|
key = arg.match(/^--(.+)/)[1]
|
|
88
100
|
|
|
101
|
+
// nargs format = '--foo a b c'
|
|
89
102
|
if (checkAllAliases(key, opts.narg)) {
|
|
90
103
|
i = eatNargs(i, key, args)
|
|
104
|
+
// array format = '--foo a b c'
|
|
105
|
+
} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
|
|
106
|
+
i = eatArray(i, key, args)
|
|
91
107
|
} else {
|
|
92
108
|
next = args[i + 1]
|
|
93
109
|
|
|
@@ -130,7 +146,21 @@ module.exports = function (args, opts) {
|
|
|
130
146
|
next = arg.slice(j + 2)
|
|
131
147
|
|
|
132
148
|
if (letters[j + 1] && letters[j + 1] === '=') {
|
|
133
|
-
|
|
149
|
+
value = arg.slice(j + 3)
|
|
150
|
+
key = letters[j]
|
|
151
|
+
|
|
152
|
+
// nargs format = '-f=monkey washing cat'
|
|
153
|
+
if (checkAllAliases(letters[j], opts.narg)) {
|
|
154
|
+
args.splice(i + 1, 0, value)
|
|
155
|
+
i = eatNargs(i, key, args)
|
|
156
|
+
// array format = '-f=a b c'
|
|
157
|
+
} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
|
|
158
|
+
args.splice(i + 1, 0, value)
|
|
159
|
+
i = eatArray(i, key, args)
|
|
160
|
+
} else {
|
|
161
|
+
setArg(key, value)
|
|
162
|
+
}
|
|
163
|
+
|
|
134
164
|
broken = true
|
|
135
165
|
break
|
|
136
166
|
}
|
|
@@ -159,8 +189,12 @@ module.exports = function (args, opts) {
|
|
|
159
189
|
key = arg.slice(-1)[0]
|
|
160
190
|
|
|
161
191
|
if (!broken && key !== '-') {
|
|
192
|
+
// nargs format = '-f a b c'
|
|
162
193
|
if (checkAllAliases(key, opts.narg)) {
|
|
163
194
|
i = eatNargs(i, key, args)
|
|
195
|
+
// array format = '-f a b c'
|
|
196
|
+
} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
|
|
197
|
+
i = eatArray(i, key, args)
|
|
164
198
|
} else {
|
|
165
199
|
if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1])
|
|
166
200
|
&& !checkAllAliases(key, flags.bools)
|
|
@@ -207,6 +241,19 @@ module.exports = function (args, opts) {
|
|
|
207
241
|
return (i + toEat)
|
|
208
242
|
}
|
|
209
243
|
|
|
244
|
+
// if an option is an array, eat all non-hyphenated arguments
|
|
245
|
+
// following it... YUM!
|
|
246
|
+
// e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
|
|
247
|
+
function eatArray (i, key, args) {
|
|
248
|
+
for (var ii = i + 1; ii < args.length; ii++) {
|
|
249
|
+
if (/^-/.test(args[ii])) break
|
|
250
|
+
i = ii
|
|
251
|
+
setArg(key, args[ii])
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return i
|
|
255
|
+
}
|
|
256
|
+
|
|
210
257
|
function setArg (key, val) {
|
|
211
258
|
// handle parsing boolean arguments --foo=true --bar false.
|
|
212
259
|
if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"coveralls": "^2.11.2",
|
|
21
21
|
"hashish": "0.0.4",
|
|
22
22
|
"mocha": "^2.2.1",
|
|
23
|
-
"nyc": "^2.
|
|
24
|
-
"standard": "^3.
|
|
23
|
+
"nyc": "^2.2.1",
|
|
24
|
+
"standard": "^3.11.1"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "standard && nyc mocha --check-leaks && nyc report",
|