yargs 16.0.4-candidate.0 → 16.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 +16 -0
- package/README.md +25 -6
- package/browser.mjs +4 -4
- package/build/index.cjs +348 -231
- package/build/lib/argsert.js +9 -5
- package/build/lib/command.js +44 -35
- package/build/lib/completion.js +27 -14
- package/build/lib/middleware.js +5 -3
- package/build/lib/parse-command.js +3 -3
- package/build/lib/usage.js +81 -47
- package/build/lib/utils/apply-extends.js +8 -7
- package/build/lib/utils/is-promise.js +2 -2
- package/build/lib/utils/obj-filter.js +1 -1
- package/build/lib/utils/set-blocking.js +4 -2
- package/build/lib/utils/which-module.js +1 -1
- package/build/lib/validation.js +37 -31
- package/build/lib/yargs-factory.js +126 -83
- package/helpers.mjs +7 -11
- package/index.cjs +17 -17
- package/index.mjs +5 -5
- package/lib/platform-shims/browser.mjs +38 -37
- package/package.json +31 -25
- package/yargs +2 -1
package/build/index.cjs
CHANGED
|
@@ -24,24 +24,25 @@ function applyExtends(config, cwd, mergeExtends, _shim) {
|
|
|
24
24
|
try {
|
|
25
25
|
pathToDefault = require.resolve(config.extends);
|
|
26
26
|
}
|
|
27
|
-
catch (
|
|
27
|
+
catch (_err) {
|
|
28
|
+
return config;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
pathToDefault = getPathToDefaultConfig(cwd, config.extends);
|
|
32
33
|
}
|
|
33
|
-
if (!pathToDefault && !isPath)
|
|
34
|
-
return config;
|
|
35
|
-
if (!pathToDefault)
|
|
36
|
-
throw new YError(`Unable to find extended config '${config.extends}' in '${cwd}'.`);
|
|
37
34
|
checkForCircularExtends(pathToDefault);
|
|
38
35
|
previouslyVisitedConfigs.push(pathToDefault);
|
|
39
|
-
defaultConfig = isPath
|
|
36
|
+
defaultConfig = isPath
|
|
37
|
+
? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
|
|
38
|
+
: require(config.extends);
|
|
40
39
|
delete config.extends;
|
|
41
40
|
defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim);
|
|
42
41
|
}
|
|
43
42
|
previouslyVisitedConfigs = [];
|
|
44
|
-
return mergeExtends
|
|
43
|
+
return mergeExtends
|
|
44
|
+
? mergeDeep(defaultConfig, config)
|
|
45
|
+
: Object.assign({}, defaultConfig, config);
|
|
45
46
|
}
|
|
46
47
|
function checkForCircularExtends(cfgPath) {
|
|
47
48
|
if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
|
|
@@ -78,7 +79,7 @@ function parseCommand(cmd) {
|
|
|
78
79
|
const parsedCommand = {
|
|
79
80
|
cmd: firstCommand.replace(bregex, ''),
|
|
80
81
|
demanded: [],
|
|
81
|
-
optional: []
|
|
82
|
+
optional: [],
|
|
82
83
|
};
|
|
83
84
|
splitCommand.forEach((cmd, i) => {
|
|
84
85
|
let variadic = false;
|
|
@@ -88,13 +89,13 @@ function parseCommand(cmd) {
|
|
|
88
89
|
if (/^\[/.test(cmd)) {
|
|
89
90
|
parsedCommand.optional.push({
|
|
90
91
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
91
|
-
variadic
|
|
92
|
+
variadic,
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
96
|
parsedCommand.demanded.push({
|
|
96
97
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
97
|
-
variadic
|
|
98
|
+
variadic,
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
101
|
});
|
|
@@ -106,15 +107,19 @@ function argsert(arg1, arg2, arg3) {
|
|
|
106
107
|
function parseArgs() {
|
|
107
108
|
return typeof arg1 === 'object'
|
|
108
109
|
? [{ demanded: [], optional: [] }, arg1, arg2]
|
|
109
|
-
: [
|
|
110
|
+
: [
|
|
111
|
+
parseCommand(`cmd ${arg1}`),
|
|
112
|
+
arg2,
|
|
113
|
+
arg3,
|
|
114
|
+
];
|
|
110
115
|
}
|
|
111
116
|
try {
|
|
112
117
|
let position = 0;
|
|
113
|
-
|
|
118
|
+
const [parsed, callerArguments, _length] = parseArgs();
|
|
114
119
|
const args = [].slice.call(callerArguments);
|
|
115
120
|
while (args.length && args[args.length - 1] === undefined)
|
|
116
121
|
args.pop();
|
|
117
|
-
length =
|
|
122
|
+
const length = _length || args.length;
|
|
118
123
|
if (length < parsed.demanded.length) {
|
|
119
124
|
throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
|
|
120
125
|
}
|
|
@@ -122,7 +127,7 @@ function argsert(arg1, arg2, arg3) {
|
|
|
122
127
|
if (length > totalCommands) {
|
|
123
128
|
throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
|
|
124
129
|
}
|
|
125
|
-
parsed.demanded.forEach(
|
|
130
|
+
parsed.demanded.forEach(demanded => {
|
|
126
131
|
const arg = args.shift();
|
|
127
132
|
const observedType = guessType(arg);
|
|
128
133
|
const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*');
|
|
@@ -130,7 +135,7 @@ function argsert(arg1, arg2, arg3) {
|
|
|
130
135
|
argumentTypeError(observedType, demanded.cmd, position);
|
|
131
136
|
position += 1;
|
|
132
137
|
});
|
|
133
|
-
parsed.optional.forEach(
|
|
138
|
+
parsed.optional.forEach(optional => {
|
|
134
139
|
if (args.length === 0)
|
|
135
140
|
return;
|
|
136
141
|
const arg = args.shift();
|
|
@@ -159,9 +164,9 @@ function argumentTypeError(observedType, allowedTypes, position) {
|
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
function isPromise(maybePromise) {
|
|
162
|
-
return !!maybePromise &&
|
|
167
|
+
return (!!maybePromise &&
|
|
163
168
|
!!maybePromise.then &&
|
|
164
|
-
|
|
169
|
+
typeof maybePromise.then === 'function');
|
|
165
170
|
}
|
|
166
171
|
|
|
167
172
|
function assertNotStrictEqual(actual, expected, shim, message) {
|
|
@@ -176,7 +181,7 @@ function objectKeys(object) {
|
|
|
176
181
|
|
|
177
182
|
function objFilter(original = {}, filter = () => true) {
|
|
178
183
|
const obj = {};
|
|
179
|
-
objectKeys(original).forEach(
|
|
184
|
+
objectKeys(original).forEach(key => {
|
|
180
185
|
if (filter(key, original[key])) {
|
|
181
186
|
obj[key] = original[key];
|
|
182
187
|
}
|
|
@@ -213,14 +218,16 @@ function commandMiddlewareFactory(commandMiddleware) {
|
|
|
213
218
|
}
|
|
214
219
|
function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
|
|
215
220
|
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true');
|
|
216
|
-
return middlewares
|
|
217
|
-
.reduce((acc, middleware) => {
|
|
221
|
+
return middlewares.reduce((acc, middleware) => {
|
|
218
222
|
if (middleware.applyBeforeValidation !== beforeValidation) {
|
|
219
223
|
return acc;
|
|
220
224
|
}
|
|
221
225
|
if (isPromise(acc)) {
|
|
222
226
|
return acc
|
|
223
|
-
.then(initialObj => Promise.all([
|
|
227
|
+
.then(initialObj => Promise.all([
|
|
228
|
+
initialObj,
|
|
229
|
+
middleware(initialObj, yargs),
|
|
230
|
+
]))
|
|
224
231
|
.then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
|
|
225
232
|
}
|
|
226
233
|
else {
|
|
@@ -261,7 +268,7 @@ var processArgv = /*#__PURE__*/Object.freeze({
|
|
|
261
268
|
function whichModule(exported) {
|
|
262
269
|
if (typeof require === 'undefined')
|
|
263
270
|
return null;
|
|
264
|
-
for (
|
|
271
|
+
for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
|
|
265
272
|
mod = require.cache[files[i]];
|
|
266
273
|
if (mod.exports === exported)
|
|
267
274
|
return mod;
|
|
@@ -284,7 +291,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
284
291
|
cmd = cmd[0];
|
|
285
292
|
}
|
|
286
293
|
else if (isCommandHandlerDefinition(cmd)) {
|
|
287
|
-
let command =
|
|
294
|
+
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
|
295
|
+
? cmd.command
|
|
296
|
+
: moduleName(cmd);
|
|
288
297
|
if (cmd.aliases)
|
|
289
298
|
command = [].concat(command).concat(cmd.aliases);
|
|
290
299
|
self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
@@ -297,7 +306,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
297
306
|
const parsedCommand = parseCommand(cmd);
|
|
298
307
|
aliases = aliases.map(alias => parseCommand(alias).cmd);
|
|
299
308
|
let isDefault = false;
|
|
300
|
-
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(
|
|
309
|
+
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
|
|
301
310
|
if (DEFAULT_MARKER.test(c)) {
|
|
302
311
|
isDefault = true;
|
|
303
312
|
return false;
|
|
@@ -311,7 +320,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
311
320
|
aliases = parsedAliases.slice(1);
|
|
312
321
|
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
|
313
322
|
}
|
|
314
|
-
aliases.forEach(
|
|
323
|
+
aliases.forEach(alias => {
|
|
315
324
|
aliasMap[alias] = parsedCommand.cmd;
|
|
316
325
|
});
|
|
317
326
|
if (description !== false) {
|
|
@@ -325,7 +334,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
325
334
|
middlewares,
|
|
326
335
|
deprecated,
|
|
327
336
|
demanded: parsedCommand.demanded,
|
|
328
|
-
optional: parsedCommand.optional
|
|
337
|
+
optional: parsedCommand.optional,
|
|
329
338
|
};
|
|
330
339
|
if (isDefault)
|
|
331
340
|
defaultCommand = handlers[parsedCommand.cmd];
|
|
@@ -358,7 +367,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
358
367
|
function commandFromFilename(filename) {
|
|
359
368
|
return shim.path.basename(filename, shim.path.extname(filename));
|
|
360
369
|
}
|
|
361
|
-
function extractDesc({ describe, description, desc }) {
|
|
370
|
+
function extractDesc({ describe, description, desc, }) {
|
|
362
371
|
for (const test of [describe, description, desc]) {
|
|
363
372
|
if (typeof test === 'string' || test === false)
|
|
364
373
|
return test;
|
|
@@ -386,7 +395,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
386
395
|
const builderOutput = builder(yargs.reset(parsed.aliases));
|
|
387
396
|
const innerYargs = isYargsInstance(builderOutput) ? builderOutput : yargs;
|
|
388
397
|
if (shouldUpdateUsage(innerYargs)) {
|
|
389
|
-
innerYargs
|
|
398
|
+
innerYargs
|
|
399
|
+
.getUsageInstance()
|
|
400
|
+
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
390
401
|
}
|
|
391
402
|
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
392
403
|
aliases = innerYargs.parsed.aliases;
|
|
@@ -394,9 +405,11 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
394
405
|
else if (isCommandBuilderOptionDefinitions(builder)) {
|
|
395
406
|
const innerYargs = yargs.reset(parsed.aliases);
|
|
396
407
|
if (shouldUpdateUsage(innerYargs)) {
|
|
397
|
-
innerYargs
|
|
408
|
+
innerYargs
|
|
409
|
+
.getUsageInstance()
|
|
410
|
+
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
398
411
|
}
|
|
399
|
-
Object.keys(commandHandler.builder).forEach(
|
|
412
|
+
Object.keys(commandHandler.builder).forEach(key => {
|
|
400
413
|
innerYargs.option(key, builder[key]);
|
|
401
414
|
});
|
|
402
415
|
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
@@ -405,7 +418,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
405
418
|
if (!yargs._hasOutput()) {
|
|
406
419
|
positionalMap = populatePositionals(commandHandler, innerArgv, currentContext);
|
|
407
420
|
}
|
|
408
|
-
const middlewares = globalMiddleware
|
|
421
|
+
const middlewares = globalMiddleware
|
|
422
|
+
.slice(0)
|
|
423
|
+
.concat(commandHandler.middlewares);
|
|
409
424
|
applyMiddleware(innerArgv, yargs, middlewares, true);
|
|
410
425
|
if (!yargs._hasOutput()) {
|
|
411
426
|
yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error, !command);
|
|
@@ -458,12 +473,16 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
458
473
|
return innerArgv;
|
|
459
474
|
};
|
|
460
475
|
function shouldUpdateUsage(yargs) {
|
|
461
|
-
return !yargs.getUsageInstance().getUsageDisabled() &&
|
|
462
|
-
yargs.getUsageInstance().getUsage().length === 0;
|
|
476
|
+
return (!yargs.getUsageInstance().getUsageDisabled() &&
|
|
477
|
+
yargs.getUsageInstance().getUsage().length === 0);
|
|
463
478
|
}
|
|
464
479
|
function usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
|
|
465
|
-
const c = DEFAULT_MARKER.test(commandHandler.original)
|
|
466
|
-
|
|
480
|
+
const c = DEFAULT_MARKER.test(commandHandler.original)
|
|
481
|
+
? commandHandler.original.replace(DEFAULT_MARKER, '').trim()
|
|
482
|
+
: commandHandler.original;
|
|
483
|
+
const pc = parentCommands.filter(c => {
|
|
484
|
+
return !DEFAULT_MARKER.test(c);
|
|
485
|
+
});
|
|
467
486
|
pc.push(c);
|
|
468
487
|
return `$0 ${pc.join(' ')}`;
|
|
469
488
|
}
|
|
@@ -471,7 +490,8 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
471
490
|
assertNotStrictEqual(defaultCommand, undefined, shim);
|
|
472
491
|
if (shouldUpdateUsage(yargs)) {
|
|
473
492
|
const commandString = DEFAULT_MARKER.test(defaultCommand.original)
|
|
474
|
-
? defaultCommand.original
|
|
493
|
+
? defaultCommand.original
|
|
494
|
+
: defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
|
|
475
495
|
yargs.getUsageInstance().usage(commandString, defaultCommand.description);
|
|
476
496
|
}
|
|
477
497
|
const builder = defaultCommand.builder;
|
|
@@ -479,7 +499,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
479
499
|
builder(yargs);
|
|
480
500
|
}
|
|
481
501
|
else {
|
|
482
|
-
Object.keys(builder).forEach(
|
|
502
|
+
Object.keys(builder).forEach(key => {
|
|
483
503
|
yargs.option(key, builder[key]);
|
|
484
504
|
});
|
|
485
505
|
}
|
|
@@ -521,8 +541,8 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
521
541
|
options.array = options.array.concat(parseOptions.array);
|
|
522
542
|
options.config = {};
|
|
523
543
|
const unparsed = [];
|
|
524
|
-
Object.keys(positionalMap).forEach(
|
|
525
|
-
positionalMap[key].map(
|
|
544
|
+
Object.keys(positionalMap).forEach(key => {
|
|
545
|
+
positionalMap[key].map(value => {
|
|
526
546
|
if (options.configuration['unknown-options-as-args'])
|
|
527
547
|
options.key[key] = true;
|
|
528
548
|
unparsed.push(`--${key}`);
|
|
@@ -532,20 +552,20 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
532
552
|
if (!unparsed.length)
|
|
533
553
|
return;
|
|
534
554
|
const config = Object.assign({}, options.configuration, {
|
|
535
|
-
'populate--': true
|
|
555
|
+
'populate--': true,
|
|
536
556
|
});
|
|
537
557
|
const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, {
|
|
538
|
-
configuration: config
|
|
558
|
+
configuration: config,
|
|
539
559
|
}));
|
|
540
560
|
if (parsed.error) {
|
|
541
561
|
yargs.getUsageInstance().fail(parsed.error.message, parsed.error);
|
|
542
562
|
}
|
|
543
563
|
else {
|
|
544
564
|
const positionalKeys = Object.keys(positionalMap);
|
|
545
|
-
Object.keys(positionalMap).forEach(
|
|
565
|
+
Object.keys(positionalMap).forEach(key => {
|
|
546
566
|
positionalKeys.push(...parsed.aliases[key]);
|
|
547
567
|
});
|
|
548
|
-
Object.keys(parsed.argv).forEach(
|
|
568
|
+
Object.keys(parsed.argv).forEach(key => {
|
|
549
569
|
if (positionalKeys.indexOf(key) !== -1) {
|
|
550
570
|
if (!positionalMap[key])
|
|
551
571
|
positionalMap[key] = parsed.argv[key];
|
|
@@ -559,10 +579,10 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
559
579
|
array: [],
|
|
560
580
|
default: {},
|
|
561
581
|
alias: {},
|
|
562
|
-
demand: {}
|
|
582
|
+
demand: {},
|
|
563
583
|
};
|
|
564
584
|
const parsed = parseCommand(cmdString);
|
|
565
|
-
parsed.demanded.forEach(
|
|
585
|
+
parsed.demanded.forEach(d => {
|
|
566
586
|
const [cmd, ...aliases] = d.cmd;
|
|
567
587
|
if (d.variadic) {
|
|
568
588
|
parseOptions.array.push(cmd);
|
|
@@ -571,7 +591,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
571
591
|
parseOptions.alias[cmd] = aliases;
|
|
572
592
|
parseOptions.demand[cmd] = true;
|
|
573
593
|
});
|
|
574
|
-
parsed.optional.forEach(
|
|
594
|
+
parsed.optional.forEach(o => {
|
|
575
595
|
const [cmd, ...aliases] = o.cmd;
|
|
576
596
|
if (o.variadic) {
|
|
577
597
|
parseOptions.array.push(cmd);
|
|
@@ -592,17 +612,13 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
592
612
|
frozens.push({
|
|
593
613
|
handlers,
|
|
594
614
|
aliasMap,
|
|
595
|
-
defaultCommand
|
|
615
|
+
defaultCommand,
|
|
596
616
|
});
|
|
597
617
|
};
|
|
598
618
|
self.unfreeze = () => {
|
|
599
619
|
const frozen = frozens.pop();
|
|
600
620
|
assertNotStrictEqual(frozen, undefined, shim);
|
|
601
|
-
({
|
|
602
|
-
handlers,
|
|
603
|
-
aliasMap,
|
|
604
|
-
defaultCommand
|
|
605
|
-
} = frozen);
|
|
621
|
+
({ handlers, aliasMap, defaultCommand } = frozen);
|
|
606
622
|
};
|
|
607
623
|
return self;
|
|
608
624
|
}
|
|
@@ -610,9 +626,9 @@ function isCommandHandlerDefinition(cmd) {
|
|
|
610
626
|
return typeof cmd === 'object';
|
|
611
627
|
}
|
|
612
628
|
function isCommandBuilderDefinition(builder) {
|
|
613
|
-
return typeof builder === 'object' &&
|
|
629
|
+
return (typeof builder === 'object' &&
|
|
614
630
|
!!builder.builder &&
|
|
615
|
-
typeof builder.handler === 'function';
|
|
631
|
+
typeof builder.handler === 'function');
|
|
616
632
|
}
|
|
617
633
|
function isCommandBuilderCallback(builder) {
|
|
618
634
|
return typeof builder === 'function';
|
|
@@ -624,9 +640,11 @@ function isCommandBuilderOptionDefinitions(builder) {
|
|
|
624
640
|
function setBlocking(blocking) {
|
|
625
641
|
if (typeof process === 'undefined')
|
|
626
642
|
return;
|
|
627
|
-
[process.stdout, process.stderr].forEach(
|
|
643
|
+
[process.stdout, process.stderr].forEach(_stream => {
|
|
628
644
|
const stream = _stream;
|
|
629
|
-
if (stream._handle &&
|
|
645
|
+
if (stream._handle &&
|
|
646
|
+
stream.isTTY &&
|
|
647
|
+
typeof stream._handle.setBlocking === 'function') {
|
|
630
648
|
stream._handle.setBlocking(blocking);
|
|
631
649
|
}
|
|
632
650
|
});
|
|
@@ -715,7 +733,7 @@ function usage(yargs, y18n, shim) {
|
|
|
715
733
|
let commands = [];
|
|
716
734
|
self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
|
|
717
735
|
if (isDefault) {
|
|
718
|
-
commands = commands.map(
|
|
736
|
+
commands = commands.map(cmdArray => {
|
|
719
737
|
cmdArray[2] = false;
|
|
720
738
|
return cmdArray;
|
|
721
739
|
});
|
|
@@ -726,12 +744,12 @@ function usage(yargs, y18n, shim) {
|
|
|
726
744
|
let descriptions = {};
|
|
727
745
|
self.describe = function describe(keyOrKeys, desc) {
|
|
728
746
|
if (Array.isArray(keyOrKeys)) {
|
|
729
|
-
keyOrKeys.forEach(
|
|
747
|
+
keyOrKeys.forEach(k => {
|
|
730
748
|
self.describe(k, desc);
|
|
731
749
|
});
|
|
732
750
|
}
|
|
733
751
|
else if (typeof keyOrKeys === 'object') {
|
|
734
|
-
Object.keys(keyOrKeys).forEach(
|
|
752
|
+
Object.keys(keyOrKeys).forEach(k => {
|
|
735
753
|
self.describe(k, keyOrKeys[k]);
|
|
736
754
|
});
|
|
737
755
|
}
|
|
@@ -741,12 +759,12 @@ function usage(yargs, y18n, shim) {
|
|
|
741
759
|
};
|
|
742
760
|
self.getDescriptions = () => descriptions;
|
|
743
761
|
let epilogs = [];
|
|
744
|
-
self.epilog =
|
|
762
|
+
self.epilog = msg => {
|
|
745
763
|
epilogs.push(msg);
|
|
746
764
|
};
|
|
747
765
|
let wrapSet = false;
|
|
748
766
|
let wrap;
|
|
749
|
-
self.wrap =
|
|
767
|
+
self.wrap = cols => {
|
|
750
768
|
wrapSet = true;
|
|
751
769
|
wrap = cols;
|
|
752
770
|
};
|
|
@@ -763,7 +781,9 @@ function usage(yargs, y18n, shim) {
|
|
|
763
781
|
if (cachedHelpMessage)
|
|
764
782
|
return cachedHelpMessage;
|
|
765
783
|
normalizeAliases();
|
|
766
|
-
const base$0 = yargs.customScriptName
|
|
784
|
+
const base$0 = yargs.customScriptName
|
|
785
|
+
? yargs.$0
|
|
786
|
+
: shim.path.basename(yargs.$0);
|
|
767
787
|
const demandedOptions = yargs.getDemandedOptions();
|
|
768
788
|
const demandedCommands = yargs.getDemandedCommands();
|
|
769
789
|
const deprecatedOptions = yargs.getDeprecatedOptions();
|
|
@@ -783,11 +803,11 @@ function usage(yargs, y18n, shim) {
|
|
|
783
803
|
const theWrap = getWrap();
|
|
784
804
|
const ui = shim.cliui({
|
|
785
805
|
width: theWrap,
|
|
786
|
-
wrap: !!theWrap
|
|
806
|
+
wrap: !!theWrap,
|
|
787
807
|
});
|
|
788
808
|
if (!usageDisabled) {
|
|
789
809
|
if (usages.length) {
|
|
790
|
-
usages.forEach(
|
|
810
|
+
usages.forEach(usage => {
|
|
791
811
|
ui.div(`${usage[0].replace(/\$0/g, base$0)}`);
|
|
792
812
|
if (usage[1]) {
|
|
793
813
|
ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] });
|
|
@@ -809,16 +829,18 @@ function usage(yargs, y18n, shim) {
|
|
|
809
829
|
if (commands.length) {
|
|
810
830
|
ui.div(__('Commands:'));
|
|
811
831
|
const context = yargs.getContext();
|
|
812
|
-
const parentCommands = context.commands.length
|
|
832
|
+
const parentCommands = context.commands.length
|
|
833
|
+
? `${context.commands.join(' ')} `
|
|
834
|
+
: '';
|
|
813
835
|
if (yargs.getParserConfiguration()['sort-commands'] === true) {
|
|
814
836
|
commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
|
|
815
837
|
}
|
|
816
|
-
commands.forEach(
|
|
838
|
+
commands.forEach(command => {
|
|
817
839
|
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
|
|
818
840
|
ui.span({
|
|
819
841
|
text: commandString,
|
|
820
842
|
padding: [0, 2, 0, 2],
|
|
821
|
-
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
|
|
843
|
+
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4,
|
|
822
844
|
}, { text: command[1] });
|
|
823
845
|
const hints = [];
|
|
824
846
|
if (command[2])
|
|
@@ -835,7 +857,11 @@ function usage(yargs, y18n, shim) {
|
|
|
835
857
|
}
|
|
836
858
|
}
|
|
837
859
|
if (hints.length) {
|
|
838
|
-
ui.div({
|
|
860
|
+
ui.div({
|
|
861
|
+
text: hints.join(' '),
|
|
862
|
+
padding: [0, 0, 0, 2],
|
|
863
|
+
align: 'right',
|
|
864
|
+
});
|
|
839
865
|
}
|
|
840
866
|
else {
|
|
841
867
|
ui.div();
|
|
@@ -843,9 +869,9 @@ function usage(yargs, y18n, shim) {
|
|
|
843
869
|
});
|
|
844
870
|
ui.div();
|
|
845
871
|
}
|
|
846
|
-
const aliasKeys = (Object.keys(options.alias) || [])
|
|
847
|
-
|
|
848
|
-
|
|
872
|
+
const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
|
|
873
|
+
keys = keys.filter(key => !yargs.parsed.newAliases[key] &&
|
|
874
|
+
aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1));
|
|
849
875
|
const defaultGroup = __('Options:');
|
|
850
876
|
if (!groups[defaultGroup])
|
|
851
877
|
groups[defaultGroup] = [];
|
|
@@ -854,7 +880,9 @@ function usage(yargs, y18n, shim) {
|
|
|
854
880
|
const displayedGroups = Object.keys(groups)
|
|
855
881
|
.filter(groupName => groups[groupName].length > 0)
|
|
856
882
|
.map(groupName => {
|
|
857
|
-
const normalizedKeys = groups[groupName]
|
|
883
|
+
const normalizedKeys = groups[groupName]
|
|
884
|
+
.filter(filterHiddenOptions)
|
|
885
|
+
.map(key => {
|
|
858
886
|
if (~aliasKeys.indexOf(key))
|
|
859
887
|
return key;
|
|
860
888
|
for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
|
|
@@ -868,17 +896,26 @@ function usage(yargs, y18n, shim) {
|
|
|
868
896
|
.filter(({ normalizedKeys }) => normalizedKeys.length > 0)
|
|
869
897
|
.map(({ groupName, normalizedKeys }) => {
|
|
870
898
|
const switches = normalizedKeys.reduce((acc, key) => {
|
|
871
|
-
acc[key] = [key]
|
|
899
|
+
acc[key] = [key]
|
|
900
|
+
.concat(options.alias[key] || [])
|
|
872
901
|
.map(sw => {
|
|
873
902
|
if (groupName === self.getPositionalGroupName())
|
|
874
903
|
return sw;
|
|
875
904
|
else {
|
|
876
|
-
return (/^[0-9]$/.test(sw)
|
|
877
|
-
? ~options.boolean.indexOf(key)
|
|
878
|
-
|
|
905
|
+
return ((/^[0-9]$/.test(sw)
|
|
906
|
+
? ~options.boolean.indexOf(key)
|
|
907
|
+
? '-'
|
|
908
|
+
: '--'
|
|
909
|
+
: sw.length > 1
|
|
910
|
+
? '--'
|
|
911
|
+
: '-') + sw);
|
|
879
912
|
}
|
|
880
913
|
})
|
|
881
|
-
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2)
|
|
914
|
+
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2)
|
|
915
|
+
? 0
|
|
916
|
+
: isLongSwitch(sw1)
|
|
917
|
+
? 1
|
|
918
|
+
: -1)
|
|
882
919
|
.join(', ');
|
|
883
920
|
return acc;
|
|
884
921
|
}, {});
|
|
@@ -900,7 +937,7 @@ function usage(yargs, y18n, shim) {
|
|
|
900
937
|
}
|
|
901
938
|
displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
|
|
902
939
|
ui.div(groupName);
|
|
903
|
-
normalizedKeys.forEach(
|
|
940
|
+
normalizedKeys.forEach(key => {
|
|
904
941
|
const kswitch = switches[key];
|
|
905
942
|
let desc = descriptions[key] || '';
|
|
906
943
|
let type = null;
|
|
@@ -922,13 +959,23 @@ function usage(yargs, y18n, shim) {
|
|
|
922
959
|
? `[${__('deprecated: %s', deprecated)}]`
|
|
923
960
|
: `[${__('deprecated')}]`;
|
|
924
961
|
const extra = [
|
|
925
|
-
|
|
962
|
+
key in deprecatedOptions
|
|
963
|
+
? deprecatedExtra(deprecatedOptions[key])
|
|
964
|
+
: null,
|
|
926
965
|
type,
|
|
927
|
-
|
|
928
|
-
options.choices && options.choices[key]
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
966
|
+
key in demandedOptions ? `[${__('required')}]` : null,
|
|
967
|
+
options.choices && options.choices[key]
|
|
968
|
+
? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]`
|
|
969
|
+
: null,
|
|
970
|
+
defaultString(options.default[key], options.defaultDescription[key]),
|
|
971
|
+
]
|
|
972
|
+
.filter(Boolean)
|
|
973
|
+
.join(' ');
|
|
974
|
+
ui.span({
|
|
975
|
+
text: getText(kswitch),
|
|
976
|
+
padding: [0, 2, 0, 2 + getIndentation(kswitch)],
|
|
977
|
+
width: maxWidth(switches, theWrap) + 4,
|
|
978
|
+
}, desc);
|
|
932
979
|
if (extra)
|
|
933
980
|
ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
|
|
934
981
|
else
|
|
@@ -938,30 +985,32 @@ function usage(yargs, y18n, shim) {
|
|
|
938
985
|
});
|
|
939
986
|
if (examples.length) {
|
|
940
987
|
ui.div(__('Examples:'));
|
|
941
|
-
examples.forEach(
|
|
988
|
+
examples.forEach(example => {
|
|
942
989
|
example[0] = example[0].replace(/\$0/g, base$0);
|
|
943
990
|
});
|
|
944
|
-
examples.forEach(
|
|
991
|
+
examples.forEach(example => {
|
|
945
992
|
if (example[1] === '') {
|
|
946
993
|
ui.div({
|
|
947
994
|
text: example[0],
|
|
948
|
-
padding: [0, 2, 0, 2]
|
|
995
|
+
padding: [0, 2, 0, 2],
|
|
949
996
|
});
|
|
950
997
|
}
|
|
951
998
|
else {
|
|
952
999
|
ui.div({
|
|
953
1000
|
text: example[0],
|
|
954
1001
|
padding: [0, 2, 0, 2],
|
|
955
|
-
width: maxWidth(examples, theWrap) + 4
|
|
1002
|
+
width: maxWidth(examples, theWrap) + 4,
|
|
956
1003
|
}, {
|
|
957
|
-
text: example[1]
|
|
1004
|
+
text: example[1],
|
|
958
1005
|
});
|
|
959
1006
|
}
|
|
960
1007
|
});
|
|
961
1008
|
ui.div();
|
|
962
1009
|
}
|
|
963
1010
|
if (epilogs.length > 0) {
|
|
964
|
-
const e = epilogs
|
|
1011
|
+
const e = epilogs
|
|
1012
|
+
.map(epilog => epilog.replace(/\$0/g, base$0))
|
|
1013
|
+
.join('\n');
|
|
965
1014
|
ui.div(`${e}\n`);
|
|
966
1015
|
}
|
|
967
1016
|
return ui.toString().replace(/\s*$/, '');
|
|
@@ -971,7 +1020,7 @@ function usage(yargs, y18n, shim) {
|
|
|
971
1020
|
if (!Array.isArray(table)) {
|
|
972
1021
|
table = Object.values(table).map(v => [v]);
|
|
973
1022
|
}
|
|
974
|
-
table.forEach(
|
|
1023
|
+
table.forEach(v => {
|
|
975
1024
|
width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
|
|
976
1025
|
});
|
|
977
1026
|
if (theWrap)
|
|
@@ -981,8 +1030,8 @@ function usage(yargs, y18n, shim) {
|
|
|
981
1030
|
function normalizeAliases() {
|
|
982
1031
|
const demandedOptions = yargs.getDemandedOptions();
|
|
983
1032
|
const options = yargs.getOptions();
|
|
984
|
-
(Object.keys(options.alias) || []).forEach(
|
|
985
|
-
options.alias[key].forEach(
|
|
1033
|
+
(Object.keys(options.alias) || []).forEach(key => {
|
|
1034
|
+
options.alias[key].forEach(alias => {
|
|
986
1035
|
if (descriptions[alias])
|
|
987
1036
|
self.describe(key, descriptions[alias]);
|
|
988
1037
|
if (alias in demandedOptions)
|
|
@@ -1012,10 +1061,10 @@ function usage(yargs, y18n, shim) {
|
|
|
1012
1061
|
function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
|
|
1013
1062
|
let groupedKeys = [];
|
|
1014
1063
|
let toCheck = null;
|
|
1015
|
-
Object.keys(groups).forEach(
|
|
1064
|
+
Object.keys(groups).forEach(group => {
|
|
1016
1065
|
groupedKeys = groupedKeys.concat(groups[group]);
|
|
1017
1066
|
});
|
|
1018
|
-
keys.forEach(
|
|
1067
|
+
keys.forEach(key => {
|
|
1019
1068
|
toCheck = [key].concat(aliases[key]);
|
|
1020
1069
|
if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
|
|
1021
1070
|
groups[defaultGroup].push(key);
|
|
@@ -1024,7 +1073,8 @@ function usage(yargs, y18n, shim) {
|
|
|
1024
1073
|
return groupedKeys;
|
|
1025
1074
|
}
|
|
1026
1075
|
function filterHiddenOptions(key) {
|
|
1027
|
-
return yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
|
|
1076
|
+
return (yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
|
|
1077
|
+
yargs.parsed.argv[yargs.getOptions().showHiddenOpt]);
|
|
1028
1078
|
}
|
|
1029
1079
|
self.showHelp = (level) => {
|
|
1030
1080
|
const logger = yargs._getLoggerInstance();
|
|
@@ -1033,8 +1083,10 @@ function usage(yargs, y18n, shim) {
|
|
|
1033
1083
|
const emit = typeof level === 'function' ? level : logger[level];
|
|
1034
1084
|
emit(self.help());
|
|
1035
1085
|
};
|
|
1036
|
-
self.functionDescription =
|
|
1037
|
-
const description = fn.name
|
|
1086
|
+
self.functionDescription = fn => {
|
|
1087
|
+
const description = fn.name
|
|
1088
|
+
? shim.Parser.decamelize(fn.name, '-')
|
|
1089
|
+
: __('generated-value');
|
|
1038
1090
|
return ['(', description, ')'].join('');
|
|
1039
1091
|
};
|
|
1040
1092
|
self.stringifiedValues = function stringifiedValues(values, separator) {
|
|
@@ -1043,7 +1095,7 @@ function usage(yargs, y18n, shim) {
|
|
|
1043
1095
|
const array = [].concat(values);
|
|
1044
1096
|
if (!values || !array.length)
|
|
1045
1097
|
return string;
|
|
1046
|
-
array.forEach(
|
|
1098
|
+
array.forEach(value => {
|
|
1047
1099
|
if (string.length)
|
|
1048
1100
|
string += sep;
|
|
1049
1101
|
string += JSON.stringify(value);
|
|
@@ -1081,7 +1133,7 @@ function usage(yargs, y18n, shim) {
|
|
|
1081
1133
|
}
|
|
1082
1134
|
}
|
|
1083
1135
|
let version = null;
|
|
1084
|
-
self.version =
|
|
1136
|
+
self.version = ver => {
|
|
1085
1137
|
version = ver;
|
|
1086
1138
|
};
|
|
1087
1139
|
self.showVersion = () => {
|
|
@@ -1109,7 +1161,7 @@ function usage(yargs, y18n, shim) {
|
|
|
1109
1161
|
epilogs,
|
|
1110
1162
|
examples,
|
|
1111
1163
|
commands,
|
|
1112
|
-
descriptions
|
|
1164
|
+
descriptions,
|
|
1113
1165
|
});
|
|
1114
1166
|
};
|
|
1115
1167
|
self.unfreeze = function unfreeze() {
|
|
@@ -1123,7 +1175,7 @@ function usage(yargs, y18n, shim) {
|
|
|
1123
1175
|
epilogs,
|
|
1124
1176
|
examples,
|
|
1125
1177
|
commands,
|
|
1126
|
-
descriptions
|
|
1178
|
+
descriptions,
|
|
1127
1179
|
} = frozen);
|
|
1128
1180
|
};
|
|
1129
1181
|
return self;
|
|
@@ -1193,7 +1245,7 @@ compdef _{{app_name}}_yargs_completions {{app_name}}
|
|
|
1193
1245
|
|
|
1194
1246
|
function completion(yargs, usage, command, shim) {
|
|
1195
1247
|
const self = {
|
|
1196
|
-
completionKey: 'get-yargs-completions'
|
|
1248
|
+
completionKey: 'get-yargs-completions',
|
|
1197
1249
|
};
|
|
1198
1250
|
let aliases;
|
|
1199
1251
|
self.setParsed = function setParsed(parsed) {
|
|
@@ -1211,22 +1263,30 @@ function completion(yargs, usage, command, shim) {
|
|
|
1211
1263
|
if (isSyncCompletionFunction(completionFunction)) {
|
|
1212
1264
|
const result = completionFunction(current, argv);
|
|
1213
1265
|
if (isPromise(result)) {
|
|
1214
|
-
return result
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1266
|
+
return result
|
|
1267
|
+
.then(list => {
|
|
1268
|
+
shim.process.nextTick(() => {
|
|
1269
|
+
done(list);
|
|
1270
|
+
});
|
|
1271
|
+
})
|
|
1272
|
+
.catch(err => {
|
|
1273
|
+
shim.process.nextTick(() => {
|
|
1274
|
+
throw err;
|
|
1275
|
+
});
|
|
1218
1276
|
});
|
|
1219
1277
|
}
|
|
1220
1278
|
return done(result);
|
|
1221
1279
|
}
|
|
1222
1280
|
else {
|
|
1223
|
-
return completionFunction(current, argv,
|
|
1281
|
+
return completionFunction(current, argv, completions => {
|
|
1224
1282
|
done(completions);
|
|
1225
1283
|
});
|
|
1226
1284
|
}
|
|
1227
1285
|
}
|
|
1228
1286
|
if (completionFunction) {
|
|
1229
|
-
return isPromise(argv)
|
|
1287
|
+
return isPromise(argv)
|
|
1288
|
+
? argv.then(runCompletionFunction)
|
|
1289
|
+
: runCompletionFunction(argv);
|
|
1230
1290
|
}
|
|
1231
1291
|
const handlers = command.getCommandHandlers();
|
|
1232
1292
|
for (let i = 0, ii = args.length; i < ii; ++i) {
|
|
@@ -1239,8 +1299,9 @@ function completion(yargs, usage, command, shim) {
|
|
|
1239
1299
|
}
|
|
1240
1300
|
}
|
|
1241
1301
|
}
|
|
1242
|
-
if (!current.match(/^-/) &&
|
|
1243
|
-
|
|
1302
|
+
if (!current.match(/^-/) &&
|
|
1303
|
+
parentCommands[parentCommands.length - 1] !== current) {
|
|
1304
|
+
usage.getCommands().forEach(usageCommand => {
|
|
1244
1305
|
const commandName = parseCommand(usageCommand[0]).cmd;
|
|
1245
1306
|
if (args.indexOf(commandName) === -1) {
|
|
1246
1307
|
if (!zshShell) {
|
|
@@ -1256,8 +1317,9 @@ function completion(yargs, usage, command, shim) {
|
|
|
1256
1317
|
if (current.match(/^-/) || (current === '' && completions.length === 0)) {
|
|
1257
1318
|
const descs = usage.getDescriptions();
|
|
1258
1319
|
const options = yargs.getOptions();
|
|
1259
|
-
Object.keys(options.key).forEach(
|
|
1260
|
-
const negable = !!options.configuration['boolean-negation'] &&
|
|
1320
|
+
Object.keys(options.key).forEach(key => {
|
|
1321
|
+
const negable = !!options.configuration['boolean-negation'] &&
|
|
1322
|
+
options.boolean.includes(key);
|
|
1261
1323
|
let keyAndAliases = [key].concat(aliases[key] || []);
|
|
1262
1324
|
if (negable)
|
|
1263
1325
|
keyAndAliases = keyAndAliases.concat(keyAndAliases.map(key => `no-${key}`));
|
|
@@ -1272,7 +1334,8 @@ function completion(yargs, usage, command, shim) {
|
|
|
1272
1334
|
}
|
|
1273
1335
|
else {
|
|
1274
1336
|
const desc = descs[key] || '';
|
|
1275
|
-
completions.push(dashes +
|
|
1337
|
+
completions.push(dashes +
|
|
1338
|
+
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`);
|
|
1276
1339
|
}
|
|
1277
1340
|
}
|
|
1278
1341
|
}
|
|
@@ -1284,7 +1347,9 @@ function completion(yargs, usage, command, shim) {
|
|
|
1284
1347
|
done(completions);
|
|
1285
1348
|
};
|
|
1286
1349
|
self.generateCompletionScript = function generateCompletionScript($0, cmd) {
|
|
1287
|
-
let script = zshShell
|
|
1350
|
+
let script = zshShell
|
|
1351
|
+
? completionZshTemplate
|
|
1352
|
+
: completionShTemplate;
|
|
1288
1353
|
const name = shim.path.basename($0);
|
|
1289
1354
|
if ($0.match(/\.js$/))
|
|
1290
1355
|
$0 = `./${$0}`;
|
|
@@ -1293,7 +1358,7 @@ function completion(yargs, usage, command, shim) {
|
|
|
1293
1358
|
return script.replace(/{{app_path}}/g, $0);
|
|
1294
1359
|
};
|
|
1295
1360
|
let completionFunction = null;
|
|
1296
|
-
self.registerFunction =
|
|
1361
|
+
self.registerFunction = fn => {
|
|
1297
1362
|
completionFunction = fn;
|
|
1298
1363
|
};
|
|
1299
1364
|
return self;
|
|
@@ -1338,11 +1403,14 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1338
1403
|
const demandedCommands = yargs.getDemandedCommands();
|
|
1339
1404
|
const positionalCount = argv._.length + (argv['--'] ? argv['--'].length : 0);
|
|
1340
1405
|
const _s = positionalCount - yargs.getContext().commands.length;
|
|
1341
|
-
if (demandedCommands._ &&
|
|
1406
|
+
if (demandedCommands._ &&
|
|
1407
|
+
(_s < demandedCommands._.min || _s > demandedCommands._.max)) {
|
|
1342
1408
|
if (_s < demandedCommands._.min) {
|
|
1343
1409
|
if (demandedCommands._.minMsg !== undefined) {
|
|
1344
1410
|
usage.fail(demandedCommands._.minMsg
|
|
1345
|
-
? demandedCommands._.minMsg
|
|
1411
|
+
? demandedCommands._.minMsg
|
|
1412
|
+
.replace(/\$0/g, _s.toString())
|
|
1413
|
+
.replace(/\$1/, demandedCommands._.min.toString())
|
|
1346
1414
|
: null);
|
|
1347
1415
|
}
|
|
1348
1416
|
else {
|
|
@@ -1352,7 +1420,9 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1352
1420
|
else if (_s > demandedCommands._.max) {
|
|
1353
1421
|
if (demandedCommands._.maxMsg !== undefined) {
|
|
1354
1422
|
usage.fail(demandedCommands._.maxMsg
|
|
1355
|
-
? demandedCommands._.maxMsg
|
|
1423
|
+
? demandedCommands._.maxMsg
|
|
1424
|
+
.replace(/\$0/g, _s.toString())
|
|
1425
|
+
.replace(/\$1/, demandedCommands._.max.toString())
|
|
1356
1426
|
: null);
|
|
1357
1427
|
}
|
|
1358
1428
|
else {
|
|
@@ -1370,7 +1440,8 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1370
1440
|
const demandedOptions = yargs.getDemandedOptions();
|
|
1371
1441
|
let missing = null;
|
|
1372
1442
|
for (const key of Object.keys(demandedOptions)) {
|
|
1373
|
-
if (!Object.prototype.hasOwnProperty.call(argv, key) ||
|
|
1443
|
+
if (!Object.prototype.hasOwnProperty.call(argv, key) ||
|
|
1444
|
+
typeof argv[key] === 'undefined') {
|
|
1374
1445
|
missing = missing || {};
|
|
1375
1446
|
missing[key] = demandedOptions[key];
|
|
1376
1447
|
}
|
|
@@ -1391,7 +1462,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1391
1462
|
const commandKeys = yargs.getCommandInstance().getCommands();
|
|
1392
1463
|
const unknown = [];
|
|
1393
1464
|
const currentContext = yargs.getContext();
|
|
1394
|
-
Object.keys(argv).forEach(
|
|
1465
|
+
Object.keys(argv).forEach(key => {
|
|
1395
1466
|
if (specialKeys.indexOf(key) === -1 &&
|
|
1396
1467
|
!Object.prototype.hasOwnProperty.call(positionalMap, key) &&
|
|
1397
1468
|
!Object.prototype.hasOwnProperty.call(yargs._getParseContext(), key) &&
|
|
@@ -1399,8 +1470,11 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1399
1470
|
unknown.push(key);
|
|
1400
1471
|
}
|
|
1401
1472
|
});
|
|
1402
|
-
if (checkPositionals &&
|
|
1403
|
-
|
|
1473
|
+
if (checkPositionals &&
|
|
1474
|
+
(currentContext.commands.length > 0 ||
|
|
1475
|
+
commandKeys.length > 0 ||
|
|
1476
|
+
isDefaultCommand)) {
|
|
1477
|
+
argv._.slice(currentContext.commands.length).forEach(key => {
|
|
1404
1478
|
if (commandKeys.indexOf('' + key) === -1) {
|
|
1405
1479
|
unknown.push('' + key);
|
|
1406
1480
|
}
|
|
@@ -1414,8 +1488,8 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1414
1488
|
const commandKeys = yargs.getCommandInstance().getCommands();
|
|
1415
1489
|
const unknown = [];
|
|
1416
1490
|
const currentContext = yargs.getContext();
|
|
1417
|
-
if (
|
|
1418
|
-
argv._.slice(currentContext.commands.length).forEach(
|
|
1491
|
+
if (currentContext.commands.length > 0 || commandKeys.length > 0) {
|
|
1492
|
+
argv._.slice(currentContext.commands.length).forEach(key => {
|
|
1419
1493
|
if (commandKeys.indexOf('' + key) === -1) {
|
|
1420
1494
|
unknown.push('' + key);
|
|
1421
1495
|
}
|
|
@@ -1435,7 +1509,8 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1435
1509
|
}
|
|
1436
1510
|
const newAliases = yargs.parsed.newAliases;
|
|
1437
1511
|
for (const a of [key, ...aliases[key]]) {
|
|
1438
|
-
if (!Object.prototype.hasOwnProperty.call(newAliases, a) ||
|
|
1512
|
+
if (!Object.prototype.hasOwnProperty.call(newAliases, a) ||
|
|
1513
|
+
!newAliases[key]) {
|
|
1439
1514
|
return true;
|
|
1440
1515
|
}
|
|
1441
1516
|
}
|
|
@@ -1446,10 +1521,10 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1446
1521
|
const invalid = {};
|
|
1447
1522
|
if (!Object.keys(options.choices).length)
|
|
1448
1523
|
return;
|
|
1449
|
-
Object.keys(argv).forEach(
|
|
1524
|
+
Object.keys(argv).forEach(key => {
|
|
1450
1525
|
if (specialKeys.indexOf(key) === -1 &&
|
|
1451
1526
|
Object.prototype.hasOwnProperty.call(options.choices, key)) {
|
|
1452
|
-
[].concat(argv[key]).forEach(
|
|
1527
|
+
[].concat(argv[key]).forEach(value => {
|
|
1453
1528
|
if (options.choices[key].indexOf(value) === -1 &&
|
|
1454
1529
|
value !== undefined) {
|
|
1455
1530
|
invalid[key] = (invalid[key] || []).concat(value);
|
|
@@ -1461,7 +1536,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1461
1536
|
if (!invalidKeys.length)
|
|
1462
1537
|
return;
|
|
1463
1538
|
let msg = __('Invalid values:');
|
|
1464
|
-
invalidKeys.forEach(
|
|
1539
|
+
invalidKeys.forEach(key => {
|
|
1465
1540
|
msg += `\n ${__('Argument: %s, Given: %s, Choices: %s', key, usage.stringifiedValues(invalid[key]), usage.stringifiedValues(options.choices[key]))}`;
|
|
1466
1541
|
});
|
|
1467
1542
|
usage.fail(msg);
|
|
@@ -1470,7 +1545,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1470
1545
|
self.check = function check(f, global) {
|
|
1471
1546
|
checks.push({
|
|
1472
1547
|
func: f,
|
|
1473
|
-
global
|
|
1548
|
+
global,
|
|
1474
1549
|
});
|
|
1475
1550
|
};
|
|
1476
1551
|
self.customChecks = function customChecks(argv, aliases) {
|
|
@@ -1496,7 +1571,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1496
1571
|
self.implies = function implies(key, value) {
|
|
1497
1572
|
argsert('<string|object> [array|number|string]', [key, value], arguments.length);
|
|
1498
1573
|
if (typeof key === 'object') {
|
|
1499
|
-
Object.keys(key).forEach(
|
|
1574
|
+
Object.keys(key).forEach(k => {
|
|
1500
1575
|
self.implies(k, key[k]);
|
|
1501
1576
|
});
|
|
1502
1577
|
}
|
|
@@ -1506,7 +1581,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1506
1581
|
implied[key] = [];
|
|
1507
1582
|
}
|
|
1508
1583
|
if (Array.isArray(value)) {
|
|
1509
|
-
value.forEach(
|
|
1584
|
+
value.forEach(i => self.implies(key, i));
|
|
1510
1585
|
}
|
|
1511
1586
|
else {
|
|
1512
1587
|
assertNotStrictEqual(value, undefined, shim);
|
|
@@ -1534,9 +1609,9 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1534
1609
|
}
|
|
1535
1610
|
self.implications = function implications(argv) {
|
|
1536
1611
|
const implyFail = [];
|
|
1537
|
-
Object.keys(implied).forEach(
|
|
1612
|
+
Object.keys(implied).forEach(key => {
|
|
1538
1613
|
const origKey = key;
|
|
1539
|
-
(implied[key] || []).forEach(
|
|
1614
|
+
(implied[key] || []).forEach(value => {
|
|
1540
1615
|
let key = origKey;
|
|
1541
1616
|
const origValue = value;
|
|
1542
1617
|
key = keyExists(argv, key);
|
|
@@ -1548,8 +1623,8 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1548
1623
|
});
|
|
1549
1624
|
if (implyFail.length) {
|
|
1550
1625
|
let msg = `${__('Implications failed:')}\n`;
|
|
1551
|
-
implyFail.forEach(
|
|
1552
|
-
msg +=
|
|
1626
|
+
implyFail.forEach(value => {
|
|
1627
|
+
msg += value;
|
|
1553
1628
|
});
|
|
1554
1629
|
usage.fail(msg);
|
|
1555
1630
|
}
|
|
@@ -1558,7 +1633,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1558
1633
|
self.conflicts = function conflicts(key, value) {
|
|
1559
1634
|
argsert('<string|object> [array|string]', [key, value], arguments.length);
|
|
1560
1635
|
if (typeof key === 'object') {
|
|
1561
|
-
Object.keys(key).forEach(
|
|
1636
|
+
Object.keys(key).forEach(k => {
|
|
1562
1637
|
self.conflicts(k, key[k]);
|
|
1563
1638
|
});
|
|
1564
1639
|
}
|
|
@@ -1568,7 +1643,7 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1568
1643
|
conflicting[key] = [];
|
|
1569
1644
|
}
|
|
1570
1645
|
if (Array.isArray(value)) {
|
|
1571
|
-
value.forEach(
|
|
1646
|
+
value.forEach(i => self.conflicts(key, i));
|
|
1572
1647
|
}
|
|
1573
1648
|
else {
|
|
1574
1649
|
conflicting[key].push(value);
|
|
@@ -1577,9 +1652,9 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1577
1652
|
};
|
|
1578
1653
|
self.getConflicting = () => conflicting;
|
|
1579
1654
|
self.conflicting = function conflictingFn(argv) {
|
|
1580
|
-
Object.keys(argv).forEach(
|
|
1655
|
+
Object.keys(argv).forEach(key => {
|
|
1581
1656
|
if (conflicting[key]) {
|
|
1582
|
-
conflicting[key].forEach(
|
|
1657
|
+
conflicting[key].forEach(value => {
|
|
1583
1658
|
if (value && argv[key] !== undefined && argv[value] !== undefined) {
|
|
1584
1659
|
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
|
|
1585
1660
|
}
|
|
@@ -1613,17 +1688,13 @@ function validation(yargs, usage, y18n, shim) {
|
|
|
1613
1688
|
frozens.push({
|
|
1614
1689
|
implied,
|
|
1615
1690
|
checks,
|
|
1616
|
-
conflicting
|
|
1691
|
+
conflicting,
|
|
1617
1692
|
});
|
|
1618
1693
|
};
|
|
1619
1694
|
self.unfreeze = function unfreeze() {
|
|
1620
1695
|
const frozen = frozens.pop();
|
|
1621
1696
|
assertNotStrictEqual(frozen, undefined, shim);
|
|
1622
|
-
({
|
|
1623
|
-
implied,
|
|
1624
|
-
checks,
|
|
1625
|
-
conflicting
|
|
1626
|
-
} = frozen);
|
|
1697
|
+
({ implied, checks, conflicting } = frozen);
|
|
1627
1698
|
};
|
|
1628
1699
|
return self;
|
|
1629
1700
|
}
|
|
@@ -1663,23 +1734,52 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1663
1734
|
const b = rebase(cwd, x);
|
|
1664
1735
|
return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
|
|
1665
1736
|
})
|
|
1666
|
-
.join(' ')
|
|
1737
|
+
.join(' ')
|
|
1738
|
+
.trim();
|
|
1667
1739
|
if (shim$1.getEnv('_') && shim$1.getProcessArgvBin() === shim$1.getEnv('_')) {
|
|
1668
|
-
self.$0 = shim$1
|
|
1740
|
+
self.$0 = shim$1
|
|
1741
|
+
.getEnv('_')
|
|
1742
|
+
.replace(`${shim$1.path.dirname(shim$1.process.execPath())}/`, '');
|
|
1669
1743
|
}
|
|
1670
1744
|
const context = { resets: -1, commands: [], fullCommands: [], files: [] };
|
|
1671
1745
|
self.getContext = () => context;
|
|
1746
|
+
let hasOutput = false;
|
|
1747
|
+
let exitError = null;
|
|
1748
|
+
self.exit = (code, err) => {
|
|
1749
|
+
hasOutput = true;
|
|
1750
|
+
exitError = err;
|
|
1751
|
+
if (exitProcess)
|
|
1752
|
+
shim$1.process.exit(code);
|
|
1753
|
+
};
|
|
1754
|
+
let completionCommand = null;
|
|
1755
|
+
self.completion = function (cmd, desc, fn) {
|
|
1756
|
+
argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
|
|
1757
|
+
if (typeof desc === 'function') {
|
|
1758
|
+
fn = desc;
|
|
1759
|
+
desc = undefined;
|
|
1760
|
+
}
|
|
1761
|
+
completionCommand = cmd || completionCommand || 'completion';
|
|
1762
|
+
if (!desc && desc !== false) {
|
|
1763
|
+
desc = 'generate completion script';
|
|
1764
|
+
}
|
|
1765
|
+
self.command(completionCommand, desc);
|
|
1766
|
+
if (fn)
|
|
1767
|
+
completion$1.registerFunction(fn);
|
|
1768
|
+
return self;
|
|
1769
|
+
};
|
|
1672
1770
|
let options;
|
|
1673
1771
|
self.resetOptions = self.reset = function resetOptions(aliases = {}) {
|
|
1674
1772
|
context.resets++;
|
|
1675
1773
|
options = options || {};
|
|
1676
1774
|
const tmpOptions = {};
|
|
1677
1775
|
tmpOptions.local = options.local ? options.local : [];
|
|
1678
|
-
tmpOptions.configObjects = options.configObjects
|
|
1776
|
+
tmpOptions.configObjects = options.configObjects
|
|
1777
|
+
? options.configObjects
|
|
1778
|
+
: [];
|
|
1679
1779
|
const localLookup = {};
|
|
1680
|
-
tmpOptions.local.forEach(
|
|
1780
|
+
tmpOptions.local.forEach(l => {
|
|
1681
1781
|
localLookup[l] = true;
|
|
1682
|
-
(aliases[l] || []).forEach(
|
|
1782
|
+
(aliases[l] || []).forEach(a => {
|
|
1683
1783
|
localLookup[a] = true;
|
|
1684
1784
|
});
|
|
1685
1785
|
});
|
|
@@ -1692,14 +1792,27 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1692
1792
|
}, {}));
|
|
1693
1793
|
groups = {};
|
|
1694
1794
|
const arrayOptions = [
|
|
1695
|
-
'array',
|
|
1696
|
-
'
|
|
1697
|
-
'
|
|
1795
|
+
'array',
|
|
1796
|
+
'boolean',
|
|
1797
|
+
'string',
|
|
1798
|
+
'skipValidation',
|
|
1799
|
+
'count',
|
|
1800
|
+
'normalize',
|
|
1801
|
+
'number',
|
|
1802
|
+
'hiddenOptions',
|
|
1698
1803
|
];
|
|
1699
1804
|
const objectOptions = [
|
|
1700
|
-
'narg',
|
|
1701
|
-
'
|
|
1702
|
-
'
|
|
1805
|
+
'narg',
|
|
1806
|
+
'key',
|
|
1807
|
+
'alias',
|
|
1808
|
+
'default',
|
|
1809
|
+
'defaultDescription',
|
|
1810
|
+
'config',
|
|
1811
|
+
'choices',
|
|
1812
|
+
'demandedOptions',
|
|
1813
|
+
'demandedCommands',
|
|
1814
|
+
'coerce',
|
|
1815
|
+
'deprecatedOptions',
|
|
1703
1816
|
];
|
|
1704
1817
|
arrayOptions.forEach(k => {
|
|
1705
1818
|
tmpOptions[k] = (options[k] || []).filter((k) => !localLookup[k]);
|
|
@@ -1710,8 +1823,12 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1710
1823
|
tmpOptions.envPrefix = options.envPrefix;
|
|
1711
1824
|
options = tmpOptions;
|
|
1712
1825
|
usage$1 = usage$1 ? usage$1.reset(localLookup) : usage(self, y18n, shim$1);
|
|
1713
|
-
validation$1 = validation$1
|
|
1714
|
-
|
|
1826
|
+
validation$1 = validation$1
|
|
1827
|
+
? validation$1.reset(localLookup)
|
|
1828
|
+
: validation(self, usage$1, y18n, shim$1);
|
|
1829
|
+
command$1 = command$1
|
|
1830
|
+
? command$1.reset()
|
|
1831
|
+
: command(self, usage$1, validation$1, globalMiddleware, shim$1);
|
|
1715
1832
|
if (!completion$1)
|
|
1716
1833
|
completion$1 = completion(self, usage$1, command$1, shim$1);
|
|
1717
1834
|
completionCommand = null;
|
|
@@ -1739,7 +1856,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1739
1856
|
parsed: self.parsed,
|
|
1740
1857
|
parseFn,
|
|
1741
1858
|
parseContext,
|
|
1742
|
-
handlerFinishCommand
|
|
1859
|
+
handlerFinishCommand,
|
|
1743
1860
|
});
|
|
1744
1861
|
usage$1.freeze();
|
|
1745
1862
|
validation$1.freeze();
|
|
@@ -1764,7 +1881,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1764
1881
|
completionCommand,
|
|
1765
1882
|
parseFn,
|
|
1766
1883
|
parseContext,
|
|
1767
|
-
handlerFinishCommand
|
|
1884
|
+
handlerFinishCommand,
|
|
1768
1885
|
} = frozen);
|
|
1769
1886
|
options.configObjects = configObjects;
|
|
1770
1887
|
usage$1.unfreeze();
|
|
@@ -1818,7 +1935,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1818
1935
|
};
|
|
1819
1936
|
function populateParserHintArray(type, keys) {
|
|
1820
1937
|
keys = [].concat(keys);
|
|
1821
|
-
keys.forEach(
|
|
1938
|
+
keys.forEach(key => {
|
|
1822
1939
|
key = sanitizeKey(key);
|
|
1823
1940
|
options[type].push(key);
|
|
1824
1941
|
});
|
|
@@ -1886,7 +2003,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1886
2003
|
}
|
|
1887
2004
|
function populateParserHintDictionary(builder, type, key, value, singleKeyHandler) {
|
|
1888
2005
|
if (Array.isArray(key)) {
|
|
1889
|
-
key.forEach(
|
|
2006
|
+
key.forEach(k => {
|
|
1890
2007
|
builder(k, value);
|
|
1891
2008
|
});
|
|
1892
2009
|
}
|
|
@@ -1921,7 +2038,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1921
2038
|
}
|
|
1922
2039
|
self.config = function config(key = 'config', msg, parseFn) {
|
|
1923
2040
|
argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length);
|
|
1924
|
-
if (
|
|
2041
|
+
if (typeof key === 'object' && !Array.isArray(key)) {
|
|
1925
2042
|
key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim$1);
|
|
1926
2043
|
options.configObjects = (options.configObjects || []).concat(key);
|
|
1927
2044
|
return self;
|
|
@@ -1931,7 +2048,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1931
2048
|
msg = undefined;
|
|
1932
2049
|
}
|
|
1933
2050
|
self.describe(key, msg || usage$1.deferY18nLookup('Path to JSON config file'));
|
|
1934
|
-
(Array.isArray(key) ? key : [key]).forEach(
|
|
2051
|
+
(Array.isArray(key) ? key : [key]).forEach(k => {
|
|
1935
2052
|
options.config[k] = parseFn || true;
|
|
1936
2053
|
});
|
|
1937
2054
|
return self;
|
|
@@ -1939,7 +2056,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1939
2056
|
self.example = function (cmd, description) {
|
|
1940
2057
|
argsert('<string|array> [string]', [cmd, description], arguments.length);
|
|
1941
2058
|
if (Array.isArray(cmd)) {
|
|
1942
|
-
cmd.forEach(
|
|
2059
|
+
cmd.forEach(exampleParams => self.example(...exampleParams));
|
|
1943
2060
|
}
|
|
1944
2061
|
else {
|
|
1945
2062
|
usage$1.example(cmd, description);
|
|
@@ -1959,7 +2076,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1959
2076
|
};
|
|
1960
2077
|
self.demand = self.required = self.require = function demand(keys, max, msg) {
|
|
1961
2078
|
if (Array.isArray(max)) {
|
|
1962
|
-
max.forEach(
|
|
2079
|
+
max.forEach(key => {
|
|
1963
2080
|
assertNotStrictEqual(msg, true, shim$1);
|
|
1964
2081
|
demandOption(key, msg);
|
|
1965
2082
|
});
|
|
@@ -1974,7 +2091,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
1974
2091
|
self.demandCommand(keys, max, msg, msg);
|
|
1975
2092
|
}
|
|
1976
2093
|
else if (Array.isArray(keys)) {
|
|
1977
|
-
keys.forEach(
|
|
2094
|
+
keys.forEach(key => {
|
|
1978
2095
|
assertNotStrictEqual(msg, true, shim$1);
|
|
1979
2096
|
demandOption(key, msg);
|
|
1980
2097
|
});
|
|
@@ -2000,7 +2117,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2000
2117
|
min,
|
|
2001
2118
|
max,
|
|
2002
2119
|
minMsg,
|
|
2003
|
-
maxMsg
|
|
2120
|
+
maxMsg,
|
|
2004
2121
|
};
|
|
2005
2122
|
return self;
|
|
2006
2123
|
};
|
|
@@ -2075,7 +2192,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2075
2192
|
options.local = options.local.filter(l => globals.indexOf(l) === -1);
|
|
2076
2193
|
}
|
|
2077
2194
|
else {
|
|
2078
|
-
globals.forEach(
|
|
2195
|
+
globals.forEach(g => {
|
|
2079
2196
|
if (options.local.indexOf(g) === -1)
|
|
2080
2197
|
options.local.push(g);
|
|
2081
2198
|
});
|
|
@@ -2114,7 +2231,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2114
2231
|
assertNotStrictEqual(pkgJsonPath, undefined, shim$1);
|
|
2115
2232
|
obj = JSON.parse(shim$1.readFileSync(pkgJsonPath, 'utf8'));
|
|
2116
2233
|
}
|
|
2117
|
-
catch (
|
|
2234
|
+
catch (_noop) { }
|
|
2118
2235
|
pkgs[npath] = obj || {};
|
|
2119
2236
|
return pkgs[npath];
|
|
2120
2237
|
}
|
|
@@ -2154,7 +2271,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2154
2271
|
self.option = self.options = function option(key, opt) {
|
|
2155
2272
|
argsert('<string|object> [object]', [key, opt], arguments.length);
|
|
2156
2273
|
if (typeof key === 'object') {
|
|
2157
|
-
Object.keys(key).forEach(
|
|
2274
|
+
Object.keys(key).forEach(k => {
|
|
2158
2275
|
self.options(k, key[k]);
|
|
2159
2276
|
});
|
|
2160
2277
|
}
|
|
@@ -2252,9 +2369,20 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2252
2369
|
if (context.resets === 0) {
|
|
2253
2370
|
throw new YError(".positional() can only be called in a command's builder function");
|
|
2254
2371
|
}
|
|
2255
|
-
const supportedOpts = [
|
|
2256
|
-
'
|
|
2257
|
-
'
|
|
2372
|
+
const supportedOpts = [
|
|
2373
|
+
'default',
|
|
2374
|
+
'defaultDescription',
|
|
2375
|
+
'implies',
|
|
2376
|
+
'normalize',
|
|
2377
|
+
'choices',
|
|
2378
|
+
'conflicts',
|
|
2379
|
+
'coerce',
|
|
2380
|
+
'type',
|
|
2381
|
+
'describe',
|
|
2382
|
+
'desc',
|
|
2383
|
+
'description',
|
|
2384
|
+
'alias',
|
|
2385
|
+
];
|
|
2258
2386
|
opts = objFilter(opts, (k, v) => {
|
|
2259
2387
|
let accept = supportedOpts.indexOf(k) !== -1;
|
|
2260
2388
|
if (k === 'type' && ['string', 'number', 'boolean'].indexOf(v) === -1)
|
|
@@ -2262,13 +2390,15 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2262
2390
|
return accept;
|
|
2263
2391
|
});
|
|
2264
2392
|
const fullCommand = context.fullCommands[context.fullCommands.length - 1];
|
|
2265
|
-
const parseOptions = fullCommand
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2393
|
+
const parseOptions = fullCommand
|
|
2394
|
+
? command$1.cmdToParseOptions(fullCommand)
|
|
2395
|
+
: {
|
|
2396
|
+
array: [],
|
|
2397
|
+
alias: {},
|
|
2398
|
+
default: {},
|
|
2399
|
+
demand: {},
|
|
2400
|
+
};
|
|
2401
|
+
objectKeys(parseOptions).forEach(pk => {
|
|
2272
2402
|
const parseOption = parseOptions[pk];
|
|
2273
2403
|
if (Array.isArray(parseOption)) {
|
|
2274
2404
|
if (parseOption.indexOf(key) !== -1)
|
|
@@ -2289,7 +2419,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2289
2419
|
delete preservedGroups[groupName];
|
|
2290
2420
|
}
|
|
2291
2421
|
const seen = {};
|
|
2292
|
-
groups[groupName] = (existing || []).concat(opts).filter(
|
|
2422
|
+
groups[groupName] = (existing || []).concat(opts).filter(key => {
|
|
2293
2423
|
if (seen[key])
|
|
2294
2424
|
return false;
|
|
2295
2425
|
return (seen[key] = true);
|
|
@@ -2425,29 +2555,13 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2425
2555
|
usage$1.showHelpOnFail(enabled, message);
|
|
2426
2556
|
return self;
|
|
2427
2557
|
};
|
|
2428
|
-
|
|
2558
|
+
let exitProcess = true;
|
|
2429
2559
|
self.exitProcess = function (enabled = true) {
|
|
2430
2560
|
argsert('[boolean]', [enabled], arguments.length);
|
|
2431
2561
|
exitProcess = enabled;
|
|
2432
2562
|
return self;
|
|
2433
2563
|
};
|
|
2434
2564
|
self.getExitProcess = () => exitProcess;
|
|
2435
|
-
var completionCommand = null;
|
|
2436
|
-
self.completion = function (cmd, desc, fn) {
|
|
2437
|
-
argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
|
|
2438
|
-
if (typeof desc === 'function') {
|
|
2439
|
-
fn = desc;
|
|
2440
|
-
desc = undefined;
|
|
2441
|
-
}
|
|
2442
|
-
completionCommand = cmd || completionCommand || 'completion';
|
|
2443
|
-
if (!desc && desc !== false) {
|
|
2444
|
-
desc = 'generate completion script';
|
|
2445
|
-
}
|
|
2446
|
-
self.command(completionCommand, desc);
|
|
2447
|
-
if (fn)
|
|
2448
|
-
completion$1.registerFunction(fn);
|
|
2449
|
-
return self;
|
|
2450
|
-
};
|
|
2451
2565
|
self.showCompletionScript = function ($0, cmd) {
|
|
2452
2566
|
argsert('[string] [string]', [$0, cmd], arguments.length);
|
|
2453
2567
|
$0 = $0 || self.$0;
|
|
@@ -2481,14 +2595,6 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2481
2595
|
return self;
|
|
2482
2596
|
};
|
|
2483
2597
|
self.getDetectLocale = () => detectLocale;
|
|
2484
|
-
var hasOutput = false;
|
|
2485
|
-
var exitError = null;
|
|
2486
|
-
self.exit = (code, err) => {
|
|
2487
|
-
hasOutput = true;
|
|
2488
|
-
exitError = err;
|
|
2489
|
-
if (exitProcess)
|
|
2490
|
-
shim$1.process.exit(code);
|
|
2491
|
-
};
|
|
2492
2598
|
const _logger = {
|
|
2493
2599
|
log(...args) {
|
|
2494
2600
|
if (!self._hasParseCallback())
|
|
@@ -2505,7 +2611,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2505
2611
|
if (output.length)
|
|
2506
2612
|
output += '\n';
|
|
2507
2613
|
output += args.join(' ');
|
|
2508
|
-
}
|
|
2614
|
+
},
|
|
2509
2615
|
};
|
|
2510
2616
|
self._getLoggerInstance = () => _logger;
|
|
2511
2617
|
self._hasOutput = () => hasOutput;
|
|
@@ -2527,7 +2633,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2527
2633
|
};
|
|
2528
2634
|
Object.defineProperty(self, 'argv', {
|
|
2529
2635
|
get: () => self._parseArgs(processArgs),
|
|
2530
|
-
enumerable: true
|
|
2636
|
+
enumerable: true,
|
|
2531
2637
|
});
|
|
2532
2638
|
self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex) {
|
|
2533
2639
|
let skipValidation = !!_calledFromCommand;
|
|
@@ -2536,10 +2642,10 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2536
2642
|
options.configuration = self.getParserConfiguration();
|
|
2537
2643
|
const populateDoubleDash = !!options.configuration['populate--'];
|
|
2538
2644
|
const config = Object.assign({}, options.configuration, {
|
|
2539
|
-
'populate--': true
|
|
2645
|
+
'populate--': true,
|
|
2540
2646
|
});
|
|
2541
2647
|
const parsed = shim$1.Parser.detailed(args, Object.assign({}, options, {
|
|
2542
|
-
configuration: Object.assign({ 'parse-positional-numbers': false }, config)
|
|
2648
|
+
configuration: Object.assign({ 'parse-positional-numbers': false }, config),
|
|
2543
2649
|
}));
|
|
2544
2650
|
let argv = parsed.argv;
|
|
2545
2651
|
if (parseContext)
|
|
@@ -2564,11 +2670,12 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2564
2670
|
const handlerKeys = command$1.getCommands();
|
|
2565
2671
|
const requestCompletions = completion$1.completionKey in argv;
|
|
2566
2672
|
const skipRecommendation = argv[helpOpt] || requestCompletions;
|
|
2567
|
-
const skipDefaultCommand = skipRecommendation &&
|
|
2673
|
+
const skipDefaultCommand = skipRecommendation &&
|
|
2674
|
+
(handlerKeys.length > 1 || handlerKeys[0] !== '$0');
|
|
2568
2675
|
if (argv._.length) {
|
|
2569
2676
|
if (handlerKeys.length) {
|
|
2570
2677
|
let firstUnknownCommand;
|
|
2571
|
-
for (let i =
|
|
2678
|
+
for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) {
|
|
2572
2679
|
cmd = String(argv._[i]);
|
|
2573
2680
|
if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
|
|
2574
2681
|
const innerArgv = command$1.runCommand(cmd, self, parsed, i + 1);
|
|
@@ -2587,7 +2694,9 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2587
2694
|
validation$1.recommendCommands(firstUnknownCommand, handlerKeys);
|
|
2588
2695
|
}
|
|
2589
2696
|
}
|
|
2590
|
-
if (completionCommand &&
|
|
2697
|
+
if (completionCommand &&
|
|
2698
|
+
~argv._.indexOf(completionCommand) &&
|
|
2699
|
+
!requestCompletions) {
|
|
2591
2700
|
if (exitProcess)
|
|
2592
2701
|
setBlocking(true);
|
|
2593
2702
|
self.showCompletionScript();
|
|
@@ -2603,9 +2712,8 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2603
2712
|
setBlocking(true);
|
|
2604
2713
|
args = [].concat(args);
|
|
2605
2714
|
const completionArgs = args.slice(args.indexOf(`--${completion$1.completionKey}`) + 1);
|
|
2606
|
-
completion$1.getCompletion(completionArgs,
|
|
2607
|
-
|
|
2608
|
-
(completions || []).forEach((completion) => {
|
|
2715
|
+
completion$1.getCompletion(completionArgs, completions => {
|
|
2716
|
+
(completions || []).forEach(completion => {
|
|
2609
2717
|
_logger.log(completion);
|
|
2610
2718
|
});
|
|
2611
2719
|
self.exit(0);
|
|
@@ -2613,7 +2721,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2613
2721
|
return self._postProcess(argv, !populateDoubleDash, _calledFromCommand);
|
|
2614
2722
|
}
|
|
2615
2723
|
if (!hasOutput) {
|
|
2616
|
-
Object.keys(argv).forEach(
|
|
2724
|
+
Object.keys(argv).forEach(key => {
|
|
2617
2725
|
if (key === helpOpt && argv[key]) {
|
|
2618
2726
|
if (exitProcess)
|
|
2619
2727
|
setBlocking(true);
|
|
@@ -2657,7 +2765,8 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2657
2765
|
if (!populateDoubleDash) {
|
|
2658
2766
|
argv = self._copyDoubleDash(argv);
|
|
2659
2767
|
}
|
|
2660
|
-
const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] ||
|
|
2768
|
+
const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] ||
|
|
2769
|
+
self.getParserConfiguration()['parse-positional-numbers'] === undefined;
|
|
2661
2770
|
if (parsePositionalNumbers) {
|
|
2662
2771
|
argv = self._parsePositionalNumbers(argv);
|
|
2663
2772
|
}
|
|
@@ -2674,9 +2783,10 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2674
2783
|
return argv;
|
|
2675
2784
|
};
|
|
2676
2785
|
self._parsePositionalNumbers = function (argv) {
|
|
2677
|
-
const args = argv['--'] ? argv['--'] : argv
|
|
2786
|
+
const args = argv['--'] ? argv['--'] : argv._;
|
|
2678
2787
|
for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
|
|
2679
|
-
if (shim$1.Parser.looksLikeNumber(arg) &&
|
|
2788
|
+
if (shim$1.Parser.looksLikeNumber(arg) &&
|
|
2789
|
+
Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
|
|
2680
2790
|
args[i] = Number(arg);
|
|
2681
2791
|
}
|
|
2682
2792
|
}
|
|
@@ -2705,7 +2815,11 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2705
2815
|
function guessLocale() {
|
|
2706
2816
|
if (!detectLocale)
|
|
2707
2817
|
return;
|
|
2708
|
-
const locale = shim$1.getEnv('LC_ALL') ||
|
|
2818
|
+
const locale = shim$1.getEnv('LC_ALL') ||
|
|
2819
|
+
shim$1.getEnv('LC_MESSAGES') ||
|
|
2820
|
+
shim$1.getEnv('LANG') ||
|
|
2821
|
+
shim$1.getEnv('LANGUAGE') ||
|
|
2822
|
+
'en_US';
|
|
2709
2823
|
self.locale(locale.replace(/[.:].*/, ''));
|
|
2710
2824
|
}
|
|
2711
2825
|
self.help();
|
|
@@ -2714,7 +2828,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
|
|
|
2714
2828
|
}
|
|
2715
2829
|
const rebase = (base, dir) => shim$1.path.relative(base, dir);
|
|
2716
2830
|
function isYargsInstance(y) {
|
|
2717
|
-
return !!y &&
|
|
2831
|
+
return !!y && typeof y._parseArgs === 'function';
|
|
2718
2832
|
}
|
|
2719
2833
|
|
|
2720
2834
|
var _a, _b;
|
|
@@ -2726,7 +2840,7 @@ const Parser = require('yargs-parser');
|
|
|
2726
2840
|
var cjsPlatformShim = {
|
|
2727
2841
|
assert: {
|
|
2728
2842
|
notStrictEqual: assert.notStrictEqual,
|
|
2729
|
-
strictEqual: assert.strictEqual
|
|
2843
|
+
strictEqual: assert.strictEqual,
|
|
2730
2844
|
},
|
|
2731
2845
|
cliui: require('cliui'),
|
|
2732
2846
|
findUp: require('escalade/sync'),
|
|
@@ -2747,7 +2861,9 @@ var cjsPlatformShim = {
|
|
|
2747
2861
|
process.exit(code);
|
|
2748
2862
|
},
|
|
2749
2863
|
nextTick: process.nextTick,
|
|
2750
|
-
stdColumns: typeof process.stdout.columns !== 'undefined'
|
|
2864
|
+
stdColumns: typeof process.stdout.columns !== 'undefined'
|
|
2865
|
+
? process.stdout.columns
|
|
2866
|
+
: null,
|
|
2751
2867
|
},
|
|
2752
2868
|
readFileSync,
|
|
2753
2869
|
require: require,
|
|
@@ -2755,12 +2871,13 @@ var cjsPlatformShim = {
|
|
|
2755
2871
|
stringWidth: require('string-width'),
|
|
2756
2872
|
y18n: y18n({
|
|
2757
2873
|
directory: resolve(__dirname, '../locales'),
|
|
2758
|
-
updateFiles: false
|
|
2759
|
-
})
|
|
2874
|
+
updateFiles: false,
|
|
2875
|
+
}),
|
|
2760
2876
|
};
|
|
2761
2877
|
|
|
2762
|
-
const minNodeVersion =
|
|
2763
|
-
? Number(process.env.YARGS_MIN_NODE_VERSION)
|
|
2878
|
+
const minNodeVersion = process && process.env && process.env.YARGS_MIN_NODE_VERSION
|
|
2879
|
+
? Number(process.env.YARGS_MIN_NODE_VERSION)
|
|
2880
|
+
: 10;
|
|
2764
2881
|
if (process && process.version) {
|
|
2765
2882
|
const major = Number(process.version.match(/v([^.]+)/)[1]);
|
|
2766
2883
|
if (major < minNodeVersion) {
|
|
@@ -2781,7 +2898,7 @@ var cjs = {
|
|
|
2781
2898
|
Parser: Parser$1,
|
|
2782
2899
|
processArgv,
|
|
2783
2900
|
rebase,
|
|
2784
|
-
YError
|
|
2901
|
+
YError,
|
|
2785
2902
|
};
|
|
2786
2903
|
|
|
2787
2904
|
module.exports = cjs;
|