yargs 4.7.0 → 4.7.1
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 +11 -0
- package/index.js +2 -2
- package/lib/command.js +1 -1
- package/lib/completion.js +7 -7
- package/lib/obj-filter.js +1 -1
- package/lib/usage.js +10 -7
- package/lib/validation.js +26 -26
- package/package.json +4 -3
- package/yargs.js +27 -19
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
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="4.7.1"></a>
|
|
6
|
+
## [4.7.1](https://github.com/yargs/yargs/compare/v4.7.0...v4.7.1) (2016-05-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* switch to using `const` rather than `var` ([#499](https://github.com/yargs/yargs/pull/499))
|
|
12
|
+
* make stdout flush on newer versions of Node.js ([#501](https://github.com/yargs/yargs/issues/501)) ([9f8c6f4](https://github.com/yargs/yargs/commit/9f8c6f4))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
<a name="4.7.0"></a>
|
|
6
17
|
# [4.7.0](https://github.com/yargs/yargs/compare/v4.6.0...v4.7.0) (2016-05-02)
|
|
7
18
|
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// classic singleton yargs API, to use yargs
|
|
2
2
|
// without running as a singleton do:
|
|
3
3
|
// require('yargs/yargs')(process.argv.slice(2))
|
|
4
|
-
|
|
4
|
+
const yargs = require('./yargs')
|
|
5
5
|
|
|
6
6
|
Argv(process.argv.slice(2))
|
|
7
7
|
|
|
8
8
|
module.exports = Argv
|
|
9
9
|
|
|
10
10
|
function Argv (processArgs, cwd) {
|
|
11
|
-
|
|
11
|
+
const argv = yargs(processArgs, cwd, require)
|
|
12
12
|
singletonify(argv)
|
|
13
13
|
return argv
|
|
14
14
|
}
|
package/lib/command.js
CHANGED
package/lib/completion.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
3
|
|
|
4
4
|
// add bash completions to your
|
|
5
5
|
// yargs-powered applications.
|
|
6
6
|
module.exports = function (yargs, usage, command) {
|
|
7
|
-
|
|
7
|
+
const self = {
|
|
8
8
|
completionKey: 'get-yargs-completions'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// get a list of completion commands.
|
|
12
12
|
// 'args' is the array of strings from the line to be completed
|
|
13
13
|
self.getCompletion = function (args, done) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const completions = []
|
|
15
|
+
const current = args.length ? args[args.length - 1] : ''
|
|
16
|
+
const argv = yargs.parse(args, true)
|
|
17
|
+
const aliases = yargs.parsed.aliases
|
|
18
18
|
|
|
19
19
|
// a custom completion function can be provided
|
|
20
20
|
// to completion().
|
package/lib/obj-filter.js
CHANGED
package/lib/usage.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// this file handles outputting usage instructions,
|
|
2
2
|
// failures, etc. keeps logging in one place.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const cliui = require('cliui')
|
|
4
|
+
const decamelize = require('decamelize')
|
|
5
|
+
const stringWidth = require('string-width')
|
|
6
|
+
const wsize = require('window-size')
|
|
7
|
+
const objFilter = require('./obj-filter')
|
|
8
|
+
const setBlocking = require('set-blocking')
|
|
8
9
|
|
|
9
10
|
module.exports = function (yargs, y18n) {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const __ = y18n.__
|
|
12
|
+
const self = {}
|
|
12
13
|
|
|
13
14
|
// methods for ouputting/building failure message.
|
|
14
15
|
var fails = []
|
|
@@ -37,6 +38,8 @@ module.exports = function (yargs, y18n) {
|
|
|
37
38
|
f(msg, err)
|
|
38
39
|
})
|
|
39
40
|
} else {
|
|
41
|
+
if (yargs.getExitProcess()) setBlocking(true)
|
|
42
|
+
|
|
40
43
|
// don't output failure message more than once
|
|
41
44
|
if (!failureOutput) {
|
|
42
45
|
failureOutput = true
|
package/lib/validation.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
const objFilter = require('./obj-filter')
|
|
2
2
|
|
|
3
3
|
// validation-type-stuff, missing params,
|
|
4
4
|
// bad implications, custom checks.
|
|
5
5
|
module.exports = function (yargs, usage, y18n) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const __ = y18n.__
|
|
7
|
+
const __n = y18n.__n
|
|
8
|
+
const self = {}
|
|
9
9
|
|
|
10
10
|
// validate appropriate # of non-option
|
|
11
11
|
// arguments were provided, i.e., '_'.
|
|
12
12
|
self.nonOptionCount = function (argv) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const demanded = yargs.getDemanded()
|
|
14
|
+
const _s = argv._.length
|
|
15
15
|
|
|
16
16
|
if (demanded._ && (_s < demanded._.count || _s > demanded._.max)) {
|
|
17
17
|
if (demanded._.msg !== undefined) {
|
|
@@ -41,14 +41,14 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
41
41
|
// make sure that any args that require an
|
|
42
42
|
// value (--foo=bar), have a value.
|
|
43
43
|
self.missingArgumentValue = function (argv) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const defaultValues = [true, false, '']
|
|
45
|
+
const options = yargs.getOptions()
|
|
46
46
|
|
|
47
47
|
if (options.requiresArg.length > 0) {
|
|
48
|
-
|
|
48
|
+
const missingRequiredArgs = []
|
|
49
49
|
|
|
50
50
|
options.requiresArg.forEach(function (key) {
|
|
51
|
-
|
|
51
|
+
const value = argv[key]
|
|
52
52
|
|
|
53
53
|
// if a value is explicitly requested,
|
|
54
54
|
// flag argument as missing if it does not
|
|
@@ -72,7 +72,7 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
72
72
|
|
|
73
73
|
// make sure all the required arguments are present.
|
|
74
74
|
self.requiredArguments = function (argv) {
|
|
75
|
-
|
|
75
|
+
const demanded = yargs.getDemanded()
|
|
76
76
|
var missing = null
|
|
77
77
|
|
|
78
78
|
Object.keys(demanded).forEach(function (key) {
|
|
@@ -83,15 +83,15 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
if (missing) {
|
|
86
|
-
|
|
86
|
+
const customMsgs = []
|
|
87
87
|
Object.keys(missing).forEach(function (key) {
|
|
88
|
-
|
|
88
|
+
const msg = missing[key].msg
|
|
89
89
|
if (msg && customMsgs.indexOf(msg) < 0) {
|
|
90
90
|
customMsgs.push(msg)
|
|
91
91
|
}
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
const customMsg = customMsgs.length ? '\n' + customMsgs.join('\n') : ''
|
|
95
95
|
|
|
96
96
|
usage.fail(__n(
|
|
97
97
|
'Missing required argument: %s',
|
|
@@ -104,12 +104,12 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
104
104
|
|
|
105
105
|
// check for unknown arguments (strict-mode).
|
|
106
106
|
self.unknownArguments = function (argv, aliases) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
const aliasLookup = {}
|
|
108
|
+
const descriptions = usage.getDescriptions()
|
|
109
|
+
const demanded = yargs.getDemanded()
|
|
110
|
+
const commandKeys = yargs.getCommandInstance().getCommands()
|
|
111
|
+
const unknown = []
|
|
112
|
+
const currentContext = yargs.getContext()
|
|
113
113
|
|
|
114
114
|
Object.keys(aliases).forEach(function (key) {
|
|
115
115
|
aliases[key].forEach(function (alias) {
|
|
@@ -146,8 +146,8 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
146
146
|
|
|
147
147
|
// validate arguments limited to enumerated choices
|
|
148
148
|
self.limitedChoices = function (argv) {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
const options = yargs.getOptions()
|
|
150
|
+
const invalid = {}
|
|
151
151
|
|
|
152
152
|
if (!Object.keys(options.choices).length) return
|
|
153
153
|
|
|
@@ -163,7 +163,7 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
163
163
|
}
|
|
164
164
|
})
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
const invalidKeys = Object.keys(invalid)
|
|
167
167
|
|
|
168
168
|
if (!invalidKeys.length) return
|
|
169
169
|
|
|
@@ -188,7 +188,7 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
188
188
|
self.customChecks = function (argv, aliases) {
|
|
189
189
|
checks.forEach(function (f) {
|
|
190
190
|
try {
|
|
191
|
-
|
|
191
|
+
const result = f(argv, aliases)
|
|
192
192
|
if (!result) {
|
|
193
193
|
usage.fail(__('Argument check failed: %s', f.toString()))
|
|
194
194
|
} else if (typeof result === 'string') {
|
|
@@ -216,11 +216,11 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
self.implications = function (argv) {
|
|
219
|
-
|
|
219
|
+
const implyFail = []
|
|
220
220
|
|
|
221
221
|
Object.keys(implied).forEach(function (key) {
|
|
222
222
|
var num
|
|
223
|
-
|
|
223
|
+
const origKey = key
|
|
224
224
|
var value = implied[key]
|
|
225
225
|
|
|
226
226
|
// convert string '1' to number 1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"LICENSE"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"camelcase": "^
|
|
15
|
+
"camelcase": "^3.0.0",
|
|
16
16
|
"cliui": "^3.2.0",
|
|
17
17
|
"decamelize": "^1.1.1",
|
|
18
18
|
"lodash.assign": "^4.0.3",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"pkg-conf": "^1.1.2",
|
|
21
21
|
"read-pkg-up": "^1.0.1",
|
|
22
22
|
"require-main-filename": "^1.0.1",
|
|
23
|
+
"set-blocking": "^1.0.0",
|
|
23
24
|
"string-width": "^1.0.1",
|
|
24
25
|
"window-size": "^0.2.0",
|
|
25
26
|
"y18n": "^3.2.1",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"pretest": "standard",
|
|
45
|
-
"test": "nyc --cache mocha --require ./test/before.js --timeout=
|
|
46
|
+
"test": "nyc --cache mocha --require ./test/before.js --timeout=8000 --check-leaks",
|
|
46
47
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
|
47
48
|
"version": "standard-version"
|
|
48
49
|
},
|
package/yargs.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
const assert = require('assert')
|
|
2
|
+
const assign = require('lodash.assign')
|
|
3
|
+
const Command = require('./lib/command')
|
|
4
|
+
const Completion = require('./lib/completion')
|
|
5
|
+
const Parser = require('yargs-parser')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const Usage = require('./lib/usage')
|
|
8
|
+
const Validation = require('./lib/validation')
|
|
9
|
+
const Y18n = require('y18n')
|
|
10
|
+
const readPkgUp = require('read-pkg-up')
|
|
11
|
+
const pkgConf = require('pkg-conf')
|
|
12
|
+
const requireMainFilename = require('require-main-filename')
|
|
13
|
+
const objFilter = require('./lib/obj-filter')
|
|
14
|
+
const setBlocking = require('set-blocking')
|
|
14
15
|
|
|
15
16
|
var exports = module.exports = Yargs
|
|
16
17
|
function Yargs (processArgs, cwd, parentRequire) {
|
|
17
18
|
processArgs = processArgs || [] // handle calling yargs().
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const self = {}
|
|
20
21
|
var command = null
|
|
21
22
|
var completion = null
|
|
22
23
|
var groups = {}
|
|
23
24
|
var preservedGroups = {}
|
|
24
25
|
var usage = null
|
|
25
26
|
var validation = null
|
|
26
|
-
|
|
27
|
+
const y18n = Y18n({
|
|
27
28
|
directory: path.resolve(__dirname, './locales'),
|
|
28
29
|
updateFiles: false
|
|
29
30
|
})
|
|
@@ -49,7 +50,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
49
50
|
|
|
50
51
|
// use context object to keep track of resets, subcommand execution, etc
|
|
51
52
|
// submodules should modify and check the state of context as necessary
|
|
52
|
-
|
|
53
|
+
const context = { resets: -1, commands: [] }
|
|
53
54
|
self.getContext = function () {
|
|
54
55
|
return context
|
|
55
56
|
}
|
|
@@ -621,8 +622,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
621
622
|
defaults: {},
|
|
622
623
|
cwd: requireMainFilename(require)
|
|
623
624
|
})
|
|
624
|
-
|
|
625
|
-
|
|
625
|
+
const parsed = Parser.detailed(args, options)
|
|
626
|
+
const argv = parsed.argv
|
|
626
627
|
var aliases = parsed.aliases
|
|
627
628
|
|
|
628
629
|
argv.$0 = self.$0
|
|
@@ -649,6 +650,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
649
650
|
|
|
650
651
|
// generate a completion script for adding to ~/.bashrc.
|
|
651
652
|
if (completionCommand && ~argv._.indexOf(completionCommand) && !argv[completion.completionKey]) {
|
|
653
|
+
if (exitProcess) setBlocking(true)
|
|
652
654
|
self.showCompletionScript()
|
|
653
655
|
if (exitProcess) {
|
|
654
656
|
process.exit(0)
|
|
@@ -658,6 +660,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
658
660
|
// we must run completions first, a user might
|
|
659
661
|
// want to complete the --help or --version option.
|
|
660
662
|
if (completion.completionKey in argv) {
|
|
663
|
+
if (exitProcess) setBlocking(true)
|
|
664
|
+
|
|
661
665
|
// we allow for asynchronous completions,
|
|
662
666
|
// e.g., loading in a list of commands from an API.
|
|
663
667
|
var completionArgs = args.slice(args.indexOf('--' + completion.completionKey) + 1)
|
|
@@ -678,12 +682,16 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
678
682
|
// Handle 'help' and 'version' options
|
|
679
683
|
Object.keys(argv).forEach(function (key) {
|
|
680
684
|
if (key === helpOpt && argv[key]) {
|
|
685
|
+
if (exitProcess) setBlocking(true)
|
|
686
|
+
|
|
681
687
|
skipValidation = true
|
|
682
688
|
self.showHelp('log')
|
|
683
689
|
if (exitProcess) {
|
|
684
690
|
process.exit(0)
|
|
685
691
|
}
|
|
686
692
|
} else if (key === versionOpt && argv[key]) {
|
|
693
|
+
if (exitProcess) setBlocking(true)
|
|
694
|
+
|
|
687
695
|
skipValidation = true
|
|
688
696
|
usage.showVersion()
|
|
689
697
|
if (exitProcess) {
|
|
@@ -726,7 +734,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
726
734
|
if (!detectLocale) return
|
|
727
735
|
|
|
728
736
|
try {
|
|
729
|
-
|
|
737
|
+
const osLocale = require('os-locale')
|
|
730
738
|
self.locale(osLocale.sync({ spawn: false }))
|
|
731
739
|
} catch (err) {
|
|
732
740
|
// if we explode looking up locale just noop
|