yargs 3.27.0 → 3.31.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 +33 -0
- package/README.md +113 -7
- package/index.js +49 -3
- package/lib/completion.js +12 -1
- package/lib/parser.js +34 -1
- package/lib/usage.js +56 -14
- package/locales/id.json +37 -0
- package/locales/ko.json +36 -0
- package/locales/nb.json +36 -0
- package/locales/pl.json +36 -0
- package/locales/pt_BR.json +36 -0
- package/locales/tr.json +36 -0
- package/package.json +12 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
+
### v3.31.0 (2015/12/03 10:15 +07:00)
|
|
4
|
+
|
|
5
|
+
- [#239](https://github.com/bcoe/yargs/pull/239) Pass argv to commands (@bcoe)
|
|
6
|
+
- [#308](https://github.com/bcoe/yargs/pull/308) Yargs now handles environment variables (@nexdrew)
|
|
7
|
+
- [#302](https://github.com/bcoe/yargs/pull/302) Add Indonesian translation (@rilut)
|
|
8
|
+
- [#300](https://github.com/bcoe/yargs/pull/300) Add Turkish translation (@feyzo)
|
|
9
|
+
- [#298](https://github.com/bcoe/yargs/pull/298) Add Norwegian Bokmål translation (@sindresorhus)
|
|
10
|
+
- [#297](https://github.com/bcoe/yargs/pull/297) Fix for layout of cjk characters (@disjukr)
|
|
11
|
+
- [#296](https://github.com/bcoe/yargs/pull/296) Add Korean translation (@disjukr)
|
|
12
|
+
|
|
13
|
+
### v3.30.0 (2015/11/13 16:29 +07:00)
|
|
14
|
+
|
|
15
|
+
- [#293](https://github.com/bcoe/yargs/pull/293) Polish language support (@kamilogorek)
|
|
16
|
+
- [#291](https://github.com/bcoe/yargs/pull/291) fix edge-cases with `.alias()` (@bcoe)
|
|
17
|
+
- [#289](https://github.com/bcoe/yargs/pull/289) group options in custom groups (@bcoe)
|
|
18
|
+
|
|
19
|
+
### v3.29.0 (2015/10/16 21:51 +07:00)
|
|
20
|
+
|
|
21
|
+
- [#282](https://github.com/bcoe/yargs/pull/282) completions now accept promises (@LinusU)
|
|
22
|
+
- [#281](https://github.com/bcoe/yargs/pull/281) fix parsing issues with dot notation (@bcoe)
|
|
23
|
+
|
|
24
|
+
### v3.28.0 (2015/10/16 1:55 +07:00)
|
|
25
|
+
|
|
26
|
+
- [#277](https://github.com/bcoe/yargs/pull/277) adds support for ansi escape codes (@bcoe)
|
|
27
|
+
|
|
28
|
+
### v3.27.0 (2015/10/08 1:55 +00:00)
|
|
29
|
+
|
|
30
|
+
- [#271](https://github.com/bcoe/yargs/pull/273) skips validation for help or version flags with exitProcess(false) (@tepez)
|
|
31
|
+
- [#273](https://github.com/bcoe/yargs/pull/273) implements single output for errors with exitProcess(false) (@nexdrew)
|
|
32
|
+
- [#269](https://github.com/bcoe/yargs/pull/269) verifies single output for errors with exitProcess(false) (@tepez)
|
|
33
|
+
- [#268](https://github.com/bcoe/yargs/pull/268) adds Chinese translation (@qiu8310)
|
|
34
|
+
- [#266](https://github.com/bcoe/yargs/pull/266) adds case for -- after -- in parser test (@geophree)
|
|
35
|
+
|
|
3
36
|
### v3.26.0 (2015/09/25 2:14 +00:00)
|
|
4
37
|
|
|
5
38
|
- [#263](https://github.com/bcoe/yargs/pull/263) document count() and option() object keys (@nexdrew)
|
package/README.md
CHANGED
|
@@ -463,8 +463,14 @@ Hidden commands don't show up in the help output and aren't available for
|
|
|
463
463
|
completion.
|
|
464
464
|
|
|
465
465
|
Optionally, you can provide a handler `fn` which will be executed when
|
|
466
|
-
a given command is provided. The handler will be
|
|
467
|
-
|
|
466
|
+
a given command is provided. The handler will be called with `yargs` and
|
|
467
|
+
`argv` as arguments.
|
|
468
|
+
|
|
469
|
+
`yargs` is a blank instance of yargs, which can be used to compose a nested
|
|
470
|
+
hierarchy of options handlers.
|
|
471
|
+
|
|
472
|
+
`argv` represents the arguments parsed prior to the
|
|
473
|
+
command being executed (those described in the outer yargs instance).
|
|
468
474
|
|
|
469
475
|
Here's an example of top-level and nested commands in action:
|
|
470
476
|
|
|
@@ -472,7 +478,7 @@ Here's an example of top-level and nested commands in action:
|
|
|
472
478
|
var argv = require('yargs')
|
|
473
479
|
.usage('npm <command>')
|
|
474
480
|
.command('install', 'tis a mighty fine package to install')
|
|
475
|
-
.command('publish', 'shiver me timbers, should you be sharing all that', function (yargs) {
|
|
481
|
+
.command('publish', 'shiver me timbers, should you be sharing all that', function (yargs, argv) {
|
|
476
482
|
argv = yargs.option('f', {
|
|
477
483
|
alias: 'force',
|
|
478
484
|
description: 'yar, it usually be a bad idea'
|
|
@@ -514,7 +520,7 @@ var argv = require('yargs')
|
|
|
514
520
|
.argv;
|
|
515
521
|
```
|
|
516
522
|
|
|
517
|
-
|
|
523
|
+
You can also provide asynchronous completions.
|
|
518
524
|
|
|
519
525
|
```js
|
|
520
526
|
var argv = require('yargs')
|
|
@@ -529,6 +535,20 @@ var argv = require('yargs')
|
|
|
529
535
|
.argv;
|
|
530
536
|
```
|
|
531
537
|
|
|
538
|
+
But wait, there's more! You can return an asynchronous promise.
|
|
539
|
+
|
|
540
|
+
```js
|
|
541
|
+
var argv = require('yargs')
|
|
542
|
+
.completion('completion', function(current, argv, done) {
|
|
543
|
+
return new Promise(function (resolve, reject) {
|
|
544
|
+
setTimeout(function () {
|
|
545
|
+
resolve(['apple', 'banana'])
|
|
546
|
+
}, 10)
|
|
547
|
+
})
|
|
548
|
+
})
|
|
549
|
+
.argv;
|
|
550
|
+
```
|
|
551
|
+
|
|
532
552
|
<a name="config"></a>.config(key, [description])
|
|
533
553
|
------------
|
|
534
554
|
|
|
@@ -600,6 +620,63 @@ Optionally `.describe()` can take an object that maps keys to descriptions.
|
|
|
600
620
|
|
|
601
621
|
Should yargs attempt to detect the os' locale? Defaults to `true`.
|
|
602
622
|
|
|
623
|
+
.env([prefix])
|
|
624
|
+
--------------
|
|
625
|
+
|
|
626
|
+
Tell yargs to parse environment variables matching the given prefix and apply
|
|
627
|
+
them to argv as though they were command line arguments.
|
|
628
|
+
|
|
629
|
+
If this method is called with no argument or with an empty string or with `true`,
|
|
630
|
+
then all env vars will be applied to argv.
|
|
631
|
+
|
|
632
|
+
Program arguments are defined in this order of precedence:
|
|
633
|
+
|
|
634
|
+
1. Command line args
|
|
635
|
+
2. Config file
|
|
636
|
+
3. Env var
|
|
637
|
+
4. Configured defaults
|
|
638
|
+
|
|
639
|
+
```js
|
|
640
|
+
var argv = require('yargs')
|
|
641
|
+
.env('MY_PROGRAM')
|
|
642
|
+
.option('f', {
|
|
643
|
+
alias: 'fruit-thing',
|
|
644
|
+
default: 'apple'
|
|
645
|
+
})
|
|
646
|
+
.argv
|
|
647
|
+
console.log(argv)
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
```
|
|
651
|
+
$ node fruity.js
|
|
652
|
+
{ _: [],
|
|
653
|
+
f: 'apple',
|
|
654
|
+
'fruit-thing': 'apple',
|
|
655
|
+
fruitThing: 'apple',
|
|
656
|
+
'$0': 'fruity.js' }
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
```
|
|
660
|
+
$ MY_PROGRAM_FRUIT_THING=banana node fruity.js
|
|
661
|
+
{ _: [],
|
|
662
|
+
fruitThing: 'banana',
|
|
663
|
+
f: 'banana',
|
|
664
|
+
'fruit-thing': 'banana',
|
|
665
|
+
'$0': 'fruity.js' }
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
```
|
|
669
|
+
$ MY_PROGRAM_FRUIT_THING=banana node fruity.js -f cat
|
|
670
|
+
{ _: [],
|
|
671
|
+
f: 'cat',
|
|
672
|
+
'fruit-thing': 'cat',
|
|
673
|
+
fruitThing: 'cat',
|
|
674
|
+
'$0': 'fruity.js' }
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
Env var parsing is disabled by default, but you can also explicitly disable it
|
|
678
|
+
by calling `.env(false)`, e.g. if you need to undo previous configuration.
|
|
679
|
+
|
|
603
680
|
.epilog(str)
|
|
604
681
|
------------
|
|
605
682
|
.epilogue(str)
|
|
@@ -635,6 +712,27 @@ Method to execute when a failure occurs, rather than printing the failure messag
|
|
|
635
712
|
|
|
636
713
|
`fn` is called with the failure message that would have been printed.
|
|
637
714
|
|
|
715
|
+
<a name="group"></a>.group(key(s), groupName)
|
|
716
|
+
--------------------
|
|
717
|
+
|
|
718
|
+
Given a key, or an array of keys, places options under an alternative heading
|
|
719
|
+
when displaying usage instructions, e.g.,
|
|
720
|
+
|
|
721
|
+
```js
|
|
722
|
+
var yargs = require('yargs')(['--help'])
|
|
723
|
+
.help('help')
|
|
724
|
+
.group('batman', 'Heroes:')
|
|
725
|
+
.describe('batman', "world's greatest detective")
|
|
726
|
+
.wrap(null)
|
|
727
|
+
.argv
|
|
728
|
+
```
|
|
729
|
+
***
|
|
730
|
+
Heroes:
|
|
731
|
+
--batman world's greatest detective
|
|
732
|
+
|
|
733
|
+
Options:
|
|
734
|
+
--help Show help [boolean]
|
|
735
|
+
|
|
638
736
|
.help([option, [description]])
|
|
639
737
|
------------------------------
|
|
640
738
|
|
|
@@ -719,16 +817,23 @@ Locales currently supported:
|
|
|
719
817
|
* **en:** American English.
|
|
720
818
|
* **es:** Spanish.
|
|
721
819
|
* **fr:** French.
|
|
820
|
+
* **id:** Indonesian.
|
|
722
821
|
* **ja:** Japanese.
|
|
822
|
+
* **ko:** Korean.
|
|
823
|
+
* **nb:** Norwegian Bokmål.
|
|
824
|
+
* **pirate:** American Pirate.
|
|
723
825
|
* **pt:** Portuguese.
|
|
826
|
+
* **pt_BR:** Brazilian Portuguese.
|
|
827
|
+
* **tr:** Turkish.
|
|
724
828
|
* **zh:** Chinese.
|
|
725
|
-
* **pirate:** American Pirate.
|
|
726
829
|
|
|
727
830
|
To submit a new translation for yargs:
|
|
728
831
|
|
|
729
832
|
1. use `./locales/en.json` as a starting point.
|
|
730
833
|
2. submit a pull request with the new locale file.
|
|
731
834
|
|
|
835
|
+
*The [Microsoft Terminology Search](http://www.microsoft.com/Language/en-US/Search.aspx) can be useful for finding the correct terminology in your locale.*
|
|
836
|
+
|
|
732
837
|
<a name="nargs"></a>.nargs(key, count)
|
|
733
838
|
-----------
|
|
734
839
|
|
|
@@ -812,6 +917,7 @@ Valid `opt` keys include:
|
|
|
812
917
|
- `defaultDescription`: string, use this description for the default value in help content, see [`default()`](#default)
|
|
813
918
|
- `demand`/`require`/`required`: boolean or string, demand the option be given, with optional error message, see [`demand()`](#demand)
|
|
814
919
|
- `desc`/`describe`/`description`: string, the option description for help content, see [`describe()`](#describe)
|
|
920
|
+
- `group`: string, when displaying usage instructions place the option under an alternative group heading, see [`group()`](#group)
|
|
815
921
|
- `nargs`: number, specify how many arguments should be consumed for the option, see [`nargs()`](#nargs)
|
|
816
922
|
- `requiresArg`: boolean, require the option be specified with a value, see [`requiresArg()`](#requiresArg)
|
|
817
923
|
- `string`: boolean, interpret option as a string, see [`string()`](#string)
|
|
@@ -1089,7 +1195,7 @@ Short numeric `-n5` style arguments work too:
|
|
|
1089
1195
|
installation
|
|
1090
1196
|
============
|
|
1091
1197
|
|
|
1092
|
-
With [npm](
|
|
1198
|
+
With [npm](https://github.com/npm/npm), just do:
|
|
1093
1199
|
|
|
1094
1200
|
npm install yargs
|
|
1095
1201
|
|
|
@@ -1115,7 +1221,7 @@ This module is loosely inspired by Perl's
|
|
|
1115
1221
|
[gemnasium-image]: https://img.shields.io/gemnasium/bcoe/yargs.svg
|
|
1116
1222
|
[coveralls-url]: https://coveralls.io/github/bcoe/yargs
|
|
1117
1223
|
[coveralls-image]: https://img.shields.io/coveralls/bcoe/yargs.svg
|
|
1118
|
-
[npm-url]: https://npmjs.
|
|
1224
|
+
[npm-url]: https://www.npmjs.com/package/yargs
|
|
1119
1225
|
[npm-image]: https://img.shields.io/npm/v/yargs.svg
|
|
1120
1226
|
[windows-url]: https://ci.appveyor.com/project/bcoe/yargs
|
|
1121
1227
|
[windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs/master.svg?label=Windows%20Tests
|
package/index.js
CHANGED
|
@@ -58,7 +58,8 @@ function Argv (processArgs, cwd) {
|
|
|
58
58
|
requiresArg: [],
|
|
59
59
|
count: [],
|
|
60
60
|
normalize: [],
|
|
61
|
-
config: []
|
|
61
|
+
config: [],
|
|
62
|
+
envPrefix: undefined
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
usage = Usage(self, y18n) // handle usage output.
|
|
@@ -166,7 +167,25 @@ function Argv (processArgs, cwd) {
|
|
|
166
167
|
self.alias(key, x[key])
|
|
167
168
|
})
|
|
168
169
|
} else {
|
|
169
|
-
|
|
170
|
+
// perhaps 'x' is already an alias in another list?
|
|
171
|
+
// if so we should append to x's list.
|
|
172
|
+
var aliases = null
|
|
173
|
+
Object.keys(options.alias).forEach(function (key) {
|
|
174
|
+
if (~options.alias[key].indexOf(x)) aliases = options.alias[key]
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
if (aliases) { // x was an alias itself.
|
|
178
|
+
aliases.push(y)
|
|
179
|
+
} else { // x is a new alias key.
|
|
180
|
+
options.alias[x] = (options.alias[x] || []).concat(y)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// wait! perhaps we've created two lists of aliases
|
|
184
|
+
// that reference each other?
|
|
185
|
+
if (options.alias[y]) {
|
|
186
|
+
Array.prototype.push.apply((options.alias[x] || aliases), options.alias[y])
|
|
187
|
+
delete options.alias[y]
|
|
188
|
+
}
|
|
170
189
|
}
|
|
171
190
|
return self
|
|
172
191
|
}
|
|
@@ -282,6 +301,8 @@ function Argv (processArgs, cwd) {
|
|
|
282
301
|
self.nargs(key, opt.nargs)
|
|
283
302
|
} if ('choices' in opt) {
|
|
284
303
|
self.choices(key, opt.choices)
|
|
304
|
+
} if ('group' in opt) {
|
|
305
|
+
self.group(key, opt.group)
|
|
285
306
|
} if (opt.boolean || opt.type === 'boolean') {
|
|
286
307
|
self.boolean(key)
|
|
287
308
|
if (opt.alias) self.boolean(opt.alias)
|
|
@@ -313,6 +334,23 @@ function Argv (processArgs, cwd) {
|
|
|
313
334
|
return options
|
|
314
335
|
}
|
|
315
336
|
|
|
337
|
+
var groups = {}
|
|
338
|
+
self.group = function (opts, groupName) {
|
|
339
|
+
groups[groupName] = (groups[groupName] || []).concat(opts)
|
|
340
|
+
return self
|
|
341
|
+
}
|
|
342
|
+
self.getGroups = function () {
|
|
343
|
+
return groups
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// as long as options.envPrefix is not undefined,
|
|
347
|
+
// parser will apply env vars matching prefix to argv
|
|
348
|
+
self.env = function (prefix) {
|
|
349
|
+
if (prefix === false) options.envPrefix = undefined
|
|
350
|
+
else options.envPrefix = prefix || ''
|
|
351
|
+
return self
|
|
352
|
+
}
|
|
353
|
+
|
|
316
354
|
self.wrap = function (cols) {
|
|
317
355
|
usage.wrap(cols)
|
|
318
356
|
return self
|
|
@@ -481,7 +519,7 @@ function Argv (processArgs, cwd) {
|
|
|
481
519
|
var handlerKeys = Object.keys(self.getCommandHandlers())
|
|
482
520
|
for (var i = 0, command; (command = handlerKeys[i]) !== undefined; i++) {
|
|
483
521
|
if (~argv._.indexOf(command)) {
|
|
484
|
-
|
|
522
|
+
runCommand(command, self, argv)
|
|
485
523
|
return self.argv
|
|
486
524
|
}
|
|
487
525
|
}
|
|
@@ -563,8 +601,16 @@ function Argv (processArgs, cwd) {
|
|
|
563
601
|
}
|
|
564
602
|
}
|
|
565
603
|
|
|
604
|
+
function runCommand (command, yargs, argv) {
|
|
605
|
+
setPlaceholderKeys(argv)
|
|
606
|
+
yargs.getCommandHandlers()[command](yargs.reset(), argv)
|
|
607
|
+
}
|
|
608
|
+
|
|
566
609
|
function setPlaceholderKeys (argv) {
|
|
567
610
|
Object.keys(options.key).forEach(function (key) {
|
|
611
|
+
// don't set placeholder keys for dot
|
|
612
|
+
// notation options 'foo.bar'.
|
|
613
|
+
if (~key.indexOf('.')) return
|
|
568
614
|
if (typeof argv[key] === 'undefined') argv[key] = undefined
|
|
569
615
|
})
|
|
570
616
|
}
|
package/lib/completion.js
CHANGED
|
@@ -19,8 +19,19 @@ module.exports = function (yargs, usage) {
|
|
|
19
19
|
// to completion().
|
|
20
20
|
if (completionFunction) {
|
|
21
21
|
if (completionFunction.length < 3) {
|
|
22
|
+
var result = completionFunction(current, argv)
|
|
23
|
+
|
|
24
|
+
// promise based completion function.
|
|
25
|
+
if (typeof result.then === 'function') {
|
|
26
|
+
return result.then(function (list) {
|
|
27
|
+
process.nextTick(function () { done(list) })
|
|
28
|
+
}).catch(function (err) {
|
|
29
|
+
process.nextTick(function () { throw err })
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
// synchronous completion function.
|
|
23
|
-
return done(
|
|
34
|
+
return done(result)
|
|
24
35
|
} else {
|
|
25
36
|
// asynchronous completion function
|
|
26
37
|
return completionFunction(current, argv, function (completions) {
|
package/lib/parser.js
CHANGED
|
@@ -220,7 +220,14 @@ module.exports = function (args, opts, y18n) {
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
// order of precedence:
|
|
224
|
+
// 1. command line arg
|
|
225
|
+
// 2. value from config file
|
|
226
|
+
// 3. value from env var
|
|
227
|
+
// 4. configured default value
|
|
228
|
+
applyEnvVars(opts, argv, true) // special case: check env vars that point to config file
|
|
223
229
|
setConfig(argv)
|
|
230
|
+
applyEnvVars(opts, argv, false)
|
|
224
231
|
applyDefaultsAndAliases(argv, aliases, defaults)
|
|
225
232
|
|
|
226
233
|
Object.keys(flags.counts).forEach(function (key) {
|
|
@@ -281,6 +288,15 @@ module.exports = function (args, opts, y18n) {
|
|
|
281
288
|
var splitKey = key.split('.')
|
|
282
289
|
setKey(argv, splitKey, value)
|
|
283
290
|
|
|
291
|
+
// alias references an inner-value within
|
|
292
|
+
// a dot-notation object. see #279.
|
|
293
|
+
if (~key.indexOf('.') && aliases[key]) {
|
|
294
|
+
aliases[key].forEach(function (x) {
|
|
295
|
+
x = x.split('.')
|
|
296
|
+
setKey(argv, x, value)
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
284
300
|
;(aliases[splitKey[0]] || []).forEach(function (x) {
|
|
285
301
|
x = x.split('.')
|
|
286
302
|
|
|
@@ -342,12 +358,27 @@ module.exports = function (args, opts, y18n) {
|
|
|
342
358
|
})
|
|
343
359
|
}
|
|
344
360
|
|
|
361
|
+
function applyEnvVars (opts, argv, configOnly) {
|
|
362
|
+
if (typeof opts.envPrefix === 'undefined') return
|
|
363
|
+
|
|
364
|
+
var prefix = typeof opts.envPrefix === 'string' ? opts.envPrefix : ''
|
|
365
|
+
Object.keys(process.env).forEach(function (envVar) {
|
|
366
|
+
if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
|
|
367
|
+
var key = camelCase(envVar.substring(prefix.length))
|
|
368
|
+
if (((configOnly && flags.configs[key]) || !configOnly) && (!(key in argv) || flags.defaulted[key])) {
|
|
369
|
+
setArg(key, process.env[envVar])
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
})
|
|
373
|
+
}
|
|
374
|
+
|
|
345
375
|
function applyDefaultsAndAliases (obj, aliases, defaults) {
|
|
346
376
|
Object.keys(defaults).forEach(function (key) {
|
|
347
377
|
if (!hasKey(obj, key.split('.'))) {
|
|
348
378
|
setKey(obj, key.split('.'), defaults[key])
|
|
349
379
|
|
|
350
380
|
;(aliases[key] || []).forEach(function (x) {
|
|
381
|
+
if (hasKey(obj, x.split('.'))) return
|
|
351
382
|
setKey(obj, x.split('.'), defaults[key])
|
|
352
383
|
})
|
|
353
384
|
}
|
|
@@ -361,7 +392,9 @@ module.exports = function (args, opts, y18n) {
|
|
|
361
392
|
})
|
|
362
393
|
|
|
363
394
|
var key = keys[keys.length - 1]
|
|
364
|
-
|
|
395
|
+
|
|
396
|
+
if (typeof o !== 'object') return false
|
|
397
|
+
else return key in o
|
|
365
398
|
}
|
|
366
399
|
|
|
367
400
|
function setKey (obj, keys, value) {
|
package/lib/usage.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// failures, etc. keeps logging in one place.
|
|
3
3
|
var cliui = require('cliui')
|
|
4
4
|
var decamelize = require('decamelize')
|
|
5
|
+
var stringWidth = require('string-width')
|
|
5
6
|
var wsize = require('window-size')
|
|
6
7
|
|
|
7
8
|
module.exports = function (yargs, y18n) {
|
|
@@ -101,10 +102,12 @@ module.exports = function (yargs, y18n) {
|
|
|
101
102
|
return deferY18nLookupPrefix + str
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
var defaultGroup = 'Options:'
|
|
104
106
|
self.help = function () {
|
|
105
107
|
normalizeAliases()
|
|
106
108
|
|
|
107
109
|
var demanded = yargs.getDemanded()
|
|
110
|
+
var groups = yargs.getGroups()
|
|
108
111
|
var options = yargs.getOptions()
|
|
109
112
|
var keys = Object.keys(
|
|
110
113
|
Object.keys(descriptions)
|
|
@@ -141,7 +144,8 @@ module.exports = function (yargs, y18n) {
|
|
|
141
144
|
ui.div()
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
// the
|
|
147
|
+
// perform some cleanup on the keys array, making it
|
|
148
|
+
// only include top-level keys not their aliases.
|
|
145
149
|
var aliasKeys = (Object.keys(options.alias) || [])
|
|
146
150
|
.concat(Object.keys(yargs.parsed.newAliases) || [])
|
|
147
151
|
|
|
@@ -151,20 +155,39 @@ module.exports = function (yargs, y18n) {
|
|
|
151
155
|
})
|
|
152
156
|
})
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
// populate 'Options:' group with any keys that have not
|
|
159
|
+
// explicitly had a group set.
|
|
160
|
+
if (!groups[defaultGroup]) groups[defaultGroup] = []
|
|
161
|
+
addUngroupedKeys(keys, options.alias, groups)
|
|
162
|
+
|
|
163
|
+
// display 'Options:' table along with any custom tables:
|
|
164
|
+
Object.keys(groups).forEach(function (groupName) {
|
|
165
|
+
if (!groups[groupName].length) return
|
|
166
|
+
|
|
167
|
+
ui.div(__(groupName))
|
|
168
|
+
|
|
169
|
+
// if we've grouped the key 'f', but 'f' aliases 'foobar',
|
|
170
|
+
// normalizedKeys should contain only 'foobar'.
|
|
171
|
+
var normalizedKeys = groups[groupName].map(function (key) {
|
|
172
|
+
if (~aliasKeys.indexOf(key)) return key
|
|
173
|
+
for (var i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
|
|
174
|
+
if (~(options.alias[aliasKey] || []).indexOf(key)) return aliasKey
|
|
175
|
+
}
|
|
176
|
+
return key
|
|
158
177
|
})
|
|
159
|
-
.join(', ')
|
|
160
178
|
|
|
161
|
-
|
|
162
|
-
|
|
179
|
+
// actually generate the switches string --foo, -f, --bar.
|
|
180
|
+
var switches = normalizedKeys.reduce(function (acc, key) {
|
|
181
|
+
acc[key] = [ key ].concat(options.alias[key] || [])
|
|
182
|
+
.map(function (sw) {
|
|
183
|
+
return (sw.length > 1 ? '--' : '-') + sw
|
|
184
|
+
})
|
|
185
|
+
.join(', ')
|
|
163
186
|
|
|
164
|
-
|
|
165
|
-
|
|
187
|
+
return acc
|
|
188
|
+
}, {})
|
|
166
189
|
|
|
167
|
-
|
|
190
|
+
normalizedKeys.forEach(function (key) {
|
|
168
191
|
var kswitch = switches[key]
|
|
169
192
|
var desc = descriptions[key] || ''
|
|
170
193
|
var type = null
|
|
@@ -195,7 +218,7 @@ module.exports = function (yargs, y18n) {
|
|
|
195
218
|
})
|
|
196
219
|
|
|
197
220
|
ui.div()
|
|
198
|
-
}
|
|
221
|
+
})
|
|
199
222
|
|
|
200
223
|
// describe some common use-cases for your application.
|
|
201
224
|
if (examples.length) {
|
|
@@ -238,7 +261,7 @@ module.exports = function (yargs, y18n) {
|
|
|
238
261
|
}
|
|
239
262
|
|
|
240
263
|
table.forEach(function (v) {
|
|
241
|
-
width = Math.max(v[0]
|
|
264
|
+
width = Math.max(stringWidth(v[0]), width)
|
|
242
265
|
})
|
|
243
266
|
|
|
244
267
|
// if we've enabled 'wrap' we should limit
|
|
@@ -260,7 +283,6 @@ module.exports = function (yargs, y18n) {
|
|
|
260
283
|
if (descriptions[alias]) self.describe(key, descriptions[alias])
|
|
261
284
|
// copy demanded.
|
|
262
285
|
if (demanded[alias]) yargs.demand(key, demanded[alias].msg)
|
|
263
|
-
|
|
264
286
|
// type messages.
|
|
265
287
|
if (~options.boolean.indexOf(alias)) yargs.boolean(key)
|
|
266
288
|
if (~options.count.indexOf(alias)) yargs.count(key)
|
|
@@ -271,6 +293,26 @@ module.exports = function (yargs, y18n) {
|
|
|
271
293
|
})
|
|
272
294
|
}
|
|
273
295
|
|
|
296
|
+
// given a set of keys, place any keys that are
|
|
297
|
+
// ungrouped under the 'Options:' grouping.
|
|
298
|
+
function addUngroupedKeys (keys, aliases, groups) {
|
|
299
|
+
var groupedKeys = []
|
|
300
|
+
var toCheck = null
|
|
301
|
+
Object.keys(groups).forEach(function (group) {
|
|
302
|
+
groupedKeys = groupedKeys.concat(groups[group])
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
keys.forEach(function (key) {
|
|
306
|
+
toCheck = [key].concat(aliases[key])
|
|
307
|
+
if (!toCheck.some(function (k) {
|
|
308
|
+
return groupedKeys.indexOf(k) !== -1
|
|
309
|
+
})) {
|
|
310
|
+
groups[defaultGroup].push(key)
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
return groupedKeys
|
|
314
|
+
}
|
|
315
|
+
|
|
274
316
|
self.showHelp = function (level) {
|
|
275
317
|
level = level || 'error'
|
|
276
318
|
console[level](self.help())
|
package/locales/id.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"Commands:": "Perintah:",
|
|
4
|
+
"Options:": "Pilihan:",
|
|
5
|
+
"Examples:": "Contoh:",
|
|
6
|
+
"boolean": "boolean",
|
|
7
|
+
"count": "jumlah",
|
|
8
|
+
"string": "string",
|
|
9
|
+
"array": "larik",
|
|
10
|
+
"required": "diperlukan",
|
|
11
|
+
"default:": "bawaan:",
|
|
12
|
+
"choices:": "pilihan:",
|
|
13
|
+
"generated-value": "nilai-yang-dihasilkan",
|
|
14
|
+
"Not enough non-option arguments: got %s, need at least %s": "Argumen wajib kurang: hanya %s, minimal %s",
|
|
15
|
+
"Too many non-option arguments: got %s, maximum of %s": "Terlalu banyak argumen wajib: ada %s, maksimal %s",
|
|
16
|
+
"Missing argument value: %s": {
|
|
17
|
+
"one": "Kurang argumen: %s",
|
|
18
|
+
"other": "Kurang argumen: %s"
|
|
19
|
+
},
|
|
20
|
+
"Missing required argument: %s": {
|
|
21
|
+
"one": "Kurang argumen wajib: %s",
|
|
22
|
+
"other": "Kurang argumen wajib: %s"
|
|
23
|
+
},
|
|
24
|
+
"Unknown argument: %s": {
|
|
25
|
+
"one": "Argumen tak diketahui: %s",
|
|
26
|
+
"other": "Argumen tak diketahui: %s"
|
|
27
|
+
},
|
|
28
|
+
"Invalid values:": "Nilai-nilai tidak valid:",
|
|
29
|
+
"Argument: %s, Given: %s, Choices: %s": "Argumen: %s, Diberikan: %s, Pilihan: %s",
|
|
30
|
+
"Argument check failed: %s": "Pemeriksaan argument gagal: %s",
|
|
31
|
+
"Implications failed:": "Implikasi gagal:",
|
|
32
|
+
"Not enough arguments following: %s": "Kurang argumen untuk: %s",
|
|
33
|
+
"Invalid JSON config file: %s": "Berkas konfigurasi JSON tidak valid: %s",
|
|
34
|
+
"Path to JSON config file": "Alamat berkas konfigurasi JSON",
|
|
35
|
+
"Show help": "Lihat bantuan",
|
|
36
|
+
"Show version number": "Lihat nomor versi"
|
|
37
|
+
}
|
package/locales/ko.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "명령:",
|
|
3
|
+
"Options:": "옵션:",
|
|
4
|
+
"Examples:": "예시:",
|
|
5
|
+
"boolean": "여부",
|
|
6
|
+
"count": "개수",
|
|
7
|
+
"string": "문자열",
|
|
8
|
+
"array": "배열",
|
|
9
|
+
"required": "필수",
|
|
10
|
+
"default:": "기본:",
|
|
11
|
+
"choices:": "선택:",
|
|
12
|
+
"generated-value": "생성된 값",
|
|
13
|
+
"Not enough non-option arguments: got %s, need at least %s": "옵션이 아닌 인자가 충분치 않습니다: %s개를 받았지만, 적어도 %s개는 필요합니다",
|
|
14
|
+
"Too many non-option arguments: got %s, maximum of %s": "옵션이 아닌 인자가 너무 많습니다: %s개를 받았지만, %s개 이하여야 합니다",
|
|
15
|
+
"Missing argument value: %s": {
|
|
16
|
+
"one": "인자값을 받지 못했습니다: %s",
|
|
17
|
+
"other": "인자값들을 받지 못했습니다: %s"
|
|
18
|
+
},
|
|
19
|
+
"Missing required argument: %s": {
|
|
20
|
+
"one": "필수 인자를 받지 못했습니다: %s",
|
|
21
|
+
"other": "필수 인자들을 받지 못했습니다: %s"
|
|
22
|
+
},
|
|
23
|
+
"Unknown argument: %s": {
|
|
24
|
+
"one": "알 수 없는 인자입니다: %s",
|
|
25
|
+
"other": "알 수 없는 인자들입니다: %s"
|
|
26
|
+
},
|
|
27
|
+
"Invalid values:": "잘못된 값입니다:",
|
|
28
|
+
"Argument: %s, Given: %s, Choices: %s": "인자: %s, 입력받은 값: %s, 선택지: %s",
|
|
29
|
+
"Argument check failed: %s": "유효하지 않은 인자입니다: %s",
|
|
30
|
+
"Implications failed:": "옵션의 조합이 잘못되었습니다:",
|
|
31
|
+
"Not enough arguments following: %s": "인자가 충분하게 주어지지 않았습니다: %s",
|
|
32
|
+
"Invalid JSON config file: %s": "유효하지 않은 JSON 설정파일입니다: %s",
|
|
33
|
+
"Path to JSON config file": "JSON 설정파일 경로",
|
|
34
|
+
"Show help": "도움말을 보여줍니다",
|
|
35
|
+
"Show version number": "버전 넘버를 보여줍니다"
|
|
36
|
+
}
|
package/locales/nb.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "Kommandoer:",
|
|
3
|
+
"Options:": "Alternativer:",
|
|
4
|
+
"Examples:": "Eksempler:",
|
|
5
|
+
"boolean": "boolsk",
|
|
6
|
+
"count": "antall",
|
|
7
|
+
"string": "streng",
|
|
8
|
+
"array": "matrise",
|
|
9
|
+
"required": "obligatorisk",
|
|
10
|
+
"default:": "standard:",
|
|
11
|
+
"choices:": "valg:",
|
|
12
|
+
"generated-value": "generert-verdi",
|
|
13
|
+
"Not enough non-option arguments: got %s, need at least %s": "Ikke nok ikke-alternativ argumenter: fikk %s, trenger minst %s",
|
|
14
|
+
"Too many non-option arguments: got %s, maximum of %s": "For mange ikke-alternativ argumenter: fikk %s, maksimum %s",
|
|
15
|
+
"Missing argument value: %s": {
|
|
16
|
+
"one": "Mangler argument verdi: %s",
|
|
17
|
+
"other": "Mangler argument verdier: %s"
|
|
18
|
+
},
|
|
19
|
+
"Missing required argument: %s": {
|
|
20
|
+
"one": "Mangler obligatorisk argument: %s",
|
|
21
|
+
"other": "Mangler obligatoriske argumenter: %s"
|
|
22
|
+
},
|
|
23
|
+
"Unknown argument: %s": {
|
|
24
|
+
"one": "Ukjent argument: %s",
|
|
25
|
+
"other": "Ukjente argumenter: %s"
|
|
26
|
+
},
|
|
27
|
+
"Invalid values:": "Ugyldige verdier:",
|
|
28
|
+
"Argument: %s, Given: %s, Choices: %s": "Argument: %s, Gitt: %s, Valg: %s",
|
|
29
|
+
"Argument check failed: %s": "Argument sjekk mislyktes: %s",
|
|
30
|
+
"Implications failed:": "Konsekvensene mislyktes:",
|
|
31
|
+
"Not enough arguments following: %s": "Ikke nok følgende argumenter: %s",
|
|
32
|
+
"Invalid JSON config file: %s": "Ugyldig JSON konfigurasjonsfil: %s",
|
|
33
|
+
"Path to JSON config file": "Bane til JSON konfigurasjonsfil",
|
|
34
|
+
"Show help": "Vis hjelp",
|
|
35
|
+
"Show version number": "Vis versjonsnummer"
|
|
36
|
+
}
|
package/locales/pl.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "Polecenia:",
|
|
3
|
+
"Options:": "Opcje:",
|
|
4
|
+
"Examples:": "Przykłady:",
|
|
5
|
+
"boolean": "boolean",
|
|
6
|
+
"count": "ilość",
|
|
7
|
+
"string": "ciąg znaków",
|
|
8
|
+
"array": "tablica",
|
|
9
|
+
"required": "wymagany",
|
|
10
|
+
"default:": "domyślny:",
|
|
11
|
+
"choices:": "dostępne:",
|
|
12
|
+
"generated-value": "wygenerowana-wartość",
|
|
13
|
+
"Not enough non-option arguments: got %s, need at least %s": "Niewystarczająca ilość argumentów: otrzymano %s, wymagane co najmniej %s",
|
|
14
|
+
"Too many non-option arguments: got %s, maximum of %s": "Zbyt duża ilość argumentów: otrzymano %s, wymagane co najwyżej %s",
|
|
15
|
+
"Missing argument value: %s": {
|
|
16
|
+
"one": "Brak wartości dla argumentu: %s",
|
|
17
|
+
"other": "Brak wartości dla argumentów: %s"
|
|
18
|
+
},
|
|
19
|
+
"Missing required argument: %s": {
|
|
20
|
+
"one": "Brak wymaganego argumentu: %s",
|
|
21
|
+
"other": "Brak wymaganych argumentów: %s"
|
|
22
|
+
},
|
|
23
|
+
"Unknown argument: %s": {
|
|
24
|
+
"one": "Nieznany argument: %s",
|
|
25
|
+
"other": "Nieznane argumenty: %s"
|
|
26
|
+
},
|
|
27
|
+
"Invalid values:": "Nieprawidłowe wartości:",
|
|
28
|
+
"Argument: %s, Given: %s, Choices: %s": "Argument: %s, Otrzymano: %s, Dostępne: %s",
|
|
29
|
+
"Argument check failed: %s": "Weryfikacja argumentów nie powiodła się: %s",
|
|
30
|
+
"Implications failed:": "Założenia nie zostały spełnione:",
|
|
31
|
+
"Not enough arguments following: %s": "Niewystarczająca ilość argumentów następujących po: %s",
|
|
32
|
+
"Invalid JSON config file: %s": "Nieprawidłowy plik konfiguracyjny JSON: %s",
|
|
33
|
+
"Path to JSON config file": "Ścieżka do pliku konfiguracyjnego JSON",
|
|
34
|
+
"Show help": "Pokaż pomoc",
|
|
35
|
+
"Show version number": "Pokaż numer wersji"
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "Comandos:",
|
|
3
|
+
"Options:": "Opções:",
|
|
4
|
+
"Examples:": "Exemplos:",
|
|
5
|
+
"boolean": "boolean",
|
|
6
|
+
"count": "contagem",
|
|
7
|
+
"string": "string",
|
|
8
|
+
"array": "array",
|
|
9
|
+
"required": "obrigatório",
|
|
10
|
+
"default:": "padrão:",
|
|
11
|
+
"choices:": "opções:",
|
|
12
|
+
"generated-value": "valor-gerado",
|
|
13
|
+
"Not enough non-option arguments: got %s, need at least %s": "Argumentos insuficientes: Argumento %s, necessário pelo menos %s",
|
|
14
|
+
"Too many non-option arguments: got %s, maximum of %s": "Excesso de argumentos: recebido %s, máximo de %s",
|
|
15
|
+
"Missing argument value: %s": {
|
|
16
|
+
"one": "Falta valor de argumento: %s",
|
|
17
|
+
"other": "Falta valores de argumento: %s"
|
|
18
|
+
},
|
|
19
|
+
"Missing required argument: %s": {
|
|
20
|
+
"one": "Falta argumento obrigatório: %s",
|
|
21
|
+
"other": "Faltando argumentos obrigatórios: %s"
|
|
22
|
+
},
|
|
23
|
+
"Unknown argument: %s": {
|
|
24
|
+
"one": "Argumento desconhecido: %s",
|
|
25
|
+
"other": "Argumentos desconhecidos: %s"
|
|
26
|
+
},
|
|
27
|
+
"Invalid values:": "Valores inválidos:",
|
|
28
|
+
"Argument: %s, Given: %s, Choices: %s": "Argumento: %s, Dado: %s, Opções: %s",
|
|
29
|
+
"Argument check failed: %s": "Verificação de argumento falhou: %s",
|
|
30
|
+
"Implications failed:": "Implicações falharam:",
|
|
31
|
+
"Not enough arguments following: %s": "Argumentos insuficientes a seguir: %s",
|
|
32
|
+
"Invalid JSON config file: %s": "Arquivo JSON de configuração inválido: %s",
|
|
33
|
+
"Path to JSON config file": "Caminho para o arquivo JSON de configuração",
|
|
34
|
+
"Show help": "Exibe ajuda",
|
|
35
|
+
"Show version number": "Exibe a versão"
|
|
36
|
+
}
|
package/locales/tr.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "Komutlar:",
|
|
3
|
+
"Options:": "Seçenekler:",
|
|
4
|
+
"Examples:": "Örnekler:",
|
|
5
|
+
"boolean": "boolean",
|
|
6
|
+
"count": "sayı",
|
|
7
|
+
"string": "string",
|
|
8
|
+
"array": "array",
|
|
9
|
+
"required": "zorunlu",
|
|
10
|
+
"default:": "varsayılan:",
|
|
11
|
+
"choices:": "seçimler:",
|
|
12
|
+
"generated-value": "oluşturulan-değer",
|
|
13
|
+
"Not enough non-option arguments: got %s, need at least %s": "Seçenek dışı argümanlar yetersiz: %s bulundu, %s gerekli",
|
|
14
|
+
"Too many non-option arguments: got %s, maximum of %s": "Seçenek dışı argümanlar gereğinden fazla: %s bulundu, azami %s",
|
|
15
|
+
"Missing argument value: %s": {
|
|
16
|
+
"one": "Eksik argüman değeri: %s",
|
|
17
|
+
"other": "Eksik argüman değerleri: %s"
|
|
18
|
+
},
|
|
19
|
+
"Missing required argument: %s": {
|
|
20
|
+
"one": "Eksik zorunlu argüman: %s",
|
|
21
|
+
"other": "Eksik zorunlu argümanlar: %s"
|
|
22
|
+
},
|
|
23
|
+
"Unknown argument: %s": {
|
|
24
|
+
"one": "Bilinmeyen argüman: %s",
|
|
25
|
+
"other": "Bilinmeyen argümanlar: %s"
|
|
26
|
+
},
|
|
27
|
+
"Invalid values:": "Geçersiz değerler:",
|
|
28
|
+
"Argument: %s, Given: %s, Choices: %s": "Argüman: %s, Verilen: %s, Seçimler: %s",
|
|
29
|
+
"Argument check failed: %s": "Argüman kontrolü başarısız oldu: %s",
|
|
30
|
+
"Implications failed:": "Sonuçlar başarısız oldu:",
|
|
31
|
+
"Not enough arguments following: %s": "%s için yeterli argüman bulunamadı",
|
|
32
|
+
"Invalid JSON config file: %s": "Geçersiz JSON yapılandırma dosyası: %s",
|
|
33
|
+
"Path to JSON config file": "JSON yapılandırma dosya konumu",
|
|
34
|
+
"Show help": "Yardım detaylarını göster",
|
|
35
|
+
"Show version number": "Versiyon detaylarını göster"
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.31.0",
|
|
4
4
|
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -11,20 +11,23 @@
|
|
|
11
11
|
"LICENSE"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"camelcase": "^
|
|
15
|
-
"cliui": "^
|
|
16
|
-
"decamelize": "^1.
|
|
14
|
+
"camelcase": "^2.0.1",
|
|
15
|
+
"cliui": "^3.0.3",
|
|
16
|
+
"decamelize": "^1.1.1",
|
|
17
17
|
"os-locale": "^1.4.0",
|
|
18
|
-
"
|
|
18
|
+
"string-width": "^1.0.1",
|
|
19
|
+
"window-size": "^0.1.4",
|
|
19
20
|
"y18n": "^3.2.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"chai": "^3.
|
|
23
|
+
"chai": "^3.4.1",
|
|
24
|
+
"chalk": "^1.1.1",
|
|
23
25
|
"coveralls": "^2.11.4",
|
|
26
|
+
"es6-promise": "^3.0.2",
|
|
24
27
|
"hashish": "0.0.4",
|
|
25
|
-
"mocha": "^2.3.
|
|
26
|
-
"nyc": "^
|
|
27
|
-
"standard": "^5.
|
|
28
|
+
"mocha": "^2.3.4",
|
|
29
|
+
"nyc": "^4.0.1",
|
|
30
|
+
"standard": "^5.4.1",
|
|
28
31
|
"which": "^1.1.2",
|
|
29
32
|
"win-spawn": "^2.0.0"
|
|
30
33
|
},
|