yargs 16.1.1 → 16.2.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 +12 -1
- package/build/index.cjs +57 -41
- package/build/lib/command.js +56 -40
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
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
|
+
## [16.2.0](https://www.github.com/yargs/yargs/compare/v16.1.1...v16.2.0) (2020-12-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* command() now accepts an array of modules ([f415388](https://www.github.com/yargs/yargs/commit/f415388cc454d02786c65c50dd6c7a0cf9d8b842))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* add package.json to module exports ([#1818](https://www.github.com/yargs/yargs/issues/1818)) ([d783a49](https://www.github.com/yargs/yargs/commit/d783a49a7f21c9bbd4eec2990268f3244c4d5662)), closes [#1817](https://www.github.com/yargs/yargs/issues/1817)
|
|
16
|
+
|
|
5
17
|
### [16.1.1](https://www.github.com/yargs/yargs/compare/v16.1.0...v16.1.1) (2020-11-15)
|
|
6
18
|
|
|
7
19
|
|
|
@@ -74,4 +86,3 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
74
86
|
* **yargs:** add missing command(module) signature ([#1707](https://www.github.com/yargs/yargs/issues/1707)) ([0f81024](https://www.github.com/yargs/yargs/commit/0f810245494ccf13a35b7786d021b30fc95ecad5)), closes [#1704](https://www.github.com/yargs/yargs/issues/1704)
|
|
75
87
|
|
|
76
88
|
[Older CHANGELOG Entries](https://github.com/yargs/yargs/blob/master/docs/CHANGELOG-historical.md)
|
|
77
|
-
|
package/build/index.cjs
CHANGED
|
@@ -287,8 +287,14 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
287
287
|
const middlewares = commandMiddlewareFactory(commandMiddleware);
|
|
288
288
|
handler = handler || (() => { });
|
|
289
289
|
if (Array.isArray(cmd)) {
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
if (isCommandAndAliases(cmd)) {
|
|
291
|
+
[cmd, ...aliases] = cmd;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
for (const command of cmd) {
|
|
295
|
+
self.addHandler(command);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
292
298
|
}
|
|
293
299
|
else if (isCommandHandlerDefinition(cmd)) {
|
|
294
300
|
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
|
@@ -299,45 +305,47 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
299
305
|
self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
300
306
|
return;
|
|
301
307
|
}
|
|
302
|
-
if (isCommandBuilderDefinition(builder)) {
|
|
308
|
+
else if (isCommandBuilderDefinition(builder)) {
|
|
303
309
|
self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
|
|
304
310
|
return;
|
|
305
311
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
parsedAliases.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
312
|
+
if (typeof cmd === 'string') {
|
|
313
|
+
const parsedCommand = parseCommand(cmd);
|
|
314
|
+
aliases = aliases.map(alias => parseCommand(alias).cmd);
|
|
315
|
+
let isDefault = false;
|
|
316
|
+
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
|
|
317
|
+
if (DEFAULT_MARKER.test(c)) {
|
|
318
|
+
isDefault = true;
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
});
|
|
323
|
+
if (parsedAliases.length === 0 && isDefault)
|
|
324
|
+
parsedAliases.push('$0');
|
|
325
|
+
if (isDefault) {
|
|
326
|
+
parsedCommand.cmd = parsedAliases[0];
|
|
327
|
+
aliases = parsedAliases.slice(1);
|
|
328
|
+
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
|
329
|
+
}
|
|
330
|
+
aliases.forEach(alias => {
|
|
331
|
+
aliasMap[alias] = parsedCommand.cmd;
|
|
332
|
+
});
|
|
333
|
+
if (description !== false) {
|
|
334
|
+
usage.command(cmd, description, isDefault, aliases, deprecated);
|
|
335
|
+
}
|
|
336
|
+
handlers[parsedCommand.cmd] = {
|
|
337
|
+
original: cmd,
|
|
338
|
+
description,
|
|
339
|
+
handler,
|
|
340
|
+
builder: builder || {},
|
|
341
|
+
middlewares,
|
|
342
|
+
deprecated,
|
|
343
|
+
demanded: parsedCommand.demanded,
|
|
344
|
+
optional: parsedCommand.optional,
|
|
345
|
+
};
|
|
346
|
+
if (isDefault)
|
|
347
|
+
defaultCommand = handlers[parsedCommand.cmd];
|
|
322
348
|
}
|
|
323
|
-
aliases.forEach(alias => {
|
|
324
|
-
aliasMap[alias] = parsedCommand.cmd;
|
|
325
|
-
});
|
|
326
|
-
if (description !== false) {
|
|
327
|
-
usage.command(cmd, description, isDefault, aliases, deprecated);
|
|
328
|
-
}
|
|
329
|
-
handlers[parsedCommand.cmd] = {
|
|
330
|
-
original: cmd,
|
|
331
|
-
description,
|
|
332
|
-
handler,
|
|
333
|
-
builder: builder || {},
|
|
334
|
-
middlewares,
|
|
335
|
-
deprecated,
|
|
336
|
-
demanded: parsedCommand.demanded,
|
|
337
|
-
optional: parsedCommand.optional,
|
|
338
|
-
};
|
|
339
|
-
if (isDefault)
|
|
340
|
-
defaultCommand = handlers[parsedCommand.cmd];
|
|
341
349
|
};
|
|
342
350
|
self.addDirectory = function addDirectory(dir, context, req, callerFile, opts) {
|
|
343
351
|
opts = opts || {};
|
|
@@ -498,7 +506,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
498
506
|
if (isCommandBuilderCallback(builder)) {
|
|
499
507
|
builder(yargs);
|
|
500
508
|
}
|
|
501
|
-
else {
|
|
509
|
+
else if (!isCommandBuilderDefinition(builder)) {
|
|
502
510
|
Object.keys(builder).forEach(key => {
|
|
503
511
|
yargs.option(key, builder[key]);
|
|
504
512
|
});
|
|
@@ -622,20 +630,28 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
622
630
|
};
|
|
623
631
|
return self;
|
|
624
632
|
}
|
|
625
|
-
function isCommandHandlerDefinition(cmd) {
|
|
626
|
-
return typeof cmd === 'object';
|
|
627
|
-
}
|
|
628
633
|
function isCommandBuilderDefinition(builder) {
|
|
629
634
|
return (typeof builder === 'object' &&
|
|
630
635
|
!!builder.builder &&
|
|
631
636
|
typeof builder.handler === 'function');
|
|
632
637
|
}
|
|
638
|
+
function isCommandAndAliases(cmd) {
|
|
639
|
+
if (cmd.every(c => typeof c === 'string')) {
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
633
646
|
function isCommandBuilderCallback(builder) {
|
|
634
647
|
return typeof builder === 'function';
|
|
635
648
|
}
|
|
636
649
|
function isCommandBuilderOptionDefinitions(builder) {
|
|
637
650
|
return typeof builder === 'object';
|
|
638
651
|
}
|
|
652
|
+
function isCommandHandlerDefinition(cmd) {
|
|
653
|
+
return typeof cmd === 'object' && !Array.isArray(cmd);
|
|
654
|
+
}
|
|
639
655
|
|
|
640
656
|
function setBlocking(blocking) {
|
|
641
657
|
if (typeof process === 'undefined')
|
package/build/lib/command.js
CHANGED
|
@@ -15,8 +15,14 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
15
15
|
const middlewares = commandMiddlewareFactory(commandMiddleware);
|
|
16
16
|
handler = handler || (() => { });
|
|
17
17
|
if (Array.isArray(cmd)) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (isCommandAndAliases(cmd)) {
|
|
19
|
+
[cmd, ...aliases] = cmd;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
for (const command of cmd) {
|
|
23
|
+
self.addHandler(command);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
else if (isCommandHandlerDefinition(cmd)) {
|
|
22
28
|
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
|
@@ -27,45 +33,47 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
27
33
|
self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
28
34
|
return;
|
|
29
35
|
}
|
|
30
|
-
if (isCommandBuilderDefinition(builder)) {
|
|
36
|
+
else if (isCommandBuilderDefinition(builder)) {
|
|
31
37
|
self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
|
|
32
38
|
return;
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (typeof cmd === 'string') {
|
|
41
|
+
const parsedCommand = parseCommand(cmd);
|
|
42
|
+
aliases = aliases.map(alias => parseCommand(alias).cmd);
|
|
43
|
+
let isDefault = false;
|
|
44
|
+
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
|
|
45
|
+
if (DEFAULT_MARKER.test(c)) {
|
|
46
|
+
isDefault = true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
if (parsedAliases.length === 0 && isDefault)
|
|
52
|
+
parsedAliases.push('$0');
|
|
53
|
+
if (isDefault) {
|
|
54
|
+
parsedCommand.cmd = parsedAliases[0];
|
|
55
|
+
aliases = parsedAliases.slice(1);
|
|
56
|
+
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
|
41
57
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
aliases.forEach(alias => {
|
|
59
|
+
aliasMap[alias] = parsedCommand.cmd;
|
|
60
|
+
});
|
|
61
|
+
if (description !== false) {
|
|
62
|
+
usage.command(cmd, description, isDefault, aliases, deprecated);
|
|
63
|
+
}
|
|
64
|
+
handlers[parsedCommand.cmd] = {
|
|
65
|
+
original: cmd,
|
|
66
|
+
description,
|
|
67
|
+
handler,
|
|
68
|
+
builder: builder || {},
|
|
69
|
+
middlewares,
|
|
70
|
+
deprecated,
|
|
71
|
+
demanded: parsedCommand.demanded,
|
|
72
|
+
optional: parsedCommand.optional,
|
|
73
|
+
};
|
|
74
|
+
if (isDefault)
|
|
75
|
+
defaultCommand = handlers[parsedCommand.cmd];
|
|
56
76
|
}
|
|
57
|
-
handlers[parsedCommand.cmd] = {
|
|
58
|
-
original: cmd,
|
|
59
|
-
description,
|
|
60
|
-
handler,
|
|
61
|
-
builder: builder || {},
|
|
62
|
-
middlewares,
|
|
63
|
-
deprecated,
|
|
64
|
-
demanded: parsedCommand.demanded,
|
|
65
|
-
optional: parsedCommand.optional,
|
|
66
|
-
};
|
|
67
|
-
if (isDefault)
|
|
68
|
-
defaultCommand = handlers[parsedCommand.cmd];
|
|
69
77
|
};
|
|
70
78
|
self.addDirectory = function addDirectory(dir, context, req, callerFile, opts) {
|
|
71
79
|
opts = opts || {};
|
|
@@ -226,7 +234,7 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
226
234
|
if (isCommandBuilderCallback(builder)) {
|
|
227
235
|
builder(yargs);
|
|
228
236
|
}
|
|
229
|
-
else {
|
|
237
|
+
else if (!isCommandBuilderDefinition(builder)) {
|
|
230
238
|
Object.keys(builder).forEach(key => {
|
|
231
239
|
yargs.option(key, builder[key]);
|
|
232
240
|
});
|
|
@@ -350,17 +358,25 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
350
358
|
};
|
|
351
359
|
return self;
|
|
352
360
|
}
|
|
353
|
-
export function isCommandHandlerDefinition(cmd) {
|
|
354
|
-
return typeof cmd === 'object';
|
|
355
|
-
}
|
|
356
361
|
export function isCommandBuilderDefinition(builder) {
|
|
357
362
|
return (typeof builder === 'object' &&
|
|
358
363
|
!!builder.builder &&
|
|
359
364
|
typeof builder.handler === 'function');
|
|
360
365
|
}
|
|
366
|
+
function isCommandAndAliases(cmd) {
|
|
367
|
+
if (cmd.every(c => typeof c === 'string')) {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
361
374
|
export function isCommandBuilderCallback(builder) {
|
|
362
375
|
return typeof builder === 'function';
|
|
363
376
|
}
|
|
364
377
|
function isCommandBuilderOptionDefinitions(builder) {
|
|
365
378
|
return typeof builder === 'object';
|
|
366
379
|
}
|
|
380
|
+
export function isCommandHandlerDefinition(cmd) {
|
|
381
|
+
return typeof cmd === 'object' && !Array.isArray(cmd);
|
|
382
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"exports": {
|
|
7
|
+
"./package.json": "./package.json",
|
|
7
8
|
".": [
|
|
8
9
|
{
|
|
9
10
|
"import": "./index.mjs",
|