yargs 10.1.0 → 11.1.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
@@ -2,6 +2,62 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="11.1.0"></a>
6
+ # [11.1.0](https://github.com/yargs/yargs/compare/v11.0.0...v11.1.0) (2018-03-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * choose correct config directory when require.main does not exist ([#1056](https://github.com/yargs/yargs/issues/1056)) ([a04678c](https://github.com/yargs/yargs/commit/a04678c))
12
+
13
+
14
+ ### Features
15
+
16
+ * allow hidden options to be displayed with --show-hidden ([#1061](https://github.com/yargs/yargs/issues/1061)) ([ea862ae](https://github.com/yargs/yargs/commit/ea862ae))
17
+ * extend *.rc files in addition to json ([#1080](https://github.com/yargs/yargs/issues/1080)) ([11691a6](https://github.com/yargs/yargs/commit/11691a6))
18
+
19
+
20
+
21
+ <a name="11.0.0"></a>
22
+ # [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * Set implicit nargs=1 when type=number requiresArg=true ([#1050](https://github.com/yargs/yargs/issues/1050)) ([2b56812](https://github.com/yargs/yargs/commit/2b56812))
28
+
29
+
30
+ ### Features
31
+
32
+ * requiresArg is now simply an alias for nargs(1) ([#1054](https://github.com/yargs/yargs/issues/1054)) ([a3ddacc](https://github.com/yargs/yargs/commit/a3ddacc))
33
+
34
+
35
+ ### BREAKING CHANGES
36
+
37
+ * requiresArg now has significantly different error output, matching nargs.
38
+
39
+
40
+
41
+ <a name="10.1.2"></a>
42
+ ## [10.1.2](https://github.com/yargs/yargs/compare/v10.1.1...v10.1.2) (2018-01-17)
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * requiresArg should only be enforced if argument exists ([#1043](https://github.com/yargs/yargs/issues/1043)) ([fbf41ae](https://github.com/yargs/yargs/commit/fbf41ae))
48
+
49
+
50
+
51
+ <a name="10.1.1"></a>
52
+ ## [10.1.1](https://github.com/yargs/yargs/compare/v10.1.0...v10.1.1) (2018-01-09)
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * Add `dirname` sanity check on `findUp` ([#1036](https://github.com/yargs/yargs/issues/1036)) ([331d103](https://github.com/yargs/yargs/commit/331d103))
58
+
59
+
60
+
5
61
  <a name="10.1.0"></a>
6
62
  # [10.1.0](https://github.com/yargs/yargs/compare/v10.0.3...v10.1.0) (2018-01-01)
7
63
 
package/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # Yargs
1
+ <p align="center">
2
+ <img width="250" src="/yargs-logo.png">
3
+ </p>
4
+ <h1 align="center"> Yargs </h1>
5
+ <p align="center">
6
+ <b >Yargs be a node.js library fer hearties tryin' ter parse optstrings</b>
7
+ </p>
8
+ <br>
2
9
 
3
10
  [![Build Status][travis-image]][travis-url]
4
11
  [![Coverage Status][coveralls-image]][coveralls-url]
@@ -8,13 +15,10 @@
8
15
  [![Conventional Commits][conventional-commits-image]][conventional-commits-url]
9
16
  [![Slack][slack-image]][slack-url]
10
17
 
11
- _Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com)_.
18
+ ## Description :
19
+ Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface.
12
20
 
13
- > Yargs be a node.js library fer hearties tryin' ter parse optstrings.
14
-
15
- <img width="250" src="/yargs-logo.png">
16
-
17
- Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you:
21
+ It gives you:
18
22
 
19
23
  * commands and (grouped) options (`my-program.js serve --port=5000`).
20
24
  * a dynamically generated help menu based on your arguments.
@@ -30,7 +34,9 @@ Yargs helps you build interactive command line tools, by parsing arguments and g
30
34
  npm i yargs --save
31
35
  ```
32
36
 
33
- ## Simple Example
37
+ ## Usage :
38
+
39
+ ### Simple Example
34
40
 
35
41
  ````javascript
36
42
  #!/usr/bin/env node
@@ -51,9 +57,9 @@ $ ./plunder.js --ships 12 --distance 98.7
51
57
  Retreat from the xupptumblers!
52
58
  ```
53
59
 
54
- ## Complex Example
60
+ ### Complex Example
55
61
 
56
- ```js
62
+ ```javascript
57
63
  #!/usr/bin/env node
58
64
  require('yargs') // eslint-disable-line
59
65
  .command('serve [port]', 'start the server', (yargs) => {
@@ -75,7 +81,13 @@ require('yargs') // eslint-disable-line
75
81
 
76
82
  Run the example above with `--help` to see the help for the application.
77
83
 
78
- ## Table of Contents
84
+ ## Community :
85
+
86
+ Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com).
87
+
88
+ ## Documentation :
89
+
90
+ ### Table of Contents
79
91
 
80
92
  * [Yargs' API](/docs/api.md)
81
93
  * [Examples](/docs/examples.md)
@@ -6,9 +6,9 @@ const YError = require('./yerror')
6
6
 
7
7
  let previouslyVisitedConfigs = []
8
8
 
9
- function checkForCircularExtends (path) {
10
- if (previouslyVisitedConfigs.indexOf(path) > -1) {
11
- throw new YError(`Circular extended configurations: '${path}'.`)
9
+ function checkForCircularExtends (cfgPath) {
10
+ if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
11
+ throw new YError(`Circular extended configurations: '${cfgPath}'.`)
12
12
  }
13
13
  }
14
14
 
@@ -21,7 +21,7 @@ function applyExtends (config, cwd) {
21
21
 
22
22
  if (config.hasOwnProperty('extends')) {
23
23
  if (typeof config.extends !== 'string') return defaultConfig
24
- const isPath = /\.json$/.test(config.extends)
24
+ const isPath = /\.json|\..*rc$/.test(config.extends)
25
25
  let pathToDefault = null
26
26
  if (!isPath) {
27
27
  try {
package/lib/usage.js CHANGED
@@ -152,16 +152,23 @@ module.exports = function usage (yargs, y18n) {
152
152
  const demandedCommands = yargs.getDemandedCommands()
153
153
  const groups = yargs.getGroups()
154
154
  const options = yargs.getOptions()
155
- let keys = Object.keys(
156
- Object.keys(descriptions)
157
- .concat(Object.keys(demandedOptions))
158
- .concat(Object.keys(demandedCommands))
159
- .concat(Object.keys(options.default))
160
- .reduce((acc, key) => {
161
- if (key !== '_') acc[key] = true
162
- return acc
163
- }, {})
164
- )
155
+
156
+ let keys = []
157
+ keys = keys.concat(Object.keys(descriptions))
158
+ keys = keys.concat(Object.keys(demandedOptions))
159
+ keys = keys.concat(Object.keys(demandedCommands))
160
+ keys = keys.concat(Object.keys(options.default))
161
+ keys = keys.filter(key => {
162
+ if (options.hiddenOptions.indexOf(key) < 0) {
163
+ return true
164
+ } else if (yargs.parsed.argv[options.showHiddenOpt]) {
165
+ return true
166
+ }
167
+ })
168
+ keys = Object.keys(keys.reduce((acc, key) => {
169
+ if (key !== '_') acc[key] = true
170
+ return acc
171
+ }, {}))
165
172
 
166
173
  const theWrap = getWrap()
167
174
  const ui = require('cliui')({
package/lib/validation.js CHANGED
@@ -54,38 +54,6 @@ module.exports = function validation (yargs, usage, y18n) {
54
54
  }
55
55
  }
56
56
 
57
- // make sure that any args that require an
58
- // value (--foo=bar), have a value.
59
- self.missingArgumentValue = function missingArgumentValue (argv) {
60
- const defaultValues = [true, false, '', undefined]
61
- const options = yargs.getOptions()
62
-
63
- if (options.requiresArg.length > 0) {
64
- const missingRequiredArgs = []
65
-
66
- options.requiresArg.forEach((key) => {
67
- const value = argv[key]
68
-
69
- // if a value is explicitly requested,
70
- // flag argument as missing if it does not
71
- // look like foo=bar was entered.
72
- if (~defaultValues.indexOf(value) ||
73
- (Array.isArray(value) && !value.length)) {
74
- missingRequiredArgs.push(key)
75
- }
76
- })
77
-
78
- if (missingRequiredArgs.length > 0) {
79
- usage.fail(__n(
80
- 'Missing argument value: %s',
81
- 'Missing argument values: %s',
82
- missingRequiredArgs.length,
83
- missingRequiredArgs.join(', ')
84
- ))
85
- }
86
- }
87
- }
88
-
89
57
  // make sure all the required arguments are present.
90
58
  self.requiredArguments = function requiredArguments (argv) {
91
59
  const demandedOptions = yargs.getDemandedOptions()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "10.1.0",
3
+ "version": "11.1.0",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.js",
6
6
  "files": [
@@ -23,14 +23,14 @@
23
23
  "string-width": "^2.0.0",
24
24
  "which-module": "^2.0.0",
25
25
  "y18n": "^3.2.1",
26
- "yargs-parser": "^8.1.0"
26
+ "yargs-parser": "^9.0.2"
27
27
  },
28
28
  "devDependencies": {
29
- "chai": "^3.4.1",
29
+ "chai": "^4.1.2",
30
30
  "chalk": "^1.1.3",
31
31
  "coveralls": "^2.11.11",
32
32
  "cpr": "^2.0.0",
33
- "cross-spawn": "^5.0.1",
33
+ "cross-spawn": "^6.0.4",
34
34
  "es6-promise": "^4.0.2",
35
35
  "hashish": "0.0.4",
36
36
  "mocha": "^3.0.1",
package/yargs.js CHANGED
@@ -92,8 +92,9 @@ function Yargs (processArgs, cwd, parentRequire) {
92
92
  groups = {}
93
93
 
94
94
  const arrayOptions = [
95
- 'array', 'boolean', 'string', 'requiresArg', 'skipValidation',
96
- 'count', 'normalize', 'number'
95
+ 'array', 'boolean', 'string', 'skipValidation',
96
+ 'count', 'normalize', 'number',
97
+ 'hiddenOptions'
97
98
  ]
98
99
 
99
100
  const objectOptions = [
@@ -204,7 +205,7 @@ function Yargs (processArgs, cwd, parentRequire) {
204
205
 
205
206
  self.requiresArg = function (keys) {
206
207
  argsert('<array|string>', [keys], arguments.length)
207
- populateParserHintArray('requiresArg', keys)
208
+ populateParserHintObject(self.nargs, false, 'narg', keys, 1)
208
209
  return self
209
210
  }
210
211
 
@@ -476,17 +477,17 @@ function Yargs (processArgs, cwd, parentRequire) {
476
477
  return self
477
478
  }
478
479
 
479
- self.pkgConf = function pkgConf (key, path) {
480
- argsert('<string> [string]', [key, path], arguments.length)
480
+ self.pkgConf = function pkgConf (key, rootPath) {
481
+ argsert('<string> [string]', [key, rootPath], arguments.length)
481
482
  let conf = null
482
483
  // prefer cwd to require-main-filename in this method
483
484
  // since we're looking for e.g. "nyc" config in nyc consumer
484
485
  // rather than "yargs" config in nyc (where nyc is the main filename)
485
- const obj = pkgUp(path || cwd)
486
+ const obj = pkgUp(rootPath || cwd)
486
487
 
487
488
  // If an object exists in the key, add it to options.configObjects
488
489
  if (obj[key] && typeof obj[key] === 'object') {
489
- conf = applyExtends(obj[key], path || cwd)
490
+ conf = applyExtends(obj[key], rootPath || cwd)
490
491
  options.configObjects = (options.configObjects || []).concat(conf)
491
492
  }
492
493
 
@@ -494,16 +495,24 @@ function Yargs (processArgs, cwd, parentRequire) {
494
495
  }
495
496
 
496
497
  const pkgs = {}
497
- function pkgUp (path) {
498
- const npath = path || '*'
498
+ function pkgUp (rootPath) {
499
+ const npath = rootPath || '*'
499
500
  if (pkgs[npath]) return pkgs[npath]
500
501
  const findUp = require('find-up')
501
502
 
502
503
  let obj = {}
503
504
  try {
505
+ let startDir = rootPath || require('require-main-filename')(parentRequire || require)
506
+
507
+ // When called in an environment that lacks require.main.filename, such as a jest test runner,
508
+ // startDir is already process.cwd(), and should not be shortened.
509
+ // Whether or not it is _actually_ a directory (e.g., extensionless bin) is irrelevant, find-up handles it.
510
+ if (!rootPath && path.extname(startDir)) {
511
+ startDir = path.dirname(startDir)
512
+ }
513
+
504
514
  const pkgJsonPath = findUp.sync('package.json', {
505
- cwd: path || require('require-main-filename')(parentRequire || require),
506
- normalize: false
515
+ cwd: startDir
507
516
  })
508
517
  obj = JSON.parse(fs.readFileSync(pkgJsonPath))
509
518
  } catch (noop) {}
@@ -649,8 +658,9 @@ function Yargs (processArgs, cwd, parentRequire) {
649
658
  }
650
659
 
651
660
  const desc = opt.describe || opt.description || opt.desc
652
- if (!opt.hidden) {
653
- self.describe(key, desc)
661
+ self.describe(key, desc)
662
+ if (opt.hidden) {
663
+ self.hide(key)
654
664
  }
655
665
 
656
666
  if (opt.requiresArg) {
@@ -816,6 +826,28 @@ function Yargs (processArgs, cwd, parentRequire) {
816
826
  return self
817
827
  }
818
828
 
829
+ const defaultShowHiddenOpt = 'show-hidden'
830
+ options.showHiddenOpt = defaultShowHiddenOpt
831
+ self.addShowHiddenOpt = self.showHidden = function addShowHiddenOpt (opt, msg) {
832
+ argsert('[string|boolean] [string]', [opt, msg], arguments.length)
833
+
834
+ if (arguments.length === 1) {
835
+ if (opt === false) return self
836
+ }
837
+
838
+ const showHiddenOpt = typeof opt === 'string' ? opt : defaultShowHiddenOpt
839
+ self.boolean(showHiddenOpt)
840
+ self.describe(showHiddenOpt, msg || usage.deferY18nLookup('Show hidden options'))
841
+ options.showHiddenOpt = showHiddenOpt
842
+ return self
843
+ }
844
+
845
+ self.hide = function hide (key) {
846
+ argsert('<string|object>', [key], arguments.length)
847
+ options.hiddenOptions.push(key)
848
+ return self
849
+ }
850
+
819
851
  self.showHelpOnFail = function showHelpOnFail (enabled, message) {
820
852
  argsert('[boolean|string] [string]', [enabled, message], arguments.length)
821
853
  usage.showHelpOnFail(enabled, message)
@@ -964,6 +996,7 @@ function Yargs (processArgs, cwd, parentRequire) {
964
996
 
965
997
  options.__ = y18n.__
966
998
  options.configuration = pkgUp()['yargs'] || {}
999
+
967
1000
  const parsed = Parser.detailed(args, options)
968
1001
  let argv = parsed.argv
969
1002
  if (parseContext) argv = Object.assign({}, argv, parseContext)
@@ -1106,7 +1139,6 @@ function Yargs (processArgs, cwd, parentRequire) {
1106
1139
  self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
1107
1140
  if (parseErrors) throw new YError(parseErrors.message)
1108
1141
  validation.nonOptionCount(argv)
1109
- validation.missingArgumentValue(argv)
1110
1142
  validation.requiredArguments(argv)
1111
1143
  if (strict) validation.unknownArguments(argv, aliases, positionalMap)
1112
1144
  validation.customChecks(argv, aliases)