yargs 11.1.1 → 12.0.2
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 +51 -4
- package/README.md +29 -11
- package/lib/apply-extends.js +1 -1
- package/lib/command.js +4 -1
- package/lib/levenshtein.js +2 -2
- package/lib/middleware.js +10 -0
- package/lib/usage.js +23 -12
- package/lib/validation.js +2 -2
- package/locales/pirate.json +2 -1
- package/package.json +12 -12
- package/yargs.js +50 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,55 @@
|
|
|
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="
|
|
6
|
-
|
|
5
|
+
<a name="12.0.2"></a>
|
|
6
|
+
## [12.0.2](https://github.com/yargs/yargs/compare/v12.0.1...v12.0.2) (2018-09-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* middleware should work regardless of when method is called ([664b265](https://github.com/yargs/yargs/commit/664b265)), closes [#1178](https://github.com/yargs/yargs/issues/1178)
|
|
12
|
+
* translation not working when using __ with a single parameter ([#1183](https://github.com/yargs/yargs/issues/1183)) ([f449aea](https://github.com/yargs/yargs/commit/f449aea))
|
|
13
|
+
* upgrade os-locale to version that addresses license issue ([#1195](https://github.com/yargs/yargs/issues/1195)) ([efc0970](https://github.com/yargs/yargs/commit/efc0970))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
<a name="12.0.1"></a>
|
|
18
|
+
## [12.0.1](https://github.com/yargs/yargs/compare/v12.0.0...v12.0.1) (2018-06-29)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<a name="12.0.0"></a>
|
|
23
|
+
# [12.0.0](https://github.com/yargs/yargs/compare/v11.1.0...v12.0.0) (2018-06-26)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* .argv and .parse() now invoke identical code path ([#1126](https://github.com/yargs/yargs/issues/1126)) ([f13ebf4](https://github.com/yargs/yargs/commit/f13ebf4))
|
|
29
|
+
* remove the trailing white spaces from the help output ([#1090](https://github.com/yargs/yargs/issues/1090)) ([3f0746c](https://github.com/yargs/yargs/commit/3f0746c))
|
|
30
|
+
* **completion:** Avoid default command and recommendations during completion ([#1123](https://github.com/yargs/yargs/issues/1123)) ([036e7c5](https://github.com/yargs/yargs/commit/036e7c5))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Chores
|
|
34
|
+
|
|
35
|
+
* test Node.js 6, 8 and 10 ([#1160](https://github.com/yargs/yargs/issues/1160)) ([84f9d2b](https://github.com/yargs/yargs/commit/84f9d2b))
|
|
36
|
+
* upgrade to version of yargs-parser that does not populate value for unset boolean ([#1104](https://github.com/yargs/yargs/issues/1104)) ([d4705f4](https://github.com/yargs/yargs/commit/d4705f4))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* add support for global middleware, useful for shared tasks like metrics ([#1119](https://github.com/yargs/yargs/issues/1119)) ([9d71ac7](https://github.com/yargs/yargs/commit/9d71ac7))
|
|
42
|
+
* allow setting scriptName $0 ([#1143](https://github.com/yargs/yargs/issues/1143)) ([a2f2eae](https://github.com/yargs/yargs/commit/a2f2eae))
|
|
43
|
+
* remove `setPlaceholderKeys` ([#1105](https://github.com/yargs/yargs/issues/1105)) ([6ee2c82](https://github.com/yargs/yargs/commit/6ee2c82))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### BREAKING CHANGES
|
|
47
|
+
|
|
48
|
+
* Options absent from `argv` (not set via CLI argument) are now absent from the parsed result object rather than being set with `undefined`
|
|
49
|
+
* drop Node 4 from testing matrix, such that we'll gradually start drifting away from supporting Node 4.
|
|
50
|
+
* yargs-parser does not populate 'false' when boolean flag is not passed
|
|
51
|
+
* tests that assert against help output will need to be updated
|
|
52
|
+
|
|
7
53
|
|
|
8
|
-
* backport security fix for os-locale.
|
|
9
54
|
|
|
10
55
|
<a name="11.1.0"></a>
|
|
11
56
|
# [11.1.0](https://github.com/yargs/yargs/compare/v11.0.0...v11.1.0) (2018-03-04)
|
|
@@ -21,6 +66,8 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
21
66
|
* 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))
|
|
22
67
|
* extend *.rc files in addition to json ([#1080](https://github.com/yargs/yargs/issues/1080)) ([11691a6](https://github.com/yargs/yargs/commit/11691a6))
|
|
23
68
|
|
|
69
|
+
|
|
70
|
+
|
|
24
71
|
<a name="11.0.0"></a>
|
|
25
72
|
# [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22)
|
|
26
73
|
|
|
@@ -656,7 +703,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
656
703
|
- [#308](https://github.com/bcoe/yargs/pull/308) Yargs now handles environment variables (@nexdrew)
|
|
657
704
|
- [#302](https://github.com/bcoe/yargs/pull/302) Add Indonesian translation (@rilut)
|
|
658
705
|
- [#300](https://github.com/bcoe/yargs/pull/300) Add Turkish translation (@feyzo)
|
|
659
|
-
- [#298](https://github.com/bcoe/yargs/pull/298) Add Norwegian
|
|
706
|
+
- [#298](https://github.com/bcoe/yargs/pull/298) Add Norwegian Bokmål translation (@sindresorhus)
|
|
660
707
|
- [#297](https://github.com/bcoe/yargs/pull/297) Fix for layout of cjk characters (@disjukr)
|
|
661
708
|
- [#296](https://github.com/bcoe/yargs/pull/296) Add Korean translation (@disjukr)
|
|
662
709
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
18
|
+
## Description :
|
|
19
|
+
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface.
|
|
12
20
|
|
|
13
|
-
|
|
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.
|
|
@@ -26,11 +30,19 @@ Yargs helps you build interactive command line tools, by parsing arguments and g
|
|
|
26
30
|
|
|
27
31
|
## Installation
|
|
28
32
|
|
|
33
|
+
Stable version:
|
|
29
34
|
```bash
|
|
30
35
|
npm i yargs --save
|
|
31
36
|
```
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
Bleeding edge version with the most recent features:
|
|
39
|
+
```bash
|
|
40
|
+
npm i yargs@next --save
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage :
|
|
44
|
+
|
|
45
|
+
### Simple Example
|
|
34
46
|
|
|
35
47
|
````javascript
|
|
36
48
|
#!/usr/bin/env node
|
|
@@ -51,9 +63,9 @@ $ ./plunder.js --ships 12 --distance 98.7
|
|
|
51
63
|
Retreat from the xupptumblers!
|
|
52
64
|
```
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
### Complex Example
|
|
55
67
|
|
|
56
|
-
```
|
|
68
|
+
```javascript
|
|
57
69
|
#!/usr/bin/env node
|
|
58
70
|
require('yargs') // eslint-disable-line
|
|
59
71
|
.command('serve [port]', 'start the server', (yargs) => {
|
|
@@ -75,7 +87,13 @@ require('yargs') // eslint-disable-line
|
|
|
75
87
|
|
|
76
88
|
Run the example above with `--help` to see the help for the application.
|
|
77
89
|
|
|
78
|
-
##
|
|
90
|
+
## Community :
|
|
91
|
+
|
|
92
|
+
Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com).
|
|
93
|
+
|
|
94
|
+
## Documentation :
|
|
95
|
+
|
|
96
|
+
### Table of Contents
|
|
79
97
|
|
|
80
98
|
* [Yargs' API](/docs/api.md)
|
|
81
99
|
* [Examples](/docs/examples.md)
|
package/lib/apply-extends.js
CHANGED
|
@@ -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/command.js
CHANGED
|
@@ -9,15 +9,18 @@ const DEFAULT_MARKER = /(^\*)|(^\$0)/
|
|
|
9
9
|
// handles parsing positional arguments,
|
|
10
10
|
// and populating argv with said positional
|
|
11
11
|
// arguments.
|
|
12
|
-
module.exports = function command (yargs, usage, validation) {
|
|
12
|
+
module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
13
13
|
const self = {}
|
|
14
14
|
let handlers = {}
|
|
15
15
|
let aliasMap = {}
|
|
16
16
|
let defaultCommand
|
|
17
|
+
globalMiddleware = globalMiddleware || []
|
|
17
18
|
self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) {
|
|
18
19
|
let aliases = []
|
|
19
20
|
handler = handler || (() => {})
|
|
20
21
|
middlewares = middlewares || []
|
|
22
|
+
globalMiddleware.push(...middlewares)
|
|
23
|
+
middlewares = globalMiddleware
|
|
21
24
|
if (Array.isArray(cmd)) {
|
|
22
25
|
aliases = cmd.slice(1)
|
|
23
26
|
cmd = cmd[0]
|
package/lib/levenshtein.js
CHANGED
|
@@ -37,8 +37,8 @@ module.exports = function levenshtein (a, b) {
|
|
|
37
37
|
matrix[i][j] = matrix[i - 1][j - 1]
|
|
38
38
|
} else {
|
|
39
39
|
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
Math.min(matrix[i][j - 1] + 1, // insertion
|
|
41
|
+
matrix[i - 1][j] + 1)) // deletion
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = function (globalMiddleware, context) {
|
|
2
|
+
return function (callback) {
|
|
3
|
+
if (Array.isArray(callback)) {
|
|
4
|
+
Array.prototype.push.apply(globalMiddleware, callback)
|
|
5
|
+
} else if (typeof callback === 'object') {
|
|
6
|
+
globalMiddleware.push(callback)
|
|
7
|
+
}
|
|
8
|
+
return context
|
|
9
|
+
}
|
|
10
|
+
}
|
package/lib/usage.js
CHANGED
|
@@ -45,7 +45,10 @@ module.exports = function usage (yargs, y18n) {
|
|
|
45
45
|
// don't output failure message more than once
|
|
46
46
|
if (!failureOutput) {
|
|
47
47
|
failureOutput = true
|
|
48
|
-
if (showHelpOnFail)
|
|
48
|
+
if (showHelpOnFail) {
|
|
49
|
+
yargs.showHelp('error')
|
|
50
|
+
logger.error()
|
|
51
|
+
}
|
|
49
52
|
if (msg || err) logger.error(msg || err)
|
|
50
53
|
if (failMessage) {
|
|
51
54
|
if (msg || err) logger.error('')
|
|
@@ -152,16 +155,23 @@ module.exports = function usage (yargs, y18n) {
|
|
|
152
155
|
const demandedCommands = yargs.getDemandedCommands()
|
|
153
156
|
const groups = yargs.getGroups()
|
|
154
157
|
const options = yargs.getOptions()
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
|
|
159
|
+
let keys = []
|
|
160
|
+
keys = keys.concat(Object.keys(descriptions))
|
|
161
|
+
keys = keys.concat(Object.keys(demandedOptions))
|
|
162
|
+
keys = keys.concat(Object.keys(demandedCommands))
|
|
163
|
+
keys = keys.concat(Object.keys(options.default))
|
|
164
|
+
keys = keys.filter(key => {
|
|
165
|
+
if (options.hiddenOptions.indexOf(key) < 0) {
|
|
166
|
+
return true
|
|
167
|
+
} else if (yargs.parsed.argv[options.showHiddenOpt]) {
|
|
168
|
+
return true
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
keys = Object.keys(keys.reduce((acc, key) => {
|
|
172
|
+
if (key !== '_') acc[key] = true
|
|
173
|
+
return acc
|
|
174
|
+
}, {}))
|
|
165
175
|
|
|
166
176
|
const theWrap = getWrap()
|
|
167
177
|
const ui = require('cliui')({
|
|
@@ -339,7 +349,8 @@ module.exports = function usage (yargs, y18n) {
|
|
|
339
349
|
ui.div(`${e}\n`)
|
|
340
350
|
}
|
|
341
351
|
|
|
342
|
-
|
|
352
|
+
// Remove the trailing white spaces
|
|
353
|
+
return ui.toString().replace(/\s*$/, '')
|
|
343
354
|
}
|
|
344
355
|
|
|
345
356
|
// return the maximum width of a string
|
package/lib/validation.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = function validation (yargs, usage, y18n) {
|
|
|
37
37
|
)
|
|
38
38
|
} else {
|
|
39
39
|
usage.fail(
|
|
40
|
-
|
|
40
|
+
__('Too many non-option arguments: got %s, maximum of %s', _s, demandedCommands._.max)
|
|
41
41
|
)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -292,7 +292,7 @@ module.exports = function validation (yargs, usage, y18n) {
|
|
|
292
292
|
// we default keys to 'undefined' that have been configured, we should not
|
|
293
293
|
// apply conflicting check unless they are a value other than 'undefined'.
|
|
294
294
|
if (value && argv[key] !== undefined && argv[value] !== undefined) {
|
|
295
|
-
usage.fail(__(
|
|
295
|
+
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value))
|
|
296
296
|
}
|
|
297
297
|
})
|
|
298
298
|
}
|
package/locales/pirate.json
CHANGED
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
"other": "Ye be havin' to set the followin' arguments land lubber: %s"
|
|
9
9
|
},
|
|
10
10
|
"Show help": "Parlay this here code of conduct",
|
|
11
|
-
"Show version number": "'Tis the version ye be askin' fer"
|
|
11
|
+
"Show version number": "'Tis the version ye be askin' fer",
|
|
12
|
+
"Arguments %s and %s are mutually exclusive" : "Yon scurvy dogs %s and %s be as bad as rum and a prudish wench"
|
|
12
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.2",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -13,36 +13,36 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"cliui": "^4.0.0",
|
|
16
|
-
"decamelize": "^
|
|
17
|
-
"find-up": "^
|
|
16
|
+
"decamelize": "^2.0.0",
|
|
17
|
+
"find-up": "^3.0.0",
|
|
18
18
|
"get-caller-file": "^1.0.1",
|
|
19
|
-
"os-locale": "^3.
|
|
19
|
+
"os-locale": "^3.0.0",
|
|
20
20
|
"require-directory": "^2.1.1",
|
|
21
21
|
"require-main-filename": "^1.0.1",
|
|
22
22
|
"set-blocking": "^2.0.0",
|
|
23
23
|
"string-width": "^2.0.0",
|
|
24
24
|
"which-module": "^2.0.0",
|
|
25
|
-
"y18n": "^3.2.1",
|
|
26
|
-
"yargs-parser": "^
|
|
25
|
+
"y18n": "^3.2.1 || ^4.0.0",
|
|
26
|
+
"yargs-parser": "^10.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"chai": "^4.1.2",
|
|
30
30
|
"chalk": "^1.1.3",
|
|
31
|
-
"coveralls": "^
|
|
31
|
+
"coveralls": "^3.0.2",
|
|
32
32
|
"cpr": "^2.0.0",
|
|
33
33
|
"cross-spawn": "^6.0.4",
|
|
34
34
|
"es6-promise": "^4.0.2",
|
|
35
35
|
"hashish": "0.0.4",
|
|
36
|
-
"mocha": "^
|
|
37
|
-
"nyc": "^11.
|
|
36
|
+
"mocha": "^5.1.1",
|
|
37
|
+
"nyc": "^11.7.3",
|
|
38
38
|
"rimraf": "^2.5.0",
|
|
39
|
-
"standard": "^
|
|
39
|
+
"standard": "^11.0.1",
|
|
40
40
|
"standard-version": "^4.2.0",
|
|
41
41
|
"which": "^1.2.9",
|
|
42
42
|
"yargs-test-extends": "^1.0.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"
|
|
45
|
+
"pretest": "standard",
|
|
46
46
|
"test": "nyc --cache mocha --require ./test/before.js --timeout=8000 --check-leaks",
|
|
47
47
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
|
48
48
|
"release": "standard-version"
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
],
|
|
69
69
|
"license": "MIT",
|
|
70
70
|
"engine": {
|
|
71
|
-
"node": ">=
|
|
71
|
+
"node": ">=6"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/yargs.js
CHANGED
|
@@ -11,6 +11,7 @@ const Y18n = require('y18n')
|
|
|
11
11
|
const objFilter = require('./lib/obj-filter')
|
|
12
12
|
const setBlocking = require('set-blocking')
|
|
13
13
|
const applyExtends = require('./lib/apply-extends')
|
|
14
|
+
const middlewareFactory = require('./lib/middleware')
|
|
14
15
|
const YError = require('./lib/yerror')
|
|
15
16
|
|
|
16
17
|
exports = module.exports = Yargs
|
|
@@ -21,6 +22,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
21
22
|
let command = null
|
|
22
23
|
let completion = null
|
|
23
24
|
let groups = {}
|
|
25
|
+
let globalMiddleware = []
|
|
24
26
|
let output = ''
|
|
25
27
|
let preservedGroups = {}
|
|
26
28
|
let usage = null
|
|
@@ -31,8 +33,15 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
31
33
|
updateFiles: false
|
|
32
34
|
})
|
|
33
35
|
|
|
36
|
+
self.middleware = middlewareFactory(globalMiddleware, self)
|
|
37
|
+
|
|
34
38
|
if (!cwd) cwd = process.cwd()
|
|
35
39
|
|
|
40
|
+
self.scriptName = function scriptName (scriptName) {
|
|
41
|
+
self.$0 = scriptName
|
|
42
|
+
return self
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
self.$0 = process.argv
|
|
37
46
|
.slice(0, 2)
|
|
38
47
|
.map((x, i) => {
|
|
@@ -93,7 +102,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
93
102
|
|
|
94
103
|
const arrayOptions = [
|
|
95
104
|
'array', 'boolean', 'string', 'skipValidation',
|
|
96
|
-
'count', 'normalize', 'number'
|
|
105
|
+
'count', 'normalize', 'number',
|
|
106
|
+
'hiddenOptions'
|
|
97
107
|
]
|
|
98
108
|
|
|
99
109
|
const objectOptions = [
|
|
@@ -116,7 +126,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
116
126
|
// instances of all our helpers -- otherwise just reset.
|
|
117
127
|
usage = usage ? usage.reset(localLookup) : Usage(self, y18n)
|
|
118
128
|
validation = validation ? validation.reset(localLookup) : Validation(self, usage, y18n)
|
|
119
|
-
command = command ? command.reset() : Command(self, usage, validation)
|
|
129
|
+
command = command ? command.reset() : Command(self, usage, validation, globalMiddleware)
|
|
120
130
|
if (!completion) completion = Completion(self, usage, command)
|
|
121
131
|
|
|
122
132
|
completionCommand = null
|
|
@@ -524,7 +534,9 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
524
534
|
let parseContext = null
|
|
525
535
|
self.parse = function parse (args, shortCircuit, _parseFn) {
|
|
526
536
|
argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length)
|
|
527
|
-
if (typeof args === 'undefined')
|
|
537
|
+
if (typeof args === 'undefined') {
|
|
538
|
+
return self._parseArgs(processArgs)
|
|
539
|
+
}
|
|
528
540
|
|
|
529
541
|
// a context object can optionally be provided, this allows
|
|
530
542
|
// additional information to be passed to a command handler.
|
|
@@ -657,8 +669,9 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
657
669
|
}
|
|
658
670
|
|
|
659
671
|
const desc = opt.describe || opt.description || opt.desc
|
|
660
|
-
|
|
661
|
-
|
|
672
|
+
self.describe(key, desc)
|
|
673
|
+
if (opt.hidden) {
|
|
674
|
+
self.hide(key)
|
|
662
675
|
}
|
|
663
676
|
|
|
664
677
|
if (opt.requiresArg) {
|
|
@@ -824,6 +837,28 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
824
837
|
return self
|
|
825
838
|
}
|
|
826
839
|
|
|
840
|
+
const defaultShowHiddenOpt = 'show-hidden'
|
|
841
|
+
options.showHiddenOpt = defaultShowHiddenOpt
|
|
842
|
+
self.addShowHiddenOpt = self.showHidden = function addShowHiddenOpt (opt, msg) {
|
|
843
|
+
argsert('[string|boolean] [string]', [opt, msg], arguments.length)
|
|
844
|
+
|
|
845
|
+
if (arguments.length === 1) {
|
|
846
|
+
if (opt === false) return self
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const showHiddenOpt = typeof opt === 'string' ? opt : defaultShowHiddenOpt
|
|
850
|
+
self.boolean(showHiddenOpt)
|
|
851
|
+
self.describe(showHiddenOpt, msg || usage.deferY18nLookup('Show hidden options'))
|
|
852
|
+
options.showHiddenOpt = showHiddenOpt
|
|
853
|
+
return self
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
self.hide = function hide (key) {
|
|
857
|
+
argsert('<string|object>', [key], arguments.length)
|
|
858
|
+
options.hiddenOptions.push(key)
|
|
859
|
+
return self
|
|
860
|
+
}
|
|
861
|
+
|
|
827
862
|
self.showHelpOnFail = function showHelpOnFail (enabled, message) {
|
|
828
863
|
argsert('[boolean|string] [string]', [enabled, message], arguments.length)
|
|
829
864
|
usage.showHelpOnFail(enabled, message)
|
|
@@ -1006,8 +1041,11 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1006
1041
|
argv[helpOpt] = true
|
|
1007
1042
|
}
|
|
1008
1043
|
}
|
|
1044
|
+
|
|
1009
1045
|
const handlerKeys = command.getCommands()
|
|
1010
|
-
const
|
|
1046
|
+
const requestCompletions = completion.completionKey in argv
|
|
1047
|
+
const skipRecommendation = argv[helpOpt] || requestCompletions
|
|
1048
|
+
const skipDefaultCommand = skipRecommendation && (handlerKeys.length > 1 || handlerKeys[0] !== '$0')
|
|
1011
1049
|
|
|
1012
1050
|
if (argv._.length) {
|
|
1013
1051
|
if (handlerKeys.length) {
|
|
@@ -1015,7 +1053,6 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1015
1053
|
for (let i = (commandIndex || 0), cmd; argv._[i] !== undefined; i++) {
|
|
1016
1054
|
cmd = String(argv._[i])
|
|
1017
1055
|
if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
|
|
1018
|
-
setPlaceholderKeys(argv)
|
|
1019
1056
|
// commands are executed using a recursive algorithm that executes
|
|
1020
1057
|
// the deepest command first; we keep track of the position in the
|
|
1021
1058
|
// argv._ array that is currently being executed.
|
|
@@ -1028,31 +1065,29 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1028
1065
|
|
|
1029
1066
|
// run the default command, if defined
|
|
1030
1067
|
if (command.hasDefaultCommand() && !skipDefaultCommand) {
|
|
1031
|
-
setPlaceholderKeys(argv)
|
|
1032
1068
|
return command.runCommand(null, self, parsed)
|
|
1033
1069
|
}
|
|
1034
1070
|
|
|
1035
1071
|
// recommend a command if recommendCommands() has
|
|
1036
1072
|
// been enabled, and no commands were found to execute
|
|
1037
|
-
if (recommendCommands && firstUnknownCommand && !
|
|
1073
|
+
if (recommendCommands && firstUnknownCommand && !skipRecommendation) {
|
|
1038
1074
|
validation.recommendCommands(firstUnknownCommand, handlerKeys)
|
|
1039
1075
|
}
|
|
1040
1076
|
}
|
|
1041
1077
|
|
|
1042
1078
|
// generate a completion script for adding to ~/.bashrc.
|
|
1043
|
-
if (completionCommand && ~argv._.indexOf(completionCommand) && !
|
|
1079
|
+
if (completionCommand && ~argv._.indexOf(completionCommand) && !requestCompletions) {
|
|
1044
1080
|
if (exitProcess) setBlocking(true)
|
|
1045
1081
|
self.showCompletionScript()
|
|
1046
1082
|
self.exit(0)
|
|
1047
1083
|
}
|
|
1048
1084
|
} else if (command.hasDefaultCommand() && !skipDefaultCommand) {
|
|
1049
|
-
setPlaceholderKeys(argv)
|
|
1050
1085
|
return command.runCommand(null, self, parsed)
|
|
1051
1086
|
}
|
|
1052
1087
|
|
|
1053
1088
|
// we must run completions first, a user might
|
|
1054
1089
|
// want to complete the --help or --version option.
|
|
1055
|
-
if (
|
|
1090
|
+
if (requestCompletions) {
|
|
1056
1091
|
if (exitProcess) setBlocking(true)
|
|
1057
1092
|
|
|
1058
1093
|
// we allow for asynchronous completions,
|
|
@@ -1065,7 +1100,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1065
1100
|
|
|
1066
1101
|
self.exit(0)
|
|
1067
1102
|
})
|
|
1068
|
-
return
|
|
1103
|
+
return argv
|
|
1069
1104
|
}
|
|
1070
1105
|
|
|
1071
1106
|
// Handle 'help' and 'version' options
|
|
@@ -1100,7 +1135,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1100
1135
|
|
|
1101
1136
|
// if we're executed via bash completion, don't
|
|
1102
1137
|
// bother with validation.
|
|
1103
|
-
if (!
|
|
1138
|
+
if (!requestCompletions) {
|
|
1104
1139
|
self._runValidation(argv, aliases, {}, parsed.error)
|
|
1105
1140
|
}
|
|
1106
1141
|
}
|
|
@@ -1109,7 +1144,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1109
1144
|
else throw err
|
|
1110
1145
|
}
|
|
1111
1146
|
|
|
1112
|
-
return
|
|
1147
|
+
return argv
|
|
1113
1148
|
}
|
|
1114
1149
|
|
|
1115
1150
|
self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
|
|
@@ -1135,16 +1170,6 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1135
1170
|
}
|
|
1136
1171
|
}
|
|
1137
1172
|
|
|
1138
|
-
function setPlaceholderKeys (argv) {
|
|
1139
|
-
Object.keys(options.key).forEach((key) => {
|
|
1140
|
-
// don't set placeholder keys for dot
|
|
1141
|
-
// notation options 'foo.bar'.
|
|
1142
|
-
if (~key.indexOf('.')) return
|
|
1143
|
-
if (typeof argv[key] === 'undefined') argv[key] = undefined
|
|
1144
|
-
})
|
|
1145
|
-
return argv
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1173
|
// an app should almost always have --version and --help,
|
|
1149
1174
|
// if you *really* want to disable this use .help(false)/.version(false).
|
|
1150
1175
|
self.help()
|