yargs 15.0.2 → 15.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 +18 -0
- package/lib/command.js +18 -6
- package/lib/completion.js +10 -3
- package/lib/usage.js +1 -1
- package/locales/fi.json +42 -0
- package/package.json +2 -2
- package/yargs.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
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
|
+
## [15.1.0](https://www.github.com/yargs/yargs/compare/v15.0.2...v15.1.0) (2020-01-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **lang:** add Finnish localization (language code fi) ([222c8fe](https://www.github.com/yargs/yargs/commit/222c8fef2e2ad46e314c337dec96940f896bec35))
|
|
11
|
+
* complete short options with a single dash ([#1507](https://www.github.com/yargs/yargs/issues/1507)) ([99011ab](https://www.github.com/yargs/yargs/commit/99011ab5ba90232506ece0a17e59e2001a1ab562))
|
|
12
|
+
* onFinishCommand handler ([#1473](https://www.github.com/yargs/yargs/issues/1473)) ([fe380cd](https://www.github.com/yargs/yargs/commit/fe380cd356aa33aef0449facd59c22cab8930ac9))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* getCompletion() was not working for options ([#1495](https://www.github.com/yargs/yargs/issues/1495)) ([463feb2](https://www.github.com/yargs/yargs/commit/463feb2870158eb9df670222b0f0a40a05cf18d0))
|
|
18
|
+
* misspelling of package.json `engines` field ([0891d0e](https://www.github.com/yargs/yargs/commit/0891d0ed35b30c83a6d9e9f6a5c5f84d13c546a0))
|
|
19
|
+
* populate positionals when unknown-options-as-args is set ([#1508](https://www.github.com/yargs/yargs/issues/1508)) ([bb0f2eb](https://www.github.com/yargs/yargs/commit/bb0f2eb996fa4e19d330b31a01c2036cafa99a7e)), closes [#1444](https://www.github.com/yargs/yargs/issues/1444)
|
|
20
|
+
* show 2 dashes on help for single digit option key or alias ([#1493](https://www.github.com/yargs/yargs/issues/1493)) ([63b3dd3](https://www.github.com/yargs/yargs/commit/63b3dd31a455d428902220c1992ae930e18aff5c))
|
|
21
|
+
* **docs:** use recommended cjs import syntax for ts examples ([#1513](https://www.github.com/yargs/yargs/issues/1513)) ([f9a18bf](https://www.github.com/yargs/yargs/commit/f9a18bfd624a5013108084f690cd8a1de794c430))
|
|
22
|
+
|
|
5
23
|
### [15.0.2](https://www.github.com/yargs/yargs/compare/v15.0.1...v15.0.2) (2019-11-19)
|
|
6
24
|
|
|
7
25
|
|
package/lib/command.js
CHANGED
|
@@ -240,15 +240,26 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
240
240
|
handlerResult = commandHandler.handler(innerArgv)
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
const handlerFinishCommand = yargs.getHandlerFinishCommand()
|
|
243
244
|
if (isPromise(handlerResult)) {
|
|
244
245
|
yargs.getUsageInstance().cacheHelpMessage()
|
|
245
|
-
handlerResult
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
handlerResult
|
|
247
|
+
.then(value => {
|
|
248
|
+
if (handlerFinishCommand) {
|
|
249
|
+
handlerFinishCommand(value)
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
.catch(error => {
|
|
253
|
+
try {
|
|
254
|
+
yargs.getUsageInstance().fail(null, error)
|
|
255
|
+
} catch (err) {
|
|
249
256
|
// fail's throwing would cause an unhandled rejection.
|
|
250
|
-
|
|
251
|
-
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
} else {
|
|
260
|
+
if (handlerFinishCommand) {
|
|
261
|
+
handlerFinishCommand(handlerResult)
|
|
262
|
+
}
|
|
252
263
|
}
|
|
253
264
|
}
|
|
254
265
|
|
|
@@ -344,6 +355,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
|
|
344
355
|
const unparsed = []
|
|
345
356
|
Object.keys(positionalMap).forEach((key) => {
|
|
346
357
|
positionalMap[key].map((value) => {
|
|
358
|
+
if (options.configuration['unknown-options-as-args']) options.key[key] = true
|
|
347
359
|
unparsed.push(`--${key}`)
|
|
348
360
|
unparsed.push(value)
|
|
349
361
|
})
|
package/lib/completion.js
CHANGED
|
@@ -8,6 +8,11 @@ module.exports = function completion (yargs, usage, command) {
|
|
|
8
8
|
completionKey: 'get-yargs-completions'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
let aliases
|
|
12
|
+
self.setParsed = function setParsed (parsed) {
|
|
13
|
+
aliases = parsed.aliases
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
const zshShell = (process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1) ||
|
|
12
17
|
(process.env.ZSH_NAME && process.env.ZSH_NAME.indexOf('zsh') !== -1)
|
|
13
18
|
// get a list of completion commands.
|
|
@@ -16,7 +21,6 @@ module.exports = function completion (yargs, usage, command) {
|
|
|
16
21
|
const completions = []
|
|
17
22
|
const current = args.length ? args[args.length - 1] : ''
|
|
18
23
|
const argv = yargs.parse(args, true)
|
|
19
|
-
const aliases = yargs.parsed.aliases
|
|
20
24
|
const parentCommands = yargs.getContext().commands
|
|
21
25
|
|
|
22
26
|
// a custom completion function can be provided
|
|
@@ -77,11 +81,14 @@ module.exports = function completion (yargs, usage, command) {
|
|
|
77
81
|
const keyAndAliases = [key].concat(aliases[key] || [])
|
|
78
82
|
const notInArgs = keyAndAliases.every(val => args.indexOf(`--${val}`) === -1)
|
|
79
83
|
if (notInArgs) {
|
|
84
|
+
const startsByTwoDashes = s => /^--/.test(s)
|
|
85
|
+
const isShortOption = s => /^[^0-9]$/.test(s)
|
|
86
|
+
const dashes = !startsByTwoDashes(current) && isShortOption(key) ? '-' : '--'
|
|
80
87
|
if (!zshShell) {
|
|
81
|
-
completions.push(
|
|
88
|
+
completions.push(dashes + key)
|
|
82
89
|
} else {
|
|
83
90
|
const desc = descs[key] || ''
|
|
84
|
-
completions.push(
|
|
91
|
+
completions.push(dashes + `${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`)
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
})
|
package/lib/usage.js
CHANGED
|
@@ -272,7 +272,7 @@ module.exports = function usage (yargs, y18n) {
|
|
|
272
272
|
// for the special positional group don't
|
|
273
273
|
// add '--' or '-' prefix.
|
|
274
274
|
if (groupName === self.getPositionalGroupName()) return sw
|
|
275
|
-
else return (sw
|
|
275
|
+
else return (/^[^0-9]$/.test(sw) ? '-' : '--') + sw
|
|
276
276
|
})
|
|
277
277
|
.join(', ')
|
|
278
278
|
|
package/locales/fi.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Commands:": "Komennot:",
|
|
3
|
+
"Options:": "Valinnat:",
|
|
4
|
+
"Examples:": "Esimerkkejä:",
|
|
5
|
+
"boolean": "totuusarvo",
|
|
6
|
+
"count": "lukumäärä",
|
|
7
|
+
"string": "merkkijono",
|
|
8
|
+
"number": "numero",
|
|
9
|
+
"array": "taulukko",
|
|
10
|
+
"required": "pakollinen",
|
|
11
|
+
"default:": "oletusarvo:",
|
|
12
|
+
"choices:": "vaihtoehdot:",
|
|
13
|
+
"aliases:": "aliakset:",
|
|
14
|
+
"generated-value": "generoitu-arvo",
|
|
15
|
+
"Not enough non-option arguments: got %s, need at least %s": "Liian vähän argumentteja, jotka eivät ole valintoja: annettu %s, vaaditaan vähintään %s",
|
|
16
|
+
"Too many non-option arguments: got %s, maximum of %s": "Liikaa argumentteja, jotka eivät ole valintoja: annettu %s, sallitaan enintään %s",
|
|
17
|
+
"Missing argument value: %s": {
|
|
18
|
+
"one": "Argumentin arvo puuttuu: %s",
|
|
19
|
+
"other": "Argumentin arvot puuttuvat: %s"
|
|
20
|
+
},
|
|
21
|
+
"Missing required argument: %s": {
|
|
22
|
+
"one": "Pakollinen argumentti puuttuu: %s",
|
|
23
|
+
"other": "Pakollisia argumentteja puuttuu: %s"
|
|
24
|
+
},
|
|
25
|
+
"Unknown argument: %s": {
|
|
26
|
+
"one": "Tuntematon argumenttn: %s",
|
|
27
|
+
"other": "Tuntemattomia argumentteja: %s"
|
|
28
|
+
},
|
|
29
|
+
"Invalid values:": "Virheelliset arvot:",
|
|
30
|
+
"Argument: %s, Given: %s, Choices: %s": "Argumentti: %s, Annettu: %s, Vaihtoehdot: %s",
|
|
31
|
+
"Argument check failed: %s": "Argumentin tarkistus epäonnistui: %s",
|
|
32
|
+
"Implications failed:": "Riippuvia argumentteja puuttuu:",
|
|
33
|
+
"Not enough arguments following: %s": "Argumentin perässä ei ole tarpeeksi argumentteja: %s",
|
|
34
|
+
"Invalid JSON config file: %s": "Epävalidi JSON-asetustiedosto: %s",
|
|
35
|
+
"Path to JSON config file": "JSON-asetustiedoston polku",
|
|
36
|
+
"Show help": "Näytä ohje",
|
|
37
|
+
"Show version number": "Näytä versionumero",
|
|
38
|
+
"Did you mean %s?": "Tarkoititko %s?",
|
|
39
|
+
"Arguments %s and %s are mutually exclusive" : "Argumentit %s ja %s eivät ole yhteensopivat",
|
|
40
|
+
"Positionals:": "Sijaintiparametrit:",
|
|
41
|
+
"command": "komento"
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "15.0
|
|
3
|
+
"version": "15.1.0",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"command"
|
|
73
73
|
],
|
|
74
74
|
"license": "MIT",
|
|
75
|
-
"
|
|
75
|
+
"engines": {
|
|
76
76
|
"node": ">=8"
|
|
77
77
|
}
|
|
78
78
|
}
|
package/yargs.js
CHANGED
|
@@ -32,6 +32,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
32
32
|
let preservedGroups = {}
|
|
33
33
|
let usage = null
|
|
34
34
|
let validation = null
|
|
35
|
+
let handlerFinishCommand = null
|
|
35
36
|
|
|
36
37
|
const y18n = Y18n({
|
|
37
38
|
directory: path.resolve(__dirname, './locales'),
|
|
@@ -172,6 +173,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
172
173
|
frozen.parsed = self.parsed
|
|
173
174
|
frozen.parseFn = parseFn
|
|
174
175
|
frozen.parseContext = parseContext
|
|
176
|
+
frozen.handlerFinishCommand = handlerFinishCommand
|
|
175
177
|
}
|
|
176
178
|
function unfreeze () {
|
|
177
179
|
let frozen = frozens.pop()
|
|
@@ -190,6 +192,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
190
192
|
completionCommand = frozen.completionCommand
|
|
191
193
|
parseFn = frozen.parseFn
|
|
192
194
|
parseContext = frozen.parseContext
|
|
195
|
+
handlerFinishCommand = frozen.handlerFinishCommand
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
self.boolean = function (keys) {
|
|
@@ -483,6 +486,14 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
483
486
|
return self
|
|
484
487
|
}
|
|
485
488
|
|
|
489
|
+
self.onFinishCommand = function (f) {
|
|
490
|
+
argsert('<function>', [f], arguments.length)
|
|
491
|
+
handlerFinishCommand = f
|
|
492
|
+
return self
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
self.getHandlerFinishCommand = () => handlerFinishCommand
|
|
496
|
+
|
|
486
497
|
self.check = function (f, _global) {
|
|
487
498
|
argsert('<function> [boolean]', [f, _global], arguments.length)
|
|
488
499
|
validation.check(f, _global !== false)
|
|
@@ -581,6 +592,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
581
592
|
if (parseFn) exitProcess = false
|
|
582
593
|
|
|
583
594
|
const parsed = self._parseArgs(args, shortCircuit)
|
|
595
|
+
completion.setParsed(self.parsed)
|
|
584
596
|
if (parseFn) parseFn(exitError, parsed, output)
|
|
585
597
|
unfreeze()
|
|
586
598
|
|