yargs 12.0.3-candidate.0 → 13.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 +65 -0
- package/README.md +0 -3
- package/completion.sh.hbs +2 -2
- package/lib/argsert.js +4 -2
- package/lib/command.js +23 -15
- package/lib/decamelize.js +32 -0
- package/lib/is-promise.js +3 -0
- package/lib/levenshtein.js +16 -5
- package/lib/middleware.js +57 -2
- package/lib/usage.js +6 -1
- package/package.json +17 -18
- package/yargs.js +19 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,71 @@
|
|
|
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="13.1.0"></a>
|
|
6
|
+
# [13.1.0](https://github.com/yargs/yargs/compare/v13.0.0...v13.1.0) (2019-02-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add applyBeforeValidation, for applying sync middleware before validation ([5be206a](https://github.com/yargs/yargs/commit/5be206a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<a name="13.0.0"></a>
|
|
16
|
+
# [13.0.0](https://github.com/yargs/yargs/compare/v12.0.5...v13.0.0) (2019-02-02)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **deps:** Update os-locale to avoid security vulnerability ([#1270](https://github.com/yargs/yargs/issues/1270)) ([27bf739](https://github.com/yargs/yargs/commit/27bf739))
|
|
22
|
+
* **validation:** Use the error as a message when none exists otherwise ([#1268](https://github.com/yargs/yargs/issues/1268)) ([0510fe6](https://github.com/yargs/yargs/commit/0510fe6))
|
|
23
|
+
* better bash path completion ([#1272](https://github.com/yargs/yargs/issues/1272)) ([da75ea2](https://github.com/yargs/yargs/commit/da75ea2))
|
|
24
|
+
* middleware added multiple times due to reference bug ([#1282](https://github.com/yargs/yargs/issues/1282)) ([64af518](https://github.com/yargs/yargs/commit/64af518))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Chores
|
|
28
|
+
|
|
29
|
+
* drop Node 6 from testing matrix ([#1287](https://github.com/yargs/yargs/issues/1287)) ([ef16792](https://github.com/yargs/yargs/commit/ef16792))
|
|
30
|
+
* update dependencies ([#1284](https://github.com/yargs/yargs/issues/1284)) ([f25de4f](https://github.com/yargs/yargs/commit/f25de4f))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* Add `.parserConfiguration()` method, deprecating package.json config ([#1262](https://github.com/yargs/yargs/issues/1262)) ([3c6869a](https://github.com/yargs/yargs/commit/3c6869a))
|
|
36
|
+
* adds config option for sorting command output ([#1256](https://github.com/yargs/yargs/issues/1256)) ([6916ce9](https://github.com/yargs/yargs/commit/6916ce9))
|
|
37
|
+
* options/positionals with leading '+' and '0' no longer parse as numbers ([#1286](https://github.com/yargs/yargs/issues/1286)) ([e9dc3aa](https://github.com/yargs/yargs/commit/e9dc3aa))
|
|
38
|
+
* support promises in middleware ([f3a4e4f](https://github.com/yargs/yargs/commit/f3a4e4f))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### BREAKING CHANGES
|
|
42
|
+
|
|
43
|
+
* options with leading '+' or '0' now parse as strings
|
|
44
|
+
* dropping Node 6 which hits end of life in April 2019
|
|
45
|
+
* see [yargs-parser@12.0.0 CHANGELOG](https://github.com/yargs/yargs-parser/blob/master/CHANGELOG.md#breaking-changes)
|
|
46
|
+
* we now warn if the yargs stanza package.json is used.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<a name="12.0.5"></a>
|
|
51
|
+
## [12.0.5](https://github.com/yargs/yargs/compare/v12.0.4...v12.0.5) (2018-11-19)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Bug Fixes
|
|
55
|
+
|
|
56
|
+
* allows camel-case, variadic arguments, and strict mode to be combined ([#1247](https://github.com/yargs/yargs/issues/1247)) ([eacc035](https://github.com/yargs/yargs/commit/eacc035))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<a name="12.0.4"></a>
|
|
61
|
+
## [12.0.4](https://github.com/yargs/yargs/compare/v12.0.3...v12.0.4) (2018-11-10)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Bug Fixes
|
|
65
|
+
|
|
66
|
+
* don't load config when processing positionals ([5d0dc92](https://github.com/yargs/yargs/commit/5d0dc92))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
5
70
|
<a name="12.0.3"></a>
|
|
6
71
|
## [12.0.3](https://github.com/yargs/yargs/compare/v12.0.2...v12.0.3) (2018-10-06)
|
|
7
72
|
|
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
[![Build Status][travis-image]][travis-url]
|
|
11
11
|
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
12
12
|
[![NPM version][npm-image]][npm-url]
|
|
13
|
-
[![Windows Tests][windows-image]][windows-url]
|
|
14
13
|
[![js-standard-style][standard-image]][standard-url]
|
|
15
14
|
[![Conventional Commits][conventional-commits-image]][conventional-commits-url]
|
|
16
15
|
[![Slack][slack-image]][slack-url]
|
|
@@ -115,8 +114,6 @@ Having problems? want to contribute? join our [community slack](http://devtoolsc
|
|
|
115
114
|
[coveralls-image]: https://img.shields.io/coveralls/yargs/yargs.svg
|
|
116
115
|
[npm-url]: https://www.npmjs.com/package/yargs
|
|
117
116
|
[npm-image]: https://img.shields.io/npm/v/yargs.svg
|
|
118
|
-
[windows-url]: https://ci.appveyor.com/project/bcoe/yargs-ljwvf
|
|
119
|
-
[windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs-ljwvf/master.svg?label=Windows%20Tests
|
|
120
117
|
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
|
|
121
118
|
[standard-url]: http://standardjs.com/
|
|
122
119
|
[conventional-commits-image]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
|
package/completion.sh.hbs
CHANGED
|
@@ -19,10 +19,10 @@ _yargs_completions()
|
|
|
19
19
|
|
|
20
20
|
# if no match was found, fall back to filename completion
|
|
21
21
|
if [ ${#COMPREPLY[@]} -eq 0 ]; then
|
|
22
|
-
COMPREPLY=(
|
|
22
|
+
COMPREPLY=()
|
|
23
23
|
fi
|
|
24
24
|
|
|
25
25
|
return 0
|
|
26
26
|
}
|
|
27
|
-
complete -F _yargs_completions {{app_name}}
|
|
27
|
+
complete -o default -F _yargs_completions {{app_name}}
|
|
28
28
|
###-end-{{app_name}}-completions-###
|
package/lib/argsert.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
3
|
+
// hoisted due to circular dependency on command.
|
|
4
|
+
module.exports = argsert
|
|
2
5
|
const command = require('./command')()
|
|
3
6
|
const YError = require('./yerror')
|
|
4
7
|
|
|
5
8
|
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
|
|
6
|
-
|
|
7
|
-
module.exports = function argsert (expected, callerArguments, length) {
|
|
9
|
+
function argsert (expected, callerArguments, length) {
|
|
8
10
|
// TODO: should this eventually raise an exception.
|
|
9
11
|
try {
|
|
10
12
|
// preface the argument description with "cmd", so
|
package/lib/command.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const inspect = require('util').inspect
|
|
4
|
+
const isPromise = require('./is-promise')
|
|
5
|
+
const {applyMiddleware, commandMiddlewareFactory} = require('./middleware')
|
|
4
6
|
const path = require('path')
|
|
5
7
|
const Parser = require('yargs-parser')
|
|
6
8
|
|
|
@@ -15,12 +17,12 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
15
17
|
let aliasMap = {}
|
|
16
18
|
let defaultCommand
|
|
17
19
|
globalMiddleware = globalMiddleware || []
|
|
18
|
-
|
|
20
|
+
|
|
21
|
+
self.addHandler = function addHandler (cmd, description, builder, handler, commandMiddleware) {
|
|
19
22
|
let aliases = []
|
|
23
|
+
const middlewares = commandMiddlewareFactory(commandMiddleware)
|
|
20
24
|
handler = handler || (() => {})
|
|
21
|
-
|
|
22
|
-
globalMiddleware.push(...middlewares)
|
|
23
|
-
middlewares = globalMiddleware
|
|
25
|
+
|
|
24
26
|
if (Array.isArray(cmd)) {
|
|
25
27
|
aliases = cmd.slice(1)
|
|
26
28
|
cmd = cmd[0]
|
|
@@ -223,23 +225,25 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
223
225
|
positionalMap = populatePositionals(commandHandler, innerArgv, currentContext, yargs)
|
|
224
226
|
}
|
|
225
227
|
|
|
228
|
+
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares || [])
|
|
229
|
+
applyMiddleware(innerArgv, yargs, middlewares, true)
|
|
230
|
+
|
|
226
231
|
// we apply validation post-hoc, so that custom
|
|
227
232
|
// checks get passed populated positional arguments.
|
|
228
233
|
if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)
|
|
229
234
|
|
|
230
235
|
if (commandHandler.handler && !yargs._hasOutput()) {
|
|
231
236
|
yargs._setHasOutput()
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (handlerResult
|
|
240
|
-
handlerResult.
|
|
241
|
-
null,
|
|
242
|
-
(error) => yargs.getUsageInstance().fail(null, error)
|
|
237
|
+
|
|
238
|
+
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false)
|
|
239
|
+
|
|
240
|
+
const handlerResult = isPromise(innerArgv)
|
|
241
|
+
? innerArgv.then(argv => commandHandler.handler(argv))
|
|
242
|
+
: commandHandler.handler(innerArgv)
|
|
243
|
+
|
|
244
|
+
if (isPromise(handlerResult)) {
|
|
245
|
+
handlerResult.catch(error =>
|
|
246
|
+
yargs.getUsageInstance().fail(null, error)
|
|
243
247
|
)
|
|
244
248
|
}
|
|
245
249
|
}
|
|
@@ -331,6 +335,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
331
335
|
options.default = Object.assign(parseOptions.default, options.default)
|
|
332
336
|
options.alias = Object.assign(parseOptions.alias, options.alias)
|
|
333
337
|
options.array = options.array.concat(parseOptions.array)
|
|
338
|
+
delete options.config // don't load config when processing positionals.
|
|
334
339
|
|
|
335
340
|
const unparsed = []
|
|
336
341
|
Object.keys(positionalMap).forEach((key) => {
|
|
@@ -357,6 +362,9 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
357
362
|
|
|
358
363
|
Object.keys(parsed.argv).forEach((key) => {
|
|
359
364
|
if (positionalKeys.indexOf(key) !== -1) {
|
|
365
|
+
// any new aliases need to be placed in positionalMap, which
|
|
366
|
+
// is used for validation.
|
|
367
|
+
if (!positionalMap[key]) positionalMap[key] = parsed.argv[key]
|
|
360
368
|
argv[key] = parsed.argv[key]
|
|
361
369
|
}
|
|
362
370
|
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
the Software without restriction, including without limitation the rights to
|
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
10
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
18
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
19
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
20
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
'use strict'
|
|
24
|
+
|
|
25
|
+
module.exports = (text, separator) => {
|
|
26
|
+
separator = typeof separator === 'undefined' ? '_' : separator
|
|
27
|
+
|
|
28
|
+
return text
|
|
29
|
+
.replace(/([a-z\d])([A-Z])/g, `$1${separator}$2`)
|
|
30
|
+
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, `$1${separator}$2`)
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
}
|
package/lib/levenshtein.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
/*
|
|
2
2
|
Copyright (c) 2011 Andrei Mackenzie
|
|
3
3
|
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
17
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
20
|
*/
|
|
10
21
|
|
|
11
22
|
// levenshtein distance algorithm, pulled from Andrei Mackenzie's MIT licensed.
|
package/lib/middleware.js
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// hoisted due to circular dependency on command.
|
|
4
|
+
module.exports = {
|
|
5
|
+
applyMiddleware,
|
|
6
|
+
commandMiddlewareFactory,
|
|
7
|
+
globalMiddlewareFactory
|
|
8
|
+
}
|
|
9
|
+
const isPromise = require('./is-promise')
|
|
10
|
+
const argsert = require('./argsert')
|
|
11
|
+
|
|
12
|
+
function globalMiddlewareFactory (globalMiddleware, context) {
|
|
13
|
+
return function (callback, applyBeforeValidation = false) {
|
|
14
|
+
argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length)
|
|
3
15
|
if (Array.isArray(callback)) {
|
|
16
|
+
for (let i = 0; i < callback.length; i++) {
|
|
17
|
+
if (typeof callback[i] !== 'function') {
|
|
18
|
+
throw Error('middleware must be a function')
|
|
19
|
+
}
|
|
20
|
+
callback[i].applyBeforeValidation = applyBeforeValidation
|
|
21
|
+
}
|
|
4
22
|
Array.prototype.push.apply(globalMiddleware, callback)
|
|
5
23
|
} else if (typeof callback === 'function') {
|
|
24
|
+
callback.applyBeforeValidation = applyBeforeValidation
|
|
6
25
|
globalMiddleware.push(callback)
|
|
7
26
|
}
|
|
8
27
|
return context
|
|
9
28
|
}
|
|
10
29
|
}
|
|
30
|
+
|
|
31
|
+
function commandMiddlewareFactory (commandMiddleware) {
|
|
32
|
+
if (!commandMiddleware) return []
|
|
33
|
+
return commandMiddleware.map(middleware => {
|
|
34
|
+
middleware.applyBeforeValidation = false
|
|
35
|
+
return middleware
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function applyMiddleware (argv, yargs, middlewares, beforeValidation) {
|
|
40
|
+
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true')
|
|
41
|
+
return middlewares
|
|
42
|
+
.reduce((accumulation, middleware) => {
|
|
43
|
+
if (middleware.applyBeforeValidation !== beforeValidation &&
|
|
44
|
+
!isPromise(accumulation)) {
|
|
45
|
+
return accumulation
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isPromise(accumulation)) {
|
|
49
|
+
return accumulation
|
|
50
|
+
.then(initialObj =>
|
|
51
|
+
Promise.all([initialObj, middleware(initialObj, yargs)])
|
|
52
|
+
)
|
|
53
|
+
.then(([initialObj, middlewareObj]) =>
|
|
54
|
+
Object.assign(initialObj, middlewareObj)
|
|
55
|
+
)
|
|
56
|
+
} else {
|
|
57
|
+
const result = middleware(argv, yargs)
|
|
58
|
+
if (beforeValidation && isPromise(result)) throw beforeValidationError
|
|
59
|
+
|
|
60
|
+
return isPromise(result)
|
|
61
|
+
? result.then(middlewareObj => Object.assign(accumulation, middlewareObj))
|
|
62
|
+
: Object.assign(accumulation, result)
|
|
63
|
+
}
|
|
64
|
+
}, argv)
|
|
65
|
+
}
|
package/lib/usage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
// this file handles outputting usage instructions,
|
|
3
3
|
// failures, etc. keeps logging in one place.
|
|
4
|
+
const decamelize = require('./decamelize')
|
|
4
5
|
const stringWidth = require('string-width')
|
|
5
6
|
const objFilter = require('./obj-filter')
|
|
6
7
|
const path = require('path')
|
|
@@ -204,6 +205,10 @@ module.exports = function usage (yargs, y18n) {
|
|
|
204
205
|
const context = yargs.getContext()
|
|
205
206
|
const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : ''
|
|
206
207
|
|
|
208
|
+
if (yargs.getParserConfiguration()['sort-commands'] === true) {
|
|
209
|
+
commands = commands.sort((a, b) => a[0].localeCompare(b[0]))
|
|
210
|
+
}
|
|
211
|
+
|
|
207
212
|
commands.forEach((command) => {
|
|
208
213
|
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.
|
|
209
214
|
ui.span(
|
|
@@ -428,7 +433,7 @@ module.exports = function usage (yargs, y18n) {
|
|
|
428
433
|
}
|
|
429
434
|
|
|
430
435
|
self.functionDescription = (fn) => {
|
|
431
|
-
const description = fn.name ?
|
|
436
|
+
const description = fn.name ? decamelize(fn.name, '-') : __('generated-value')
|
|
432
437
|
return ['(', description, ')'].join('')
|
|
433
438
|
}
|
|
434
439
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -19,37 +19,36 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"cliui": "^4.0.0",
|
|
22
|
-
"decamelize": "^1.2.0",
|
|
23
22
|
"find-up": "^3.0.0",
|
|
24
|
-
"get-caller-file": "^
|
|
25
|
-
"os-locale": "^3.
|
|
23
|
+
"get-caller-file": "^2.0.1",
|
|
24
|
+
"os-locale": "^3.1.0",
|
|
26
25
|
"require-directory": "^2.1.1",
|
|
27
|
-
"require-main-filename": "^
|
|
26
|
+
"require-main-filename": "^2.0.0",
|
|
28
27
|
"set-blocking": "^2.0.0",
|
|
29
|
-
"string-width": "^
|
|
28
|
+
"string-width": "^3.0.0",
|
|
30
29
|
"which-module": "^2.0.0",
|
|
31
|
-
"y18n": "^
|
|
32
|
-
"yargs-parser": "^
|
|
30
|
+
"y18n": "^4.0.0",
|
|
31
|
+
"yargs-parser": "^13.0.0"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"chai": "^4.
|
|
36
|
-
"chalk": "^
|
|
34
|
+
"chai": "^4.2.0",
|
|
35
|
+
"chalk": "^2.4.2",
|
|
37
36
|
"coveralls": "^3.0.2",
|
|
38
|
-
"cpr": "^
|
|
37
|
+
"cpr": "^3.0.1",
|
|
39
38
|
"cross-spawn": "^6.0.4",
|
|
40
|
-
"es6-promise": "^4.
|
|
39
|
+
"es6-promise": "^4.2.5",
|
|
41
40
|
"hashish": "0.0.4",
|
|
42
|
-
"mocha": "^5.
|
|
43
|
-
"nyc": "^
|
|
44
|
-
"rimraf": "^2.
|
|
41
|
+
"mocha": "^5.2.0",
|
|
42
|
+
"nyc": "^13.2.0",
|
|
43
|
+
"rimraf": "^2.6.3",
|
|
45
44
|
"standard": "^11.0.1",
|
|
46
|
-
"standard-version": "^4.
|
|
47
|
-
"which": "^1.
|
|
45
|
+
"standard-version": "^4.4.0",
|
|
46
|
+
"which": "^1.3.1",
|
|
48
47
|
"yargs-test-extends": "^1.0.1"
|
|
49
48
|
},
|
|
50
49
|
"scripts": {
|
|
51
50
|
"pretest": "standard",
|
|
52
|
-
"test": "nyc --cache mocha --require ./test/before.js --timeout=
|
|
51
|
+
"test": "nyc --cache mocha --require ./test/before.js --timeout=12000 --check-leaks",
|
|
53
52
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
|
54
53
|
"release": "standard-version"
|
|
55
54
|
},
|
package/yargs.js
CHANGED
|
@@ -11,7 +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
|
|
14
|
+
const {globalMiddlewareFactory} = require('./lib/middleware')
|
|
15
15
|
const YError = require('./lib/yerror')
|
|
16
16
|
|
|
17
17
|
exports = module.exports = Yargs
|
|
@@ -33,7 +33,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
33
33
|
updateFiles: false
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
self.middleware =
|
|
36
|
+
self.middleware = globalMiddlewareFactory(globalMiddleware, self)
|
|
37
37
|
|
|
38
38
|
if (!cwd) cwd = process.cwd()
|
|
39
39
|
|
|
@@ -765,6 +765,14 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
765
765
|
}
|
|
766
766
|
self.getStrict = () => strict
|
|
767
767
|
|
|
768
|
+
let parserConfig = {}
|
|
769
|
+
self.parserConfiguration = function parserConfiguration (config) {
|
|
770
|
+
argsert('<object>', [config], arguments.length)
|
|
771
|
+
parserConfig = config
|
|
772
|
+
return self
|
|
773
|
+
}
|
|
774
|
+
self.getParserConfiguration = () => parserConfig
|
|
775
|
+
|
|
768
776
|
self.showHelp = function (level) {
|
|
769
777
|
argsert('[string|function]', [level], arguments.length)
|
|
770
778
|
if (!self.parsed) self._parseArgs(processArgs) // run parser, if it has not already been executed.
|
|
@@ -1010,7 +1018,14 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1010
1018
|
args = args || processArgs
|
|
1011
1019
|
|
|
1012
1020
|
options.__ = y18n.__
|
|
1013
|
-
options.configuration =
|
|
1021
|
+
options.configuration = self.getParserConfiguration()
|
|
1022
|
+
|
|
1023
|
+
// Deprecated
|
|
1024
|
+
let pkgConfig = pkgUp()['yargs']
|
|
1025
|
+
if (pkgConfig) {
|
|
1026
|
+
console.warn('Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.')
|
|
1027
|
+
options.configuration = Object.assign({}, pkgConfig, options.configuration)
|
|
1028
|
+
}
|
|
1014
1029
|
|
|
1015
1030
|
const parsed = Parser.detailed(args, options)
|
|
1016
1031
|
let argv = parsed.argv
|
|
@@ -1152,7 +1167,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
1152
1167
|
}
|
|
1153
1168
|
|
|
1154
1169
|
self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
|
|
1155
|
-
if (parseErrors) throw new YError(parseErrors.message)
|
|
1170
|
+
if (parseErrors) throw new YError(parseErrors.message || parseErrors)
|
|
1156
1171
|
validation.nonOptionCount(argv)
|
|
1157
1172
|
validation.requiredArguments(argv)
|
|
1158
1173
|
if (strict) validation.unknownArguments(argv, aliases, positionalMap)
|