yargs 14.0.0 → 14.2.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 +46 -0
- package/README.md +3 -2
- package/index.js +0 -1
- package/lib/apply-extends.js +17 -3
- package/lib/command.js +25 -9
- package/lib/completion.js +2 -1
- package/lib/is-promise.js +1 -1
- package/lib/middleware.js +1 -2
- package/lib/usage.js +8 -0
- package/lib/validation.js +37 -29
- package/package.json +2 -2
- package/yargs.js +52 -23
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
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
|
+
### 14.2.2
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* temporary fix for libraries that call Object.freeze() ([#1483](https://www.github.com/yargs/yargs/issues/1483)) ([99c2dc8](https://www.github.com/yargs/yargs/commit/99c2dc850e67c606644f8b0c0bca1a59c87dcbcd))
|
|
10
|
+
|
|
11
|
+
### [14.2.1](https://github.com/yargs/yargs/compare/v14.2.0...v14.2.1) (2019-10-30)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* stop-parse was not being respected by commands ([#1459](https://github.com/yargs/yargs/issues/1459)) ([e78e76e](https://github.com/yargs/yargs/commit/e78e76e3ac0551d4f30c71a05ddb21582960fcef))
|
|
17
|
+
|
|
18
|
+
## [14.2.0](https://github.com/yargs/yargs/compare/v14.1.0...v14.2.0) (2019-10-07)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* async middleware was called twice ([#1422](https://github.com/yargs/yargs/issues/1422)) ([9a42b63](https://github.com/yargs/yargs/commit/9a42b63))
|
|
24
|
+
* fix promise check to accept any spec conform object ([#1424](https://github.com/yargs/yargs/issues/1424)) ([0be43d2](https://github.com/yargs/yargs/commit/0be43d2))
|
|
25
|
+
* groups were not being maintained for nested commands ([#1430](https://github.com/yargs/yargs/issues/1430)) ([d38650e](https://github.com/yargs/yargs/commit/d38650e))
|
|
26
|
+
* **docs:** broken markdown link ([#1426](https://github.com/yargs/yargs/issues/1426)) ([236e24e](https://github.com/yargs/yargs/commit/236e24e))
|
|
27
|
+
* support merging deeply nested configuration ([#1423](https://github.com/yargs/yargs/issues/1423)) ([bae66fe](https://github.com/yargs/yargs/commit/bae66fe))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* **deps:** introduce yargs-parser with support for unknown-options-as-args ([#1440](https://github.com/yargs/yargs/issues/1440)) ([4d21520](https://github.com/yargs/yargs/commit/4d21520))
|
|
33
|
+
|
|
34
|
+
## [14.1.0](https://github.com/yargs/yargs/compare/v14.0.0...v14.1.0) (2019-09-06)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* **docs:** fix incorrect parserConfiguration documentation ([2a99124](https://github.com/yargs/yargs/commit/2a99124))
|
|
40
|
+
* detect zsh when zsh isnt run as a login prompt ([#1395](https://github.com/yargs/yargs/issues/1395)) ([8792d13](https://github.com/yargs/yargs/commit/8792d13))
|
|
41
|
+
* populate correct value on yargs.parsed and stop warning on access ([#1412](https://github.com/yargs/yargs/issues/1412)) ([bb0eb52](https://github.com/yargs/yargs/commit/bb0eb52))
|
|
42
|
+
* showCompletionScript was logging script twice ([#1388](https://github.com/yargs/yargs/issues/1388)) ([07c8537](https://github.com/yargs/yargs/commit/07c8537))
|
|
43
|
+
* strict() should not ignore hyphenated arguments ([#1414](https://github.com/yargs/yargs/issues/1414)) ([b774b5e](https://github.com/yargs/yargs/commit/b774b5e))
|
|
44
|
+
* **docs:** formalize existing callback argument to showHelp ([#1386](https://github.com/yargs/yargs/issues/1386)) ([d217764](https://github.com/yargs/yargs/commit/d217764))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Features
|
|
48
|
+
|
|
49
|
+
* make it possible to merge configurations when extending other config. ([#1411](https://github.com/yargs/yargs/issues/1411)) ([5d7ad98](https://github.com/yargs/yargs/commit/5d7ad98))
|
|
50
|
+
|
|
5
51
|
## [14.0.0](https://github.com/yargs/yargs/compare/v13.3.0...v14.0.0) (2019-07-30)
|
|
6
52
|
|
|
7
53
|
|
package/README.md
CHANGED
|
@@ -80,7 +80,8 @@ require('yargs') // eslint-disable-line
|
|
|
80
80
|
})
|
|
81
81
|
.option('verbose', {
|
|
82
82
|
alias: 'v',
|
|
83
|
-
|
|
83
|
+
type: 'boolean',
|
|
84
|
+
description: 'Run with verbose logging'
|
|
84
85
|
})
|
|
85
86
|
.argv
|
|
86
87
|
```
|
|
@@ -95,7 +96,7 @@ yargs has type definitions at [@types/yargs][type-definitions].
|
|
|
95
96
|
npm i @types/yargs --save-dev
|
|
96
97
|
```
|
|
97
98
|
|
|
98
|
-
See usage examples in [docs](/docs/typescript.md)
|
|
99
|
+
See usage examples in [docs](/docs/typescript.md).
|
|
99
100
|
|
|
100
101
|
## Community :
|
|
101
102
|
|
package/index.js
CHANGED
|
@@ -32,7 +32,6 @@ function singletonify (inst) {
|
|
|
32
32
|
return inst.$0
|
|
33
33
|
})
|
|
34
34
|
Argv.__defineGetter__('parsed', () => {
|
|
35
|
-
console.warn('In future major releases of yargs, "parsed" will be a private field. Use the return value of ".parse()" or ".argv" instead')
|
|
36
35
|
return inst.parsed
|
|
37
36
|
})
|
|
38
37
|
}
|
package/lib/apply-extends.js
CHANGED
|
@@ -16,7 +16,21 @@ function getPathToDefaultConfig (cwd, pathToExtend) {
|
|
|
16
16
|
return path.resolve(cwd, pathToExtend)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function
|
|
19
|
+
function mergeDeep (config1, config2) {
|
|
20
|
+
const target = {}
|
|
21
|
+
const isObject = obj => obj && typeof obj === 'object' && !Array.isArray(obj)
|
|
22
|
+
Object.assign(target, config1)
|
|
23
|
+
for (let key of Object.keys(config2)) {
|
|
24
|
+
if (isObject(config2[key]) && isObject(target[key])) {
|
|
25
|
+
target[key] = mergeDeep(config1[key], config2[key])
|
|
26
|
+
} else {
|
|
27
|
+
target[key] = config2[key]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function applyExtends (config, cwd, mergeExtends) {
|
|
20
34
|
let defaultConfig = {}
|
|
21
35
|
|
|
22
36
|
if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
|
|
@@ -42,12 +56,12 @@ function applyExtends (config, cwd) {
|
|
|
42
56
|
|
|
43
57
|
defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
|
|
44
58
|
delete config.extends
|
|
45
|
-
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
|
|
59
|
+
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), mergeExtends)
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
previouslyVisitedConfigs = []
|
|
49
63
|
|
|
50
|
-
return Object.assign({}, defaultConfig, config)
|
|
64
|
+
return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config)
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
module.exports = applyExtends
|
package/lib/command.js
CHANGED
|
@@ -174,7 +174,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
174
174
|
let numFiles = currentContext.files.length
|
|
175
175
|
const parentCommands = currentContext.commands.slice()
|
|
176
176
|
|
|
177
|
-
// what does yargs look like after the
|
|
177
|
+
// what does yargs look like after the builder is run?
|
|
178
178
|
let innerArgv = parsed.argv
|
|
179
179
|
let innerYargs = null
|
|
180
180
|
let positionalMap = {}
|
|
@@ -227,17 +227,28 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
227
227
|
|
|
228
228
|
if (commandHandler.handler && !yargs._hasOutput()) {
|
|
229
229
|
yargs._setHasOutput()
|
|
230
|
+
// to simplify the parsing of positionals in commands,
|
|
231
|
+
// we temporarily populate '--' rather than _, with arguments
|
|
232
|
+
const populateDoubleDash = !!yargs.getOptions().configuration['populate--']
|
|
233
|
+
if (!populateDoubleDash) yargs._copyDoubleDash(innerArgv)
|
|
230
234
|
|
|
231
235
|
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
let handlerResult
|
|
237
|
+
if (isPromise(innerArgv)) {
|
|
238
|
+
handlerResult = innerArgv.then(argv => commandHandler.handler(argv))
|
|
239
|
+
} else {
|
|
240
|
+
handlerResult = commandHandler.handler(innerArgv)
|
|
241
|
+
}
|
|
236
242
|
|
|
237
243
|
if (isPromise(handlerResult)) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
yargs.getUsageInstance().cacheHelpMessage()
|
|
245
|
+
handlerResult.catch(error => {
|
|
246
|
+
try {
|
|
247
|
+
yargs.getUsageInstance().fail(null, error)
|
|
248
|
+
} catch (err) {
|
|
249
|
+
// fail's throwing would cause an unhandled rejection.
|
|
250
|
+
}
|
|
251
|
+
})
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
|
|
@@ -341,7 +352,12 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
341
352
|
// short-circuit parse.
|
|
342
353
|
if (!unparsed.length) return
|
|
343
354
|
|
|
344
|
-
const
|
|
355
|
+
const config = Object.assign({}, options.configuration, {
|
|
356
|
+
'populate--': true
|
|
357
|
+
})
|
|
358
|
+
const parsed = Parser.detailed(unparsed, Object.assign({}, options, {
|
|
359
|
+
configuration: config
|
|
360
|
+
}))
|
|
345
361
|
|
|
346
362
|
if (parsed.error) {
|
|
347
363
|
yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
|
package/lib/completion.js
CHANGED
|
@@ -8,7 +8,8 @@ module.exports = function completion (yargs, usage, command) {
|
|
|
8
8
|
completionKey: 'get-yargs-completions'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const zshShell = process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1
|
|
11
|
+
const zshShell = (process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1) ||
|
|
12
|
+
(process.env.ZSH_NAME && process.env.ZSH_NAME.indexOf('zsh') !== -1)
|
|
12
13
|
// get a list of completion commands.
|
|
13
14
|
// 'args' is the array of strings from the line to be completed
|
|
14
15
|
self.getCompletion = function getCompletion (args, done) {
|
package/lib/is-promise.js
CHANGED
package/lib/middleware.js
CHANGED
|
@@ -40,8 +40,7 @@ function applyMiddleware (argv, yargs, middlewares, beforeValidation) {
|
|
|
40
40
|
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true')
|
|
41
41
|
return middlewares
|
|
42
42
|
.reduce((accumulation, middleware) => {
|
|
43
|
-
if (middleware.applyBeforeValidation !== beforeValidation
|
|
44
|
-
!isPromise(accumulation)) {
|
|
43
|
+
if (middleware.applyBeforeValidation !== beforeValidation) {
|
|
45
44
|
return accumulation
|
|
46
45
|
}
|
|
47
46
|
|
package/lib/usage.js
CHANGED
|
@@ -148,6 +148,7 @@ module.exports = function usage (yargs, y18n) {
|
|
|
148
148
|
|
|
149
149
|
const defaultGroup = 'Options:'
|
|
150
150
|
self.help = function help () {
|
|
151
|
+
if (cachedHelpMessage) return cachedHelpMessage
|
|
151
152
|
normalizeAliases()
|
|
152
153
|
|
|
153
154
|
// handle old demanded API
|
|
@@ -403,6 +404,13 @@ module.exports = function usage (yargs, y18n) {
|
|
|
403
404
|
})
|
|
404
405
|
}
|
|
405
406
|
|
|
407
|
+
// if yargs is executing an async handler, we take a snapshot of the
|
|
408
|
+
// help message to display on failure:
|
|
409
|
+
let cachedHelpMessage
|
|
410
|
+
self.cacheHelpMessage = function () {
|
|
411
|
+
cachedHelpMessage = this.help()
|
|
412
|
+
}
|
|
413
|
+
|
|
406
414
|
// given a set of keys, place any keys that are
|
|
407
415
|
// ungrouped under the 'Options:' grouping.
|
|
408
416
|
function addUngroupedKeys (keys, aliases, groups) {
|
package/lib/validation.js
CHANGED
|
@@ -96,7 +96,7 @@ module.exports = function validation (yargs, usage, y18n) {
|
|
|
96
96
|
if (specialKeys.indexOf(key) === -1 &&
|
|
97
97
|
!positionalMap.hasOwnProperty(key) &&
|
|
98
98
|
!yargs._getParseContext().hasOwnProperty(key) &&
|
|
99
|
-
!
|
|
99
|
+
!self.isValidAndSomeAliasIsNotNew(key, aliases)
|
|
100
100
|
) {
|
|
101
101
|
unknown.push(key)
|
|
102
102
|
}
|
|
@@ -120,6 +120,21 @@ module.exports = function validation (yargs, usage, y18n) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// check for a key that is not an alias, or for which every alias is new,
|
|
124
|
+
// implying that it was invented by the parser, e.g., during camelization
|
|
125
|
+
self.isValidAndSomeAliasIsNotNew = function isValidAndSomeAliasIsNotNew (key, aliases) {
|
|
126
|
+
if (!aliases.hasOwnProperty(key)) {
|
|
127
|
+
return false
|
|
128
|
+
}
|
|
129
|
+
const newAliases = yargs.parsed.newAliases
|
|
130
|
+
for (let a of [key, ...aliases[key]]) {
|
|
131
|
+
if (!newAliases.hasOwnProperty(a) || !newAliases[key]) {
|
|
132
|
+
return true
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
// validate arguments limited to enumerated choices
|
|
124
139
|
self.limitedChoices = function limitedChoices (argv) {
|
|
125
140
|
const options = yargs.getOptions()
|
|
@@ -209,43 +224,36 @@ module.exports = function validation (yargs, usage, y18n) {
|
|
|
209
224
|
return implied
|
|
210
225
|
}
|
|
211
226
|
|
|
227
|
+
function keyExists (argv, val) {
|
|
228
|
+
// convert string '1' to number 1
|
|
229
|
+
let num = Number(val)
|
|
230
|
+
val = isNaN(num) ? val : num
|
|
231
|
+
|
|
232
|
+
if (typeof val === 'number') {
|
|
233
|
+
// check length of argv._
|
|
234
|
+
val = argv._.length >= val
|
|
235
|
+
} else if (val.match(/^--no-.+/)) {
|
|
236
|
+
// check if key/value doesn't exist
|
|
237
|
+
val = val.match(/^--no-(.+)/)[1]
|
|
238
|
+
val = !argv[val]
|
|
239
|
+
} else {
|
|
240
|
+
// check if key/value exists
|
|
241
|
+
val = argv[val]
|
|
242
|
+
}
|
|
243
|
+
return val
|
|
244
|
+
}
|
|
245
|
+
|
|
212
246
|
self.implications = function implications (argv) {
|
|
213
247
|
const implyFail = []
|
|
214
248
|
|
|
215
249
|
Object.keys(implied).forEach((key) => {
|
|
216
250
|
const origKey = key
|
|
217
251
|
;(implied[key] || []).forEach((value) => {
|
|
218
|
-
let num
|
|
219
252
|
let key = origKey
|
|
220
253
|
const origValue = value
|
|
254
|
+
key = keyExists(argv, key)
|
|
255
|
+
value = keyExists(argv, value)
|
|
221
256
|
|
|
222
|
-
// convert string '1' to number 1
|
|
223
|
-
num = Number(key)
|
|
224
|
-
key = isNaN(num) ? key : num
|
|
225
|
-
|
|
226
|
-
if (typeof key === 'number') {
|
|
227
|
-
// check length of argv._
|
|
228
|
-
key = argv._.length >= key
|
|
229
|
-
} else if (key.match(/^--no-.+/)) {
|
|
230
|
-
// check if key doesn't exist
|
|
231
|
-
key = key.match(/^--no-(.+)/)[1]
|
|
232
|
-
key = !argv[key]
|
|
233
|
-
} else {
|
|
234
|
-
// check if key exists
|
|
235
|
-
key = argv[key]
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
num = Number(value)
|
|
239
|
-
value = isNaN(num) ? value : num
|
|
240
|
-
|
|
241
|
-
if (typeof value === 'number') {
|
|
242
|
-
value = argv._.length >= value
|
|
243
|
-
} else if (value.match(/^--no-.+/)) {
|
|
244
|
-
value = value.match(/^--no-(.+)/)[1]
|
|
245
|
-
value = !argv[value]
|
|
246
|
-
} else {
|
|
247
|
-
value = argv[value]
|
|
248
|
-
}
|
|
249
257
|
if (key && !value) {
|
|
250
258
|
implyFail.push(` ${origKey} -> ${origValue}`)
|
|
251
259
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.2.2",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"string-width": "^3.0.0",
|
|
30
30
|
"which-module": "^2.0.0",
|
|
31
31
|
"y18n": "^4.0.0",
|
|
32
|
-
"yargs-parser": "^
|
|
32
|
+
"yargs-parser": "^15.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"chai": "^4.2.0",
|
package/yargs.js
CHANGED
|
@@ -94,14 +94,17 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
// add all groups not set to local to preserved groups
|
|
98
|
+
Object.assign(
|
|
99
|
+
preservedGroups,
|
|
100
|
+
Object.keys(groups).reduce((acc, groupName) => {
|
|
101
|
+
const keys = groups[groupName].filter(key => !(key in localLookup))
|
|
102
|
+
if (keys.length > 0) {
|
|
103
|
+
acc[groupName] = keys
|
|
104
|
+
}
|
|
105
|
+
return acc
|
|
106
|
+
}, {})
|
|
107
|
+
)
|
|
105
108
|
// groups can now be reset
|
|
106
109
|
groups = {}
|
|
107
110
|
|
|
@@ -330,7 +333,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
330
333
|
argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length)
|
|
331
334
|
// allow a config object to be provided directly.
|
|
332
335
|
if (typeof key === 'object') {
|
|
333
|
-
key = applyExtends(key, cwd)
|
|
336
|
+
key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'])
|
|
334
337
|
options.configObjects = (options.configObjects || []).concat(key)
|
|
335
338
|
return self
|
|
336
339
|
}
|
|
@@ -504,7 +507,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
504
507
|
|
|
505
508
|
// If an object exists in the key, add it to options.configObjects
|
|
506
509
|
if (obj[key] && typeof obj[key] === 'object') {
|
|
507
|
-
conf = applyExtends(obj[key], rootPath || cwd)
|
|
510
|
+
conf = applyExtends(obj[key], rootPath || cwd, self.getParserConfiguration()['deep-merge-config'])
|
|
508
511
|
options.configObjects = (options.configObjects || []).concat(conf)
|
|
509
512
|
}
|
|
510
513
|
|
|
@@ -544,10 +547,12 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
544
547
|
argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length)
|
|
545
548
|
freeze()
|
|
546
549
|
if (typeof args === 'undefined') {
|
|
547
|
-
const
|
|
550
|
+
const argv = self._parseArgs(processArgs)
|
|
551
|
+
const tmpParsed = self.parsed
|
|
548
552
|
unfreeze()
|
|
549
553
|
// TODO: remove this compatibility hack when we release yargs@15.x:
|
|
550
|
-
|
|
554
|
+
self.parsed = tmpParsed
|
|
555
|
+
return argv
|
|
551
556
|
}
|
|
552
557
|
|
|
553
558
|
// a context object can optionally be provided, this allows
|
|
@@ -923,8 +928,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
923
928
|
self.showCompletionScript = function ($0, cmd) {
|
|
924
929
|
argsert('[string] [string]', [$0, cmd], arguments.length)
|
|
925
930
|
$0 = $0 || self.$0
|
|
926
|
-
|
|
927
|
-
_logger.log(completion.generateCompletionScript($0, completionCommand))
|
|
931
|
+
_logger.log(completion.generateCompletionScript($0, cmd || completionCommand || 'completion'))
|
|
928
932
|
return self
|
|
929
933
|
}
|
|
930
934
|
|
|
@@ -1021,13 +1025,12 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1021
1025
|
enumerable: true
|
|
1022
1026
|
})
|
|
1023
1027
|
|
|
1024
|
-
self._parseArgs = function parseArgs (args, shortCircuit,
|
|
1025
|
-
let skipValidation = !!
|
|
1028
|
+
self._parseArgs = function parseArgs (args, shortCircuit, _calledFromCommand, commandIndex) {
|
|
1029
|
+
let skipValidation = !!_calledFromCommand
|
|
1026
1030
|
args = args || processArgs
|
|
1027
1031
|
|
|
1028
1032
|
options.__ = y18n.__
|
|
1029
1033
|
options.configuration = self.getParserConfiguration()
|
|
1030
|
-
|
|
1031
1034
|
// Deprecated
|
|
1032
1035
|
let pkgConfig = pkgUp()['yargs']
|
|
1033
1036
|
if (pkgConfig) {
|
|
@@ -1035,7 +1038,14 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1035
1038
|
options.configuration = Object.assign({}, pkgConfig, options.configuration)
|
|
1036
1039
|
}
|
|
1037
1040
|
|
|
1038
|
-
const
|
|
1041
|
+
const populateDoubleDash = !!options.configuration['populate--']
|
|
1042
|
+
const config = Object.assign({}, options.configuration, {
|
|
1043
|
+
'populate--': true
|
|
1044
|
+
})
|
|
1045
|
+
const parsed = Parser.detailed(args, Object.assign({}, options, {
|
|
1046
|
+
configuration: config
|
|
1047
|
+
}))
|
|
1048
|
+
|
|
1039
1049
|
let argv = parsed.argv
|
|
1040
1050
|
if (parseContext) argv = Object.assign({}, argv, parseContext)
|
|
1041
1051
|
const aliases = parsed.aliases
|
|
@@ -1050,7 +1060,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1050
1060
|
// are two passes through the parser. If completion
|
|
1051
1061
|
// is being performed short-circuit on the first pass.
|
|
1052
1062
|
if (shortCircuit) {
|
|
1053
|
-
return argv
|
|
1063
|
+
return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
|
|
1054
1064
|
}
|
|
1055
1065
|
|
|
1056
1066
|
// if there's a handler associated with a
|
|
@@ -1083,7 +1093,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1083
1093
|
// commands are executed using a recursive algorithm that executes
|
|
1084
1094
|
// the deepest command first; we keep track of the position in the
|
|
1085
1095
|
// argv._ array that is currently being executed.
|
|
1086
|
-
|
|
1096
|
+
const innerArgv = command.runCommand(cmd, self, parsed, i + 1)
|
|
1097
|
+
return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
|
|
1087
1098
|
} else if (!firstUnknownCommand && cmd !== completionCommand) {
|
|
1088
1099
|
firstUnknownCommand = cmd
|
|
1089
1100
|
break
|
|
@@ -1092,7 +1103,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1092
1103
|
|
|
1093
1104
|
// run the default command, if defined
|
|
1094
1105
|
if (command.hasDefaultCommand() && !skipDefaultCommand) {
|
|
1095
|
-
|
|
1106
|
+
const innerArgv = command.runCommand(null, self, parsed)
|
|
1107
|
+
return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
|
|
1096
1108
|
}
|
|
1097
1109
|
|
|
1098
1110
|
// recommend a command if recommendCommands() has
|
|
@@ -1109,7 +1121,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1109
1121
|
self.exit(0)
|
|
1110
1122
|
}
|
|
1111
1123
|
} else if (command.hasDefaultCommand() && !skipDefaultCommand) {
|
|
1112
|
-
|
|
1124
|
+
const innerArgv = command.runCommand(null, self, parsed)
|
|
1125
|
+
return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
|
|
1113
1126
|
}
|
|
1114
1127
|
|
|
1115
1128
|
// we must run completions first, a user might
|
|
@@ -1127,7 +1140,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1127
1140
|
|
|
1128
1141
|
self.exit(0)
|
|
1129
1142
|
})
|
|
1130
|
-
return argv
|
|
1143
|
+
return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
|
|
1131
1144
|
}
|
|
1132
1145
|
|
|
1133
1146
|
// Handle 'help' and 'version' options
|
|
@@ -1171,6 +1184,22 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1171
1184
|
else throw err
|
|
1172
1185
|
}
|
|
1173
1186
|
|
|
1187
|
+
return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
// to simplify the parsing of positionals in commands,
|
|
1191
|
+
// we temporarily populate '--' rather than _, with arguments
|
|
1192
|
+
// after the '--' directive. After the parse, we copy these back.
|
|
1193
|
+
self._copyDoubleDash = function (argv) {
|
|
1194
|
+
if (!argv._ || !argv['--']) return argv
|
|
1195
|
+
argv._.push.apply(argv._, argv['--'])
|
|
1196
|
+
|
|
1197
|
+
// TODO(bcoe): refactor command parsing such that this delete is not
|
|
1198
|
+
// necessary: https://github.com/yargs/yargs/issues/1482
|
|
1199
|
+
try {
|
|
1200
|
+
delete argv['--']
|
|
1201
|
+
} catch (_err) {}
|
|
1202
|
+
|
|
1174
1203
|
return argv
|
|
1175
1204
|
}
|
|
1176
1205
|
|