storybook 10.1.0-alpha.1 → 10.1.0-alpha.11
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/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
- package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
- package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
- package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
- package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
- package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
- package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
- package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
- package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-74YHFU5B.js} +44 -109
- package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
- package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
- package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
- package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
- package/dist/_browser-chunks/chunk-BE2DAXKJ.js +2966 -0
- package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
- package/dist/_browser-chunks/chunk-EBHB6RPS.js +61 -0
- package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
- package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
- package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
- package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
- package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
- package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
- package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
- package/dist/_browser-chunks/chunk-L4RMQ7D7.js +223 -0
- package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
- package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
- package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
- package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
- package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
- package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
- package/dist/_browser-chunks/chunk-WXP2XJ3O.js +950 -0
- package/dist/_browser-chunks/chunk-X3DUQ5RA.js +47 -0
- package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
- package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
- package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
- package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
- package/dist/_browser-chunks/{syntaxhighlighter-DK2ODWXH.js → syntaxhighlighter-WKBQ5RC7.js} +707 -1851
- package/dist/_node-chunks/{builder-manager-6UBDPV7P.js → builder-manager-PMPHOSM2.js} +495 -1013
- package/dist/_node-chunks/camelcase-K3IOOFQW.js +18 -0
- package/dist/_node-chunks/{chunk-QNUGJO6L.js → chunk-32NE3UE3.js} +15 -24
- package/dist/_node-chunks/chunk-4GZCFQFG.js +58 -0
- package/dist/_node-chunks/chunk-5QK5MSOI.js +943 -0
- package/dist/_node-chunks/{chunk-3FPF5Y2F.js → chunk-6ZOLETQK.js} +8 -10
- package/dist/_node-chunks/chunk-7I22Y76Z.js +1047 -0
- package/dist/_node-chunks/chunk-AKTRSR3O.js +72 -0
- package/dist/_node-chunks/chunk-BBOP3XCK.js +119 -0
- package/dist/_node-chunks/chunk-C2GQVDWI.js +34 -0
- package/dist/_node-chunks/{chunk-SCTKVDWR.js → chunk-GG2WQZSG.js} +4619 -7350
- package/dist/_node-chunks/chunk-GQJOWVVR.js +3214 -0
- package/dist/_node-chunks/chunk-JCRM2YVK.js +3009 -0
- package/dist/_node-chunks/chunk-KK4AT5F3.js +1029 -0
- package/dist/_node-chunks/chunk-L7MYXJUM.js +1114 -0
- package/dist/_node-chunks/{chunk-LAU7VVPC.js → chunk-LCZO45L7.js} +469 -983
- package/dist/_node-chunks/chunk-LR3QITDI.js +209 -0
- package/dist/_node-chunks/chunk-LXG4DK35.js +3171 -0
- package/dist/_node-chunks/chunk-MJ3WOS6F.js +37 -0
- package/dist/_node-chunks/chunk-PHOZWZZO.js +61 -0
- package/dist/_node-chunks/chunk-QECOQWRJ.js +936 -0
- package/dist/_node-chunks/chunk-QH4V5YDB.js +20 -0
- package/dist/_node-chunks/chunk-R6HWGZWD.js +26 -0
- package/dist/_node-chunks/chunk-SPQXMU2Q.js +759 -0
- package/dist/_node-chunks/chunk-TXZY6V6O.js +1564 -0
- package/dist/_node-chunks/chunk-UGDPX5LE.js +756 -0
- package/dist/_node-chunks/chunk-UY26MQLT.js +603 -0
- package/dist/_node-chunks/chunk-WK3EMYK6.js +61 -0
- package/dist/_node-chunks/{chunk-CJHAP7SE.js → chunk-WLHMN7AP.js} +292 -688
- package/dist/_node-chunks/chunk-XGVLB4UJ.js +54 -0
- package/dist/_node-chunks/{chunk-J7N7PD5Q.js → chunk-YHRFI6BE.js} +87 -227
- package/dist/_node-chunks/chunk-YK4KVMFW.js +18 -0
- package/dist/_node-chunks/chunk-ZZALGOA6.js +4523 -0
- package/dist/_node-chunks/chunk-ZZPBSYA5.js +301 -0
- package/dist/_node-chunks/chunk-ZZSRFAC6.js +45571 -0
- package/dist/_node-chunks/dist-4DWOCZUD.js +121 -0
- package/dist/_node-chunks/globby-AAARUKEU.js +3452 -0
- package/dist/_node-chunks/lib-HEUKGL62.js +366 -0
- package/dist/_node-chunks/mdx-N42X6CFJ-DCVRPS6N.js +14329 -0
- package/dist/_node-chunks/p-limit-F5ZKJ6WZ.js +116 -0
- package/dist/_node-chunks/plugin-7YY7JXCH.js +123 -0
- package/dist/_node-chunks/{plugin-HJLCLGNT.js → plugin-SZP3CW6W.js} +36 -56
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-TGKNDPO6.js +46623 -0
- package/dist/_node-chunks/webpack-mock-plugin-LNTZZFBE.js +92 -0
- package/dist/actions/decorator.js +21 -42
- package/dist/actions/index.js +3 -3
- package/dist/babel/index.d.ts +671 -335
- package/dist/babel/index.js +11 -11
- package/dist/bin/core.js +592 -1546
- package/dist/bin/dispatcher.js +26 -37
- package/dist/bin/loader.js +23 -34
- package/dist/channels/index.js +98 -234
- package/dist/cli/index.js +1966 -5347
- package/dist/client-logger/index.js +31 -61
- package/dist/common/index.d.ts +210 -3
- package/dist/common/index.js +28 -20
- package/dist/components/index.d.ts +472 -280
- package/dist/components/index.js +15992 -75
- package/dist/core-events/index.js +2 -66
- package/dist/core-server/index.js +3837 -7191
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +2511 -5219
- package/dist/core-server/presets/common-override-preset.js +31 -60
- package/dist/core-server/presets/common-preset.js +434 -924
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +15 -19
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +12 -17
- package/dist/csf/index.js +534 -1172
- package/dist/csf-tools/index.d.ts +15 -4
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +6 -6
- package/dist/highlight/index.js +2 -2
- package/dist/instrumenter/index.js +199 -415
- package/dist/manager/globals-runtime.js +47968 -56484
- package/dist/manager/globals.js +2 -3
- package/dist/manager/runtime.js +4901 -10318
- package/dist/manager-api/index.d.ts +11 -3
- package/dist/manager-api/index.js +1250 -2397
- package/dist/manager-errors.d.ts +3 -0
- package/dist/manager-errors.js +3 -3
- package/dist/node-logger/index.d.ts +1 -1
- package/dist/node-logger/index.js +1270 -2593
- package/dist/preview/globals.js +2 -3
- package/dist/preview/runtime.js +10767 -22386
- package/dist/preview-api/index.d.ts +67 -68
- package/dist/preview-api/index.js +15 -15
- package/dist/preview-errors.d.ts +3 -0
- package/dist/preview-errors.js +4 -4
- package/dist/router/index.js +347 -899
- package/dist/server-errors.d.ts +3 -0
- package/dist/server-errors.js +10 -10
- package/dist/telemetry/index.js +24 -24
- package/dist/test/index.js +6129 -11914
- package/dist/theming/create.d.ts +4 -2
- package/dist/theming/create.js +4 -4
- package/dist/theming/index.d.ts +3397 -2628
- package/dist/theming/index.js +502 -1091
- package/dist/types/index.d.ts +50 -5
- package/dist/types/index.js +2 -11
- package/dist/viewport/index.js +3 -3
- package/package.json +17 -9
- package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
- package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
- package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
- package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
- package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
- package/dist/_browser-chunks/chunk-C4XOKMDU.js +0 -270
- package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
- package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
- package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
- package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
- package/dist/_browser-chunks/chunk-I74EUU5O.js +0 -5809
- package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
- package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
- package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
- package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
- package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
- package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
- package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
- package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
- package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
- package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
- package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
- package/dist/_browser-chunks/chunk-W4QKLQSC.js +0 -4182
- package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
- package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
- package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
- package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
- package/dist/_node-chunks/camelcase-WKJOVNPM.js +0 -18
- package/dist/_node-chunks/chunk-2RIKHYCS.js +0 -304
- package/dist/_node-chunks/chunk-3JCSHYSU.js +0 -1657
- package/dist/_node-chunks/chunk-4GE6Q4MX.js +0 -1531
- package/dist/_node-chunks/chunk-5SEHHENC.js +0 -64656
- package/dist/_node-chunks/chunk-6GD23U64.js +0 -420
- package/dist/_node-chunks/chunk-6OAXYS5T.js +0 -1544
- package/dist/_node-chunks/chunk-7TNUMFKR.js +0 -4741
- package/dist/_node-chunks/chunk-BCDHUXAJ.js +0 -4272
- package/dist/_node-chunks/chunk-BYVQZ2HU.js +0 -220
- package/dist/_node-chunks/chunk-DAMVKHAC.js +0 -101
- package/dist/_node-chunks/chunk-FEOC7OX2.js +0 -1586
- package/dist/_node-chunks/chunk-FY7XZPLY.js +0 -2248
- package/dist/_node-chunks/chunk-GD2FXWDF.js +0 -697
- package/dist/_node-chunks/chunk-HM6B7FE5.js +0 -18
- package/dist/_node-chunks/chunk-HORWITP7.js +0 -90
- package/dist/_node-chunks/chunk-II4AFH3V.js +0 -28
- package/dist/_node-chunks/chunk-MF2PUEWG.js +0 -5029
- package/dist/_node-chunks/chunk-RVE4UTVQ.js +0 -1518
- package/dist/_node-chunks/chunk-TUFWZUTO.js +0 -69
- package/dist/_node-chunks/chunk-TXHNWNH4.js +0 -79
- package/dist/_node-chunks/chunk-ULWNTI6M.js +0 -1198
- package/dist/_node-chunks/chunk-VYRFXLRO.js +0 -6712
- package/dist/_node-chunks/chunk-WNOSTIYP.js +0 -34
- package/dist/_node-chunks/chunk-X67VGZN4.js +0 -1250
- package/dist/_node-chunks/chunk-XCEBYOA4.js +0 -61
- package/dist/_node-chunks/chunk-XW7YMR7I.js +0 -111
- package/dist/_node-chunks/chunk-ZRFYQ46H.js +0 -61
- package/dist/_node-chunks/dist-APCKHSY3.js +0 -175
- package/dist/_node-chunks/globby-TSGXGDA2.js +0 -5222
- package/dist/_node-chunks/lib-DZ5TVIU5.js +0 -518
- package/dist/_node-chunks/mdx-N42X6CFJ-Z6BYQCPN.js +0 -22017
- package/dist/_node-chunks/p-limit-MLJNGG2K.js +0 -168
- package/dist/_node-chunks/plugin-J3JI3ZKJ.js +0 -159
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-3QHNTM5B.js +0 -69102
- package/dist/_node-chunks/webpack-mock-plugin-4Y3MWPJ6.js +0 -124
package/dist/bin/core.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_843v2rliy1 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_843v2rliy1 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_843v2rliy1 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_843v2rliy1.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_843v2rliy1.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_843v2rliy1.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
version
|
|
14
|
-
} from "../_node-chunks/chunk-
|
|
14
|
+
} from "../_node-chunks/chunk-YK4KVMFW.js";
|
|
15
15
|
import {
|
|
16
16
|
globalSettings
|
|
17
|
-
} from "../_node-chunks/chunk-
|
|
17
|
+
} from "../_node-chunks/chunk-JCRM2YVK.js";
|
|
18
18
|
import {
|
|
19
19
|
require_dist
|
|
20
|
-
} from "../_node-chunks/chunk-
|
|
20
|
+
} from "../_node-chunks/chunk-PHOZWZZO.js";
|
|
21
21
|
import {
|
|
22
22
|
require_picocolors
|
|
23
|
-
} from "../_node-chunks/chunk-
|
|
23
|
+
} from "../_node-chunks/chunk-32NE3UE3.js";
|
|
24
24
|
import {
|
|
25
25
|
__commonJS,
|
|
26
|
-
__name,
|
|
27
26
|
__require,
|
|
28
27
|
__toESM
|
|
29
|
-
} from "../_node-chunks/chunk-
|
|
28
|
+
} from "../_node-chunks/chunk-XGVLB4UJ.js";
|
|
30
29
|
|
|
31
30
|
// ../node_modules/commander/lib/error.js
|
|
32
31
|
var require_error = __commonJS({
|
|
33
32
|
"../node_modules/commander/lib/error.js"(exports) {
|
|
34
33
|
var CommanderError2 = class extends Error {
|
|
35
|
-
static {
|
|
36
|
-
__name(this, "CommanderError");
|
|
37
|
-
}
|
|
38
34
|
/**
|
|
39
35
|
* Constructs the CommanderError class
|
|
40
36
|
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
@@ -42,26 +38,15 @@ var require_error = __commonJS({
|
|
|
42
38
|
* @param {string} message human-readable description of the error
|
|
43
39
|
*/
|
|
44
40
|
constructor(exitCode, code, message) {
|
|
45
|
-
super(message);
|
|
46
|
-
Error.captureStackTrace(this, this.constructor);
|
|
47
|
-
this.name = this.constructor.name;
|
|
48
|
-
this.code = code;
|
|
49
|
-
this.exitCode = exitCode;
|
|
50
|
-
this.nestedError = void 0;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
54
|
-
static {
|
|
55
|
-
__name(this, "InvalidArgumentError");
|
|
41
|
+
super(message), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name, this.code = code, this.exitCode = exitCode, this.nestedError = void 0;
|
|
56
42
|
}
|
|
43
|
+
}, InvalidArgumentError2 = class extends CommanderError2 {
|
|
57
44
|
/**
|
|
58
45
|
* Constructs the InvalidArgumentError class
|
|
59
46
|
* @param {string} [message] explanation of why argument is invalid
|
|
60
47
|
*/
|
|
61
48
|
constructor(message) {
|
|
62
|
-
super(1, "commander.invalidArgument", message);
|
|
63
|
-
Error.captureStackTrace(this, this.constructor);
|
|
64
|
-
this.name = this.constructor.name;
|
|
49
|
+
super(1, "commander.invalidArgument", message), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name;
|
|
65
50
|
}
|
|
66
51
|
};
|
|
67
52
|
exports.CommanderError = CommanderError2;
|
|
@@ -72,11 +57,7 @@ var require_error = __commonJS({
|
|
|
72
57
|
// ../node_modules/commander/lib/argument.js
|
|
73
58
|
var require_argument = __commonJS({
|
|
74
59
|
"../node_modules/commander/lib/argument.js"(exports) {
|
|
75
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error()
|
|
76
|
-
var Argument2 = class {
|
|
77
|
-
static {
|
|
78
|
-
__name(this, "Argument");
|
|
79
|
-
}
|
|
60
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error(), Argument2 = class {
|
|
80
61
|
/**
|
|
81
62
|
* Initialize a new command argument with the given name and description.
|
|
82
63
|
* The default is that the argument is required, and you can explicitly
|
|
@@ -86,30 +67,18 @@ var require_argument = __commonJS({
|
|
|
86
67
|
* @param {string} [description]
|
|
87
68
|
*/
|
|
88
69
|
constructor(name, description) {
|
|
89
|
-
this.description = description || ""
|
|
90
|
-
this.variadic = false;
|
|
91
|
-
this.parseArg = void 0;
|
|
92
|
-
this.defaultValue = void 0;
|
|
93
|
-
this.defaultValueDescription = void 0;
|
|
94
|
-
this.argChoices = void 0;
|
|
95
|
-
switch (name[0]) {
|
|
70
|
+
switch (this.description = description || "", this.variadic = !1, this.parseArg = void 0, this.defaultValue = void 0, this.defaultValueDescription = void 0, this.argChoices = void 0, name[0]) {
|
|
96
71
|
case "<":
|
|
97
|
-
this.required =
|
|
98
|
-
this._name = name.slice(1, -1);
|
|
72
|
+
this.required = !0, this._name = name.slice(1, -1);
|
|
99
73
|
break;
|
|
100
74
|
case "[":
|
|
101
|
-
this.required =
|
|
102
|
-
this._name = name.slice(1, -1);
|
|
75
|
+
this.required = !1, this._name = name.slice(1, -1);
|
|
103
76
|
break;
|
|
104
77
|
default:
|
|
105
|
-
this.required =
|
|
106
|
-
this._name = name;
|
|
78
|
+
this.required = !0, this._name = name;
|
|
107
79
|
break;
|
|
108
80
|
}
|
|
109
|
-
|
|
110
|
-
this.variadic = true;
|
|
111
|
-
this._name = this._name.slice(0, -3);
|
|
112
|
-
}
|
|
81
|
+
this._name.endsWith("...") && (this.variadic = !0, this._name = this._name.slice(0, -3));
|
|
113
82
|
}
|
|
114
83
|
/**
|
|
115
84
|
* Return argument name.
|
|
@@ -123,11 +92,7 @@ var require_argument = __commonJS({
|
|
|
123
92
|
* @package
|
|
124
93
|
*/
|
|
125
94
|
_collectValue(value, previous) {
|
|
126
|
-
|
|
127
|
-
return [value];
|
|
128
|
-
}
|
|
129
|
-
previous.push(value);
|
|
130
|
-
return previous;
|
|
95
|
+
return previous === this.defaultValue || !Array.isArray(previous) ? [value] : (previous.push(value), previous);
|
|
131
96
|
}
|
|
132
97
|
/**
|
|
133
98
|
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
@@ -137,9 +102,7 @@ var require_argument = __commonJS({
|
|
|
137
102
|
* @return {Argument}
|
|
138
103
|
*/
|
|
139
104
|
default(value, description) {
|
|
140
|
-
this.defaultValue = value;
|
|
141
|
-
this.defaultValueDescription = description;
|
|
142
|
-
return this;
|
|
105
|
+
return this.defaultValue = value, this.defaultValueDescription = description, this;
|
|
143
106
|
}
|
|
144
107
|
/**
|
|
145
108
|
* Set the custom handler for processing CLI command arguments into argument values.
|
|
@@ -148,8 +111,7 @@ var require_argument = __commonJS({
|
|
|
148
111
|
* @return {Argument}
|
|
149
112
|
*/
|
|
150
113
|
argParser(fn) {
|
|
151
|
-
this.parseArg = fn;
|
|
152
|
-
return this;
|
|
114
|
+
return this.parseArg = fn, this;
|
|
153
115
|
}
|
|
154
116
|
/**
|
|
155
117
|
* Only allow argument value to be one of choices.
|
|
@@ -158,19 +120,13 @@ var require_argument = __commonJS({
|
|
|
158
120
|
* @return {Argument}
|
|
159
121
|
*/
|
|
160
122
|
choices(values) {
|
|
161
|
-
this.argChoices = values.slice()
|
|
162
|
-
|
|
163
|
-
if (!this.argChoices.includes(arg)) {
|
|
123
|
+
return this.argChoices = values.slice(), this.parseArg = (arg, previous) => {
|
|
124
|
+
if (!this.argChoices.includes(arg))
|
|
164
125
|
throw new InvalidArgumentError2(
|
|
165
126
|
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
166
127
|
);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return this._collectValue(arg, previous);
|
|
170
|
-
}
|
|
171
|
-
return arg;
|
|
172
|
-
};
|
|
173
|
-
return this;
|
|
128
|
+
return this.variadic ? this._collectValue(arg, previous) : arg;
|
|
129
|
+
}, this;
|
|
174
130
|
}
|
|
175
131
|
/**
|
|
176
132
|
* Make argument required.
|
|
@@ -178,8 +134,7 @@ var require_argument = __commonJS({
|
|
|
178
134
|
* @returns {Argument}
|
|
179
135
|
*/
|
|
180
136
|
argRequired() {
|
|
181
|
-
this.required =
|
|
182
|
-
return this;
|
|
137
|
+
return this.required = !0, this;
|
|
183
138
|
}
|
|
184
139
|
/**
|
|
185
140
|
* Make argument optional.
|
|
@@ -187,15 +142,13 @@ var require_argument = __commonJS({
|
|
|
187
142
|
* @returns {Argument}
|
|
188
143
|
*/
|
|
189
144
|
argOptional() {
|
|
190
|
-
this.required =
|
|
191
|
-
return this;
|
|
145
|
+
return this.required = !1, this;
|
|
192
146
|
}
|
|
193
147
|
};
|
|
194
148
|
function humanReadableArgName(arg) {
|
|
195
|
-
|
|
149
|
+
let nameOutput = arg.name() + (arg.variadic === !0 ? "..." : "");
|
|
196
150
|
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
197
151
|
}
|
|
198
|
-
__name(humanReadableArgName, "humanReadableArgName");
|
|
199
152
|
exports.Argument = Argument2;
|
|
200
153
|
exports.humanReadableArgName = humanReadableArgName;
|
|
201
154
|
}
|
|
@@ -204,17 +157,9 @@ var require_argument = __commonJS({
|
|
|
204
157
|
// ../node_modules/commander/lib/help.js
|
|
205
158
|
var require_help = __commonJS({
|
|
206
159
|
"../node_modules/commander/lib/help.js"(exports) {
|
|
207
|
-
var { humanReadableArgName } = require_argument()
|
|
208
|
-
var Help2 = class {
|
|
209
|
-
static {
|
|
210
|
-
__name(this, "Help");
|
|
211
|
-
}
|
|
160
|
+
var { humanReadableArgName } = require_argument(), Help2 = class {
|
|
212
161
|
constructor() {
|
|
213
|
-
this.helpWidth = void 0;
|
|
214
|
-
this.minWidthToWrap = 40;
|
|
215
|
-
this.sortSubcommands = false;
|
|
216
|
-
this.sortOptions = false;
|
|
217
|
-
this.showGlobalOptions = false;
|
|
162
|
+
this.helpWidth = void 0, this.minWidthToWrap = 40, this.sortSubcommands = !1, this.sortOptions = !1, this.showGlobalOptions = !1;
|
|
218
163
|
}
|
|
219
164
|
/**
|
|
220
165
|
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
@@ -234,17 +179,8 @@ var require_help = __commonJS({
|
|
|
234
179
|
* @returns {Command[]}
|
|
235
180
|
*/
|
|
236
181
|
visibleCommands(cmd) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (helpCommand && !helpCommand._hidden) {
|
|
240
|
-
visibleCommands.push(helpCommand);
|
|
241
|
-
}
|
|
242
|
-
if (this.sortSubcommands) {
|
|
243
|
-
visibleCommands.sort((a, b) => {
|
|
244
|
-
return a.name().localeCompare(b.name());
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return visibleCommands;
|
|
182
|
+
let visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden), helpCommand = cmd._getHelpCommand();
|
|
183
|
+
return helpCommand && !helpCommand._hidden && visibleCommands.push(helpCommand), this.sortSubcommands && visibleCommands.sort((a, b) => a.name().localeCompare(b.name())), visibleCommands;
|
|
248
184
|
}
|
|
249
185
|
/**
|
|
250
186
|
* Compare options for sort.
|
|
@@ -254,9 +190,7 @@ var require_help = __commonJS({
|
|
|
254
190
|
* @returns {number}
|
|
255
191
|
*/
|
|
256
192
|
compareOptions(a, b) {
|
|
257
|
-
|
|
258
|
-
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
259
|
-
}, "getSortKey");
|
|
193
|
+
let getSortKey = (option) => option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
260
194
|
return getSortKey(a).localeCompare(getSortKey(b));
|
|
261
195
|
}
|
|
262
196
|
/**
|
|
@@ -266,27 +200,16 @@ var require_help = __commonJS({
|
|
|
266
200
|
* @returns {Option[]}
|
|
267
201
|
*/
|
|
268
202
|
visibleOptions(cmd) {
|
|
269
|
-
|
|
270
|
-
const helpOption = cmd._getHelpOption();
|
|
203
|
+
let visibleOptions = cmd.options.filter((option) => !option.hidden), helpOption = cmd._getHelpOption();
|
|
271
204
|
if (helpOption && !helpOption.hidden) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
cmd.createOption(helpOption.long, helpOption.description)
|
|
279
|
-
);
|
|
280
|
-
} else if (helpOption.short && !removeShort) {
|
|
281
|
-
visibleOptions.push(
|
|
282
|
-
cmd.createOption(helpOption.short, helpOption.description)
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (this.sortOptions) {
|
|
287
|
-
visibleOptions.sort(this.compareOptions);
|
|
205
|
+
let removeShort = helpOption.short && cmd._findOption(helpOption.short), removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
206
|
+
!removeShort && !removeLong ? visibleOptions.push(helpOption) : helpOption.long && !removeLong ? visibleOptions.push(
|
|
207
|
+
cmd.createOption(helpOption.long, helpOption.description)
|
|
208
|
+
) : helpOption.short && !removeShort && visibleOptions.push(
|
|
209
|
+
cmd.createOption(helpOption.short, helpOption.description)
|
|
210
|
+
);
|
|
288
211
|
}
|
|
289
|
-
return visibleOptions;
|
|
212
|
+
return this.sortOptions && visibleOptions.sort(this.compareOptions), visibleOptions;
|
|
290
213
|
}
|
|
291
214
|
/**
|
|
292
215
|
* Get an array of the visible global options. (Not including help.)
|
|
@@ -296,17 +219,14 @@ var require_help = __commonJS({
|
|
|
296
219
|
*/
|
|
297
220
|
visibleGlobalOptions(cmd) {
|
|
298
221
|
if (!this.showGlobalOptions) return [];
|
|
299
|
-
|
|
222
|
+
let globalOptions = [];
|
|
300
223
|
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
301
|
-
|
|
224
|
+
let visibleOptions = ancestorCmd.options.filter(
|
|
302
225
|
(option) => !option.hidden
|
|
303
226
|
);
|
|
304
227
|
globalOptions.push(...visibleOptions);
|
|
305
228
|
}
|
|
306
|
-
|
|
307
|
-
globalOptions.sort(this.compareOptions);
|
|
308
|
-
}
|
|
309
|
-
return globalOptions;
|
|
229
|
+
return this.sortOptions && globalOptions.sort(this.compareOptions), globalOptions;
|
|
310
230
|
}
|
|
311
231
|
/**
|
|
312
232
|
* Get an array of the arguments if any have a description.
|
|
@@ -315,15 +235,9 @@ var require_help = __commonJS({
|
|
|
315
235
|
* @returns {Argument[]}
|
|
316
236
|
*/
|
|
317
237
|
visibleArguments(cmd) {
|
|
318
|
-
|
|
319
|
-
cmd.
|
|
320
|
-
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
324
|
-
return cmd.registeredArguments;
|
|
325
|
-
}
|
|
326
|
-
return [];
|
|
238
|
+
return cmd._argsDescription && cmd.registeredArguments.forEach((argument) => {
|
|
239
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
240
|
+
}), cmd.registeredArguments.find((argument) => argument.description) ? cmd.registeredArguments : [];
|
|
327
241
|
}
|
|
328
242
|
/**
|
|
329
243
|
* Get the command term to show in the list of subcommands.
|
|
@@ -332,7 +246,7 @@ var require_help = __commonJS({
|
|
|
332
246
|
* @returns {string}
|
|
333
247
|
*/
|
|
334
248
|
subcommandTerm(cmd) {
|
|
335
|
-
|
|
249
|
+
let args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
336
250
|
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
337
251
|
(args ? " " + args : "");
|
|
338
252
|
}
|
|
@@ -362,14 +276,12 @@ var require_help = __commonJS({
|
|
|
362
276
|
* @returns {number}
|
|
363
277
|
*/
|
|
364
278
|
longestSubcommandTermLength(cmd, helper) {
|
|
365
|
-
return helper.visibleCommands(cmd).reduce((max, command2) =>
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
);
|
|
372
|
-
}, 0);
|
|
279
|
+
return helper.visibleCommands(cmd).reduce((max, command2) => Math.max(
|
|
280
|
+
max,
|
|
281
|
+
this.displayWidth(
|
|
282
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(command2))
|
|
283
|
+
)
|
|
284
|
+
), 0);
|
|
373
285
|
}
|
|
374
286
|
/**
|
|
375
287
|
* Get the longest option term length.
|
|
@@ -379,12 +291,10 @@ var require_help = __commonJS({
|
|
|
379
291
|
* @returns {number}
|
|
380
292
|
*/
|
|
381
293
|
longestOptionTermLength(cmd, helper) {
|
|
382
|
-
return helper.visibleOptions(cmd).reduce((max, option) =>
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
);
|
|
387
|
-
}, 0);
|
|
294
|
+
return helper.visibleOptions(cmd).reduce((max, option) => Math.max(
|
|
295
|
+
max,
|
|
296
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
297
|
+
), 0);
|
|
388
298
|
}
|
|
389
299
|
/**
|
|
390
300
|
* Get the longest global option term length.
|
|
@@ -394,12 +304,10 @@ var require_help = __commonJS({
|
|
|
394
304
|
* @returns {number}
|
|
395
305
|
*/
|
|
396
306
|
longestGlobalOptionTermLength(cmd, helper) {
|
|
397
|
-
return helper.visibleGlobalOptions(cmd).reduce((max, option) =>
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
);
|
|
402
|
-
}, 0);
|
|
307
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => Math.max(
|
|
308
|
+
max,
|
|
309
|
+
this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option)))
|
|
310
|
+
), 0);
|
|
403
311
|
}
|
|
404
312
|
/**
|
|
405
313
|
* Get the longest argument term length.
|
|
@@ -409,14 +317,12 @@ var require_help = __commonJS({
|
|
|
409
317
|
* @returns {number}
|
|
410
318
|
*/
|
|
411
319
|
longestArgumentTermLength(cmd, helper) {
|
|
412
|
-
return helper.visibleArguments(cmd).reduce((max, argument) =>
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
);
|
|
419
|
-
}, 0);
|
|
320
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => Math.max(
|
|
321
|
+
max,
|
|
322
|
+
this.displayWidth(
|
|
323
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument))
|
|
324
|
+
)
|
|
325
|
+
), 0);
|
|
420
326
|
}
|
|
421
327
|
/**
|
|
422
328
|
* Get the command usage to be displayed at the top of the built-in help.
|
|
@@ -426,13 +332,10 @@ var require_help = __commonJS({
|
|
|
426
332
|
*/
|
|
427
333
|
commandUsage(cmd) {
|
|
428
334
|
let cmdName = cmd._name;
|
|
429
|
-
|
|
430
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
431
|
-
}
|
|
335
|
+
cmd._aliases[0] && (cmdName = cmdName + "|" + cmd._aliases[0]);
|
|
432
336
|
let ancestorCmdNames = "";
|
|
433
|
-
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent)
|
|
337
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent)
|
|
434
338
|
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
435
|
-
}
|
|
436
339
|
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
437
340
|
}
|
|
438
341
|
/**
|
|
@@ -461,33 +364,15 @@ var require_help = __commonJS({
|
|
|
461
364
|
* @return {string}
|
|
462
365
|
*/
|
|
463
366
|
optionDescription(option) {
|
|
464
|
-
|
|
465
|
-
if (option.argChoices
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
)
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (showDefault) {
|
|
474
|
-
extraInfo.push(
|
|
475
|
-
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (option.presetArg !== void 0 && option.optional) {
|
|
480
|
-
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
481
|
-
}
|
|
482
|
-
if (option.envVar !== void 0) {
|
|
483
|
-
extraInfo.push(`env: ${option.envVar}`);
|
|
484
|
-
}
|
|
485
|
-
if (extraInfo.length > 0) {
|
|
486
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
487
|
-
if (option.description) {
|
|
488
|
-
return `${option.description} ${extraDescription}`;
|
|
489
|
-
}
|
|
490
|
-
return extraDescription;
|
|
367
|
+
let extraInfo = [];
|
|
368
|
+
if (option.argChoices && extraInfo.push(
|
|
369
|
+
// use stringify to match the display of the default value
|
|
370
|
+
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
371
|
+
), option.defaultValue !== void 0 && (option.required || option.optional || option.isBoolean() && typeof option.defaultValue == "boolean") && extraInfo.push(
|
|
372
|
+
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`
|
|
373
|
+
), option.presetArg !== void 0 && option.optional && extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`), option.envVar !== void 0 && extraInfo.push(`env: ${option.envVar}`), extraInfo.length > 0) {
|
|
374
|
+
let extraDescription = `(${extraInfo.join(", ")})`;
|
|
375
|
+
return option.description ? `${option.description} ${extraDescription}` : extraDescription;
|
|
491
376
|
}
|
|
492
377
|
return option.description;
|
|
493
378
|
}
|
|
@@ -498,24 +383,15 @@ var require_help = __commonJS({
|
|
|
498
383
|
* @return {string}
|
|
499
384
|
*/
|
|
500
385
|
argumentDescription(argument) {
|
|
501
|
-
|
|
502
|
-
if (argument.argChoices
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
)
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
if (extraInfo.length > 0) {
|
|
514
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
515
|
-
if (argument.description) {
|
|
516
|
-
return `${argument.description} ${extraDescription}`;
|
|
517
|
-
}
|
|
518
|
-
return extraDescription;
|
|
386
|
+
let extraInfo = [];
|
|
387
|
+
if (argument.argChoices && extraInfo.push(
|
|
388
|
+
// use stringify to match the display of the default value
|
|
389
|
+
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
390
|
+
), argument.defaultValue !== void 0 && extraInfo.push(
|
|
391
|
+
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`
|
|
392
|
+
), extraInfo.length > 0) {
|
|
393
|
+
let extraDescription = `(${extraInfo.join(", ")})`;
|
|
394
|
+
return argument.description ? `${argument.description} ${extraDescription}` : extraDescription;
|
|
519
395
|
}
|
|
520
396
|
return argument.description;
|
|
521
397
|
}
|
|
@@ -528,8 +404,7 @@ var require_help = __commonJS({
|
|
|
528
404
|
* @returns string[]
|
|
529
405
|
*/
|
|
530
406
|
formatItemList(heading, items, helper) {
|
|
531
|
-
|
|
532
|
-
return [helper.styleTitle(heading), ...items, ""];
|
|
407
|
+
return items.length === 0 ? [] : [helper.styleTitle(heading), ...items, ""];
|
|
533
408
|
}
|
|
534
409
|
/**
|
|
535
410
|
* Group items by their help group heading.
|
|
@@ -540,19 +415,14 @@ var require_help = __commonJS({
|
|
|
540
415
|
* @returns {Map<string, Command[] | Option[]>}
|
|
541
416
|
*/
|
|
542
417
|
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
543
|
-
|
|
544
|
-
unsortedItems.forEach((item) => {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
result.set(group, []);
|
|
552
|
-
}
|
|
553
|
-
result.get(group).push(item);
|
|
554
|
-
});
|
|
555
|
-
return result;
|
|
418
|
+
let result = /* @__PURE__ */ new Map();
|
|
419
|
+
return unsortedItems.forEach((item) => {
|
|
420
|
+
let group = getGroup(item);
|
|
421
|
+
result.has(group) || result.set(group, []);
|
|
422
|
+
}), visibleItems.forEach((item) => {
|
|
423
|
+
let group = getGroup(item);
|
|
424
|
+
result.has(group) || result.set(group, []), result.get(group).push(item);
|
|
425
|
+
}), result;
|
|
556
426
|
}
|
|
557
427
|
/**
|
|
558
428
|
* Generate the built-in help text.
|
|
@@ -562,75 +432,58 @@ var require_help = __commonJS({
|
|
|
562
432
|
* @returns {string}
|
|
563
433
|
*/
|
|
564
434
|
formatHelp(cmd, helper) {
|
|
565
|
-
|
|
566
|
-
const helpWidth = helper.helpWidth ?? 80;
|
|
435
|
+
let termWidth = helper.padWidth(cmd, helper), helpWidth = helper.helpWidth ?? 80;
|
|
567
436
|
function callFormatItem(term, description) {
|
|
568
437
|
return helper.formatItem(term, termWidth, description, helper);
|
|
569
438
|
}
|
|
570
|
-
__name(callFormatItem, "callFormatItem");
|
|
571
439
|
let output = [
|
|
572
440
|
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
573
441
|
""
|
|
574
|
-
];
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
588
|
-
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
589
|
-
);
|
|
590
|
-
});
|
|
591
|
-
output = output.concat(
|
|
442
|
+
], commandDescription = helper.commandDescription(cmd);
|
|
443
|
+
commandDescription.length > 0 && (output = output.concat([
|
|
444
|
+
helper.boxWrap(
|
|
445
|
+
helper.styleCommandDescription(commandDescription),
|
|
446
|
+
helpWidth
|
|
447
|
+
),
|
|
448
|
+
""
|
|
449
|
+
]));
|
|
450
|
+
let argumentList = helper.visibleArguments(cmd).map((argument) => callFormatItem(
|
|
451
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
452
|
+
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
453
|
+
));
|
|
454
|
+
if (output = output.concat(
|
|
592
455
|
this.formatItemList("Arguments:", argumentList, helper)
|
|
593
|
-
)
|
|
594
|
-
const optionGroups = this.groupItems(
|
|
456
|
+
), this.groupItems(
|
|
595
457
|
cmd.options,
|
|
596
458
|
helper.visibleOptions(cmd),
|
|
597
459
|
(option) => option.helpGroupHeading ?? "Options:"
|
|
598
|
-
)
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
helper.styleOptionDescription(helper.optionDescription(option))
|
|
604
|
-
);
|
|
605
|
-
});
|
|
460
|
+
).forEach((options, group) => {
|
|
461
|
+
let optionList = options.map((option) => callFormatItem(
|
|
462
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
463
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
464
|
+
));
|
|
606
465
|
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
607
|
-
})
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
helper.styleOptionDescription(helper.optionDescription(option))
|
|
613
|
-
);
|
|
614
|
-
});
|
|
466
|
+
}), helper.showGlobalOptions) {
|
|
467
|
+
let globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => callFormatItem(
|
|
468
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
469
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
470
|
+
));
|
|
615
471
|
output = output.concat(
|
|
616
472
|
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
617
473
|
);
|
|
618
474
|
}
|
|
619
|
-
|
|
475
|
+
return this.groupItems(
|
|
620
476
|
cmd.commands,
|
|
621
477
|
helper.visibleCommands(cmd),
|
|
622
478
|
(sub) => sub.helpGroup() || "Commands:"
|
|
623
|
-
)
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
629
|
-
);
|
|
630
|
-
});
|
|
479
|
+
).forEach((commands, group) => {
|
|
480
|
+
let commandList = commands.map((sub) => callFormatItem(
|
|
481
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
482
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
483
|
+
));
|
|
631
484
|
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
632
|
-
})
|
|
633
|
-
|
|
485
|
+
}), output.join(`
|
|
486
|
+
`);
|
|
634
487
|
}
|
|
635
488
|
/**
|
|
636
489
|
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
@@ -651,13 +504,7 @@ var require_help = __commonJS({
|
|
|
651
504
|
return str;
|
|
652
505
|
}
|
|
653
506
|
styleUsage(str) {
|
|
654
|
-
return str.split(" ").map((word) =>
|
|
655
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
656
|
-
if (word === "[command]") return this.styleSubcommandText(word);
|
|
657
|
-
if (word[0] === "[" || word[0] === "<")
|
|
658
|
-
return this.styleArgumentText(word);
|
|
659
|
-
return this.styleCommandText(word);
|
|
660
|
-
}).join(" ");
|
|
507
|
+
return str.split(" ").map((word) => word === "[options]" ? this.styleOptionText(word) : word === "[command]" ? this.styleSubcommandText(word) : word[0] === "[" || word[0] === "<" ? this.styleArgumentText(word) : this.styleCommandText(word)).join(" ");
|
|
661
508
|
}
|
|
662
509
|
styleCommandDescription(str) {
|
|
663
510
|
return this.styleDescriptionText(str);
|
|
@@ -678,12 +525,7 @@ var require_help = __commonJS({
|
|
|
678
525
|
return this.styleOptionText(str);
|
|
679
526
|
}
|
|
680
527
|
styleSubcommandTerm(str) {
|
|
681
|
-
return str.split(" ").map((word) =>
|
|
682
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
683
|
-
if (word[0] === "[" || word[0] === "<")
|
|
684
|
-
return this.styleArgumentText(word);
|
|
685
|
-
return this.styleSubcommandText(word);
|
|
686
|
-
}).join(" ");
|
|
528
|
+
return str.split(" ").map((word) => word === "[options]" ? this.styleOptionText(word) : word[0] === "[" || word[0] === "<" ? this.styleArgumentText(word) : this.styleSubcommandText(word)).join(" ");
|
|
687
529
|
}
|
|
688
530
|
styleArgumentTerm(str) {
|
|
689
531
|
return this.styleArgumentText(str);
|
|
@@ -738,26 +580,16 @@ var require_help = __commonJS({
|
|
|
738
580
|
* @returns {string}
|
|
739
581
|
*/
|
|
740
582
|
formatItem(term, termWidth, description, helper) {
|
|
741
|
-
|
|
742
|
-
const itemIndentStr = " ".repeat(itemIndent);
|
|
583
|
+
let itemIndentStr = " ".repeat(2);
|
|
743
584
|
if (!description) return itemIndentStr + term;
|
|
744
|
-
|
|
585
|
+
let paddedTerm = term.padEnd(
|
|
745
586
|
termWidth + term.length - helper.displayWidth(term)
|
|
746
|
-
);
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
formattedDescription = description;
|
|
753
|
-
} else {
|
|
754
|
-
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
755
|
-
formattedDescription = wrappedDescription.replace(
|
|
756
|
-
/\n/g,
|
|
757
|
-
"\n" + " ".repeat(termWidth + spacerWidth)
|
|
758
|
-
);
|
|
759
|
-
}
|
|
760
|
-
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
587
|
+
), spacerWidth = 2, remainingWidth = (this.helpWidth ?? 80) - termWidth - spacerWidth - 2, formattedDescription;
|
|
588
|
+
return remainingWidth < this.minWidthToWrap || helper.preformatted(description) ? formattedDescription = description : formattedDescription = helper.boxWrap(description, remainingWidth).replace(
|
|
589
|
+
/\n/g,
|
|
590
|
+
`
|
|
591
|
+
` + " ".repeat(termWidth + spacerWidth)
|
|
592
|
+
), itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
761
593
|
${itemIndentStr}`);
|
|
762
594
|
}
|
|
763
595
|
/**
|
|
@@ -770,39 +602,32 @@ ${itemIndentStr}`);
|
|
|
770
602
|
*/
|
|
771
603
|
boxWrap(str, width) {
|
|
772
604
|
if (width < this.minWidthToWrap) return str;
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
rawLines.forEach((line) => {
|
|
777
|
-
const chunks = line.match(chunkPattern);
|
|
605
|
+
let rawLines = str.split(/\r\n|\n/), chunkPattern = /[\s]*[^\s]+/g, wrappedLines = [];
|
|
606
|
+
return rawLines.forEach((line) => {
|
|
607
|
+
let chunks = line.match(chunkPattern);
|
|
778
608
|
if (chunks === null) {
|
|
779
609
|
wrappedLines.push("");
|
|
780
610
|
return;
|
|
781
611
|
}
|
|
782
|
-
let sumChunks = [chunks.shift()];
|
|
783
|
-
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
612
|
+
let sumChunks = [chunks.shift()], sumWidth = this.displayWidth(sumChunks[0]);
|
|
784
613
|
chunks.forEach((chunk) => {
|
|
785
|
-
|
|
614
|
+
let visibleWidth = this.displayWidth(chunk);
|
|
786
615
|
if (sumWidth + visibleWidth <= width) {
|
|
787
|
-
sumChunks.push(chunk);
|
|
788
|
-
sumWidth += visibleWidth;
|
|
616
|
+
sumChunks.push(chunk), sumWidth += visibleWidth;
|
|
789
617
|
return;
|
|
790
618
|
}
|
|
791
619
|
wrappedLines.push(sumChunks.join(""));
|
|
792
|
-
|
|
793
|
-
sumChunks = [nextChunk];
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
});
|
|
798
|
-
return wrappedLines.join("\n");
|
|
620
|
+
let nextChunk = chunk.trimStart();
|
|
621
|
+
sumChunks = [nextChunk], sumWidth = this.displayWidth(nextChunk);
|
|
622
|
+
}), wrappedLines.push(sumChunks.join(""));
|
|
623
|
+
}), wrappedLines.join(`
|
|
624
|
+
`);
|
|
799
625
|
}
|
|
800
626
|
};
|
|
801
627
|
function stripColor(str) {
|
|
802
|
-
|
|
628
|
+
let sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
803
629
|
return str.replace(sgrPattern, "");
|
|
804
630
|
}
|
|
805
|
-
__name(stripColor, "stripColor");
|
|
806
631
|
exports.Help = Help2;
|
|
807
632
|
exports.stripColor = stripColor;
|
|
808
633
|
}
|
|
@@ -811,11 +636,7 @@ ${itemIndentStr}`);
|
|
|
811
636
|
// ../node_modules/commander/lib/option.js
|
|
812
637
|
var require_option = __commonJS({
|
|
813
638
|
"../node_modules/commander/lib/option.js"(exports) {
|
|
814
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error()
|
|
815
|
-
var Option2 = class {
|
|
816
|
-
static {
|
|
817
|
-
__name(this, "Option");
|
|
818
|
-
}
|
|
639
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error(), Option2 = class {
|
|
819
640
|
/**
|
|
820
641
|
* Initialize a new `Option` with the given `flags` and `description`.
|
|
821
642
|
*
|
|
@@ -823,29 +644,9 @@ var require_option = __commonJS({
|
|
|
823
644
|
* @param {string} [description]
|
|
824
645
|
*/
|
|
825
646
|
constructor(flags, description) {
|
|
826
|
-
this.flags = flags;
|
|
827
|
-
|
|
828
|
-
this.
|
|
829
|
-
this.optional = flags.includes("[");
|
|
830
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
831
|
-
this.mandatory = false;
|
|
832
|
-
const optionFlags = splitOptionFlags(flags);
|
|
833
|
-
this.short = optionFlags.shortFlag;
|
|
834
|
-
this.long = optionFlags.longFlag;
|
|
835
|
-
this.negate = false;
|
|
836
|
-
if (this.long) {
|
|
837
|
-
this.negate = this.long.startsWith("--no-");
|
|
838
|
-
}
|
|
839
|
-
this.defaultValue = void 0;
|
|
840
|
-
this.defaultValueDescription = void 0;
|
|
841
|
-
this.presetArg = void 0;
|
|
842
|
-
this.envVar = void 0;
|
|
843
|
-
this.parseArg = void 0;
|
|
844
|
-
this.hidden = false;
|
|
845
|
-
this.argChoices = void 0;
|
|
846
|
-
this.conflictsWith = [];
|
|
847
|
-
this.implied = void 0;
|
|
848
|
-
this.helpGroupHeading = void 0;
|
|
647
|
+
this.flags = flags, this.description = description || "", this.required = flags.includes("<"), this.optional = flags.includes("["), this.variadic = /\w\.\.\.[>\]]$/.test(flags), this.mandatory = !1;
|
|
648
|
+
let optionFlags = splitOptionFlags(flags);
|
|
649
|
+
this.short = optionFlags.shortFlag, this.long = optionFlags.longFlag, this.negate = !1, this.long && (this.negate = this.long.startsWith("--no-")), this.defaultValue = void 0, this.defaultValueDescription = void 0, this.presetArg = void 0, this.envVar = void 0, this.parseArg = void 0, this.hidden = !1, this.argChoices = void 0, this.conflictsWith = [], this.implied = void 0, this.helpGroupHeading = void 0;
|
|
849
650
|
}
|
|
850
651
|
/**
|
|
851
652
|
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
@@ -855,9 +656,7 @@ var require_option = __commonJS({
|
|
|
855
656
|
* @return {Option}
|
|
856
657
|
*/
|
|
857
658
|
default(value, description) {
|
|
858
|
-
this.defaultValue = value;
|
|
859
|
-
this.defaultValueDescription = description;
|
|
860
|
-
return this;
|
|
659
|
+
return this.defaultValue = value, this.defaultValueDescription = description, this;
|
|
861
660
|
}
|
|
862
661
|
/**
|
|
863
662
|
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
@@ -871,8 +670,7 @@ var require_option = __commonJS({
|
|
|
871
670
|
* @return {Option}
|
|
872
671
|
*/
|
|
873
672
|
preset(arg) {
|
|
874
|
-
this.presetArg = arg;
|
|
875
|
-
return this;
|
|
673
|
+
return this.presetArg = arg, this;
|
|
876
674
|
}
|
|
877
675
|
/**
|
|
878
676
|
* Add option name(s) that conflict with this option.
|
|
@@ -886,8 +684,7 @@ var require_option = __commonJS({
|
|
|
886
684
|
* @return {Option}
|
|
887
685
|
*/
|
|
888
686
|
conflicts(names) {
|
|
889
|
-
this.conflictsWith = this.conflictsWith.concat(names);
|
|
890
|
-
return this;
|
|
687
|
+
return this.conflictsWith = this.conflictsWith.concat(names), this;
|
|
891
688
|
}
|
|
892
689
|
/**
|
|
893
690
|
* Specify implied option values for when this option is set and the implied options are not.
|
|
@@ -904,11 +701,7 @@ var require_option = __commonJS({
|
|
|
904
701
|
*/
|
|
905
702
|
implies(impliedOptionValues) {
|
|
906
703
|
let newImplied = impliedOptionValues;
|
|
907
|
-
|
|
908
|
-
newImplied = { [impliedOptionValues]: true };
|
|
909
|
-
}
|
|
910
|
-
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
911
|
-
return this;
|
|
704
|
+
return typeof impliedOptionValues == "string" && (newImplied = { [impliedOptionValues]: !0 }), this.implied = Object.assign(this.implied || {}, newImplied), this;
|
|
912
705
|
}
|
|
913
706
|
/**
|
|
914
707
|
* Set environment variable to check for option value.
|
|
@@ -920,8 +713,7 @@ var require_option = __commonJS({
|
|
|
920
713
|
* @return {Option}
|
|
921
714
|
*/
|
|
922
715
|
env(name) {
|
|
923
|
-
this.envVar = name;
|
|
924
|
-
return this;
|
|
716
|
+
return this.envVar = name, this;
|
|
925
717
|
}
|
|
926
718
|
/**
|
|
927
719
|
* Set the custom handler for processing CLI option arguments into option values.
|
|
@@ -930,8 +722,7 @@ var require_option = __commonJS({
|
|
|
930
722
|
* @return {Option}
|
|
931
723
|
*/
|
|
932
724
|
argParser(fn) {
|
|
933
|
-
this.parseArg = fn;
|
|
934
|
-
return this;
|
|
725
|
+
return this.parseArg = fn, this;
|
|
935
726
|
}
|
|
936
727
|
/**
|
|
937
728
|
* Whether the option is mandatory and must have a value after parsing.
|
|
@@ -939,9 +730,8 @@ var require_option = __commonJS({
|
|
|
939
730
|
* @param {boolean} [mandatory=true]
|
|
940
731
|
* @return {Option}
|
|
941
732
|
*/
|
|
942
|
-
makeOptionMandatory(mandatory =
|
|
943
|
-
this.mandatory = !!mandatory;
|
|
944
|
-
return this;
|
|
733
|
+
makeOptionMandatory(mandatory = !0) {
|
|
734
|
+
return this.mandatory = !!mandatory, this;
|
|
945
735
|
}
|
|
946
736
|
/**
|
|
947
737
|
* Hide option in help.
|
|
@@ -949,19 +739,14 @@ var require_option = __commonJS({
|
|
|
949
739
|
* @param {boolean} [hide=true]
|
|
950
740
|
* @return {Option}
|
|
951
741
|
*/
|
|
952
|
-
hideHelp(hide =
|
|
953
|
-
this.hidden = !!hide;
|
|
954
|
-
return this;
|
|
742
|
+
hideHelp(hide = !0) {
|
|
743
|
+
return this.hidden = !!hide, this;
|
|
955
744
|
}
|
|
956
745
|
/**
|
|
957
746
|
* @package
|
|
958
747
|
*/
|
|
959
748
|
_collectValue(value, previous) {
|
|
960
|
-
|
|
961
|
-
return [value];
|
|
962
|
-
}
|
|
963
|
-
previous.push(value);
|
|
964
|
-
return previous;
|
|
749
|
+
return previous === this.defaultValue || !Array.isArray(previous) ? [value] : (previous.push(value), previous);
|
|
965
750
|
}
|
|
966
751
|
/**
|
|
967
752
|
* Only allow option value to be one of choices.
|
|
@@ -970,19 +755,13 @@ var require_option = __commonJS({
|
|
|
970
755
|
* @return {Option}
|
|
971
756
|
*/
|
|
972
757
|
choices(values) {
|
|
973
|
-
this.argChoices = values.slice()
|
|
974
|
-
|
|
975
|
-
if (!this.argChoices.includes(arg)) {
|
|
758
|
+
return this.argChoices = values.slice(), this.parseArg = (arg, previous) => {
|
|
759
|
+
if (!this.argChoices.includes(arg))
|
|
976
760
|
throw new InvalidArgumentError2(
|
|
977
761
|
`Allowed choices are ${this.argChoices.join(", ")}.`
|
|
978
762
|
);
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
return this._collectValue(arg, previous);
|
|
982
|
-
}
|
|
983
|
-
return arg;
|
|
984
|
-
};
|
|
985
|
-
return this;
|
|
763
|
+
return this.variadic ? this._collectValue(arg, previous) : arg;
|
|
764
|
+
}, this;
|
|
986
765
|
}
|
|
987
766
|
/**
|
|
988
767
|
* Return option name.
|
|
@@ -990,10 +769,7 @@ var require_option = __commonJS({
|
|
|
990
769
|
* @return {string}
|
|
991
770
|
*/
|
|
992
771
|
name() {
|
|
993
|
-
|
|
994
|
-
return this.long.replace(/^--/, "");
|
|
995
|
-
}
|
|
996
|
-
return this.short.replace(/^-/, "");
|
|
772
|
+
return this.long ? this.long.replace(/^--/, "") : this.short.replace(/^-/, "");
|
|
997
773
|
}
|
|
998
774
|
/**
|
|
999
775
|
* Return option name, in a camelcase format that can be used
|
|
@@ -1002,10 +778,7 @@ var require_option = __commonJS({
|
|
|
1002
778
|
* @return {string}
|
|
1003
779
|
*/
|
|
1004
780
|
attributeName() {
|
|
1005
|
-
|
|
1006
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
1007
|
-
}
|
|
1008
|
-
return camelcase(this.name());
|
|
781
|
+
return this.negate ? camelcase(this.name().replace(/^no-/, "")) : camelcase(this.name());
|
|
1009
782
|
}
|
|
1010
783
|
/**
|
|
1011
784
|
* Set the help group heading.
|
|
@@ -1014,8 +787,7 @@ var require_option = __commonJS({
|
|
|
1014
787
|
* @return {Option}
|
|
1015
788
|
*/
|
|
1016
789
|
helpGroup(heading) {
|
|
1017
|
-
this.helpGroupHeading = heading;
|
|
1018
|
-
return this;
|
|
790
|
+
return this.helpGroupHeading = heading, this;
|
|
1019
791
|
}
|
|
1020
792
|
/**
|
|
1021
793
|
* Check if `arg` matches the short or long flag.
|
|
@@ -1038,29 +810,15 @@ var require_option = __commonJS({
|
|
|
1038
810
|
isBoolean() {
|
|
1039
811
|
return !this.required && !this.optional && !this.negate;
|
|
1040
812
|
}
|
|
1041
|
-
}
|
|
1042
|
-
var DualOptions = class {
|
|
1043
|
-
static {
|
|
1044
|
-
__name(this, "DualOptions");
|
|
1045
|
-
}
|
|
813
|
+
}, DualOptions = class {
|
|
1046
814
|
/**
|
|
1047
815
|
* @param {Option[]} options
|
|
1048
816
|
*/
|
|
1049
817
|
constructor(options) {
|
|
1050
|
-
this.positiveOptions = /* @__PURE__ */ new Map()
|
|
1051
|
-
|
|
1052
|
-
this.
|
|
1053
|
-
|
|
1054
|
-
if (option.negate) {
|
|
1055
|
-
this.negativeOptions.set(option.attributeName(), option);
|
|
1056
|
-
} else {
|
|
1057
|
-
this.positiveOptions.set(option.attributeName(), option);
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
this.negativeOptions.forEach((value, key) => {
|
|
1061
|
-
if (this.positiveOptions.has(key)) {
|
|
1062
|
-
this.dualOptions.add(key);
|
|
1063
|
-
}
|
|
818
|
+
this.positiveOptions = /* @__PURE__ */ new Map(), this.negativeOptions = /* @__PURE__ */ new Map(), this.dualOptions = /* @__PURE__ */ new Set(), options.forEach((option) => {
|
|
819
|
+
option.negate ? this.negativeOptions.set(option.attributeName(), option) : this.positiveOptions.set(option.attributeName(), option);
|
|
820
|
+
}), this.negativeOptions.forEach((value, key) => {
|
|
821
|
+
this.positiveOptions.has(key) && this.dualOptions.add(key);
|
|
1064
822
|
});
|
|
1065
823
|
}
|
|
1066
824
|
/**
|
|
@@ -1071,50 +829,27 @@ var require_option = __commonJS({
|
|
|
1071
829
|
* @returns {boolean}
|
|
1072
830
|
*/
|
|
1073
831
|
valueFromOption(value, option) {
|
|
1074
|
-
|
|
1075
|
-
if (!this.dualOptions.has(optionKey)) return
|
|
1076
|
-
|
|
1077
|
-
const negativeValue = preset !== void 0 ? preset : false;
|
|
832
|
+
let optionKey = option.attributeName();
|
|
833
|
+
if (!this.dualOptions.has(optionKey)) return !0;
|
|
834
|
+
let preset = this.negativeOptions.get(optionKey).presetArg, negativeValue = preset !== void 0 ? preset : !1;
|
|
1078
835
|
return option.negate === (negativeValue === value);
|
|
1079
836
|
}
|
|
1080
837
|
};
|
|
1081
838
|
function camelcase(str) {
|
|
1082
|
-
return str.split("-").reduce((str2, word) =>
|
|
1083
|
-
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
1084
|
-
});
|
|
839
|
+
return str.split("-").reduce((str2, word) => str2 + word[0].toUpperCase() + word.slice(1));
|
|
1085
840
|
}
|
|
1086
|
-
__name(camelcase, "camelcase");
|
|
1087
841
|
function splitOptionFlags(flags) {
|
|
1088
|
-
let shortFlag;
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
1094
|
-
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
1095
|
-
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
1096
|
-
shortFlag = flagParts.shift();
|
|
1097
|
-
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
1098
|
-
shortFlag = longFlag;
|
|
1099
|
-
longFlag = flagParts.shift();
|
|
1100
|
-
}
|
|
1101
|
-
if (flagParts[0].startsWith("-")) {
|
|
1102
|
-
const unsupportedFlag = flagParts[0];
|
|
1103
|
-
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
1104
|
-
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
1105
|
-
throw new Error(
|
|
1106
|
-
`${baseError}
|
|
842
|
+
let shortFlag, longFlag, shortFlagExp = /^-[^-]$/, longFlagExp = /^--[^-]/, flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
843
|
+
if (shortFlagExp.test(flagParts[0]) && (shortFlag = flagParts.shift()), longFlagExp.test(flagParts[0]) && (longFlag = flagParts.shift()), !shortFlag && shortFlagExp.test(flagParts[0]) && (shortFlag = flagParts.shift()), !shortFlag && longFlagExp.test(flagParts[0]) && (shortFlag = longFlag, longFlag = flagParts.shift()), flagParts[0].startsWith("-")) {
|
|
844
|
+
let unsupportedFlag = flagParts[0], baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
845
|
+
throw /^-[^-][^-]/.test(unsupportedFlag) ? new Error(
|
|
846
|
+
`${baseError}
|
|
1107
847
|
- a short flag is a single dash and a single character
|
|
1108
848
|
- either use a single dash and a single character (for a short flag)
|
|
1109
849
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
- too many short flags`);
|
|
1114
|
-
if (longFlagExp.test(unsupportedFlag))
|
|
1115
|
-
throw new Error(`${baseError}
|
|
1116
|
-
- too many long flags`);
|
|
1117
|
-
throw new Error(`${baseError}
|
|
850
|
+
) : shortFlagExp.test(unsupportedFlag) ? new Error(`${baseError}
|
|
851
|
+
- too many short flags`) : longFlagExp.test(unsupportedFlag) ? new Error(`${baseError}
|
|
852
|
+
- too many long flags`) : new Error(`${baseError}
|
|
1118
853
|
- unrecognised flag format`);
|
|
1119
854
|
}
|
|
1120
855
|
if (shortFlag === void 0 && longFlag === void 0)
|
|
@@ -1123,7 +858,6 @@ var require_option = __commonJS({
|
|
|
1123
858
|
);
|
|
1124
859
|
return { shortFlag, longFlag };
|
|
1125
860
|
}
|
|
1126
|
-
__name(splitOptionFlags, "splitOptionFlags");
|
|
1127
861
|
exports.Option = Option2;
|
|
1128
862
|
exports.DualOptions = DualOptions;
|
|
1129
863
|
}
|
|
@@ -1132,81 +866,42 @@ var require_option = __commonJS({
|
|
|
1132
866
|
// ../node_modules/commander/lib/suggestSimilar.js
|
|
1133
867
|
var require_suggestSimilar = __commonJS({
|
|
1134
868
|
"../node_modules/commander/lib/suggestSimilar.js"(exports) {
|
|
1135
|
-
var maxDistance = 3;
|
|
1136
869
|
function editDistance(a, b) {
|
|
1137
|
-
if (Math.abs(a.length - b.length) >
|
|
870
|
+
if (Math.abs(a.length - b.length) > 3)
|
|
1138
871
|
return Math.max(a.length, b.length);
|
|
1139
|
-
|
|
1140
|
-
for (let i = 0; i <= a.length; i++)
|
|
872
|
+
let d = [];
|
|
873
|
+
for (let i = 0; i <= a.length; i++)
|
|
1141
874
|
d[i] = [i];
|
|
1142
|
-
|
|
1143
|
-
for (let j = 0; j <= b.length; j++) {
|
|
875
|
+
for (let j = 0; j <= b.length; j++)
|
|
1144
876
|
d[0][j] = j;
|
|
1145
|
-
|
|
1146
|
-
for (let j = 1; j <= b.length; j++) {
|
|
877
|
+
for (let j = 1; j <= b.length; j++)
|
|
1147
878
|
for (let i = 1; i <= a.length; i++) {
|
|
1148
879
|
let cost = 1;
|
|
1149
|
-
|
|
1150
|
-
cost = 0;
|
|
1151
|
-
} else {
|
|
1152
|
-
cost = 1;
|
|
1153
|
-
}
|
|
1154
|
-
d[i][j] = Math.min(
|
|
880
|
+
a[i - 1] === b[j - 1] ? cost = 0 : cost = 1, d[i][j] = Math.min(
|
|
1155
881
|
d[i - 1][j] + 1,
|
|
1156
882
|
// deletion
|
|
1157
883
|
d[i][j - 1] + 1,
|
|
1158
884
|
// insertion
|
|
1159
885
|
d[i - 1][j - 1] + cost
|
|
1160
886
|
// substitution
|
|
1161
|
-
);
|
|
1162
|
-
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
1163
|
-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
1164
|
-
}
|
|
887
|
+
), i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1] && (d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1));
|
|
1165
888
|
}
|
|
1166
|
-
}
|
|
1167
889
|
return d[a.length][b.length];
|
|
1168
890
|
}
|
|
1169
|
-
__name(editDistance, "editDistance");
|
|
1170
891
|
function suggestSimilar(word, candidates) {
|
|
1171
892
|
if (!candidates || candidates.length === 0) return "";
|
|
1172
893
|
candidates = Array.from(new Set(candidates));
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1178
|
-
let similar = [];
|
|
1179
|
-
let bestDistance = maxDistance;
|
|
1180
|
-
const minSimilarity = 0.4;
|
|
1181
|
-
candidates.forEach((candidate) => {
|
|
894
|
+
let searchingOptions = word.startsWith("--");
|
|
895
|
+
searchingOptions && (word = word.slice(2), candidates = candidates.map((candidate) => candidate.slice(2)));
|
|
896
|
+
let similar = [], bestDistance = 3, minSimilarity = 0.4;
|
|
897
|
+
return candidates.forEach((candidate) => {
|
|
1182
898
|
if (candidate.length <= 1) return;
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
bestDistance = distance;
|
|
1189
|
-
similar = [candidate];
|
|
1190
|
-
} else if (distance === bestDistance) {
|
|
1191
|
-
similar.push(candidate);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
similar.sort((a, b) => a.localeCompare(b));
|
|
1196
|
-
if (searchingOptions) {
|
|
1197
|
-
similar = similar.map((candidate) => `--${candidate}`);
|
|
1198
|
-
}
|
|
1199
|
-
if (similar.length > 1) {
|
|
1200
|
-
return `
|
|
1201
|
-
(Did you mean one of ${similar.join(", ")}?)`;
|
|
1202
|
-
}
|
|
1203
|
-
if (similar.length === 1) {
|
|
1204
|
-
return `
|
|
1205
|
-
(Did you mean ${similar[0]}?)`;
|
|
1206
|
-
}
|
|
1207
|
-
return "";
|
|
899
|
+
let distance = editDistance(word, candidate), length = Math.max(word.length, candidate.length);
|
|
900
|
+
(length - distance) / length > minSimilarity && (distance < bestDistance ? (bestDistance = distance, similar = [candidate]) : distance === bestDistance && similar.push(candidate));
|
|
901
|
+
}), similar.sort((a, b) => a.localeCompare(b)), searchingOptions && (similar = similar.map((candidate) => `--${candidate}`)), similar.length > 1 ? `
|
|
902
|
+
(Did you mean one of ${similar.join(", ")}?)` : similar.length === 1 ? `
|
|
903
|
+
(Did you mean ${similar[0]}?)` : "";
|
|
1208
904
|
}
|
|
1209
|
-
__name(suggestSimilar, "suggestSimilar");
|
|
1210
905
|
exports.suggestSimilar = suggestSimilar;
|
|
1211
906
|
}
|
|
1212
907
|
});
|
|
@@ -1214,77 +909,23 @@ var require_suggestSimilar = __commonJS({
|
|
|
1214
909
|
// ../node_modules/commander/lib/command.js
|
|
1215
910
|
var require_command = __commonJS({
|
|
1216
911
|
"../node_modules/commander/lib/command.js"(exports) {
|
|
1217
|
-
var EventEmitter = __require("node:events").EventEmitter
|
|
1218
|
-
var childProcess = __require("node:child_process");
|
|
1219
|
-
var path = __require("node:path");
|
|
1220
|
-
var fs = __require("node:fs");
|
|
1221
|
-
var process2 = __require("node:process");
|
|
1222
|
-
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1223
|
-
var { CommanderError: CommanderError2 } = require_error();
|
|
1224
|
-
var { Help: Help2, stripColor } = require_help();
|
|
1225
|
-
var { Option: Option2, DualOptions } = require_option();
|
|
1226
|
-
var { suggestSimilar } = require_suggestSimilar();
|
|
1227
|
-
var Command2 = class _Command extends EventEmitter {
|
|
1228
|
-
static {
|
|
1229
|
-
__name(this, "Command");
|
|
1230
|
-
}
|
|
912
|
+
var EventEmitter = __require("node:events").EventEmitter, childProcess = __require("node:child_process"), path = __require("node:path"), fs = __require("node:fs"), process2 = __require("node:process"), { Argument: Argument2, humanReadableArgName } = require_argument(), { CommanderError: CommanderError2 } = require_error(), { Help: Help2, stripColor } = require_help(), { Option: Option2, DualOptions } = require_option(), { suggestSimilar } = require_suggestSimilar(), Command2 = class _Command extends EventEmitter {
|
|
1231
913
|
/**
|
|
1232
914
|
* Initialize a new `Command`.
|
|
1233
915
|
*
|
|
1234
916
|
* @param {string} [name]
|
|
1235
917
|
*/
|
|
1236
918
|
constructor(name) {
|
|
1237
|
-
super()
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
this.
|
|
1247
|
-
this.processedArgs = [];
|
|
1248
|
-
this._scriptPath = null;
|
|
1249
|
-
this._name = name || "";
|
|
1250
|
-
this._optionValues = {};
|
|
1251
|
-
this._optionValueSources = {};
|
|
1252
|
-
this._storeOptionsAsProperties = false;
|
|
1253
|
-
this._actionHandler = null;
|
|
1254
|
-
this._executableHandler = false;
|
|
1255
|
-
this._executableFile = null;
|
|
1256
|
-
this._executableDir = null;
|
|
1257
|
-
this._defaultCommandName = null;
|
|
1258
|
-
this._exitCallback = null;
|
|
1259
|
-
this._aliases = [];
|
|
1260
|
-
this._combineFlagAndOptionalValue = true;
|
|
1261
|
-
this._description = "";
|
|
1262
|
-
this._summary = "";
|
|
1263
|
-
this._argsDescription = void 0;
|
|
1264
|
-
this._enablePositionalOptions = false;
|
|
1265
|
-
this._passThroughOptions = false;
|
|
1266
|
-
this._lifeCycleHooks = {};
|
|
1267
|
-
this._showHelpAfterError = false;
|
|
1268
|
-
this._showSuggestionAfterError = true;
|
|
1269
|
-
this._savedState = null;
|
|
1270
|
-
this._outputConfiguration = {
|
|
1271
|
-
writeOut: /* @__PURE__ */ __name((str) => process2.stdout.write(str), "writeOut"),
|
|
1272
|
-
writeErr: /* @__PURE__ */ __name((str) => process2.stderr.write(str), "writeErr"),
|
|
1273
|
-
outputError: /* @__PURE__ */ __name((str, write) => write(str), "outputError"),
|
|
1274
|
-
getOutHelpWidth: /* @__PURE__ */ __name(() => process2.stdout.isTTY ? process2.stdout.columns : void 0, "getOutHelpWidth"),
|
|
1275
|
-
getErrHelpWidth: /* @__PURE__ */ __name(() => process2.stderr.isTTY ? process2.stderr.columns : void 0, "getErrHelpWidth"),
|
|
1276
|
-
getOutHasColors: /* @__PURE__ */ __name(() => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()), "getOutHasColors"),
|
|
1277
|
-
getErrHasColors: /* @__PURE__ */ __name(() => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()), "getErrHasColors"),
|
|
1278
|
-
stripColor: /* @__PURE__ */ __name((str) => stripColor(str), "stripColor")
|
|
1279
|
-
};
|
|
1280
|
-
this._hidden = false;
|
|
1281
|
-
this._helpOption = void 0;
|
|
1282
|
-
this._addImplicitHelpCommand = void 0;
|
|
1283
|
-
this._helpCommand = void 0;
|
|
1284
|
-
this._helpConfiguration = {};
|
|
1285
|
-
this._helpGroupHeading = void 0;
|
|
1286
|
-
this._defaultCommandGroup = void 0;
|
|
1287
|
-
this._defaultOptionGroup = void 0;
|
|
919
|
+
super(), this.commands = [], this.options = [], this.parent = null, this._allowUnknownOption = !1, this._allowExcessArguments = !1, this.registeredArguments = [], this._args = this.registeredArguments, this.args = [], this.rawArgs = [], this.processedArgs = [], this._scriptPath = null, this._name = name || "", this._optionValues = {}, this._optionValueSources = {}, this._storeOptionsAsProperties = !1, this._actionHandler = null, this._executableHandler = !1, this._executableFile = null, this._executableDir = null, this._defaultCommandName = null, this._exitCallback = null, this._aliases = [], this._combineFlagAndOptionalValue = !0, this._description = "", this._summary = "", this._argsDescription = void 0, this._enablePositionalOptions = !1, this._passThroughOptions = !1, this._lifeCycleHooks = {}, this._showHelpAfterError = !1, this._showSuggestionAfterError = !0, this._savedState = null, this._outputConfiguration = {
|
|
920
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
921
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
922
|
+
outputError: (str, write) => write(str),
|
|
923
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : void 0,
|
|
924
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : void 0,
|
|
925
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
926
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
927
|
+
stripColor: (str) => stripColor(str)
|
|
928
|
+
}, this._hidden = !1, this._helpOption = void 0, this._addImplicitHelpCommand = void 0, this._helpCommand = void 0, this._helpConfiguration = {}, this._helpGroupHeading = void 0, this._defaultCommandGroup = void 0, this._defaultOptionGroup = void 0;
|
|
1288
929
|
}
|
|
1289
930
|
/**
|
|
1290
931
|
* Copy settings that are useful to have in common across root command and subcommands.
|
|
@@ -1295,28 +936,16 @@ var require_command = __commonJS({
|
|
|
1295
936
|
* @return {Command} `this` command for chaining
|
|
1296
937
|
*/
|
|
1297
938
|
copyInheritedSettings(sourceCommand) {
|
|
1298
|
-
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1299
|
-
this._helpOption = sourceCommand._helpOption;
|
|
1300
|
-
this._helpCommand = sourceCommand._helpCommand;
|
|
1301
|
-
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1302
|
-
this._exitCallback = sourceCommand._exitCallback;
|
|
1303
|
-
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1304
|
-
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1305
|
-
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1306
|
-
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1307
|
-
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1308
|
-
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1309
|
-
return this;
|
|
939
|
+
return this._outputConfiguration = sourceCommand._outputConfiguration, this._helpOption = sourceCommand._helpOption, this._helpCommand = sourceCommand._helpCommand, this._helpConfiguration = sourceCommand._helpConfiguration, this._exitCallback = sourceCommand._exitCallback, this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties, this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue, this._allowExcessArguments = sourceCommand._allowExcessArguments, this._enablePositionalOptions = sourceCommand._enablePositionalOptions, this._showHelpAfterError = sourceCommand._showHelpAfterError, this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError, this;
|
|
1310
940
|
}
|
|
1311
941
|
/**
|
|
1312
942
|
* @returns {Command[]}
|
|
1313
943
|
* @private
|
|
1314
944
|
*/
|
|
1315
945
|
_getCommandAndAncestors() {
|
|
1316
|
-
|
|
1317
|
-
for (let command2 = this; command2; command2 = command2.parent)
|
|
946
|
+
let result = [];
|
|
947
|
+
for (let command2 = this; command2; command2 = command2.parent)
|
|
1318
948
|
result.push(command2);
|
|
1319
|
-
}
|
|
1320
949
|
return result;
|
|
1321
950
|
}
|
|
1322
951
|
/**
|
|
@@ -1344,28 +973,10 @@ var require_command = __commonJS({
|
|
|
1344
973
|
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
1345
974
|
*/
|
|
1346
975
|
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1347
|
-
let desc = actionOptsOrExecDesc;
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
desc = null;
|
|
1352
|
-
}
|
|
1353
|
-
opts = opts || {};
|
|
1354
|
-
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1355
|
-
const cmd = this.createCommand(name);
|
|
1356
|
-
if (desc) {
|
|
1357
|
-
cmd.description(desc);
|
|
1358
|
-
cmd._executableHandler = true;
|
|
1359
|
-
}
|
|
1360
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1361
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1362
|
-
cmd._executableFile = opts.executableFile || null;
|
|
1363
|
-
if (args) cmd.arguments(args);
|
|
1364
|
-
this._registerCommand(cmd);
|
|
1365
|
-
cmd.parent = this;
|
|
1366
|
-
cmd.copyInheritedSettings(this);
|
|
1367
|
-
if (desc) return this;
|
|
1368
|
-
return cmd;
|
|
976
|
+
let desc = actionOptsOrExecDesc, opts = execOpts;
|
|
977
|
+
typeof desc == "object" && desc !== null && (opts = desc, desc = null), opts = opts || {};
|
|
978
|
+
let [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/), cmd = this.createCommand(name);
|
|
979
|
+
return desc && (cmd.description(desc), cmd._executableHandler = !0), opts.isDefault && (this._defaultCommandName = cmd._name), cmd._hidden = !!(opts.noHelp || opts.hidden), cmd._executableFile = opts.executableFile || null, args && cmd.arguments(args), this._registerCommand(cmd), cmd.parent = this, cmd.copyInheritedSettings(this), desc ? this : cmd;
|
|
1369
980
|
}
|
|
1370
981
|
/**
|
|
1371
982
|
* Factory routine to create a new unattached command.
|
|
@@ -1396,9 +1007,7 @@ var require_command = __commonJS({
|
|
|
1396
1007
|
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1397
1008
|
*/
|
|
1398
1009
|
configureHelp(configuration) {
|
|
1399
|
-
|
|
1400
|
-
this._helpConfiguration = configuration;
|
|
1401
|
-
return this;
|
|
1010
|
+
return configuration === void 0 ? this._helpConfiguration : (this._helpConfiguration = configuration, this);
|
|
1402
1011
|
}
|
|
1403
1012
|
/**
|
|
1404
1013
|
* The default output goes to stdout and stderr. You can customise this for special
|
|
@@ -1423,12 +1032,10 @@ var require_command = __commonJS({
|
|
|
1423
1032
|
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1424
1033
|
*/
|
|
1425
1034
|
configureOutput(configuration) {
|
|
1426
|
-
|
|
1427
|
-
this._outputConfiguration = {
|
|
1035
|
+
return configuration === void 0 ? this._outputConfiguration : (this._outputConfiguration = {
|
|
1428
1036
|
...this._outputConfiguration,
|
|
1429
1037
|
...configuration
|
|
1430
|
-
};
|
|
1431
|
-
return this;
|
|
1038
|
+
}, this);
|
|
1432
1039
|
}
|
|
1433
1040
|
/**
|
|
1434
1041
|
* Display the help or a custom message after an error occurs.
|
|
@@ -1436,10 +1043,8 @@ var require_command = __commonJS({
|
|
|
1436
1043
|
* @param {(boolean|string)} [displayHelp]
|
|
1437
1044
|
* @return {Command} `this` command for chaining
|
|
1438
1045
|
*/
|
|
1439
|
-
showHelpAfterError(displayHelp =
|
|
1440
|
-
|
|
1441
|
-
this._showHelpAfterError = displayHelp;
|
|
1442
|
-
return this;
|
|
1046
|
+
showHelpAfterError(displayHelp = !0) {
|
|
1047
|
+
return typeof displayHelp != "string" && (displayHelp = !!displayHelp), this._showHelpAfterError = displayHelp, this;
|
|
1443
1048
|
}
|
|
1444
1049
|
/**
|
|
1445
1050
|
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
@@ -1447,9 +1052,8 @@ var require_command = __commonJS({
|
|
|
1447
1052
|
* @param {boolean} [displaySuggestion]
|
|
1448
1053
|
* @return {Command} `this` command for chaining
|
|
1449
1054
|
*/
|
|
1450
|
-
showSuggestionAfterError(displaySuggestion =
|
|
1451
|
-
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1452
|
-
return this;
|
|
1055
|
+
showSuggestionAfterError(displaySuggestion = !0) {
|
|
1056
|
+
return this._showSuggestionAfterError = !!displaySuggestion, this;
|
|
1453
1057
|
}
|
|
1454
1058
|
/**
|
|
1455
1059
|
* Add a prepared subcommand.
|
|
@@ -1461,17 +1065,10 @@ var require_command = __commonJS({
|
|
|
1461
1065
|
* @return {Command} `this` command for chaining
|
|
1462
1066
|
*/
|
|
1463
1067
|
addCommand(cmd, opts) {
|
|
1464
|
-
if (!cmd._name)
|
|
1068
|
+
if (!cmd._name)
|
|
1465
1069
|
throw new Error(`Command passed to .addCommand() must have a name
|
|
1466
1070
|
- specify the name in Command constructor or using .name()`);
|
|
1467
|
-
}
|
|
1468
|
-
opts = opts || {};
|
|
1469
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1470
|
-
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
1471
|
-
this._registerCommand(cmd);
|
|
1472
|
-
cmd.parent = this;
|
|
1473
|
-
cmd._checkForBrokenPassThrough();
|
|
1474
|
-
return this;
|
|
1071
|
+
return opts = opts || {}, opts.isDefault && (this._defaultCommandName = cmd._name), (opts.noHelp || opts.hidden) && (cmd._hidden = !0), this._registerCommand(cmd), cmd.parent = this, cmd._checkForBrokenPassThrough(), this;
|
|
1475
1072
|
}
|
|
1476
1073
|
/**
|
|
1477
1074
|
* Factory routine to create a new unattached argument.
|
|
@@ -1503,14 +1100,8 @@ var require_command = __commonJS({
|
|
|
1503
1100
|
* @return {Command} `this` command for chaining
|
|
1504
1101
|
*/
|
|
1505
1102
|
argument(name, description, parseArg, defaultValue) {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
argument.default(defaultValue).argParser(parseArg);
|
|
1509
|
-
} else {
|
|
1510
|
-
argument.default(parseArg);
|
|
1511
|
-
}
|
|
1512
|
-
this.addArgument(argument);
|
|
1513
|
-
return this;
|
|
1103
|
+
let argument = this.createArgument(name, description);
|
|
1104
|
+
return typeof parseArg == "function" ? argument.default(defaultValue).argParser(parseArg) : argument.default(parseArg), this.addArgument(argument), this;
|
|
1514
1105
|
}
|
|
1515
1106
|
/**
|
|
1516
1107
|
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
@@ -1524,10 +1115,9 @@ var require_command = __commonJS({
|
|
|
1524
1115
|
* @return {Command} `this` command for chaining
|
|
1525
1116
|
*/
|
|
1526
1117
|
arguments(names) {
|
|
1527
|
-
names.trim().split(/ +/).forEach((detail) => {
|
|
1118
|
+
return names.trim().split(/ +/).forEach((detail) => {
|
|
1528
1119
|
this.argument(detail);
|
|
1529
|
-
});
|
|
1530
|
-
return this;
|
|
1120
|
+
}), this;
|
|
1531
1121
|
}
|
|
1532
1122
|
/**
|
|
1533
1123
|
* Define argument syntax for command, adding a prepared argument.
|
|
@@ -1536,19 +1126,16 @@ var require_command = __commonJS({
|
|
|
1536
1126
|
* @return {Command} `this` command for chaining
|
|
1537
1127
|
*/
|
|
1538
1128
|
addArgument(argument) {
|
|
1539
|
-
|
|
1540
|
-
if (previousArgument?.variadic)
|
|
1129
|
+
let previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1130
|
+
if (previousArgument?.variadic)
|
|
1541
1131
|
throw new Error(
|
|
1542
1132
|
`only the last argument can be variadic '${previousArgument.name()}'`
|
|
1543
1133
|
);
|
|
1544
|
-
|
|
1545
|
-
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
1134
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0)
|
|
1546
1135
|
throw new Error(
|
|
1547
1136
|
`a default value for a required argument is never used: '${argument.name()}'`
|
|
1548
1137
|
);
|
|
1549
|
-
|
|
1550
|
-
this.registeredArguments.push(argument);
|
|
1551
|
-
return this;
|
|
1138
|
+
return this.registeredArguments.push(argument), this;
|
|
1552
1139
|
}
|
|
1553
1140
|
/**
|
|
1554
1141
|
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
@@ -1564,24 +1151,10 @@ var require_command = __commonJS({
|
|
|
1564
1151
|
* @return {Command} `this` command for chaining
|
|
1565
1152
|
*/
|
|
1566
1153
|
helpCommand(enableOrNameAndArgs, description) {
|
|
1567
|
-
if (typeof enableOrNameAndArgs
|
|
1568
|
-
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
}
|
|
1572
|
-
return this;
|
|
1573
|
-
}
|
|
1574
|
-
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1575
|
-
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1576
|
-
const helpDescription = description ?? "display help for command";
|
|
1577
|
-
const helpCommand = this.createCommand(helpName);
|
|
1578
|
-
helpCommand.helpOption(false);
|
|
1579
|
-
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
1580
|
-
if (helpDescription) helpCommand.description(helpDescription);
|
|
1581
|
-
this._addImplicitHelpCommand = true;
|
|
1582
|
-
this._helpCommand = helpCommand;
|
|
1583
|
-
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
1584
|
-
return this;
|
|
1154
|
+
if (typeof enableOrNameAndArgs == "boolean")
|
|
1155
|
+
return this._addImplicitHelpCommand = enableOrNameAndArgs, enableOrNameAndArgs && this._defaultCommandGroup && this._initCommandGroup(this._getHelpCommand()), this;
|
|
1156
|
+
let nameAndArgs = enableOrNameAndArgs ?? "help [command]", [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/), helpDescription = description ?? "display help for command", helpCommand = this.createCommand(helpName);
|
|
1157
|
+
return helpCommand.helpOption(!1), helpArgs && helpCommand.arguments(helpArgs), helpDescription && helpCommand.description(helpDescription), this._addImplicitHelpCommand = !0, this._helpCommand = helpCommand, (enableOrNameAndArgs || description) && this._initCommandGroup(helpCommand), this;
|
|
1585
1158
|
}
|
|
1586
1159
|
/**
|
|
1587
1160
|
* Add prepared custom help command.
|
|
@@ -1591,14 +1164,7 @@ var require_command = __commonJS({
|
|
|
1591
1164
|
* @return {Command} `this` command for chaining
|
|
1592
1165
|
*/
|
|
1593
1166
|
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1594
|
-
|
|
1595
|
-
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1596
|
-
return this;
|
|
1597
|
-
}
|
|
1598
|
-
this._addImplicitHelpCommand = true;
|
|
1599
|
-
this._helpCommand = helpCommand;
|
|
1600
|
-
this._initCommandGroup(helpCommand);
|
|
1601
|
-
return this;
|
|
1167
|
+
return typeof helpCommand != "object" ? (this.helpCommand(helpCommand, deprecatedDescription), this) : (this._addImplicitHelpCommand = !0, this._helpCommand = helpCommand, this._initCommandGroup(helpCommand), this);
|
|
1602
1168
|
}
|
|
1603
1169
|
/**
|
|
1604
1170
|
* Lazy create help command.
|
|
@@ -1607,14 +1173,7 @@ var require_command = __commonJS({
|
|
|
1607
1173
|
* @package
|
|
1608
1174
|
*/
|
|
1609
1175
|
_getHelpCommand() {
|
|
1610
|
-
|
|
1611
|
-
if (hasImplicitHelpCommand) {
|
|
1612
|
-
if (this._helpCommand === void 0) {
|
|
1613
|
-
this.helpCommand(void 0, void 0);
|
|
1614
|
-
}
|
|
1615
|
-
return this._helpCommand;
|
|
1616
|
-
}
|
|
1617
|
-
return null;
|
|
1176
|
+
return this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help")) ? (this._helpCommand === void 0 && this.helpCommand(void 0, void 0), this._helpCommand) : null;
|
|
1618
1177
|
}
|
|
1619
1178
|
/**
|
|
1620
1179
|
* Add hook for life cycle event.
|
|
@@ -1624,17 +1183,11 @@ var require_command = __commonJS({
|
|
|
1624
1183
|
* @return {Command} `this` command for chaining
|
|
1625
1184
|
*/
|
|
1626
1185
|
hook(event, listener) {
|
|
1627
|
-
|
|
1628
|
-
if (!allowedValues.includes(event))
|
|
1186
|
+
let allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1187
|
+
if (!allowedValues.includes(event))
|
|
1629
1188
|
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1630
1189
|
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1631
|
-
|
|
1632
|
-
if (this._lifeCycleHooks[event]) {
|
|
1633
|
-
this._lifeCycleHooks[event].push(listener);
|
|
1634
|
-
} else {
|
|
1635
|
-
this._lifeCycleHooks[event] = [listener];
|
|
1636
|
-
}
|
|
1637
|
-
return this;
|
|
1190
|
+
return this._lifeCycleHooks[event] ? this._lifeCycleHooks[event].push(listener) : this._lifeCycleHooks[event] = [listener], this;
|
|
1638
1191
|
}
|
|
1639
1192
|
/**
|
|
1640
1193
|
* Register callback to use as replacement for calling process.exit.
|
|
@@ -1643,17 +1196,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1643
1196
|
* @return {Command} `this` command for chaining
|
|
1644
1197
|
*/
|
|
1645
1198
|
exitOverride(fn) {
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1651
|
-
throw err;
|
|
1652
|
-
} else {
|
|
1653
|
-
}
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
return this;
|
|
1199
|
+
return fn ? this._exitCallback = fn : this._exitCallback = (err) => {
|
|
1200
|
+
if (err.code !== "commander.executeSubCommandAsync")
|
|
1201
|
+
throw err;
|
|
1202
|
+
}, this;
|
|
1657
1203
|
}
|
|
1658
1204
|
/**
|
|
1659
1205
|
* Call process.exit, and _exitCallback if defined.
|
|
@@ -1665,10 +1211,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1665
1211
|
* @private
|
|
1666
1212
|
*/
|
|
1667
1213
|
_exit(exitCode, code, message) {
|
|
1668
|
-
|
|
1669
|
-
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
1670
|
-
}
|
|
1671
|
-
process2.exit(exitCode);
|
|
1214
|
+
this._exitCallback && this._exitCallback(new CommanderError2(exitCode, code, message)), process2.exit(exitCode);
|
|
1672
1215
|
}
|
|
1673
1216
|
/**
|
|
1674
1217
|
* Register callback `fn` for the command.
|
|
@@ -1685,19 +1228,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1685
1228
|
* @return {Command} `this` command for chaining
|
|
1686
1229
|
*/
|
|
1687
1230
|
action(fn) {
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
} else {
|
|
1694
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
1695
|
-
}
|
|
1696
|
-
actionArgs.push(this);
|
|
1697
|
-
return fn.apply(this, actionArgs);
|
|
1698
|
-
}, "listener");
|
|
1699
|
-
this._actionHandler = listener;
|
|
1700
|
-
return this;
|
|
1231
|
+
let listener = (args) => {
|
|
1232
|
+
let expectedArgsCount = this.registeredArguments.length, actionArgs = args.slice(0, expectedArgsCount);
|
|
1233
|
+
return this._storeOptionsAsProperties ? actionArgs[expectedArgsCount] = this : actionArgs[expectedArgsCount] = this.opts(), actionArgs.push(this), fn.apply(this, actionArgs);
|
|
1234
|
+
};
|
|
1235
|
+
return this._actionHandler = listener, this;
|
|
1701
1236
|
}
|
|
1702
1237
|
/**
|
|
1703
1238
|
* Factory routine to create a new unattached option.
|
|
@@ -1726,7 +1261,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1726
1261
|
return target.parseArg(value, previous);
|
|
1727
1262
|
} catch (err) {
|
|
1728
1263
|
if (err.code === "commander.invalidArgument") {
|
|
1729
|
-
|
|
1264
|
+
let message = `${invalidArgumentMessage} ${err.message}`;
|
|
1730
1265
|
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1731
1266
|
}
|
|
1732
1267
|
throw err;
|
|
@@ -1740,14 +1275,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1740
1275
|
* @private
|
|
1741
1276
|
*/
|
|
1742
1277
|
_registerOption(option) {
|
|
1743
|
-
|
|
1278
|
+
let matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1744
1279
|
if (matchingOption) {
|
|
1745
|
-
|
|
1280
|
+
let matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1746
1281
|
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1747
1282
|
- already used by option '${matchingOption.flags}'`);
|
|
1748
1283
|
}
|
|
1749
|
-
this._initOptionGroup(option);
|
|
1750
|
-
this.options.push(option);
|
|
1284
|
+
this._initOptionGroup(option), this.options.push(option);
|
|
1751
1285
|
}
|
|
1752
1286
|
/**
|
|
1753
1287
|
* Check for command name and alias conflicts with existing commands.
|
|
@@ -1757,21 +1291,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1757
1291
|
* @private
|
|
1758
1292
|
*/
|
|
1759
1293
|
_registerCommand(command2) {
|
|
1760
|
-
|
|
1761
|
-
return [cmd.name()].concat(cmd.aliases());
|
|
1762
|
-
}, "knownBy");
|
|
1763
|
-
const alreadyUsed = knownBy(command2).find(
|
|
1294
|
+
let knownBy = (cmd) => [cmd.name()].concat(cmd.aliases()), alreadyUsed = knownBy(command2).find(
|
|
1764
1295
|
(name) => this._findCommand(name)
|
|
1765
1296
|
);
|
|
1766
1297
|
if (alreadyUsed) {
|
|
1767
|
-
|
|
1768
|
-
const newCmd = knownBy(command2).join("|");
|
|
1298
|
+
let existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|"), newCmd = knownBy(command2).join("|");
|
|
1769
1299
|
throw new Error(
|
|
1770
1300
|
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
1771
1301
|
);
|
|
1772
1302
|
}
|
|
1773
|
-
this._initCommandGroup(command2);
|
|
1774
|
-
this.commands.push(command2);
|
|
1303
|
+
this._initCommandGroup(command2), this.commands.push(command2);
|
|
1775
1304
|
}
|
|
1776
1305
|
/**
|
|
1777
1306
|
* Add an option.
|
|
@@ -1781,52 +1310,27 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1781
1310
|
*/
|
|
1782
1311
|
addOption(option) {
|
|
1783
1312
|
this._registerOption(option);
|
|
1784
|
-
|
|
1785
|
-
const name = option.attributeName();
|
|
1313
|
+
let oname = option.name(), name = option.attributeName();
|
|
1786
1314
|
if (option.negate) {
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
this.
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1802
|
-
const oldValue = this.getOptionValue(name);
|
|
1803
|
-
if (val !== null && option.parseArg) {
|
|
1804
|
-
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1805
|
-
} else if (val !== null && option.variadic) {
|
|
1806
|
-
val = option._collectValue(val, oldValue);
|
|
1807
|
-
}
|
|
1808
|
-
if (val == null) {
|
|
1809
|
-
if (option.negate) {
|
|
1810
|
-
val = false;
|
|
1811
|
-
} else if (option.isBoolean() || option.optional) {
|
|
1812
|
-
val = true;
|
|
1813
|
-
} else {
|
|
1814
|
-
val = "";
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
this.setOptionValueWithSource(name, val, valueSource);
|
|
1818
|
-
}, "handleOptionValue");
|
|
1819
|
-
this.on("option:" + oname, (val) => {
|
|
1820
|
-
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1315
|
+
let positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1316
|
+
this._findOption(positiveLongFlag) || this.setOptionValueWithSource(
|
|
1317
|
+
name,
|
|
1318
|
+
option.defaultValue === void 0 ? !0 : option.defaultValue,
|
|
1319
|
+
"default"
|
|
1320
|
+
);
|
|
1321
|
+
} else option.defaultValue !== void 0 && this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1322
|
+
let handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1323
|
+
val == null && option.presetArg !== void 0 && (val = option.presetArg);
|
|
1324
|
+
let oldValue = this.getOptionValue(name);
|
|
1325
|
+
val !== null && option.parseArg ? val = this._callParseArg(option, val, oldValue, invalidValueMessage) : val !== null && option.variadic && (val = option._collectValue(val, oldValue)), val == null && (option.negate ? val = !1 : option.isBoolean() || option.optional ? val = !0 : val = ""), this.setOptionValueWithSource(name, val, valueSource);
|
|
1326
|
+
};
|
|
1327
|
+
return this.on("option:" + oname, (val) => {
|
|
1328
|
+
let invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1821
1329
|
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1822
|
-
})
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
handleOptionValue(val, invalidValueMessage, "env");
|
|
1827
|
-
});
|
|
1828
|
-
}
|
|
1829
|
-
return this;
|
|
1330
|
+
}), option.envVar && this.on("optionEnv:" + oname, (val) => {
|
|
1331
|
+
let invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1332
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1333
|
+
}), this;
|
|
1830
1334
|
}
|
|
1831
1335
|
/**
|
|
1832
1336
|
* Internal implementation shared by .option() and .requiredOption()
|
|
@@ -1835,25 +1339,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1835
1339
|
* @private
|
|
1836
1340
|
*/
|
|
1837
1341
|
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1838
|
-
if (typeof flags
|
|
1342
|
+
if (typeof flags == "object" && flags instanceof Option2)
|
|
1839
1343
|
throw new Error(
|
|
1840
1344
|
"To add an Option object use addOption() instead of option() or requiredOption()"
|
|
1841
1345
|
);
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
1845
|
-
if (typeof fn === "function") {
|
|
1346
|
+
let option = this.createOption(flags, description);
|
|
1347
|
+
if (option.makeOptionMandatory(!!config.mandatory), typeof fn == "function")
|
|
1846
1348
|
option.default(defaultValue).argParser(fn);
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
fn =
|
|
1850
|
-
|
|
1349
|
+
else if (fn instanceof RegExp) {
|
|
1350
|
+
let regex = fn;
|
|
1351
|
+
fn = (val, def) => {
|
|
1352
|
+
let m = regex.exec(val);
|
|
1851
1353
|
return m ? m[0] : def;
|
|
1852
|
-
},
|
|
1853
|
-
|
|
1854
|
-
} else {
|
|
1354
|
+
}, option.default(defaultValue).argParser(fn);
|
|
1355
|
+
} else
|
|
1855
1356
|
option.default(fn);
|
|
1856
|
-
}
|
|
1857
1357
|
return this.addOption(option);
|
|
1858
1358
|
}
|
|
1859
1359
|
/**
|
|
@@ -1894,7 +1394,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1894
1394
|
*/
|
|
1895
1395
|
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1896
1396
|
return this._optionEx(
|
|
1897
|
-
{ mandatory:
|
|
1397
|
+
{ mandatory: !0 },
|
|
1898
1398
|
flags,
|
|
1899
1399
|
description,
|
|
1900
1400
|
parseArg,
|
|
@@ -1912,9 +1412,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1912
1412
|
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
1913
1413
|
* @return {Command} `this` command for chaining
|
|
1914
1414
|
*/
|
|
1915
|
-
combineFlagAndOptionalValue(combine =
|
|
1916
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
1917
|
-
return this;
|
|
1415
|
+
combineFlagAndOptionalValue(combine = !0) {
|
|
1416
|
+
return this._combineFlagAndOptionalValue = !!combine, this;
|
|
1918
1417
|
}
|
|
1919
1418
|
/**
|
|
1920
1419
|
* Allow unknown options on the command line.
|
|
@@ -1922,9 +1421,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1922
1421
|
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
1923
1422
|
* @return {Command} `this` command for chaining
|
|
1924
1423
|
*/
|
|
1925
|
-
allowUnknownOption(allowUnknown =
|
|
1926
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
1927
|
-
return this;
|
|
1424
|
+
allowUnknownOption(allowUnknown = !0) {
|
|
1425
|
+
return this._allowUnknownOption = !!allowUnknown, this;
|
|
1928
1426
|
}
|
|
1929
1427
|
/**
|
|
1930
1428
|
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
@@ -1932,9 +1430,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1932
1430
|
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
1933
1431
|
* @return {Command} `this` command for chaining
|
|
1934
1432
|
*/
|
|
1935
|
-
allowExcessArguments(allowExcess =
|
|
1936
|
-
this._allowExcessArguments = !!allowExcess;
|
|
1937
|
-
return this;
|
|
1433
|
+
allowExcessArguments(allowExcess = !0) {
|
|
1434
|
+
return this._allowExcessArguments = !!allowExcess, this;
|
|
1938
1435
|
}
|
|
1939
1436
|
/**
|
|
1940
1437
|
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
@@ -1944,9 +1441,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1944
1441
|
* @param {boolean} [positional]
|
|
1945
1442
|
* @return {Command} `this` command for chaining
|
|
1946
1443
|
*/
|
|
1947
|
-
enablePositionalOptions(positional =
|
|
1948
|
-
this._enablePositionalOptions = !!positional;
|
|
1949
|
-
return this;
|
|
1444
|
+
enablePositionalOptions(positional = !0) {
|
|
1445
|
+
return this._enablePositionalOptions = !!positional, this;
|
|
1950
1446
|
}
|
|
1951
1447
|
/**
|
|
1952
1448
|
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
@@ -1957,20 +1453,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1957
1453
|
* @param {boolean} [passThrough] for unknown options.
|
|
1958
1454
|
* @return {Command} `this` command for chaining
|
|
1959
1455
|
*/
|
|
1960
|
-
passThroughOptions(passThrough =
|
|
1961
|
-
this._passThroughOptions = !!passThrough;
|
|
1962
|
-
this._checkForBrokenPassThrough();
|
|
1963
|
-
return this;
|
|
1456
|
+
passThroughOptions(passThrough = !0) {
|
|
1457
|
+
return this._passThroughOptions = !!passThrough, this._checkForBrokenPassThrough(), this;
|
|
1964
1458
|
}
|
|
1965
1459
|
/**
|
|
1966
1460
|
* @private
|
|
1967
1461
|
*/
|
|
1968
1462
|
_checkForBrokenPassThrough() {
|
|
1969
|
-
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions)
|
|
1463
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions)
|
|
1970
1464
|
throw new Error(
|
|
1971
1465
|
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
|
|
1972
1466
|
);
|
|
1973
|
-
}
|
|
1974
1467
|
}
|
|
1975
1468
|
/**
|
|
1976
1469
|
* Whether to store option values as properties on command object,
|
|
@@ -1979,17 +1472,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1979
1472
|
* @param {boolean} [storeAsProperties=true]
|
|
1980
1473
|
* @return {Command} `this` command for chaining
|
|
1981
1474
|
*/
|
|
1982
|
-
storeOptionsAsProperties(storeAsProperties =
|
|
1983
|
-
if (this.options.length)
|
|
1475
|
+
storeOptionsAsProperties(storeAsProperties = !0) {
|
|
1476
|
+
if (this.options.length)
|
|
1984
1477
|
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1985
|
-
|
|
1986
|
-
if (Object.keys(this._optionValues).length) {
|
|
1478
|
+
if (Object.keys(this._optionValues).length)
|
|
1987
1479
|
throw new Error(
|
|
1988
1480
|
"call .storeOptionsAsProperties() before setting option values"
|
|
1989
1481
|
);
|
|
1990
|
-
|
|
1991
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1992
|
-
return this;
|
|
1482
|
+
return this._storeOptionsAsProperties = !!storeAsProperties, this;
|
|
1993
1483
|
}
|
|
1994
1484
|
/**
|
|
1995
1485
|
* Retrieve option value.
|
|
@@ -1998,10 +1488,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1998
1488
|
* @return {object} value
|
|
1999
1489
|
*/
|
|
2000
1490
|
getOptionValue(key) {
|
|
2001
|
-
|
|
2002
|
-
return this[key];
|
|
2003
|
-
}
|
|
2004
|
-
return this._optionValues[key];
|
|
1491
|
+
return this._storeOptionsAsProperties ? this[key] : this._optionValues[key];
|
|
2005
1492
|
}
|
|
2006
1493
|
/**
|
|
2007
1494
|
* Store option value.
|
|
@@ -2022,13 +1509,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2022
1509
|
* @return {Command} `this` command for chaining
|
|
2023
1510
|
*/
|
|
2024
1511
|
setOptionValueWithSource(key, value, source) {
|
|
2025
|
-
|
|
2026
|
-
this[key] = value;
|
|
2027
|
-
} else {
|
|
2028
|
-
this._optionValues[key] = value;
|
|
2029
|
-
}
|
|
2030
|
-
this._optionValueSources[key] = source;
|
|
2031
|
-
return this;
|
|
1512
|
+
return this._storeOptionsAsProperties ? this[key] = value : this._optionValues[key] = value, this._optionValueSources[key] = source, this;
|
|
2032
1513
|
}
|
|
2033
1514
|
/**
|
|
2034
1515
|
* Get source of option value.
|
|
@@ -2049,12 +1530,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2049
1530
|
*/
|
|
2050
1531
|
getOptionValueSourceWithGlobals(key) {
|
|
2051
1532
|
let source;
|
|
2052
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
}
|
|
2056
|
-
});
|
|
2057
|
-
return source;
|
|
1533
|
+
return this._getCommandAndAncestors().forEach((cmd) => {
|
|
1534
|
+
cmd.getOptionValueSource(key) !== void 0 && (source = cmd.getOptionValueSource(key));
|
|
1535
|
+
}), source;
|
|
2058
1536
|
}
|
|
2059
1537
|
/**
|
|
2060
1538
|
* Get user arguments from implied or explicit arguments.
|
|
@@ -2063,37 +1541,22 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2063
1541
|
* @private
|
|
2064
1542
|
*/
|
|
2065
1543
|
_prepareUserArgs(argv, parseOptions) {
|
|
2066
|
-
if (argv !== void 0 && !Array.isArray(argv))
|
|
1544
|
+
if (argv !== void 0 && !Array.isArray(argv))
|
|
2067
1545
|
throw new Error("first parameter to parse must be array or undefined");
|
|
1546
|
+
if (parseOptions = parseOptions || {}, argv === void 0 && parseOptions.from === void 0) {
|
|
1547
|
+
process2.versions?.electron && (parseOptions.from = "electron");
|
|
1548
|
+
let execArgv = process2.execArgv ?? [];
|
|
1549
|
+
(execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) && (parseOptions.from = "eval");
|
|
2068
1550
|
}
|
|
2069
|
-
|
|
2070
|
-
if (argv === void 0 && parseOptions.from === void 0) {
|
|
2071
|
-
if (process2.versions?.electron) {
|
|
2072
|
-
parseOptions.from = "electron";
|
|
2073
|
-
}
|
|
2074
|
-
const execArgv = process2.execArgv ?? [];
|
|
2075
|
-
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
2076
|
-
parseOptions.from = "eval";
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
if (argv === void 0) {
|
|
2080
|
-
argv = process2.argv;
|
|
2081
|
-
}
|
|
2082
|
-
this.rawArgs = argv.slice();
|
|
1551
|
+
argv === void 0 && (argv = process2.argv), this.rawArgs = argv.slice();
|
|
2083
1552
|
let userArgs;
|
|
2084
1553
|
switch (parseOptions.from) {
|
|
2085
1554
|
case void 0:
|
|
2086
1555
|
case "node":
|
|
2087
|
-
this._scriptPath = argv[1];
|
|
2088
|
-
userArgs = argv.slice(2);
|
|
1556
|
+
this._scriptPath = argv[1], userArgs = argv.slice(2);
|
|
2089
1557
|
break;
|
|
2090
1558
|
case "electron":
|
|
2091
|
-
|
|
2092
|
-
this._scriptPath = argv[1];
|
|
2093
|
-
userArgs = argv.slice(2);
|
|
2094
|
-
} else {
|
|
2095
|
-
userArgs = argv.slice(1);
|
|
2096
|
-
}
|
|
1559
|
+
process2.defaultApp ? (this._scriptPath = argv[1], userArgs = argv.slice(2)) : userArgs = argv.slice(1);
|
|
2097
1560
|
break;
|
|
2098
1561
|
case "user":
|
|
2099
1562
|
userArgs = argv.slice(0);
|
|
@@ -2106,10 +1569,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2106
1569
|
`unexpected parse option { from: '${parseOptions.from}' }`
|
|
2107
1570
|
);
|
|
2108
1571
|
}
|
|
2109
|
-
|
|
2110
|
-
this.nameFromFilename(this._scriptPath);
|
|
2111
|
-
this._name = this._name || "program";
|
|
2112
|
-
return userArgs;
|
|
1572
|
+
return !this._name && this._scriptPath && this.nameFromFilename(this._scriptPath), this._name = this._name || "program", userArgs;
|
|
2113
1573
|
}
|
|
2114
1574
|
/**
|
|
2115
1575
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
@@ -2135,9 +1595,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2135
1595
|
*/
|
|
2136
1596
|
parse(argv, parseOptions) {
|
|
2137
1597
|
this._prepareForParse();
|
|
2138
|
-
|
|
2139
|
-
this._parseCommand([], userArgs);
|
|
2140
|
-
return this;
|
|
1598
|
+
let userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1599
|
+
return this._parseCommand([], userArgs), this;
|
|
2141
1600
|
}
|
|
2142
1601
|
/**
|
|
2143
1602
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
@@ -2161,16 +1620,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2161
1620
|
*/
|
|
2162
1621
|
async parseAsync(argv, parseOptions) {
|
|
2163
1622
|
this._prepareForParse();
|
|
2164
|
-
|
|
2165
|
-
await this._parseCommand([], userArgs);
|
|
2166
|
-
return this;
|
|
1623
|
+
let userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1624
|
+
return await this._parseCommand([], userArgs), this;
|
|
2167
1625
|
}
|
|
2168
1626
|
_prepareForParse() {
|
|
2169
|
-
|
|
2170
|
-
this.saveStateBeforeParse();
|
|
2171
|
-
} else {
|
|
2172
|
-
this.restoreStateBeforeParse();
|
|
2173
|
-
}
|
|
1627
|
+
this._savedState === null ? this.saveStateBeforeParse() : this.restoreStateBeforeParse();
|
|
2174
1628
|
}
|
|
2175
1629
|
/**
|
|
2176
1630
|
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
@@ -2198,13 +1652,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2198
1652
|
if (this._storeOptionsAsProperties)
|
|
2199
1653
|
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
2200
1654
|
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
2201
|
-
this._name = this._savedState._name;
|
|
2202
|
-
this._scriptPath = null;
|
|
2203
|
-
this.rawArgs = [];
|
|
2204
|
-
this._optionValues = { ...this._savedState._optionValues };
|
|
2205
|
-
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
2206
|
-
this.args = [];
|
|
2207
|
-
this.processedArgs = [];
|
|
1655
|
+
this._name = this._savedState._name, this._scriptPath = null, this.rawArgs = [], this._optionValues = { ...this._savedState._optionValues }, this._optionValueSources = { ...this._savedState._optionValueSources }, this.args = [], this.processedArgs = [];
|
|
2208
1656
|
}
|
|
2209
1657
|
/**
|
|
2210
1658
|
* Throw if expected executable is missing. Add lots of help for author.
|
|
@@ -2215,8 +1663,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2215
1663
|
*/
|
|
2216
1664
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2217
1665
|
if (fs.existsSync(executableFile)) return;
|
|
2218
|
-
|
|
2219
|
-
const executableMissing = `'${executableFile}' does not exist
|
|
1666
|
+
let executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory", executableMissing = `'${executableFile}' does not exist
|
|
2220
1667
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2221
1668
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2222
1669
|
- ${executableDirMessage}`;
|
|
@@ -2229,23 +1676,18 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2229
1676
|
*/
|
|
2230
1677
|
_executeSubCommand(subcommand, args) {
|
|
2231
1678
|
args = args.slice();
|
|
2232
|
-
let launchWithNode =
|
|
2233
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1679
|
+
let launchWithNode = !1, sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2234
1680
|
function findFile(baseDir, baseName) {
|
|
2235
|
-
|
|
1681
|
+
let localBin = path.resolve(baseDir, baseName);
|
|
2236
1682
|
if (fs.existsSync(localBin)) return localBin;
|
|
2237
|
-
if (sourceExt.includes(path.extname(baseName))) return
|
|
2238
|
-
|
|
1683
|
+
if (sourceExt.includes(path.extname(baseName))) return;
|
|
1684
|
+
let foundExt = sourceExt.find(
|
|
2239
1685
|
(ext) => fs.existsSync(`${localBin}${ext}`)
|
|
2240
1686
|
);
|
|
2241
1687
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2242
|
-
return void 0;
|
|
2243
1688
|
}
|
|
2244
|
-
|
|
2245
|
-
this.
|
|
2246
|
-
this._checkForConflictingOptions();
|
|
2247
|
-
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
2248
|
-
let executableDir = this._executableDir || "";
|
|
1689
|
+
this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
|
|
1690
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`, executableDir = this._executableDir || "";
|
|
2249
1691
|
if (this._scriptPath) {
|
|
2250
1692
|
let resolvedScriptPath;
|
|
2251
1693
|
try {
|
|
@@ -2261,109 +1703,75 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2261
1703
|
if (executableDir) {
|
|
2262
1704
|
let localFile = findFile(executableDir, executableFile);
|
|
2263
1705
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2264
|
-
|
|
1706
|
+
let legacyName = path.basename(
|
|
2265
1707
|
this._scriptPath,
|
|
2266
1708
|
path.extname(this._scriptPath)
|
|
2267
1709
|
);
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
);
|
|
2273
|
-
}
|
|
1710
|
+
legacyName !== this._name && (localFile = findFile(
|
|
1711
|
+
executableDir,
|
|
1712
|
+
`${legacyName}-${subcommand._name}`
|
|
1713
|
+
));
|
|
2274
1714
|
}
|
|
2275
1715
|
executableFile = localFile || executableFile;
|
|
2276
1716
|
}
|
|
2277
1717
|
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
2278
1718
|
let proc;
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
proc
|
|
2286
|
-
}
|
|
2287
|
-
} else {
|
|
2288
|
-
this._checkForMissingExecutable(
|
|
2289
|
-
executableFile,
|
|
2290
|
-
executableDir,
|
|
2291
|
-
subcommand._name
|
|
2292
|
-
);
|
|
2293
|
-
args.unshift(executableFile);
|
|
2294
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2295
|
-
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
2296
|
-
}
|
|
2297
|
-
if (!proc.killed) {
|
|
2298
|
-
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2299
|
-
signals.forEach((signal) => {
|
|
2300
|
-
process2.on(signal, () => {
|
|
2301
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
2302
|
-
proc.kill(signal);
|
|
2303
|
-
}
|
|
2304
|
-
});
|
|
1719
|
+
process2.platform !== "win32" ? launchWithNode ? (args.unshift(executableFile), args = incrementNodeInspectorPort(process2.execArgv).concat(args), proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" })) : proc = childProcess.spawn(executableFile, args, { stdio: "inherit" }) : (this._checkForMissingExecutable(
|
|
1720
|
+
executableFile,
|
|
1721
|
+
executableDir,
|
|
1722
|
+
subcommand._name
|
|
1723
|
+
), args.unshift(executableFile), args = incrementNodeInspectorPort(process2.execArgv).concat(args), proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" })), proc.killed || ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"].forEach((signal) => {
|
|
1724
|
+
process2.on(signal, () => {
|
|
1725
|
+
proc.killed === !1 && proc.exitCode === null && proc.kill(signal);
|
|
2305
1726
|
});
|
|
2306
|
-
}
|
|
2307
|
-
const exitCallback = this._exitCallback;
|
|
2308
|
-
proc.on("close", (code) => {
|
|
2309
|
-
code = code ?? 1;
|
|
2310
|
-
if (!exitCallback) {
|
|
2311
|
-
process2.exit(code);
|
|
2312
|
-
} else {
|
|
2313
|
-
exitCallback(
|
|
2314
|
-
new CommanderError2(
|
|
2315
|
-
code,
|
|
2316
|
-
"commander.executeSubCommandAsync",
|
|
2317
|
-
"(close)"
|
|
2318
|
-
)
|
|
2319
|
-
);
|
|
2320
|
-
}
|
|
2321
1727
|
});
|
|
2322
|
-
|
|
2323
|
-
|
|
1728
|
+
let exitCallback = this._exitCallback;
|
|
1729
|
+
proc.on("close", (code) => {
|
|
1730
|
+
code = code ?? 1, exitCallback ? exitCallback(
|
|
1731
|
+
new CommanderError2(
|
|
1732
|
+
code,
|
|
1733
|
+
"commander.executeSubCommandAsync",
|
|
1734
|
+
"(close)"
|
|
1735
|
+
)
|
|
1736
|
+
) : process2.exit(code);
|
|
1737
|
+
}), proc.on("error", (err) => {
|
|
1738
|
+
if (err.code === "ENOENT")
|
|
2324
1739
|
this._checkForMissingExecutable(
|
|
2325
1740
|
executableFile,
|
|
2326
1741
|
executableDir,
|
|
2327
1742
|
subcommand._name
|
|
2328
1743
|
);
|
|
2329
|
-
|
|
1744
|
+
else if (err.code === "EACCES")
|
|
2330
1745
|
throw new Error(`'${executableFile}' not executable`);
|
|
2331
|
-
|
|
2332
|
-
if (!exitCallback) {
|
|
1746
|
+
if (!exitCallback)
|
|
2333
1747
|
process2.exit(1);
|
|
2334
|
-
|
|
2335
|
-
|
|
1748
|
+
else {
|
|
1749
|
+
let wrappedError = new CommanderError2(
|
|
2336
1750
|
1,
|
|
2337
1751
|
"commander.executeSubCommandAsync",
|
|
2338
1752
|
"(error)"
|
|
2339
1753
|
);
|
|
2340
|
-
wrappedError.nestedError = err;
|
|
2341
|
-
exitCallback(wrappedError);
|
|
1754
|
+
wrappedError.nestedError = err, exitCallback(wrappedError);
|
|
2342
1755
|
}
|
|
2343
|
-
});
|
|
2344
|
-
this.runningCommand = proc;
|
|
1756
|
+
}), this.runningCommand = proc;
|
|
2345
1757
|
}
|
|
2346
1758
|
/**
|
|
2347
1759
|
* @private
|
|
2348
1760
|
*/
|
|
2349
1761
|
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
subCommand._prepareForParse();
|
|
1762
|
+
let subCommand = this._findCommand(commandName);
|
|
1763
|
+
subCommand || this.help({ error: !0 }), subCommand._prepareForParse();
|
|
2353
1764
|
let promiseChain;
|
|
2354
|
-
promiseChain = this._chainOrCallSubCommandHook(
|
|
1765
|
+
return promiseChain = this._chainOrCallSubCommandHook(
|
|
2355
1766
|
promiseChain,
|
|
2356
1767
|
subCommand,
|
|
2357
1768
|
"preSubcommand"
|
|
2358
|
-
)
|
|
2359
|
-
|
|
2360
|
-
if (subCommand._executableHandler) {
|
|
1769
|
+
), promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1770
|
+
if (subCommand._executableHandler)
|
|
2361
1771
|
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2362
|
-
|
|
1772
|
+
else
|
|
2363
1773
|
return subCommand._parseCommand(operands, unknown);
|
|
2364
|
-
|
|
2365
|
-
});
|
|
2366
|
-
return promiseChain;
|
|
1774
|
+
}), promiseChain;
|
|
2367
1775
|
}
|
|
2368
1776
|
/**
|
|
2369
1777
|
* Invoke help directly if possible, or dispatch if necessary.
|
|
@@ -2372,14 +1780,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2372
1780
|
* @private
|
|
2373
1781
|
*/
|
|
2374
1782
|
_dispatchHelpCommand(subcommandName) {
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
const subCommand = this._findCommand(subcommandName);
|
|
2379
|
-
if (subCommand && !subCommand._executableHandler) {
|
|
2380
|
-
subCommand.help();
|
|
2381
|
-
}
|
|
2382
|
-
return this._dispatchSubcommand(
|
|
1783
|
+
subcommandName || this.help();
|
|
1784
|
+
let subCommand = this._findCommand(subcommandName);
|
|
1785
|
+
return subCommand && !subCommand._executableHandler && subCommand.help(), this._dispatchSubcommand(
|
|
2383
1786
|
subcommandName,
|
|
2384
1787
|
[],
|
|
2385
1788
|
[this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
|
|
@@ -2392,16 +1795,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2392
1795
|
*/
|
|
2393
1796
|
_checkNumberOfArguments() {
|
|
2394
1797
|
this.registeredArguments.forEach((arg, i) => {
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
}
|
|
2398
|
-
});
|
|
2399
|
-
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2400
|
-
return;
|
|
2401
|
-
}
|
|
2402
|
-
if (this.args.length > this.registeredArguments.length) {
|
|
2403
|
-
this._excessArguments(this.args);
|
|
2404
|
-
}
|
|
1798
|
+
arg.required && this.args[i] == null && this.missingArgument(arg.name());
|
|
1799
|
+
}), !(this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) && this.args.length > this.registeredArguments.length && this._excessArguments(this.args);
|
|
2405
1800
|
}
|
|
2406
1801
|
/**
|
|
2407
1802
|
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
@@ -2409,10 +1804,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2409
1804
|
* @private
|
|
2410
1805
|
*/
|
|
2411
1806
|
_processArguments() {
|
|
2412
|
-
|
|
1807
|
+
let myParseArg = (argument, value, previous) => {
|
|
2413
1808
|
let parsedValue = value;
|
|
2414
1809
|
if (value !== null && argument.parseArg) {
|
|
2415
|
-
|
|
1810
|
+
let invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2416
1811
|
parsedValue = this._callParseArg(
|
|
2417
1812
|
argument,
|
|
2418
1813
|
value,
|
|
@@ -2421,31 +1816,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2421
1816
|
);
|
|
2422
1817
|
}
|
|
2423
1818
|
return parsedValue;
|
|
2424
|
-
}
|
|
1819
|
+
};
|
|
2425
1820
|
this._checkNumberOfArguments();
|
|
2426
|
-
|
|
1821
|
+
let processedArgs = [];
|
|
2427
1822
|
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2428
1823
|
let value = declaredArg.defaultValue;
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
value = this.args.slice(index);
|
|
2432
|
-
if (declaredArg.parseArg) {
|
|
2433
|
-
value = value.reduce((processed, v) => {
|
|
2434
|
-
return myParseArg(declaredArg, v, processed);
|
|
2435
|
-
}, declaredArg.defaultValue);
|
|
2436
|
-
}
|
|
2437
|
-
} else if (value === void 0) {
|
|
2438
|
-
value = [];
|
|
2439
|
-
}
|
|
2440
|
-
} else if (index < this.args.length) {
|
|
2441
|
-
value = this.args[index];
|
|
2442
|
-
if (declaredArg.parseArg) {
|
|
2443
|
-
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
processedArgs[index] = value;
|
|
2447
|
-
});
|
|
2448
|
-
this.processedArgs = processedArgs;
|
|
1824
|
+
declaredArg.variadic ? index < this.args.length ? (value = this.args.slice(index), declaredArg.parseArg && (value = value.reduce((processed, v) => myParseArg(declaredArg, v, processed), declaredArg.defaultValue))) : value === void 0 && (value = []) : index < this.args.length && (value = this.args[index], declaredArg.parseArg && (value = myParseArg(declaredArg, value, declaredArg.defaultValue))), processedArgs[index] = value;
|
|
1825
|
+
}), this.processedArgs = processedArgs;
|
|
2449
1826
|
}
|
|
2450
1827
|
/**
|
|
2451
1828
|
* Once we have a promise we chain, but call synchronously until then.
|
|
@@ -2456,10 +1833,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2456
1833
|
* @private
|
|
2457
1834
|
*/
|
|
2458
1835
|
_chainOrCall(promise, fn) {
|
|
2459
|
-
|
|
2460
|
-
return promise.then(() => fn());
|
|
2461
|
-
}
|
|
2462
|
-
return fn();
|
|
1836
|
+
return promise?.then && typeof promise.then == "function" ? promise.then(() => fn()) : fn();
|
|
2463
1837
|
}
|
|
2464
1838
|
/**
|
|
2465
1839
|
*
|
|
@@ -2469,22 +1843,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2469
1843
|
* @private
|
|
2470
1844
|
*/
|
|
2471
1845
|
_chainOrCallHooks(promise, event) {
|
|
2472
|
-
let result = promise;
|
|
2473
|
-
|
|
2474
|
-
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
1846
|
+
let result = promise, hooks = [];
|
|
1847
|
+
return this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
2475
1848
|
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2476
1849
|
hooks.push({ hookedCommand, callback });
|
|
2477
1850
|
});
|
|
2478
|
-
})
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
hooks.forEach((hookDetail) => {
|
|
2483
|
-
result = this._chainOrCall(result, () => {
|
|
2484
|
-
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2485
|
-
});
|
|
2486
|
-
});
|
|
2487
|
-
return result;
|
|
1851
|
+
}), event === "postAction" && hooks.reverse(), hooks.forEach((hookDetail) => {
|
|
1852
|
+
result = this._chainOrCall(result, () => hookDetail.callback(hookDetail.hookedCommand, this));
|
|
1853
|
+
}), result;
|
|
2488
1854
|
}
|
|
2489
1855
|
/**
|
|
2490
1856
|
*
|
|
@@ -2496,14 +1862,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2496
1862
|
*/
|
|
2497
1863
|
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2498
1864
|
let result = promise;
|
|
2499
|
-
|
|
2500
|
-
this.
|
|
2501
|
-
|
|
2502
|
-
return hook(this, subCommand);
|
|
2503
|
-
});
|
|
2504
|
-
});
|
|
2505
|
-
}
|
|
2506
|
-
return result;
|
|
1865
|
+
return this._lifeCycleHooks[event] !== void 0 && this._lifeCycleHooks[event].forEach((hook) => {
|
|
1866
|
+
result = this._chainOrCall(result, () => hook(this, subCommand));
|
|
1867
|
+
}), result;
|
|
2507
1868
|
}
|
|
2508
1869
|
/**
|
|
2509
1870
|
* Process arguments in context of this command.
|
|
@@ -2512,78 +1873,38 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2512
1873
|
* @private
|
|
2513
1874
|
*/
|
|
2514
1875
|
_parseCommand(operands, unknown) {
|
|
2515
|
-
|
|
2516
|
-
this._parseOptionsEnv()
|
|
2517
|
-
this._parseOptionsImplied();
|
|
2518
|
-
operands = operands.concat(parsed.operands);
|
|
2519
|
-
unknown = parsed.unknown;
|
|
2520
|
-
this.args = operands.concat(unknown);
|
|
2521
|
-
if (operands && this._findCommand(operands[0])) {
|
|
1876
|
+
let parsed = this.parseOptions(unknown);
|
|
1877
|
+
if (this._parseOptionsEnv(), this._parseOptionsImplied(), operands = operands.concat(parsed.operands), unknown = parsed.unknown, this.args = operands.concat(unknown), operands && this._findCommand(operands[0]))
|
|
2522
1878
|
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2523
|
-
|
|
2524
|
-
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1879
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name())
|
|
2525
1880
|
return this._dispatchHelpCommand(operands[1]);
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
this._outputHelpIfRequested(unknown);
|
|
2529
|
-
return this._dispatchSubcommand(
|
|
1881
|
+
if (this._defaultCommandName)
|
|
1882
|
+
return this._outputHelpIfRequested(unknown), this._dispatchSubcommand(
|
|
2530
1883
|
this._defaultCommandName,
|
|
2531
1884
|
operands,
|
|
2532
1885
|
unknown
|
|
2533
1886
|
);
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
}
|
|
2538
|
-
this._outputHelpIfRequested(parsed.unknown);
|
|
2539
|
-
this._checkForMissingMandatoryOptions();
|
|
2540
|
-
this._checkForConflictingOptions();
|
|
2541
|
-
const checkForUnknownOptions = /* @__PURE__ */ __name(() => {
|
|
2542
|
-
if (parsed.unknown.length > 0) {
|
|
2543
|
-
this.unknownOption(parsed.unknown[0]);
|
|
2544
|
-
}
|
|
2545
|
-
}, "checkForUnknownOptions");
|
|
2546
|
-
const commandEvent = `command:${this.name()}`;
|
|
1887
|
+
this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName && this.help({ error: !0 }), this._outputHelpIfRequested(parsed.unknown), this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
|
|
1888
|
+
let checkForUnknownOptions = () => {
|
|
1889
|
+
parsed.unknown.length > 0 && this.unknownOption(parsed.unknown[0]);
|
|
1890
|
+
}, commandEvent = `command:${this.name()}`;
|
|
2547
1891
|
if (this._actionHandler) {
|
|
2548
|
-
checkForUnknownOptions();
|
|
2549
|
-
this._processArguments();
|
|
1892
|
+
checkForUnknownOptions(), this._processArguments();
|
|
2550
1893
|
let promiseChain;
|
|
2551
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "preAction")
|
|
2552
|
-
promiseChain = this._chainOrCall(
|
|
1894
|
+
return promiseChain = this._chainOrCallHooks(promiseChain, "preAction"), promiseChain = this._chainOrCall(
|
|
2553
1895
|
promiseChain,
|
|
2554
1896
|
() => this._actionHandler(this.processedArgs)
|
|
2555
|
-
)
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
}
|
|
2564
|
-
if (this.parent?.listenerCount(commandEvent)) {
|
|
2565
|
-
checkForUnknownOptions();
|
|
2566
|
-
this._processArguments();
|
|
2567
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
2568
|
-
} else if (operands.length) {
|
|
2569
|
-
if (this._findCommand("*")) {
|
|
1897
|
+
), this.parent && (promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1898
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1899
|
+
})), promiseChain = this._chainOrCallHooks(promiseChain, "postAction"), promiseChain;
|
|
1900
|
+
}
|
|
1901
|
+
if (this.parent?.listenerCount(commandEvent))
|
|
1902
|
+
checkForUnknownOptions(), this._processArguments(), this.parent.emit(commandEvent, operands, unknown);
|
|
1903
|
+
else if (operands.length) {
|
|
1904
|
+
if (this._findCommand("*"))
|
|
2570
1905
|
return this._dispatchSubcommand("*", operands, unknown);
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
this.emit("command:*", operands, unknown);
|
|
2574
|
-
} else if (this.commands.length) {
|
|
2575
|
-
this.unknownCommand();
|
|
2576
|
-
} else {
|
|
2577
|
-
checkForUnknownOptions();
|
|
2578
|
-
this._processArguments();
|
|
2579
|
-
}
|
|
2580
|
-
} else if (this.commands.length) {
|
|
2581
|
-
checkForUnknownOptions();
|
|
2582
|
-
this.help({ error: true });
|
|
2583
|
-
} else {
|
|
2584
|
-
checkForUnknownOptions();
|
|
2585
|
-
this._processArguments();
|
|
2586
|
-
}
|
|
1906
|
+
this.listenerCount("command:*") ? this.emit("command:*", operands, unknown) : this.commands.length ? this.unknownCommand() : (checkForUnknownOptions(), this._processArguments());
|
|
1907
|
+
} else this.commands.length ? (checkForUnknownOptions(), this.help({ error: !0 })) : (checkForUnknownOptions(), this._processArguments());
|
|
2587
1908
|
}
|
|
2588
1909
|
/**
|
|
2589
1910
|
* Find matching command.
|
|
@@ -2592,10 +1913,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2592
1913
|
* @return {Command | undefined}
|
|
2593
1914
|
*/
|
|
2594
1915
|
_findCommand(name) {
|
|
2595
|
-
if (
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
1916
|
+
if (name)
|
|
1917
|
+
return this.commands.find(
|
|
1918
|
+
(cmd) => cmd._name === name || cmd._aliases.includes(name)
|
|
1919
|
+
);
|
|
2599
1920
|
}
|
|
2600
1921
|
/**
|
|
2601
1922
|
* Return an option matching `arg` if any.
|
|
@@ -2616,9 +1937,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2616
1937
|
_checkForMissingMandatoryOptions() {
|
|
2617
1938
|
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2618
1939
|
cmd.options.forEach((anOption) => {
|
|
2619
|
-
|
|
2620
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
2621
|
-
}
|
|
1940
|
+
anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0 && cmd.missingMandatoryOptionValue(anOption);
|
|
2622
1941
|
});
|
|
2623
1942
|
});
|
|
2624
1943
|
}
|
|
@@ -2628,23 +1947,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2628
1947
|
* @private
|
|
2629
1948
|
*/
|
|
2630
1949
|
_checkForConflictingLocalOptions() {
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
return false;
|
|
2635
|
-
}
|
|
2636
|
-
return this.getOptionValueSource(optionKey) !== "default";
|
|
1950
|
+
let definedNonDefaultOptions = this.options.filter((option) => {
|
|
1951
|
+
let optionKey = option.attributeName();
|
|
1952
|
+
return this.getOptionValue(optionKey) === void 0 ? !1 : this.getOptionValueSource(optionKey) !== "default";
|
|
2637
1953
|
});
|
|
2638
|
-
|
|
1954
|
+
definedNonDefaultOptions.filter(
|
|
2639
1955
|
(option) => option.conflictsWith.length > 0
|
|
2640
|
-
)
|
|
2641
|
-
|
|
2642
|
-
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
1956
|
+
).forEach((option) => {
|
|
1957
|
+
let conflictingAndDefined = definedNonDefaultOptions.find(
|
|
2643
1958
|
(defined) => option.conflictsWith.includes(defined.attributeName())
|
|
2644
1959
|
);
|
|
2645
|
-
|
|
2646
|
-
this._conflictingOption(option, conflictingAndDefined);
|
|
2647
|
-
}
|
|
1960
|
+
conflictingAndDefined && this._conflictingOption(option, conflictingAndDefined);
|
|
2648
1961
|
});
|
|
2649
1962
|
}
|
|
2650
1963
|
/**
|
|
@@ -2676,82 +1989,55 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2676
1989
|
* @return {{operands: string[], unknown: string[]}}
|
|
2677
1990
|
*/
|
|
2678
1991
|
parseOptions(args) {
|
|
2679
|
-
|
|
2680
|
-
const unknown = [];
|
|
2681
|
-
let dest = operands;
|
|
1992
|
+
let operands = [], unknown = [], dest = operands;
|
|
2682
1993
|
function maybeOption(arg) {
|
|
2683
1994
|
return arg.length > 1 && arg[0] === "-";
|
|
2684
1995
|
}
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
)
|
|
2691
|
-
|
|
2692
|
-
let activeVariadicOption = null;
|
|
2693
|
-
let activeGroup = null;
|
|
2694
|
-
let i = 0;
|
|
2695
|
-
while (i < args.length || activeGroup) {
|
|
2696
|
-
const arg = activeGroup ?? args[i++];
|
|
2697
|
-
activeGroup = null;
|
|
2698
|
-
if (arg === "--") {
|
|
2699
|
-
if (dest === unknown) dest.push(arg);
|
|
2700
|
-
dest.push(...args.slice(i));
|
|
1996
|
+
let negativeNumberArg = (arg) => /^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg) ? !this._getCommandAndAncestors().some(
|
|
1997
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
1998
|
+
) : !1, activeVariadicOption = null, activeGroup = null, i = 0;
|
|
1999
|
+
for (; i < args.length || activeGroup; ) {
|
|
2000
|
+
let arg = activeGroup ?? args[i++];
|
|
2001
|
+
if (activeGroup = null, arg === "--") {
|
|
2002
|
+
dest === unknown && dest.push(arg), dest.push(...args.slice(i));
|
|
2701
2003
|
break;
|
|
2702
2004
|
}
|
|
2703
2005
|
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2704
2006
|
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2705
2007
|
continue;
|
|
2706
2008
|
}
|
|
2707
|
-
activeVariadicOption = null
|
|
2708
|
-
|
|
2709
|
-
const option = this._findOption(arg);
|
|
2009
|
+
if (activeVariadicOption = null, maybeOption(arg)) {
|
|
2010
|
+
let option = this._findOption(arg);
|
|
2710
2011
|
if (option) {
|
|
2711
2012
|
if (option.required) {
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
this.emit(`option:${option.name()}`, value);
|
|
2013
|
+
let value = args[i++];
|
|
2014
|
+
value === void 0 && this.optionMissingArgument(option), this.emit(`option:${option.name()}`, value);
|
|
2715
2015
|
} else if (option.optional) {
|
|
2716
2016
|
let value = null;
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
}
|
|
2720
|
-
this.emit(`option:${option.name()}`, value);
|
|
2721
|
-
} else {
|
|
2017
|
+
i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i])) && (value = args[i++]), this.emit(`option:${option.name()}`, value);
|
|
2018
|
+
} else
|
|
2722
2019
|
this.emit(`option:${option.name()}`);
|
|
2723
|
-
}
|
|
2724
2020
|
activeVariadicOption = option.variadic ? option : null;
|
|
2725
2021
|
continue;
|
|
2726
2022
|
}
|
|
2727
2023
|
}
|
|
2728
2024
|
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
2729
|
-
|
|
2025
|
+
let option = this._findOption(`-${arg[1]}`);
|
|
2730
2026
|
if (option) {
|
|
2731
|
-
|
|
2732
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2733
|
-
} else {
|
|
2734
|
-
this.emit(`option:${option.name()}`);
|
|
2735
|
-
activeGroup = `-${arg.slice(2)}`;
|
|
2736
|
-
}
|
|
2027
|
+
option.required || option.optional && this._combineFlagAndOptionalValue ? this.emit(`option:${option.name()}`, arg.slice(2)) : (this.emit(`option:${option.name()}`), activeGroup = `-${arg.slice(2)}`);
|
|
2737
2028
|
continue;
|
|
2738
2029
|
}
|
|
2739
2030
|
}
|
|
2740
2031
|
if (/^--[^=]+=/.test(arg)) {
|
|
2741
|
-
|
|
2742
|
-
const option = this._findOption(arg.slice(0, index));
|
|
2032
|
+
let index = arg.indexOf("="), option = this._findOption(arg.slice(0, index));
|
|
2743
2033
|
if (option && (option.required || option.optional)) {
|
|
2744
2034
|
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
2745
2035
|
continue;
|
|
2746
2036
|
}
|
|
2747
2037
|
}
|
|
2748
|
-
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
2749
|
-
dest = unknown;
|
|
2750
|
-
}
|
|
2751
|
-
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2038
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg)) && (dest = unknown), (this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2752
2039
|
if (this._findCommand(arg)) {
|
|
2753
|
-
operands.push(arg);
|
|
2754
|
-
unknown.push(...args.slice(i));
|
|
2040
|
+
operands.push(arg), unknown.push(...args.slice(i));
|
|
2755
2041
|
break;
|
|
2756
2042
|
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2757
2043
|
operands.push(arg, ...args.slice(i));
|
|
@@ -2776,10 +2062,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2776
2062
|
*/
|
|
2777
2063
|
opts() {
|
|
2778
2064
|
if (this._storeOptionsAsProperties) {
|
|
2779
|
-
|
|
2780
|
-
const len = this.options.length;
|
|
2065
|
+
let result = {}, len = this.options.length;
|
|
2781
2066
|
for (let i = 0; i < len; i++) {
|
|
2782
|
-
|
|
2067
|
+
let key = this.options[i].attributeName();
|
|
2783
2068
|
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
2784
2069
|
}
|
|
2785
2070
|
return result;
|
|
@@ -2810,17 +2095,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2810
2095
|
`${message}
|
|
2811
2096
|
`,
|
|
2812
2097
|
this._outputConfiguration.writeErr
|
|
2813
|
-
)
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
} else if (this._showHelpAfterError) {
|
|
2818
|
-
this._outputConfiguration.writeErr("\n");
|
|
2819
|
-
this.outputHelp({ error: true });
|
|
2820
|
-
}
|
|
2821
|
-
const config = errorOptions || {};
|
|
2822
|
-
const exitCode = config.exitCode || 1;
|
|
2823
|
-
const code = config.code || "commander.error";
|
|
2098
|
+
), typeof this._showHelpAfterError == "string" ? this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
2099
|
+
`) : this._showHelpAfterError && (this._outputConfiguration.writeErr(`
|
|
2100
|
+
`), this.outputHelp({ error: !0 }));
|
|
2101
|
+
let config = errorOptions || {}, exitCode = config.exitCode || 1, code = config.code || "commander.error";
|
|
2824
2102
|
this._exit(exitCode, code, message);
|
|
2825
2103
|
}
|
|
2826
2104
|
/**
|
|
@@ -2832,16 +2110,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2832
2110
|
_parseOptionsEnv() {
|
|
2833
2111
|
this.options.forEach((option) => {
|
|
2834
2112
|
if (option.envVar && option.envVar in process2.env) {
|
|
2835
|
-
|
|
2836
|
-
|
|
2113
|
+
let optionKey = option.attributeName();
|
|
2114
|
+
(this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
2837
2115
|
this.getOptionValueSource(optionKey)
|
|
2838
|
-
)) {
|
|
2839
|
-
if (option.required || option.optional) {
|
|
2840
|
-
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
2841
|
-
} else {
|
|
2842
|
-
this.emit(`optionEnv:${option.name()}`);
|
|
2843
|
-
}
|
|
2844
|
-
}
|
|
2116
|
+
)) && (option.required || option.optional ? this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]) : this.emit(`optionEnv:${option.name()}`));
|
|
2845
2117
|
}
|
|
2846
2118
|
});
|
|
2847
2119
|
}
|
|
@@ -2851,10 +2123,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2851
2123
|
* @private
|
|
2852
2124
|
*/
|
|
2853
2125
|
_parseOptionsImplied() {
|
|
2854
|
-
|
|
2855
|
-
const hasCustomOptionValue = /* @__PURE__ */ __name((optionKey) => {
|
|
2856
|
-
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2857
|
-
}, "hasCustomOptionValue");
|
|
2126
|
+
let dualHelper = new DualOptions(this.options), hasCustomOptionValue = (optionKey) => this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2858
2127
|
this.options.filter(
|
|
2859
2128
|
(option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(
|
|
2860
2129
|
this.getOptionValue(option.attributeName()),
|
|
@@ -2877,7 +2146,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2877
2146
|
* @private
|
|
2878
2147
|
*/
|
|
2879
2148
|
missingArgument(name) {
|
|
2880
|
-
|
|
2149
|
+
let message = `error: missing required argument '${name}'`;
|
|
2881
2150
|
this.error(message, { code: "commander.missingArgument" });
|
|
2882
2151
|
}
|
|
2883
2152
|
/**
|
|
@@ -2887,7 +2156,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2887
2156
|
* @private
|
|
2888
2157
|
*/
|
|
2889
2158
|
optionMissingArgument(option) {
|
|
2890
|
-
|
|
2159
|
+
let message = `error: option '${option.flags}' argument missing`;
|
|
2891
2160
|
this.error(message, { code: "commander.optionMissingArgument" });
|
|
2892
2161
|
}
|
|
2893
2162
|
/**
|
|
@@ -2897,7 +2166,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2897
2166
|
* @private
|
|
2898
2167
|
*/
|
|
2899
2168
|
missingMandatoryOptionValue(option) {
|
|
2900
|
-
|
|
2169
|
+
let message = `error: required option '${option.flags}' not specified`;
|
|
2901
2170
|
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
2902
2171
|
}
|
|
2903
2172
|
/**
|
|
@@ -2908,30 +2177,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2908
2177
|
* @private
|
|
2909
2178
|
*/
|
|
2910
2179
|
_conflictingOption(option, conflictingOption) {
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
const optionValue = this.getOptionValue(optionKey);
|
|
2914
|
-
const negativeOption = this.options.find(
|
|
2180
|
+
let findBestOptionFromValue = (option2) => {
|
|
2181
|
+
let optionKey = option2.attributeName(), optionValue = this.getOptionValue(optionKey), negativeOption = this.options.find(
|
|
2915
2182
|
(target) => target.negate && optionKey === target.attributeName()
|
|
2916
|
-
)
|
|
2917
|
-
const positiveOption = this.options.find(
|
|
2183
|
+
), positiveOption = this.options.find(
|
|
2918
2184
|
(target) => !target.negate && optionKey === target.attributeName()
|
|
2919
2185
|
);
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
return
|
|
2924
|
-
},
|
|
2925
|
-
const getErrorMessage = /* @__PURE__ */ __name((option2) => {
|
|
2926
|
-
const bestOption = findBestOptionFromValue(option2);
|
|
2927
|
-
const optionKey = bestOption.attributeName();
|
|
2928
|
-
const source = this.getOptionValueSource(optionKey);
|
|
2929
|
-
if (source === "env") {
|
|
2930
|
-
return `environment variable '${bestOption.envVar}'`;
|
|
2931
|
-
}
|
|
2932
|
-
return `option '${bestOption.flags}'`;
|
|
2933
|
-
}, "getErrorMessage");
|
|
2934
|
-
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2186
|
+
return negativeOption && (negativeOption.presetArg === void 0 && optionValue === !1 || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg) ? negativeOption : positiveOption || option2;
|
|
2187
|
+
}, getErrorMessage = (option2) => {
|
|
2188
|
+
let bestOption = findBestOptionFromValue(option2), optionKey = bestOption.attributeName();
|
|
2189
|
+
return this.getOptionValueSource(optionKey) === "env" ? `environment variable '${bestOption.envVar}'` : `option '${bestOption.flags}'`;
|
|
2190
|
+
}, message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2935
2191
|
this.error(message, { code: "commander.conflictingOption" });
|
|
2936
2192
|
}
|
|
2937
2193
|
/**
|
|
@@ -2944,16 +2200,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2944
2200
|
if (this._allowUnknownOption) return;
|
|
2945
2201
|
let suggestion = "";
|
|
2946
2202
|
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2947
|
-
let candidateFlags = [];
|
|
2948
|
-
let command2 = this;
|
|
2203
|
+
let candidateFlags = [], command2 = this;
|
|
2949
2204
|
do {
|
|
2950
|
-
|
|
2951
|
-
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2952
|
-
command2 = command2.parent;
|
|
2205
|
+
let moreFlags = command2.createHelp().visibleOptions(command2).filter((option) => option.long).map((option) => option.long);
|
|
2206
|
+
candidateFlags = candidateFlags.concat(moreFlags), command2 = command2.parent;
|
|
2953
2207
|
} while (command2 && !command2._enablePositionalOptions);
|
|
2954
2208
|
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2955
2209
|
}
|
|
2956
|
-
|
|
2210
|
+
let message = `error: unknown option '${flag}'${suggestion}`;
|
|
2957
2211
|
this.error(message, { code: "commander.unknownOption" });
|
|
2958
2212
|
}
|
|
2959
2213
|
/**
|
|
@@ -2964,10 +2218,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2964
2218
|
*/
|
|
2965
2219
|
_excessArguments(receivedArgs) {
|
|
2966
2220
|
if (this._allowExcessArguments) return;
|
|
2967
|
-
|
|
2968
|
-
const s = expected === 1 ? "" : "s";
|
|
2969
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
2970
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2221
|
+
let expected = this.registeredArguments.length, s = expected === 1 ? "" : "s", message = `error: too many arguments${this.parent ? ` for '${this.name()}'` : ""}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2971
2222
|
this.error(message, { code: "commander.excessArguments" });
|
|
2972
2223
|
}
|
|
2973
2224
|
/**
|
|
@@ -2976,17 +2227,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2976
2227
|
* @private
|
|
2977
2228
|
*/
|
|
2978
2229
|
unknownCommand() {
|
|
2979
|
-
|
|
2980
|
-
let suggestion = "";
|
|
2230
|
+
let unknownName = this.args[0], suggestion = "";
|
|
2981
2231
|
if (this._showSuggestionAfterError) {
|
|
2982
|
-
|
|
2232
|
+
let candidateNames = [];
|
|
2983
2233
|
this.createHelp().visibleCommands(this).forEach((command2) => {
|
|
2984
|
-
candidateNames.push(command2.name());
|
|
2985
|
-
|
|
2986
|
-
});
|
|
2987
|
-
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2234
|
+
candidateNames.push(command2.name()), command2.alias() && candidateNames.push(command2.alias());
|
|
2235
|
+
}), suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2988
2236
|
}
|
|
2989
|
-
|
|
2237
|
+
let message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2990
2238
|
this.error(message, { code: "commander.unknownCommand" });
|
|
2991
2239
|
}
|
|
2992
2240
|
/**
|
|
@@ -3003,18 +2251,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3003
2251
|
*/
|
|
3004
2252
|
version(str, flags, description) {
|
|
3005
2253
|
if (str === void 0) return this._version;
|
|
3006
|
-
this._version = str;
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
const versionOption = this.createOption(flags, description);
|
|
3010
|
-
this._versionOptionName = versionOption.attributeName();
|
|
3011
|
-
this._registerOption(versionOption);
|
|
3012
|
-
this.on("option:" + versionOption.name(), () => {
|
|
2254
|
+
this._version = str, flags = flags || "-V, --version", description = description || "output the version number";
|
|
2255
|
+
let versionOption = this.createOption(flags, description);
|
|
2256
|
+
return this._versionOptionName = versionOption.attributeName(), this._registerOption(versionOption), this.on("option:" + versionOption.name(), () => {
|
|
3013
2257
|
this._outputConfiguration.writeOut(`${str}
|
|
3014
|
-
`);
|
|
3015
|
-
|
|
3016
|
-
});
|
|
3017
|
-
return this;
|
|
2258
|
+
`), this._exit(0, "commander.version", str);
|
|
2259
|
+
}), this;
|
|
3018
2260
|
}
|
|
3019
2261
|
/**
|
|
3020
2262
|
* Set the description.
|
|
@@ -3024,13 +2266,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3024
2266
|
* @return {(string|Command)}
|
|
3025
2267
|
*/
|
|
3026
2268
|
description(str, argsDescription) {
|
|
3027
|
-
|
|
3028
|
-
return this._description;
|
|
3029
|
-
this._description = str;
|
|
3030
|
-
if (argsDescription) {
|
|
3031
|
-
this._argsDescription = argsDescription;
|
|
3032
|
-
}
|
|
3033
|
-
return this;
|
|
2269
|
+
return str === void 0 && argsDescription === void 0 ? this._description : (this._description = str, argsDescription && (this._argsDescription = argsDescription), this);
|
|
3034
2270
|
}
|
|
3035
2271
|
/**
|
|
3036
2272
|
* Set the summary. Used when listed as subcommand of parent.
|
|
@@ -3039,9 +2275,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3039
2275
|
* @return {(string|Command)}
|
|
3040
2276
|
*/
|
|
3041
2277
|
summary(str) {
|
|
3042
|
-
|
|
3043
|
-
this._summary = str;
|
|
3044
|
-
return this;
|
|
2278
|
+
return str === void 0 ? this._summary : (this._summary = str, this);
|
|
3045
2279
|
}
|
|
3046
2280
|
/**
|
|
3047
2281
|
* Set an alias for the command.
|
|
@@ -3054,20 +2288,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3054
2288
|
alias(alias) {
|
|
3055
2289
|
if (alias === void 0) return this._aliases[0];
|
|
3056
2290
|
let command2 = this;
|
|
3057
|
-
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler)
|
|
3058
|
-
command2 = this.commands[this.commands.length - 1];
|
|
3059
|
-
}
|
|
3060
|
-
if (alias === command2._name)
|
|
2291
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler && (command2 = this.commands[this.commands.length - 1]), alias === command2._name)
|
|
3061
2292
|
throw new Error("Command alias can't be the same as its name");
|
|
3062
|
-
|
|
2293
|
+
let matchingCommand = this.parent?._findCommand(alias);
|
|
3063
2294
|
if (matchingCommand) {
|
|
3064
|
-
|
|
2295
|
+
let existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
3065
2296
|
throw new Error(
|
|
3066
2297
|
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`
|
|
3067
2298
|
);
|
|
3068
2299
|
}
|
|
3069
|
-
command2._aliases.push(alias);
|
|
3070
|
-
return this;
|
|
2300
|
+
return command2._aliases.push(alias), this;
|
|
3071
2301
|
}
|
|
3072
2302
|
/**
|
|
3073
2303
|
* Set aliases for the command.
|
|
@@ -3078,9 +2308,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3078
2308
|
* @return {(string[]|Command)}
|
|
3079
2309
|
*/
|
|
3080
2310
|
aliases(aliases) {
|
|
3081
|
-
|
|
3082
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
3083
|
-
return this;
|
|
2311
|
+
return aliases === void 0 ? this._aliases : (aliases.forEach((alias) => this.alias(alias)), this);
|
|
3084
2312
|
}
|
|
3085
2313
|
/**
|
|
3086
2314
|
* Set / get the command usage `str`.
|
|
@@ -3091,17 +2319,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3091
2319
|
usage(str) {
|
|
3092
2320
|
if (str === void 0) {
|
|
3093
2321
|
if (this._usage) return this._usage;
|
|
3094
|
-
|
|
3095
|
-
return humanReadableArgName(arg);
|
|
3096
|
-
});
|
|
2322
|
+
let args = this.registeredArguments.map((arg) => humanReadableArgName(arg));
|
|
3097
2323
|
return [].concat(
|
|
3098
2324
|
this.options.length || this._helpOption !== null ? "[options]" : [],
|
|
3099
2325
|
this.commands.length ? "[command]" : [],
|
|
3100
2326
|
this.registeredArguments.length ? args : []
|
|
3101
2327
|
).join(" ");
|
|
3102
2328
|
}
|
|
3103
|
-
this._usage = str;
|
|
3104
|
-
return this;
|
|
2329
|
+
return this._usage = str, this;
|
|
3105
2330
|
}
|
|
3106
2331
|
/**
|
|
3107
2332
|
* Get or set the name of the command.
|
|
@@ -3110,9 +2335,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3110
2335
|
* @return {(string|Command)}
|
|
3111
2336
|
*/
|
|
3112
2337
|
name(str) {
|
|
3113
|
-
|
|
3114
|
-
this._name = str;
|
|
3115
|
-
return this;
|
|
2338
|
+
return str === void 0 ? this._name : (this._name = str, this);
|
|
3116
2339
|
}
|
|
3117
2340
|
/**
|
|
3118
2341
|
* Set/get the help group heading for this subcommand in parent command's help.
|
|
@@ -3121,9 +2344,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3121
2344
|
* @return {Command | string}
|
|
3122
2345
|
*/
|
|
3123
2346
|
helpGroup(heading) {
|
|
3124
|
-
|
|
3125
|
-
this._helpGroupHeading = heading;
|
|
3126
|
-
return this;
|
|
2347
|
+
return heading === void 0 ? this._helpGroupHeading ?? "" : (this._helpGroupHeading = heading, this);
|
|
3127
2348
|
}
|
|
3128
2349
|
/**
|
|
3129
2350
|
* Set/get the default help group heading for subcommands added to this command.
|
|
@@ -3139,9 +2360,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3139
2360
|
* @returns {Command | string}
|
|
3140
2361
|
*/
|
|
3141
2362
|
commandsGroup(heading) {
|
|
3142
|
-
|
|
3143
|
-
this._defaultCommandGroup = heading;
|
|
3144
|
-
return this;
|
|
2363
|
+
return heading === void 0 ? this._defaultCommandGroup ?? "" : (this._defaultCommandGroup = heading, this);
|
|
3145
2364
|
}
|
|
3146
2365
|
/**
|
|
3147
2366
|
* Set/get the default help group heading for options added to this command.
|
|
@@ -3157,25 +2376,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3157
2376
|
* @returns {Command | string}
|
|
3158
2377
|
*/
|
|
3159
2378
|
optionsGroup(heading) {
|
|
3160
|
-
|
|
3161
|
-
this._defaultOptionGroup = heading;
|
|
3162
|
-
return this;
|
|
2379
|
+
return heading === void 0 ? this._defaultOptionGroup ?? "" : (this._defaultOptionGroup = heading, this);
|
|
3163
2380
|
}
|
|
3164
2381
|
/**
|
|
3165
2382
|
* @param {Option} option
|
|
3166
2383
|
* @private
|
|
3167
2384
|
*/
|
|
3168
2385
|
_initOptionGroup(option) {
|
|
3169
|
-
|
|
3170
|
-
option.helpGroup(this._defaultOptionGroup);
|
|
2386
|
+
this._defaultOptionGroup && !option.helpGroupHeading && option.helpGroup(this._defaultOptionGroup);
|
|
3171
2387
|
}
|
|
3172
2388
|
/**
|
|
3173
2389
|
* @param {Command} cmd
|
|
3174
2390
|
* @private
|
|
3175
2391
|
*/
|
|
3176
2392
|
_initCommandGroup(cmd) {
|
|
3177
|
-
|
|
3178
|
-
cmd.helpGroup(this._defaultCommandGroup);
|
|
2393
|
+
this._defaultCommandGroup && !cmd.helpGroup() && cmd.helpGroup(this._defaultCommandGroup);
|
|
3179
2394
|
}
|
|
3180
2395
|
/**
|
|
3181
2396
|
* Set the name of the command from script filename, such as process.argv[1],
|
|
@@ -3190,8 +2405,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3190
2405
|
* @return {Command}
|
|
3191
2406
|
*/
|
|
3192
2407
|
nameFromFilename(filename) {
|
|
3193
|
-
this._name = path.basename(filename, path.extname(filename));
|
|
3194
|
-
return this;
|
|
2408
|
+
return this._name = path.basename(filename, path.extname(filename)), this;
|
|
3195
2409
|
}
|
|
3196
2410
|
/**
|
|
3197
2411
|
* Get or set the directory for searching for executable subcommands of this command.
|
|
@@ -3205,9 +2419,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3205
2419
|
* @return {(string|null|Command)}
|
|
3206
2420
|
*/
|
|
3207
2421
|
executableDir(path2) {
|
|
3208
|
-
|
|
3209
|
-
this._executableDir = path2;
|
|
3210
|
-
return this;
|
|
2422
|
+
return path2 === void 0 ? this._executableDir : (this._executableDir = path2, this);
|
|
3211
2423
|
}
|
|
3212
2424
|
/**
|
|
3213
2425
|
* Return program help documentation.
|
|
@@ -3216,16 +2428,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3216
2428
|
* @return {string}
|
|
3217
2429
|
*/
|
|
3218
2430
|
helpInformation(contextOptions) {
|
|
3219
|
-
|
|
3220
|
-
const context = this._getOutputContext(contextOptions);
|
|
2431
|
+
let helper = this.createHelp(), context = this._getOutputContext(contextOptions);
|
|
3221
2432
|
helper.prepareContext({
|
|
3222
2433
|
error: context.error,
|
|
3223
2434
|
helpWidth: context.helpWidth,
|
|
3224
2435
|
outputHasColors: context.hasColors
|
|
3225
2436
|
});
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
return this._outputConfiguration.stripColor(text);
|
|
2437
|
+
let text = helper.formatHelp(this, helper);
|
|
2438
|
+
return context.hasColors ? text : this._outputConfiguration.stripColor(text);
|
|
3229
2439
|
}
|
|
3230
2440
|
/**
|
|
3231
2441
|
* @typedef HelpContext
|
|
@@ -3240,24 +2450,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3240
2450
|
*/
|
|
3241
2451
|
_getOutputContext(contextOptions) {
|
|
3242
2452
|
contextOptions = contextOptions || {};
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
let hasColors;
|
|
3246
|
-
let helpWidth;
|
|
3247
|
-
if (error) {
|
|
3248
|
-
baseWrite = /* @__PURE__ */ __name((str) => this._outputConfiguration.writeErr(str), "baseWrite");
|
|
3249
|
-
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3250
|
-
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
3251
|
-
} else {
|
|
3252
|
-
baseWrite = /* @__PURE__ */ __name((str) => this._outputConfiguration.writeOut(str), "baseWrite");
|
|
3253
|
-
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3254
|
-
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
3255
|
-
}
|
|
3256
|
-
const write = /* @__PURE__ */ __name((str) => {
|
|
3257
|
-
if (!hasColors) str = this._outputConfiguration.stripColor(str);
|
|
3258
|
-
return baseWrite(str);
|
|
3259
|
-
}, "write");
|
|
3260
|
-
return { error, write, hasColors, helpWidth };
|
|
2453
|
+
let error = !!contextOptions.error, baseWrite, hasColors, helpWidth;
|
|
2454
|
+
return error ? (baseWrite = (str) => this._outputConfiguration.writeErr(str), hasColors = this._outputConfiguration.getErrHasColors(), helpWidth = this._outputConfiguration.getErrHelpWidth()) : (baseWrite = (str) => this._outputConfiguration.writeOut(str), hasColors = this._outputConfiguration.getOutHasColors(), helpWidth = this._outputConfiguration.getOutHelpWidth()), { error, write: (str) => (hasColors || (str = this._outputConfiguration.stripColor(str)), baseWrite(str)), hasColors, helpWidth };
|
|
3261
2455
|
}
|
|
3262
2456
|
/**
|
|
3263
2457
|
* Output help information for this command.
|
|
@@ -3268,31 +2462,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3268
2462
|
*/
|
|
3269
2463
|
outputHelp(contextOptions) {
|
|
3270
2464
|
let deprecatedCallback;
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
contextOptions = void 0;
|
|
3274
|
-
}
|
|
3275
|
-
const outputContext = this._getOutputContext(contextOptions);
|
|
3276
|
-
const eventContext = {
|
|
2465
|
+
typeof contextOptions == "function" && (deprecatedCallback = contextOptions, contextOptions = void 0);
|
|
2466
|
+
let outputContext = this._getOutputContext(contextOptions), eventContext = {
|
|
3277
2467
|
error: outputContext.error,
|
|
3278
2468
|
write: outputContext.write,
|
|
3279
2469
|
command: this
|
|
3280
2470
|
};
|
|
3281
|
-
this._getCommandAndAncestors().reverse().forEach((command2) => command2.emit("beforeAllHelp", eventContext));
|
|
3282
|
-
this.emit("beforeHelp", eventContext);
|
|
2471
|
+
this._getCommandAndAncestors().reverse().forEach((command2) => command2.emit("beforeAllHelp", eventContext)), this.emit("beforeHelp", eventContext);
|
|
3283
2472
|
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
3284
|
-
if (deprecatedCallback)
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
outputContext.write(helpInformation);
|
|
3291
|
-
if (this._getHelpOption()?.long) {
|
|
3292
|
-
this.emit(this._getHelpOption().long);
|
|
3293
|
-
}
|
|
3294
|
-
this.emit("afterHelp", eventContext);
|
|
3295
|
-
this._getCommandAndAncestors().forEach(
|
|
2473
|
+
if (deprecatedCallback && (helpInformation = deprecatedCallback(helpInformation), typeof helpInformation != "string" && !Buffer.isBuffer(helpInformation)))
|
|
2474
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2475
|
+
outputContext.write(helpInformation), this._getHelpOption()?.long && this.emit(this._getHelpOption().long), this.emit("afterHelp", eventContext), this._getCommandAndAncestors().forEach(
|
|
3296
2476
|
(command2) => command2.emit("afterAllHelp", eventContext)
|
|
3297
2477
|
);
|
|
3298
2478
|
}
|
|
@@ -3309,23 +2489,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3309
2489
|
* @return {Command} `this` command for chaining
|
|
3310
2490
|
*/
|
|
3311
2491
|
helpOption(flags, description) {
|
|
3312
|
-
|
|
3313
|
-
if (flags) {
|
|
3314
|
-
if (this._helpOption === null) this._helpOption = void 0;
|
|
3315
|
-
if (this._defaultOptionGroup) {
|
|
3316
|
-
this._initOptionGroup(this._getHelpOption());
|
|
3317
|
-
}
|
|
3318
|
-
} else {
|
|
3319
|
-
this._helpOption = null;
|
|
3320
|
-
}
|
|
3321
|
-
return this;
|
|
3322
|
-
}
|
|
3323
|
-
this._helpOption = this.createOption(
|
|
2492
|
+
return typeof flags == "boolean" ? (flags ? (this._helpOption === null && (this._helpOption = void 0), this._defaultOptionGroup && this._initOptionGroup(this._getHelpOption())) : this._helpOption = null, this) : (this._helpOption = this.createOption(
|
|
3324
2493
|
flags ?? "-h, --help",
|
|
3325
2494
|
description ?? "display help for command"
|
|
3326
|
-
);
|
|
3327
|
-
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
3328
|
-
return this;
|
|
2495
|
+
), (flags || description) && this._initOptionGroup(this._helpOption), this);
|
|
3329
2496
|
}
|
|
3330
2497
|
/**
|
|
3331
2498
|
* Lazy create help option.
|
|
@@ -3335,10 +2502,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3335
2502
|
* @package
|
|
3336
2503
|
*/
|
|
3337
2504
|
_getHelpOption() {
|
|
3338
|
-
|
|
3339
|
-
this.helpOption(void 0, void 0);
|
|
3340
|
-
}
|
|
3341
|
-
return this._helpOption;
|
|
2505
|
+
return this._helpOption === void 0 && this.helpOption(void 0, void 0), this._helpOption;
|
|
3342
2506
|
}
|
|
3343
2507
|
/**
|
|
3344
2508
|
* Supply your own option to use for the built-in help option.
|
|
@@ -3348,9 +2512,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3348
2512
|
* @return {Command} `this` command for chaining
|
|
3349
2513
|
*/
|
|
3350
2514
|
addHelpOption(option) {
|
|
3351
|
-
this._helpOption = option;
|
|
3352
|
-
this._initOptionGroup(option);
|
|
3353
|
-
return this;
|
|
2515
|
+
return this._helpOption = option, this._initOptionGroup(option), this;
|
|
3354
2516
|
}
|
|
3355
2517
|
/**
|
|
3356
2518
|
* Output help information and exit.
|
|
@@ -3362,10 +2524,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3362
2524
|
help(contextOptions) {
|
|
3363
2525
|
this.outputHelp(contextOptions);
|
|
3364
2526
|
let exitCode = Number(process2.exitCode ?? 0);
|
|
3365
|
-
|
|
3366
|
-
exitCode = 1;
|
|
3367
|
-
}
|
|
3368
|
-
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2527
|
+
exitCode === 0 && contextOptions && typeof contextOptions != "function" && contextOptions.error && (exitCode = 1), this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
3369
2528
|
}
|
|
3370
2529
|
/**
|
|
3371
2530
|
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
@@ -3386,25 +2545,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3386
2545
|
* @return {Command} `this` command for chaining
|
|
3387
2546
|
*/
|
|
3388
2547
|
addHelpText(position, text) {
|
|
3389
|
-
|
|
3390
|
-
if (!allowedValues.includes(position))
|
|
2548
|
+
let allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2549
|
+
if (!allowedValues.includes(position))
|
|
3391
2550
|
throw new Error(`Unexpected value for position to addHelpText.
|
|
3392
2551
|
Expecting one of '${allowedValues.join("', '")}'`);
|
|
3393
|
-
}
|
|
3394
|
-
|
|
3395
|
-
this.on(helpEvent, (context) => {
|
|
2552
|
+
let helpEvent = `${position}Help`;
|
|
2553
|
+
return this.on(helpEvent, (context) => {
|
|
3396
2554
|
let helpStr;
|
|
3397
|
-
|
|
3398
|
-
helpStr = text({ error: context.error, command: context.command });
|
|
3399
|
-
} else {
|
|
3400
|
-
helpStr = text;
|
|
3401
|
-
}
|
|
3402
|
-
if (helpStr) {
|
|
3403
|
-
context.write(`${helpStr}
|
|
2555
|
+
typeof text == "function" ? helpStr = text({ error: context.error, command: context.command }) : helpStr = text, helpStr && context.write(`${helpStr}
|
|
3404
2556
|
`);
|
|
3405
|
-
|
|
3406
|
-
});
|
|
3407
|
-
return this;
|
|
2557
|
+
}), this;
|
|
3408
2558
|
}
|
|
3409
2559
|
/**
|
|
3410
2560
|
* Output help information if help flags specified
|
|
@@ -3413,52 +2563,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3413
2563
|
* @private
|
|
3414
2564
|
*/
|
|
3415
2565
|
_outputHelpIfRequested(args) {
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
if (helpRequested) {
|
|
3419
|
-
this.outputHelp();
|
|
3420
|
-
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
3421
|
-
}
|
|
2566
|
+
let helpOption = this._getHelpOption();
|
|
2567
|
+
helpOption && args.find((arg) => helpOption.is(arg)) && (this.outputHelp(), this._exit(0, "commander.helpDisplayed", "(outputHelp)"));
|
|
3422
2568
|
}
|
|
3423
2569
|
};
|
|
3424
2570
|
function incrementNodeInspectorPort(args) {
|
|
3425
2571
|
return args.map((arg) => {
|
|
3426
|
-
if (!arg.startsWith("--inspect"))
|
|
2572
|
+
if (!arg.startsWith("--inspect"))
|
|
3427
2573
|
return arg;
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
let debugHost = "127.0.0.1";
|
|
3431
|
-
let debugPort = "9229";
|
|
3432
|
-
let match;
|
|
3433
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
3434
|
-
debugOption = match[1];
|
|
3435
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
3436
|
-
debugOption = match[1];
|
|
3437
|
-
if (/^\d+$/.test(match[3])) {
|
|
3438
|
-
debugPort = match[3];
|
|
3439
|
-
} else {
|
|
3440
|
-
debugHost = match[3];
|
|
3441
|
-
}
|
|
3442
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
3443
|
-
debugOption = match[1];
|
|
3444
|
-
debugHost = match[3];
|
|
3445
|
-
debugPort = match[4];
|
|
3446
|
-
}
|
|
3447
|
-
if (debugOption && debugPort !== "0") {
|
|
3448
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
3449
|
-
}
|
|
3450
|
-
return arg;
|
|
2574
|
+
let debugOption, debugHost = "127.0.0.1", debugPort = "9229", match;
|
|
2575
|
+
return (match = arg.match(/^(--inspect(-brk)?)$/)) !== null ? debugOption = match[1] : (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null ? (debugOption = match[1], /^\d+$/.test(match[3]) ? debugPort = match[3] : debugHost = match[3]) : (match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null && (debugOption = match[1], debugHost = match[3], debugPort = match[4]), debugOption && debugPort !== "0" ? `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}` : arg;
|
|
3451
2576
|
});
|
|
3452
2577
|
}
|
|
3453
|
-
__name(incrementNodeInspectorPort, "incrementNodeInspectorPort");
|
|
3454
2578
|
function useColor() {
|
|
3455
2579
|
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
3456
|
-
return
|
|
2580
|
+
return !1;
|
|
3457
2581
|
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== void 0)
|
|
3458
|
-
return
|
|
3459
|
-
return void 0;
|
|
2582
|
+
return !0;
|
|
3460
2583
|
}
|
|
3461
|
-
__name(useColor, "useColor");
|
|
3462
2584
|
exports.Command = Command2;
|
|
3463
2585
|
exports.useColor = useColor;
|
|
3464
2586
|
}
|
|
@@ -3467,11 +2589,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3467
2589
|
// ../node_modules/commander/index.js
|
|
3468
2590
|
var require_commander = __commonJS({
|
|
3469
2591
|
"../node_modules/commander/index.js"(exports) {
|
|
3470
|
-
var { Argument: Argument2 } = require_argument();
|
|
3471
|
-
var { Command: Command2 } = require_command();
|
|
3472
|
-
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
3473
|
-
var { Help: Help2 } = require_help();
|
|
3474
|
-
var { Option: Option2 } = require_option();
|
|
2592
|
+
var { Argument: Argument2 } = require_argument(), { Command: Command2 } = require_command(), { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error(), { Help: Help2 } = require_help(), { Option: Option2 } = require_option();
|
|
3475
2593
|
exports.program = new Command2();
|
|
3476
2594
|
exports.createCommand = (name) => new Command2(name);
|
|
3477
2595
|
exports.createOption = (flags, description) => new Option2(flags, description);
|
|
@@ -3492,8 +2610,7 @@ import { logTracker, logger as logger2 } from "storybook/internal/node-logger";
|
|
|
3492
2610
|
import { addToGlobalContext } from "storybook/internal/telemetry";
|
|
3493
2611
|
|
|
3494
2612
|
// ../node_modules/commander/esm.mjs
|
|
3495
|
-
var import_index = __toESM(require_commander(), 1)
|
|
3496
|
-
var {
|
|
2613
|
+
var import_index = __toESM(require_commander(), 1), {
|
|
3497
2614
|
program,
|
|
3498
2615
|
createCommand,
|
|
3499
2616
|
createArgument,
|
|
@@ -3509,72 +2626,38 @@ var {
|
|
|
3509
2626
|
} = import_index.default;
|
|
3510
2627
|
|
|
3511
2628
|
// ../node_modules/leven/index.js
|
|
3512
|
-
var array = [];
|
|
3513
|
-
var characterCodeCache = [];
|
|
2629
|
+
var array = [], characterCodeCache = [];
|
|
3514
2630
|
function leven(first, second, options) {
|
|
3515
|
-
if (first === second)
|
|
2631
|
+
if (first === second)
|
|
3516
2632
|
return 0;
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
second = swap;
|
|
3523
|
-
}
|
|
3524
|
-
let firstLength = first.length;
|
|
3525
|
-
let secondLength = second.length;
|
|
3526
|
-
while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) {
|
|
3527
|
-
firstLength--;
|
|
3528
|
-
secondLength--;
|
|
3529
|
-
}
|
|
2633
|
+
let maxDistance = options?.maxDistance, swap = first;
|
|
2634
|
+
first.length > second.length && (first = second, second = swap);
|
|
2635
|
+
let firstLength = first.length, secondLength = second.length;
|
|
2636
|
+
for (; firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength); )
|
|
2637
|
+
firstLength--, secondLength--;
|
|
3530
2638
|
let start = 0;
|
|
3531
|
-
|
|
2639
|
+
for (; start < firstLength && first.charCodeAt(start) === second.charCodeAt(start); )
|
|
3532
2640
|
start++;
|
|
3533
|
-
|
|
3534
|
-
firstLength -= start;
|
|
3535
|
-
secondLength -= start;
|
|
3536
|
-
if (maxDistance !== void 0 && secondLength - firstLength > maxDistance) {
|
|
2641
|
+
if (firstLength -= start, secondLength -= start, maxDistance !== void 0 && secondLength - firstLength > maxDistance)
|
|
3537
2642
|
return maxDistance;
|
|
3538
|
-
|
|
3539
|
-
if (firstLength === 0) {
|
|
2643
|
+
if (firstLength === 0)
|
|
3540
2644
|
return maxDistance !== void 0 && secondLength > maxDistance ? maxDistance : secondLength;
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
let index2 = 0;
|
|
3548
|
-
while (index < firstLength) {
|
|
3549
|
-
characterCodeCache[index] = first.charCodeAt(start + index);
|
|
3550
|
-
array[index] = ++index;
|
|
3551
|
-
}
|
|
3552
|
-
while (index2 < secondLength) {
|
|
3553
|
-
bCharacterCode = second.charCodeAt(start + index2);
|
|
3554
|
-
temporary = index2++;
|
|
3555
|
-
result = index2;
|
|
3556
|
-
for (index = 0; index < firstLength; index++) {
|
|
3557
|
-
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1;
|
|
3558
|
-
temporary = array[index];
|
|
3559
|
-
result = array[index] = temporary > result ? temporary2 > result ? result + 1 : temporary2 : temporary2 > temporary ? temporary + 1 : temporary2;
|
|
3560
|
-
}
|
|
2645
|
+
let bCharacterCode, result, temporary, temporary2, index = 0, index2 = 0;
|
|
2646
|
+
for (; index < firstLength; )
|
|
2647
|
+
characterCodeCache[index] = first.charCodeAt(start + index), array[index] = ++index;
|
|
2648
|
+
for (; index2 < secondLength; ) {
|
|
2649
|
+
for (bCharacterCode = second.charCodeAt(start + index2), temporary = index2++, result = index2, index = 0; index < firstLength; index++)
|
|
2650
|
+
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1, temporary = array[index], result = array[index] = temporary > result ? temporary2 > result ? result + 1 : temporary2 : temporary2 > temporary ? temporary + 1 : temporary2;
|
|
3561
2651
|
if (maxDistance !== void 0) {
|
|
3562
2652
|
let rowMinimum = result;
|
|
3563
|
-
for (index = 0; index < firstLength; index++)
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
if (rowMinimum > maxDistance) {
|
|
2653
|
+
for (index = 0; index < firstLength; index++)
|
|
2654
|
+
array[index] < rowMinimum && (rowMinimum = array[index]);
|
|
2655
|
+
if (rowMinimum > maxDistance)
|
|
3569
2656
|
return maxDistance;
|
|
3570
|
-
}
|
|
3571
2657
|
}
|
|
3572
2658
|
}
|
|
3573
|
-
array.length = firstLength;
|
|
3574
|
-
characterCodeCache.length = firstLength;
|
|
3575
|
-
return maxDistance !== void 0 && result > maxDistance ? maxDistance : result;
|
|
2659
|
+
return array.length = firstLength, characterCodeCache.length = firstLength, maxDistance !== void 0 && result > maxDistance ? maxDistance : result;
|
|
3576
2660
|
}
|
|
3577
|
-
__name(leven, "leven");
|
|
3578
2661
|
|
|
3579
2662
|
// src/bin/core.ts
|
|
3580
2663
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
@@ -3582,9 +2665,8 @@ var import_picocolors = __toESM(require_picocolors(), 1);
|
|
|
3582
2665
|
// src/cli/build.ts
|
|
3583
2666
|
import { cache } from "storybook/internal/common";
|
|
3584
2667
|
import { buildStaticStandalone, withTelemetry } from "storybook/internal/core-server";
|
|
3585
|
-
var build =
|
|
3586
|
-
|
|
3587
|
-
const options = {
|
|
2668
|
+
var build = async (cliOptions) => {
|
|
2669
|
+
let { default: packageJson } = await import("storybook/package.json", { with: { type: "json" } }), options = {
|
|
3588
2670
|
...cliOptions,
|
|
3589
2671
|
configDir: cliOptions.configDir || "./.storybook",
|
|
3590
2672
|
outputDir: cliOptions.outputDir || "./storybook-static",
|
|
@@ -3598,28 +2680,27 @@ var build = /* @__PURE__ */ __name(async (cliOptions) => {
|
|
|
3598
2680
|
{ cliOptions, presetOptions: options },
|
|
3599
2681
|
() => buildStaticStandalone(options)
|
|
3600
2682
|
);
|
|
3601
|
-
}
|
|
2683
|
+
};
|
|
3602
2684
|
|
|
3603
2685
|
// src/cli/buildIndex.ts
|
|
3604
2686
|
import { cache as cache2 } from "storybook/internal/common";
|
|
3605
2687
|
import { buildIndexStandalone, withTelemetry as withTelemetry2 } from "storybook/internal/core-server";
|
|
3606
|
-
var buildIndex =
|
|
3607
|
-
|
|
2688
|
+
var buildIndex = async (cliOptions) => {
|
|
2689
|
+
let options = {
|
|
3608
2690
|
...cliOptions,
|
|
3609
2691
|
configDir: cliOptions.configDir || ".storybook",
|
|
3610
2692
|
outputFile: cliOptions.outputFile || "index.json",
|
|
3611
|
-
ignorePreview:
|
|
2693
|
+
ignorePreview: !0,
|
|
3612
2694
|
configType: "PRODUCTION",
|
|
3613
2695
|
cache: cache2,
|
|
3614
2696
|
packageJson: cliOptions.packageJson
|
|
3615
|
-
}
|
|
3616
|
-
const presetOptions = {
|
|
2697
|
+
}, presetOptions = {
|
|
3617
2698
|
...options,
|
|
3618
2699
|
corePresets: [],
|
|
3619
2700
|
overridePresets: []
|
|
3620
2701
|
};
|
|
3621
2702
|
await withTelemetry2("index", { cliOptions, presetOptions }, () => buildIndexStandalone(options));
|
|
3622
|
-
}
|
|
2703
|
+
};
|
|
3623
2704
|
|
|
3624
2705
|
// src/cli/dev.ts
|
|
3625
2706
|
var import_ts_dedent = __toESM(require_dist(), 1);
|
|
@@ -3627,20 +2708,7 @@ import { cache as cache3 } from "storybook/internal/common";
|
|
|
3627
2708
|
import { buildDevStandalone, withTelemetry as withTelemetry3 } from "storybook/internal/core-server";
|
|
3628
2709
|
import { logger, instance as npmLog } from "storybook/internal/node-logger";
|
|
3629
2710
|
function printError(error) {
|
|
3630
|
-
npmLog.heading = ""
|
|
3631
|
-
if (error instanceof Error) {
|
|
3632
|
-
if (error.error) {
|
|
3633
|
-
logger.error(error.error);
|
|
3634
|
-
} else if (error.stats && error.stats.compilation.errors) {
|
|
3635
|
-
error.stats.compilation.errors.forEach((e) => logger.plain(e));
|
|
3636
|
-
} else {
|
|
3637
|
-
logger.error(error);
|
|
3638
|
-
}
|
|
3639
|
-
} else if (error.compilation?.errors) {
|
|
3640
|
-
error.compilation.errors.forEach((e) => logger.plain(e));
|
|
3641
|
-
}
|
|
3642
|
-
logger.line();
|
|
3643
|
-
logger.warn(
|
|
2711
|
+
npmLog.heading = "", error instanceof Error ? error.error ? logger.error(error.error) : error.stats && error.stats.compilation.errors ? error.stats.compilation.errors.forEach((e) => logger.plain(e)) : logger.error(error) : error.compilation?.errors && error.compilation.errors.forEach((e) => logger.plain(e)), logger.line(), logger.warn(
|
|
3644
2712
|
error.close ? import_ts_dedent.dedent`
|
|
3645
2713
|
FATAL broken build!, will close the process,
|
|
3646
2714
|
Fix the error below and restart storybook.
|
|
@@ -3648,15 +2716,12 @@ function printError(error) {
|
|
|
3648
2716
|
Broken build, fix the error above.
|
|
3649
2717
|
You may need to refresh the browser.
|
|
3650
2718
|
`
|
|
3651
|
-
);
|
|
3652
|
-
logger.line();
|
|
2719
|
+
), logger.line();
|
|
3653
2720
|
}
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
const { env } = process;
|
|
2721
|
+
var dev = async (cliOptions) => {
|
|
2722
|
+
let { env } = process;
|
|
3657
2723
|
env.NODE_ENV = env.NODE_ENV || "development";
|
|
3658
|
-
|
|
3659
|
-
const options = {
|
|
2724
|
+
let { default: packageJson } = await import("storybook/package.json", { with: { type: "json" } }), options = {
|
|
3660
2725
|
...cliOptions,
|
|
3661
2726
|
configDir: cliOptions.configDir || "./.storybook",
|
|
3662
2727
|
configType: "DEVELOPMENT",
|
|
@@ -3674,33 +2739,28 @@ var dev = /* @__PURE__ */ __name(async (cliOptions) => {
|
|
|
3674
2739
|
},
|
|
3675
2740
|
() => buildDevStandalone(options)
|
|
3676
2741
|
);
|
|
3677
|
-
}
|
|
2742
|
+
};
|
|
3678
2743
|
|
|
3679
2744
|
// src/bin/core.ts
|
|
3680
2745
|
addToGlobalContext("cliVersion", version);
|
|
3681
|
-
var command =
|
|
2746
|
+
var command = (name) => program.command(name).option(
|
|
3682
2747
|
"--disable-telemetry",
|
|
3683
2748
|
"Disable sending telemetry data",
|
|
3684
2749
|
optionalEnvToBoolean(process.env.STORYBOOK_DISABLE_TELEMETRY)
|
|
3685
|
-
).option("--debug", "Get more logs in debug mode",
|
|
2750
|
+
).option("--debug", "Get more logs in debug mode", !1).option("--enable-crash-reports", "Enable sending crash reports to telemetry data").option("--loglevel <trace | debug | info | warn | error | silent>", "Define log level", "info").option("--write-logs", "Write all debug logs to a file at the end of the run").hook("preAction", async (self) => {
|
|
3686
2751
|
try {
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
logger2.setLogLevel(options.loglevel);
|
|
3690
|
-
}
|
|
3691
|
-
if (options.writeLogs) {
|
|
3692
|
-
logTracker.enableLogWriting();
|
|
3693
|
-
}
|
|
3694
|
-
await globalSettings();
|
|
2752
|
+
let options = self.opts();
|
|
2753
|
+
options.loglevel && logger2.setLogLevel(options.loglevel), options.writeLogs && logTracker.enableLogWriting(), await globalSettings();
|
|
3695
2754
|
} catch (e) {
|
|
3696
|
-
logger2.error(
|
|
2755
|
+
logger2.error(`Error loading global settings:
|
|
2756
|
+
` + String(e));
|
|
3697
2757
|
}
|
|
3698
2758
|
}).hook("postAction", async () => {
|
|
3699
2759
|
if (logTracker.shouldWriteLogsToFile) {
|
|
3700
|
-
|
|
2760
|
+
let logFile = await logTracker.writeToFile();
|
|
3701
2761
|
logger2.outro(`Storybook debug logs can be found at: ${logFile}`);
|
|
3702
2762
|
}
|
|
3703
|
-
})
|
|
2763
|
+
});
|
|
3704
2764
|
command("dev").option("-p, --port <number>", "Port to run Storybook", (str) => parseInt(str, 10)).option("-h, --host <string>", "Host to run Storybook").option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option(
|
|
3705
2765
|
"--https",
|
|
3706
2766
|
"Serve Storybook over HTTPS. Note: You must provide your own certificate information."
|
|
@@ -3708,7 +2768,7 @@ command("dev").option("-p, --port <number>", "Port to run Storybook", (str) => p
|
|
|
3708
2768
|
"--ssl-ca <ca>",
|
|
3709
2769
|
"Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)",
|
|
3710
2770
|
parseList
|
|
3711
|
-
).option("--ssl-cert <cert>", "Provide an SSL certificate. (Required with --https)").option("--ssl-key <key>", "Provide an SSL key. (Required with --https)").option("--smoke-test", "Exit after successful start").option("--ci", "CI mode (skip interactive prompts, don't open browser)").option("--no-open", "Do not open Storybook automatically in the browser").option("--quiet", "Suppress verbose build output").option("--no-version-updates", "Suppress update check",
|
|
2771
|
+
).option("--ssl-cert <cert>", "Provide an SSL certificate. (Required with --https)").option("--ssl-key <key>", "Provide an SSL key. (Required with --https)").option("--smoke-test", "Exit after successful start").option("--ci", "CI mode (skip interactive prompts, don't open browser)").option("--no-open", "Do not open Storybook automatically in the browser").option("--quiet", "Suppress verbose build output").option("--no-version-updates", "Suppress update check", !0).option("--debug-webpack", "Display final webpack configurations for debugging purposes").option(
|
|
3712
2772
|
"--webpack-stats-json [directory]",
|
|
3713
2773
|
"Write Webpack stats JSON to disk (synonym for `--stats-json`)"
|
|
3714
2774
|
).option("--stats-json [directory]", "Write stats JSON to disk").option(
|
|
@@ -3718,21 +2778,17 @@ command("dev").option("-p, --port <number>", "Port to run Storybook", (str) => p
|
|
|
3718
2778
|
"--initial-path [path]",
|
|
3719
2779
|
"URL path to be appended when visiting Storybook for the first time"
|
|
3720
2780
|
).option("--preview-only", "Use the preview without the manager UI").action(async (options) => {
|
|
3721
|
-
|
|
2781
|
+
let { default: packageJson } = await import("storybook/package.json", { with: { type: "json" } });
|
|
3722
2782
|
logger2.log(
|
|
3723
|
-
import_picocolors.default.bold(`${packageJson.name} v${packageJson.version}`) + import_picocolors.default.reset(
|
|
3724
|
-
|
|
3725
|
-
getEnvConfig(options, {
|
|
2783
|
+
import_picocolors.default.bold(`${packageJson.name} v${packageJson.version}`) + import_picocolors.default.reset(`
|
|
2784
|
+
`)
|
|
2785
|
+
), getEnvConfig(options, {
|
|
3726
2786
|
port: "SBCONFIG_PORT",
|
|
3727
2787
|
host: "SBCONFIG_HOSTNAME",
|
|
3728
2788
|
staticDir: "SBCONFIG_STATIC_DIR",
|
|
3729
2789
|
configDir: "SBCONFIG_CONFIG_DIR",
|
|
3730
2790
|
ci: "CI"
|
|
3731
|
-
});
|
|
3732
|
-
if (parseInt(`${options.port}`, 10)) {
|
|
3733
|
-
options.port = parseInt(`${options.port}`, 10);
|
|
3734
|
-
}
|
|
3735
|
-
await dev({ ...options, packageJson }).catch(() => process.exit(1));
|
|
2791
|
+
}), parseInt(`${options.port}`, 10) && (options.port = parseInt(`${options.port}`, 10)), await dev({ ...options, packageJson }).catch(() => process.exit(1));
|
|
3736
2792
|
});
|
|
3737
2793
|
command("build").option("-o, --output-dir <dir-name>", "Directory where to store built files").option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option("--quiet", "Suppress verbose build output").option("--debug-webpack", "Display final webpack configurations for debugging purposes").option(
|
|
3738
2794
|
"--webpack-stats-json [directory]",
|
|
@@ -3741,47 +2797,37 @@ command("build").option("-o, --output-dir <dir-name>", "Directory where to store
|
|
|
3741
2797
|
"--preview-url <string>",
|
|
3742
2798
|
"Disables the default storybook preview and lets your use your own"
|
|
3743
2799
|
).option("--force-build-preview", "Build the preview iframe even if you are using --preview-url").option("--docs", "Build a documentation-only site using addon-docs").option("--test", "Build stories optimized for testing purposes.").option("--preview-only", "Use the preview without the manager UI").action(async (options) => {
|
|
3744
|
-
|
|
2800
|
+
let { env } = process;
|
|
3745
2801
|
env.NODE_ENV = env.NODE_ENV || "production";
|
|
3746
|
-
|
|
2802
|
+
let { default: packageJson } = await import("storybook/package.json", { with: { type: "json" } });
|
|
3747
2803
|
logger2.log(import_picocolors.default.bold(`${packageJson.name} v${packageJson.version}
|
|
3748
|
-
`))
|
|
3749
|
-
getEnvConfig(options, {
|
|
2804
|
+
`)), getEnvConfig(options, {
|
|
3750
2805
|
staticDir: "SBCONFIG_STATIC_DIR",
|
|
3751
2806
|
outputDir: "SBCONFIG_OUTPUT_DIR",
|
|
3752
2807
|
configDir: "SBCONFIG_CONFIG_DIR"
|
|
3753
|
-
})
|
|
3754
|
-
await build({
|
|
2808
|
+
}), await build({
|
|
3755
2809
|
...options,
|
|
3756
2810
|
packageJson,
|
|
3757
2811
|
test: !!options.test || optionalEnvToBoolean(process.env.SB_TESTBUILD)
|
|
3758
2812
|
}).catch(() => process.exit(1));
|
|
3759
2813
|
});
|
|
3760
2814
|
command("index").option("-o, --output-file <file-name>", "JSON file to output index").option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option("--quiet", "Suppress verbose build output").action(async (options) => {
|
|
3761
|
-
|
|
2815
|
+
let { env } = process;
|
|
3762
2816
|
env.NODE_ENV = env.NODE_ENV || "production";
|
|
3763
|
-
|
|
2817
|
+
let { default: packageJson } = await import("storybook/package.json", { with: { type: "json" } });
|
|
3764
2818
|
logger2.log(import_picocolors.default.bold(`${packageJson.name} v${packageJson.version}
|
|
3765
|
-
`))
|
|
3766
|
-
getEnvConfig(options, {
|
|
2819
|
+
`)), getEnvConfig(options, {
|
|
3767
2820
|
configDir: "SBCONFIG_CONFIG_DIR",
|
|
3768
2821
|
outputFile: "SBCONFIG_OUTPUT_FILE"
|
|
3769
|
-
})
|
|
3770
|
-
await buildIndex({
|
|
2822
|
+
}), await buildIndex({
|
|
3771
2823
|
...options,
|
|
3772
2824
|
packageJson
|
|
3773
2825
|
}).catch(() => process.exit(1));
|
|
3774
2826
|
});
|
|
3775
2827
|
program.on("command:*", ([invalidCmd]) => {
|
|
3776
2828
|
let errorMessage = ` Invalid command: ${import_picocolors.default.bold(invalidCmd)}.
|
|
3777
|
-
See --help for a list of available commands
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
if (suggestion) {
|
|
3781
|
-
errorMessage += `
|
|
3782
|
-
Did you mean ${import_picocolors.default.yellow(suggestion)}?`;
|
|
3783
|
-
}
|
|
3784
|
-
logger2.error(errorMessage);
|
|
3785
|
-
process.exit(1);
|
|
2829
|
+
See --help for a list of available commands.`, suggestion = program.commands.map((cmd) => cmd.name()).find((cmd) => leven(cmd, invalidCmd) < 3);
|
|
2830
|
+
suggestion && (errorMessage += `
|
|
2831
|
+
Did you mean ${import_picocolors.default.yellow(suggestion)}?`), logger2.error(errorMessage), process.exit(1);
|
|
3786
2832
|
});
|
|
3787
2833
|
program.usage("<command> [options]").version(String(version)).parse(process.argv);
|