yargs 16.0.2 → 16.1.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 +32 -295
- package/README.md +27 -8
- package/browser.mjs +4 -4
- package/build/index.cjs +378 -238
- package/build/lib/argsert.js +9 -5
- package/build/lib/command.js +45 -37
- 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 +39 -32
- package/build/lib/yargs-factory.js +153 -87
- package/helpers/helpers.mjs +10 -0
- package/helpers/index.js +14 -0
- package/helpers/package.json +3 -0
- package/index.cjs +17 -17
- package/index.mjs +5 -5
- package/lib/platform-shims/browser.mjs +38 -37
- package/package.json +35 -27
- package/{yargs.cjs → yargs} +3 -2
- package/helpers.mjs +0 -14
package/build/lib/argsert.js
CHANGED
|
@@ -5,15 +5,19 @@ export function argsert(arg1, arg2, arg3) {
|
|
|
5
5
|
function parseArgs() {
|
|
6
6
|
return typeof arg1 === 'object'
|
|
7
7
|
? [{ demanded: [], optional: [] }, arg1, arg2]
|
|
8
|
-
: [
|
|
8
|
+
: [
|
|
9
|
+
parseCommand(`cmd ${arg1}`),
|
|
10
|
+
arg2,
|
|
11
|
+
arg3,
|
|
12
|
+
];
|
|
9
13
|
}
|
|
10
14
|
try {
|
|
11
15
|
let position = 0;
|
|
12
|
-
|
|
16
|
+
const [parsed, callerArguments, _length] = parseArgs();
|
|
13
17
|
const args = [].slice.call(callerArguments);
|
|
14
18
|
while (args.length && args[args.length - 1] === undefined)
|
|
15
19
|
args.pop();
|
|
16
|
-
length =
|
|
20
|
+
const length = _length || args.length;
|
|
17
21
|
if (length < parsed.demanded.length) {
|
|
18
22
|
throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
|
|
19
23
|
}
|
|
@@ -21,7 +25,7 @@ export function argsert(arg1, arg2, arg3) {
|
|
|
21
25
|
if (length > totalCommands) {
|
|
22
26
|
throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
|
|
23
27
|
}
|
|
24
|
-
parsed.demanded.forEach(
|
|
28
|
+
parsed.demanded.forEach(demanded => {
|
|
25
29
|
const arg = args.shift();
|
|
26
30
|
const observedType = guessType(arg);
|
|
27
31
|
const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*');
|
|
@@ -29,7 +33,7 @@ export function argsert(arg1, arg2, arg3) {
|
|
|
29
33
|
argumentTypeError(observedType, demanded.cmd, position);
|
|
30
34
|
position += 1;
|
|
31
35
|
});
|
|
32
|
-
parsed.optional.forEach(
|
|
36
|
+
parsed.optional.forEach(optional => {
|
|
33
37
|
if (args.length === 0)
|
|
34
38
|
return;
|
|
35
39
|
const arg = args.shift();
|
package/build/lib/command.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { assertNotStrictEqual } from './typings/common-types.js';
|
|
1
|
+
import { assertNotStrictEqual, } from './typings/common-types.js';
|
|
2
2
|
import { isPromise } from './utils/is-promise.js';
|
|
3
|
-
import { applyMiddleware, commandMiddlewareFactory } from './middleware.js';
|
|
3
|
+
import { applyMiddleware, commandMiddlewareFactory, } from './middleware.js';
|
|
4
4
|
import { parseCommand } from './parse-command.js';
|
|
5
|
-
import { isYargsInstance } from './yargs-factory.js';
|
|
5
|
+
import { isYargsInstance, } from './yargs-factory.js';
|
|
6
6
|
import whichModule from './utils/which-module.js';
|
|
7
7
|
const DEFAULT_MARKER = /(^\*)|(^\$0)/;
|
|
8
8
|
export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
@@ -19,7 +19,9 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
19
19
|
cmd = cmd[0];
|
|
20
20
|
}
|
|
21
21
|
else if (isCommandHandlerDefinition(cmd)) {
|
|
22
|
-
let command =
|
|
22
|
+
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
|
23
|
+
? cmd.command
|
|
24
|
+
: moduleName(cmd);
|
|
23
25
|
if (cmd.aliases)
|
|
24
26
|
command = [].concat(command).concat(cmd.aliases);
|
|
25
27
|
self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
@@ -32,7 +34,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
32
34
|
const parsedCommand = parseCommand(cmd);
|
|
33
35
|
aliases = aliases.map(alias => parseCommand(alias).cmd);
|
|
34
36
|
let isDefault = false;
|
|
35
|
-
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(
|
|
37
|
+
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
|
|
36
38
|
if (DEFAULT_MARKER.test(c)) {
|
|
37
39
|
isDefault = true;
|
|
38
40
|
return false;
|
|
@@ -46,7 +48,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
46
48
|
aliases = parsedAliases.slice(1);
|
|
47
49
|
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
|
48
50
|
}
|
|
49
|
-
aliases.forEach(
|
|
51
|
+
aliases.forEach(alias => {
|
|
50
52
|
aliasMap[alias] = parsedCommand.cmd;
|
|
51
53
|
});
|
|
52
54
|
if (description !== false) {
|
|
@@ -60,7 +62,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
60
62
|
middlewares,
|
|
61
63
|
deprecated,
|
|
62
64
|
demanded: parsedCommand.demanded,
|
|
63
|
-
optional: parsedCommand.optional
|
|
65
|
+
optional: parsedCommand.optional,
|
|
64
66
|
};
|
|
65
67
|
if (isDefault)
|
|
66
68
|
defaultCommand = handlers[parsedCommand.cmd];
|
|
@@ -93,7 +95,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
93
95
|
function commandFromFilename(filename) {
|
|
94
96
|
return shim.path.basename(filename, shim.path.extname(filename));
|
|
95
97
|
}
|
|
96
|
-
function extractDesc({ describe, description, desc }) {
|
|
98
|
+
function extractDesc({ describe, description, desc, }) {
|
|
97
99
|
for (const test of [describe, description, desc]) {
|
|
98
100
|
if (typeof test === 'string' || test === false)
|
|
99
101
|
return test;
|
|
@@ -121,7 +123,9 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
121
123
|
const builderOutput = builder(yargs.reset(parsed.aliases));
|
|
122
124
|
const innerYargs = isYargsInstance(builderOutput) ? builderOutput : yargs;
|
|
123
125
|
if (shouldUpdateUsage(innerYargs)) {
|
|
124
|
-
innerYargs
|
|
126
|
+
innerYargs
|
|
127
|
+
.getUsageInstance()
|
|
128
|
+
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
125
129
|
}
|
|
126
130
|
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
127
131
|
aliases = innerYargs.parsed.aliases;
|
|
@@ -129,9 +133,11 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
129
133
|
else if (isCommandBuilderOptionDefinitions(builder)) {
|
|
130
134
|
const innerYargs = yargs.reset(parsed.aliases);
|
|
131
135
|
if (shouldUpdateUsage(innerYargs)) {
|
|
132
|
-
innerYargs
|
|
136
|
+
innerYargs
|
|
137
|
+
.getUsageInstance()
|
|
138
|
+
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
133
139
|
}
|
|
134
|
-
Object.keys(commandHandler.builder).forEach(
|
|
140
|
+
Object.keys(commandHandler.builder).forEach(key => {
|
|
135
141
|
innerYargs.option(key, builder[key]);
|
|
136
142
|
});
|
|
137
143
|
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
@@ -140,7 +146,9 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
140
146
|
if (!yargs._hasOutput()) {
|
|
141
147
|
positionalMap = populatePositionals(commandHandler, innerArgv, currentContext);
|
|
142
148
|
}
|
|
143
|
-
const middlewares = globalMiddleware
|
|
149
|
+
const middlewares = globalMiddleware
|
|
150
|
+
.slice(0)
|
|
151
|
+
.concat(commandHandler.middlewares);
|
|
144
152
|
applyMiddleware(innerArgv, yargs, middlewares, true);
|
|
145
153
|
if (!yargs._hasOutput()) {
|
|
146
154
|
yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error, !command);
|
|
@@ -148,8 +156,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
148
156
|
if (commandHandler.handler && !yargs._hasOutput()) {
|
|
149
157
|
yargs._setHasOutput();
|
|
150
158
|
const populateDoubleDash = !!yargs.getOptions().configuration['populate--'];
|
|
151
|
-
|
|
152
|
-
yargs._copyDoubleDash(innerArgv);
|
|
159
|
+
yargs._postProcess(innerArgv, populateDoubleDash);
|
|
153
160
|
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false);
|
|
154
161
|
let handlerResult;
|
|
155
162
|
if (isPromise(innerArgv)) {
|
|
@@ -194,12 +201,16 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
194
201
|
return innerArgv;
|
|
195
202
|
};
|
|
196
203
|
function shouldUpdateUsage(yargs) {
|
|
197
|
-
return !yargs.getUsageInstance().getUsageDisabled() &&
|
|
198
|
-
yargs.getUsageInstance().getUsage().length === 0;
|
|
204
|
+
return (!yargs.getUsageInstance().getUsageDisabled() &&
|
|
205
|
+
yargs.getUsageInstance().getUsage().length === 0);
|
|
199
206
|
}
|
|
200
207
|
function usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
|
|
201
|
-
const c = DEFAULT_MARKER.test(commandHandler.original)
|
|
202
|
-
|
|
208
|
+
const c = DEFAULT_MARKER.test(commandHandler.original)
|
|
209
|
+
? commandHandler.original.replace(DEFAULT_MARKER, '').trim()
|
|
210
|
+
: commandHandler.original;
|
|
211
|
+
const pc = parentCommands.filter(c => {
|
|
212
|
+
return !DEFAULT_MARKER.test(c);
|
|
213
|
+
});
|
|
203
214
|
pc.push(c);
|
|
204
215
|
return `$0 ${pc.join(' ')}`;
|
|
205
216
|
}
|
|
@@ -207,7 +218,8 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
207
218
|
assertNotStrictEqual(defaultCommand, undefined, shim);
|
|
208
219
|
if (shouldUpdateUsage(yargs)) {
|
|
209
220
|
const commandString = DEFAULT_MARKER.test(defaultCommand.original)
|
|
210
|
-
? defaultCommand.original
|
|
221
|
+
? defaultCommand.original
|
|
222
|
+
: defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
|
|
211
223
|
yargs.getUsageInstance().usage(commandString, defaultCommand.description);
|
|
212
224
|
}
|
|
213
225
|
const builder = defaultCommand.builder;
|
|
@@ -215,7 +227,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
215
227
|
builder(yargs);
|
|
216
228
|
}
|
|
217
229
|
else {
|
|
218
|
-
Object.keys(builder).forEach(
|
|
230
|
+
Object.keys(builder).forEach(key => {
|
|
219
231
|
yargs.option(key, builder[key]);
|
|
220
232
|
});
|
|
221
233
|
}
|
|
@@ -257,8 +269,8 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
257
269
|
options.array = options.array.concat(parseOptions.array);
|
|
258
270
|
options.config = {};
|
|
259
271
|
const unparsed = [];
|
|
260
|
-
Object.keys(positionalMap).forEach(
|
|
261
|
-
positionalMap[key].map(
|
|
272
|
+
Object.keys(positionalMap).forEach(key => {
|
|
273
|
+
positionalMap[key].map(value => {
|
|
262
274
|
if (options.configuration['unknown-options-as-args'])
|
|
263
275
|
options.key[key] = true;
|
|
264
276
|
unparsed.push(`--${key}`);
|
|
@@ -268,20 +280,20 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
268
280
|
if (!unparsed.length)
|
|
269
281
|
return;
|
|
270
282
|
const config = Object.assign({}, options.configuration, {
|
|
271
|
-
'populate--': true
|
|
283
|
+
'populate--': true,
|
|
272
284
|
});
|
|
273
285
|
const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, {
|
|
274
|
-
configuration: config
|
|
286
|
+
configuration: config,
|
|
275
287
|
}));
|
|
276
288
|
if (parsed.error) {
|
|
277
289
|
yargs.getUsageInstance().fail(parsed.error.message, parsed.error);
|
|
278
290
|
}
|
|
279
291
|
else {
|
|
280
292
|
const positionalKeys = Object.keys(positionalMap);
|
|
281
|
-
Object.keys(positionalMap).forEach(
|
|
293
|
+
Object.keys(positionalMap).forEach(key => {
|
|
282
294
|
positionalKeys.push(...parsed.aliases[key]);
|
|
283
295
|
});
|
|
284
|
-
Object.keys(parsed.argv).forEach(
|
|
296
|
+
Object.keys(parsed.argv).forEach(key => {
|
|
285
297
|
if (positionalKeys.indexOf(key) !== -1) {
|
|
286
298
|
if (!positionalMap[key])
|
|
287
299
|
positionalMap[key] = parsed.argv[key];
|
|
@@ -295,10 +307,10 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
295
307
|
array: [],
|
|
296
308
|
default: {},
|
|
297
309
|
alias: {},
|
|
298
|
-
demand: {}
|
|
310
|
+
demand: {},
|
|
299
311
|
};
|
|
300
312
|
const parsed = parseCommand(cmdString);
|
|
301
|
-
parsed.demanded.forEach(
|
|
313
|
+
parsed.demanded.forEach(d => {
|
|
302
314
|
const [cmd, ...aliases] = d.cmd;
|
|
303
315
|
if (d.variadic) {
|
|
304
316
|
parseOptions.array.push(cmd);
|
|
@@ -307,7 +319,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
307
319
|
parseOptions.alias[cmd] = aliases;
|
|
308
320
|
parseOptions.demand[cmd] = true;
|
|
309
321
|
});
|
|
310
|
-
parsed.optional.forEach(
|
|
322
|
+
parsed.optional.forEach(o => {
|
|
311
323
|
const [cmd, ...aliases] = o.cmd;
|
|
312
324
|
if (o.variadic) {
|
|
313
325
|
parseOptions.array.push(cmd);
|
|
@@ -328,17 +340,13 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
328
340
|
frozens.push({
|
|
329
341
|
handlers,
|
|
330
342
|
aliasMap,
|
|
331
|
-
defaultCommand
|
|
343
|
+
defaultCommand,
|
|
332
344
|
});
|
|
333
345
|
};
|
|
334
346
|
self.unfreeze = () => {
|
|
335
347
|
const frozen = frozens.pop();
|
|
336
348
|
assertNotStrictEqual(frozen, undefined, shim);
|
|
337
|
-
({
|
|
338
|
-
handlers,
|
|
339
|
-
aliasMap,
|
|
340
|
-
defaultCommand
|
|
341
|
-
} = frozen);
|
|
349
|
+
({ handlers, aliasMap, defaultCommand } = frozen);
|
|
342
350
|
};
|
|
343
351
|
return self;
|
|
344
352
|
}
|
|
@@ -346,9 +354,9 @@ export function isCommandHandlerDefinition(cmd) {
|
|
|
346
354
|
return typeof cmd === 'object';
|
|
347
355
|
}
|
|
348
356
|
export function isCommandBuilderDefinition(builder) {
|
|
349
|
-
return typeof builder === 'object' &&
|
|
357
|
+
return (typeof builder === 'object' &&
|
|
350
358
|
!!builder.builder &&
|
|
351
|
-
typeof builder.handler === 'function';
|
|
359
|
+
typeof builder.handler === 'function');
|
|
352
360
|
}
|
|
353
361
|
export function isCommandBuilderCallback(builder) {
|
|
354
362
|
return typeof builder === 'function';
|
package/build/lib/completion.js
CHANGED
|
@@ -5,7 +5,7 @@ import { isPromise } from './utils/is-promise.js';
|
|
|
5
5
|
import { parseCommand } from './parse-command.js';
|
|
6
6
|
export function completion(yargs, usage, command, shim) {
|
|
7
7
|
const self = {
|
|
8
|
-
completionKey: 'get-yargs-completions'
|
|
8
|
+
completionKey: 'get-yargs-completions',
|
|
9
9
|
};
|
|
10
10
|
let aliases;
|
|
11
11
|
self.setParsed = function setParsed(parsed) {
|
|
@@ -23,22 +23,30 @@ export function completion(yargs, usage, command, shim) {
|
|
|
23
23
|
if (isSyncCompletionFunction(completionFunction)) {
|
|
24
24
|
const result = completionFunction(current, argv);
|
|
25
25
|
if (isPromise(result)) {
|
|
26
|
-
return result
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return result
|
|
27
|
+
.then(list => {
|
|
28
|
+
shim.process.nextTick(() => {
|
|
29
|
+
done(list);
|
|
30
|
+
});
|
|
31
|
+
})
|
|
32
|
+
.catch(err => {
|
|
33
|
+
shim.process.nextTick(() => {
|
|
34
|
+
throw err;
|
|
35
|
+
});
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
return done(result);
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
35
|
-
return completionFunction(current, argv,
|
|
41
|
+
return completionFunction(current, argv, completions => {
|
|
36
42
|
done(completions);
|
|
37
43
|
});
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
if (completionFunction) {
|
|
41
|
-
return isPromise(argv)
|
|
47
|
+
return isPromise(argv)
|
|
48
|
+
? argv.then(runCompletionFunction)
|
|
49
|
+
: runCompletionFunction(argv);
|
|
42
50
|
}
|
|
43
51
|
const handlers = command.getCommandHandlers();
|
|
44
52
|
for (let i = 0, ii = args.length; i < ii; ++i) {
|
|
@@ -51,8 +59,9 @@ export function completion(yargs, usage, command, shim) {
|
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
|
-
if (!current.match(/^-/) &&
|
|
55
|
-
|
|
62
|
+
if (!current.match(/^-/) &&
|
|
63
|
+
parentCommands[parentCommands.length - 1] !== current) {
|
|
64
|
+
usage.getCommands().forEach(usageCommand => {
|
|
56
65
|
const commandName = parseCommand(usageCommand[0]).cmd;
|
|
57
66
|
if (args.indexOf(commandName) === -1) {
|
|
58
67
|
if (!zshShell) {
|
|
@@ -68,8 +77,9 @@ export function completion(yargs, usage, command, shim) {
|
|
|
68
77
|
if (current.match(/^-/) || (current === '' && completions.length === 0)) {
|
|
69
78
|
const descs = usage.getDescriptions();
|
|
70
79
|
const options = yargs.getOptions();
|
|
71
|
-
Object.keys(options.key).forEach(
|
|
72
|
-
const negable = !!options.configuration['boolean-negation'] &&
|
|
80
|
+
Object.keys(options.key).forEach(key => {
|
|
81
|
+
const negable = !!options.configuration['boolean-negation'] &&
|
|
82
|
+
options.boolean.includes(key);
|
|
73
83
|
let keyAndAliases = [key].concat(aliases[key] || []);
|
|
74
84
|
if (negable)
|
|
75
85
|
keyAndAliases = keyAndAliases.concat(keyAndAliases.map(key => `no-${key}`));
|
|
@@ -84,7 +94,8 @@ export function completion(yargs, usage, command, shim) {
|
|
|
84
94
|
}
|
|
85
95
|
else {
|
|
86
96
|
const desc = descs[key] || '';
|
|
87
|
-
completions.push(dashes +
|
|
97
|
+
completions.push(dashes +
|
|
98
|
+
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`);
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
}
|
|
@@ -96,7 +107,9 @@ export function completion(yargs, usage, command, shim) {
|
|
|
96
107
|
done(completions);
|
|
97
108
|
};
|
|
98
109
|
self.generateCompletionScript = function generateCompletionScript($0, cmd) {
|
|
99
|
-
let script = zshShell
|
|
110
|
+
let script = zshShell
|
|
111
|
+
? templates.completionZshTemplate
|
|
112
|
+
: templates.completionShTemplate;
|
|
100
113
|
const name = shim.path.basename($0);
|
|
101
114
|
if ($0.match(/\.js$/))
|
|
102
115
|
$0 = `./${$0}`;
|
|
@@ -105,7 +118,7 @@ export function completion(yargs, usage, command, shim) {
|
|
|
105
118
|
return script.replace(/{{app_path}}/g, $0);
|
|
106
119
|
};
|
|
107
120
|
let completionFunction = null;
|
|
108
|
-
self.registerFunction =
|
|
121
|
+
self.registerFunction = fn => {
|
|
109
122
|
completionFunction = fn;
|
|
110
123
|
};
|
|
111
124
|
return self;
|
package/build/lib/middleware.js
CHANGED
|
@@ -29,14 +29,16 @@ export function commandMiddlewareFactory(commandMiddleware) {
|
|
|
29
29
|
}
|
|
30
30
|
export function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
|
|
31
31
|
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true');
|
|
32
|
-
return middlewares
|
|
33
|
-
.reduce((acc, middleware) => {
|
|
32
|
+
return middlewares.reduce((acc, middleware) => {
|
|
34
33
|
if (middleware.applyBeforeValidation !== beforeValidation) {
|
|
35
34
|
return acc;
|
|
36
35
|
}
|
|
37
36
|
if (isPromise(acc)) {
|
|
38
37
|
return acc
|
|
39
|
-
.then(initialObj => Promise.all([
|
|
38
|
+
.then(initialObj => Promise.all([
|
|
39
|
+
initialObj,
|
|
40
|
+
middleware(initialObj, yargs),
|
|
41
|
+
]))
|
|
40
42
|
.then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
@@ -8,7 +8,7 @@ export function parseCommand(cmd) {
|
|
|
8
8
|
const parsedCommand = {
|
|
9
9
|
cmd: firstCommand.replace(bregex, ''),
|
|
10
10
|
demanded: [],
|
|
11
|
-
optional: []
|
|
11
|
+
optional: [],
|
|
12
12
|
};
|
|
13
13
|
splitCommand.forEach((cmd, i) => {
|
|
14
14
|
let variadic = false;
|
|
@@ -18,13 +18,13 @@ export function parseCommand(cmd) {
|
|
|
18
18
|
if (/^\[/.test(cmd)) {
|
|
19
19
|
parsedCommand.optional.push({
|
|
20
20
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
21
|
-
variadic
|
|
21
|
+
variadic,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
parsedCommand.demanded.push({
|
|
26
26
|
cmd: cmd.replace(bregex, '').split('|'),
|
|
27
|
-
variadic
|
|
27
|
+
variadic,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
});
|