yargs 3.30.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 CHANGED
@@ -1,8 +1,18 @@
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
+
3
13
  ### v3.30.0 (2015/11/13 16:29 +07:00)
4
14
 
5
- - [#293](https://github.com/bcoe/yargs/pull/293) Polish language support (@kamilogorek).
15
+ - [#293](https://github.com/bcoe/yargs/pull/293) Polish language support (@kamilogorek)
6
16
  - [#291](https://github.com/bcoe/yargs/pull/291) fix edge-cases with `.alias()` (@bcoe)
7
17
  - [#289](https://github.com/bcoe/yargs/pull/289) group options in custom groups (@bcoe)
8
18
 
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 executed with an instance
467
- of `yargs`, which can be used to compose nested commands.
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'
@@ -614,6 +620,63 @@ Optionally `.describe()` can take an object that maps keys to descriptions.
614
620
 
615
621
  Should yargs attempt to detect the os' locale? Defaults to `true`.
616
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
+
617
680
  .epilog(str)
618
681
  ------------
619
682
  .epilogue(str)
@@ -754,17 +817,23 @@ Locales currently supported:
754
817
  * **en:** American English.
755
818
  * **es:** Spanish.
756
819
  * **fr:** French.
820
+ * **id:** Indonesian.
757
821
  * **ja:** Japanese.
822
+ * **ko:** Korean.
823
+ * **nb:** Norwegian Bokmål.
824
+ * **pirate:** American Pirate.
758
825
  * **pt:** Portuguese.
759
826
  * **pt_BR:** Brazilian Portuguese.
827
+ * **tr:** Turkish.
760
828
  * **zh:** Chinese.
761
- * **pirate:** American Pirate.
762
829
 
763
830
  To submit a new translation for yargs:
764
831
 
765
832
  1. use `./locales/en.json` as a starting point.
766
833
  2. submit a pull request with the new locale file.
767
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
+
768
837
  <a name="nargs"></a>.nargs(key, count)
769
838
  -----------
770
839
 
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.
@@ -342,6 +343,14 @@ function Argv (processArgs, cwd) {
342
343
  return groups
343
344
  }
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
+
345
354
  self.wrap = function (cols) {
346
355
  usage.wrap(cols)
347
356
  return self
@@ -510,7 +519,7 @@ function Argv (processArgs, cwd) {
510
519
  var handlerKeys = Object.keys(self.getCommandHandlers())
511
520
  for (var i = 0, command; (command = handlerKeys[i]) !== undefined; i++) {
512
521
  if (~argv._.indexOf(command)) {
513
- self.getCommandHandlers()[command](self.reset())
522
+ runCommand(command, self, argv)
514
523
  return self.argv
515
524
  }
516
525
  }
@@ -592,6 +601,11 @@ function Argv (processArgs, cwd) {
592
601
  }
593
602
  }
594
603
 
604
+ function runCommand (command, yargs, argv) {
605
+ setPlaceholderKeys(argv)
606
+ yargs.getCommandHandlers()[command](yargs.reset(), argv)
607
+ }
608
+
595
609
  function setPlaceholderKeys (argv) {
596
610
  Object.keys(options.key).forEach(function (key) {
597
611
  // don't set placeholder keys for dot
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) {
@@ -351,6 +358,20 @@ module.exports = function (args, opts, y18n) {
351
358
  })
352
359
  }
353
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
+
354
375
  function applyDefaultsAndAliases (obj, aliases, defaults) {
355
376
  Object.keys(defaults).forEach(function (key) {
356
377
  if (!hasKey(obj, key.split('.'))) {
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) {
@@ -260,7 +261,7 @@ module.exports = function (yargs, y18n) {
260
261
  }
261
262
 
262
263
  table.forEach(function (v) {
263
- width = Math.max(v[0].length, width)
264
+ width = Math.max(stringWidth(v[0]), width)
264
265
  })
265
266
 
266
267
  // if we've enabled 'wrap' we should limit
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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.30.0",
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,11 +11,12 @@
11
11
  "LICENSE"
12
12
  ],
13
13
  "dependencies": {
14
- "camelcase": "^1.2.1",
14
+ "camelcase": "^2.0.1",
15
15
  "cliui": "^3.0.3",
16
16
  "decamelize": "^1.1.1",
17
17
  "os-locale": "^1.4.0",
18
- "window-size": "^0.1.2",
18
+ "string-width": "^1.0.1",
19
+ "window-size": "^0.1.4",
19
20
  "y18n": "^3.2.0"
20
21
  },
21
22
  "devDependencies": {
@@ -24,9 +25,9 @@
24
25
  "coveralls": "^2.11.4",
25
26
  "es6-promise": "^3.0.2",
26
27
  "hashish": "0.0.4",
27
- "mocha": "^2.3.3",
28
- "nyc": "^3.2.2",
29
- "standard": "^5.3.1",
28
+ "mocha": "^2.3.4",
29
+ "nyc": "^4.0.1",
30
+ "standard": "^5.4.1",
30
31
  "which": "^1.1.2",
31
32
  "win-spawn": "^2.0.0"
32
33
  },