@unpackjs/core 1.7.5 → 1.7.7
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/compiled/css-loader/index.js +180 -178
- package/compiled/less-loader/index.js +11 -11
- package/compiled/line-diff/index.js +4 -4
- package/compiled/line-diff/license +1 -1
- package/compiled/line-diff/package.json +1 -1
- package/compiled/portfinder/index.js +37 -37
- package/compiled/postcss-loader/index.js +261 -256
- package/compiled/sass-loader/index.js +24 -20
- package/compiled/sass-loader/package.json +1 -1
- package/compiled/semver/index.js +188 -170
- package/compiled/semver/package.json +1 -1
- package/compiled/style-loader/index.js +13 -13
- package/compiled/webpack-bundle-analyzer/index.js +198 -198
- package/compiled/webpack-merge/index.js +29 -29
- package/dist/bundler-config/chunkSplit.cjs +169 -156
- package/dist/bundler-config/chunkSplit.js +125 -134
- package/dist/bundler-config/css.cjs +181 -158
- package/dist/bundler-config/css.js +139 -151
- package/dist/bundler-config/experimentCss.cjs +203 -159
- package/dist/bundler-config/experimentCss.js +162 -152
- package/dist/bundler-config/helper.cjs +82 -78
- package/dist/bundler-config/helper.js +36 -55
- package/dist/bundler-config/index.cjs +260 -209
- package/dist/bundler-config/index.d.ts.map +1 -1
- package/dist/bundler-config/index.js +209 -182
- package/dist/bundler-config/jsMinify.cjs +114 -95
- package/dist/bundler-config/jsMinify.js +70 -73
- package/dist/colors.cjs +83 -56
- package/dist/colors.js +38 -37
- package/dist/config.cjs +107 -93
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +64 -70
- package/dist/constants.cjs +65 -62
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +22 -38
- package/dist/createUnpack.cjs +111 -104
- package/dist/createUnpack.js +67 -82
- package/dist/global.cjs +36 -0
- package/dist/global.d.ts +2 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/global.js +4 -0
- package/dist/index.cjs +174 -51
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -15
- package/dist/lightningcss/loader.cjs +56 -53
- package/dist/lightningcss/loader.d.ts.map +1 -1
- package/dist/lightningcss/loader.js +25 -34
- package/dist/lightningcss/minimizer.cjs +90 -109
- package/dist/lightningcss/minimizer.d.ts.map +1 -1
- package/dist/lightningcss/minimizer.js +59 -87
- package/dist/logger.cjs +104 -98
- package/dist/logger.js +59 -76
- package/dist/openBrowser.cjs +104 -81
- package/dist/openBrowser.js +56 -52
- package/dist/plugin-progress/rspack.cjs +104 -79
- package/dist/plugin-progress/rspack.js +59 -57
- package/dist/plugin-progress/webpack.cjs +111 -89
- package/dist/plugin-progress/webpack.js +65 -67
- package/dist/plugin.cjs +38 -29
- package/dist/plugin.js +8 -17
- package/dist/prebundleDeps.cjs +327 -337
- package/dist/prebundleDeps.d.ts.map +1 -1
- package/dist/prebundleDeps.js +278 -324
- package/dist/progressBar.cjs +82 -65
- package/dist/progressBar.js +38 -43
- package/dist/reporter.cjs +149 -124
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +102 -102
- package/dist/run/build.cjs +68 -67
- package/dist/run/build.js +24 -45
- package/dist/run/dev.cjs +96 -83
- package/dist/run/dev.d.ts.map +1 -1
- package/dist/run/dev.js +50 -61
- package/dist/run/index.cjs +74 -21
- package/dist/run/index.js +2 -9
- package/dist/typed-css-modules/loader.cjs +179 -188
- package/dist/typed-css-modules/loader.js +118 -151
- package/dist/typed-css-modules/plugin.cjs +113 -88
- package/dist/typed-css-modules/plugin.js +68 -66
- package/dist/typed-css-modules/utils.cjs +43 -42
- package/dist/typed-css-modules/utils.js +13 -30
- package/dist/types/chunkSplit.cjs +19 -15
- package/dist/types/chunkSplit.d.ts +2 -10
- package/dist/types/chunkSplit.d.ts.map +1 -1
- package/dist/types/chunkSplit.js +2 -9
- package/dist/types/config.cjs +19 -15
- package/dist/types/config.js +2 -9
- package/dist/types/index.cjs +101 -27
- package/dist/types/index.js +2 -9
- package/dist/types/lightningcss.cjs +19 -15
- package/dist/types/lightningcss.js +2 -9
- package/dist/types/logger.cjs +43 -34
- package/dist/types/logger.js +13 -22
- package/dist/types/plugin.cjs +19 -15
- package/dist/types/plugin.js +2 -9
- package/dist/utils.cjs +280 -304
- package/dist/utils.js +195 -241
- package/dist/watchFiles.cjs +73 -0
- package/dist/watchFiles.d.ts +3 -0
- package/dist/watchFiles.d.ts.map +1 -0
- package/dist/watchFiles.js +27 -0
- package/package.json +18 -21
- package/compiled/commander/index.d.ts +0 -1047
- package/compiled/commander/index.js +0 -2428
- package/compiled/commander/license +0 -22
- package/compiled/commander/package.json +0 -1
- package/dist/bundleRequire.cjs +0 -200
- package/dist/bundleRequire.d.ts +0 -5
- package/dist/bundleRequire.d.ts.map +0 -1
- package/dist/bundleRequire.js +0 -173
- package/dist/lightningcss/cache.cjs +0 -36
- package/dist/lightningcss/cache.d.ts +0 -2
- package/dist/lightningcss/cache.d.ts.map +0 -1
- package/dist/lightningcss/cache.js +0 -22
|
@@ -1,2428 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
var __webpack_modules__ = {
|
|
3
|
-
718: (module) => {
|
|
4
|
-
"use strict";
|
|
5
|
-
module.exports = require("node:child_process");
|
|
6
|
-
},
|
|
7
|
-
673: (module) => {
|
|
8
|
-
"use strict";
|
|
9
|
-
module.exports = require("node:events");
|
|
10
|
-
},
|
|
11
|
-
561: (module) => {
|
|
12
|
-
"use strict";
|
|
13
|
-
module.exports = require("node:fs");
|
|
14
|
-
},
|
|
15
|
-
411: (module) => {
|
|
16
|
-
"use strict";
|
|
17
|
-
module.exports = require("node:path");
|
|
18
|
-
},
|
|
19
|
-
742: (module) => {
|
|
20
|
-
"use strict";
|
|
21
|
-
module.exports = require("node:process");
|
|
22
|
-
},
|
|
23
|
-
429: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
24
|
-
const { InvalidArgumentError } = __nccwpck_require__(848);
|
|
25
|
-
class Argument {
|
|
26
|
-
constructor(name, description) {
|
|
27
|
-
this.description = description || "";
|
|
28
|
-
this.variadic = false;
|
|
29
|
-
this.parseArg = undefined;
|
|
30
|
-
this.defaultValue = undefined;
|
|
31
|
-
this.defaultValueDescription = undefined;
|
|
32
|
-
this.argChoices = undefined;
|
|
33
|
-
switch (name[0]) {
|
|
34
|
-
case "<":
|
|
35
|
-
this.required = true;
|
|
36
|
-
this._name = name.slice(1, -1);
|
|
37
|
-
break;
|
|
38
|
-
case "[":
|
|
39
|
-
this.required = false;
|
|
40
|
-
this._name = name.slice(1, -1);
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
this.required = true;
|
|
44
|
-
this._name = name;
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
48
|
-
this.variadic = true;
|
|
49
|
-
this._name = this._name.slice(0, -3);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
name() {
|
|
53
|
-
return this._name;
|
|
54
|
-
}
|
|
55
|
-
_concatValue(value, previous) {
|
|
56
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
57
|
-
return [value];
|
|
58
|
-
}
|
|
59
|
-
return previous.concat(value);
|
|
60
|
-
}
|
|
61
|
-
default(value, description) {
|
|
62
|
-
this.defaultValue = value;
|
|
63
|
-
this.defaultValueDescription = description;
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
argParser(fn) {
|
|
67
|
-
this.parseArg = fn;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
choices(values) {
|
|
71
|
-
this.argChoices = values.slice();
|
|
72
|
-
this.parseArg = (arg, previous) => {
|
|
73
|
-
if (!this.argChoices.includes(arg)) {
|
|
74
|
-
throw new InvalidArgumentError(
|
|
75
|
-
`Allowed choices are ${this.argChoices.join(", ")}.`,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
if (this.variadic) {
|
|
79
|
-
return this._concatValue(arg, previous);
|
|
80
|
-
}
|
|
81
|
-
return arg;
|
|
82
|
-
};
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
argRequired() {
|
|
86
|
-
this.required = true;
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
argOptional() {
|
|
90
|
-
this.required = false;
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function humanReadableArgName(arg) {
|
|
95
|
-
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
96
|
-
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
97
|
-
}
|
|
98
|
-
exports.Argument = Argument;
|
|
99
|
-
exports.humanReadableArgName = humanReadableArgName;
|
|
100
|
-
},
|
|
101
|
-
745: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
102
|
-
const EventEmitter = __nccwpck_require__(673).EventEmitter;
|
|
103
|
-
const childProcess = __nccwpck_require__(718);
|
|
104
|
-
const path = __nccwpck_require__(411);
|
|
105
|
-
const fs = __nccwpck_require__(561);
|
|
106
|
-
const process = __nccwpck_require__(742);
|
|
107
|
-
const { Argument, humanReadableArgName } = __nccwpck_require__(429);
|
|
108
|
-
const { CommanderError } = __nccwpck_require__(848);
|
|
109
|
-
const { Help, stripColor } = __nccwpck_require__(613);
|
|
110
|
-
const { Option, DualOptions } = __nccwpck_require__(234);
|
|
111
|
-
const { suggestSimilar } = __nccwpck_require__(824);
|
|
112
|
-
class Command extends EventEmitter {
|
|
113
|
-
constructor(name) {
|
|
114
|
-
super();
|
|
115
|
-
this.commands = [];
|
|
116
|
-
this.options = [];
|
|
117
|
-
this.parent = null;
|
|
118
|
-
this._allowUnknownOption = false;
|
|
119
|
-
this._allowExcessArguments = false;
|
|
120
|
-
this.registeredArguments = [];
|
|
121
|
-
this._args = this.registeredArguments;
|
|
122
|
-
this.args = [];
|
|
123
|
-
this.rawArgs = [];
|
|
124
|
-
this.processedArgs = [];
|
|
125
|
-
this._scriptPath = null;
|
|
126
|
-
this._name = name || "";
|
|
127
|
-
this._optionValues = {};
|
|
128
|
-
this._optionValueSources = {};
|
|
129
|
-
this._storeOptionsAsProperties = false;
|
|
130
|
-
this._actionHandler = null;
|
|
131
|
-
this._executableHandler = false;
|
|
132
|
-
this._executableFile = null;
|
|
133
|
-
this._executableDir = null;
|
|
134
|
-
this._defaultCommandName = null;
|
|
135
|
-
this._exitCallback = null;
|
|
136
|
-
this._aliases = [];
|
|
137
|
-
this._combineFlagAndOptionalValue = true;
|
|
138
|
-
this._description = "";
|
|
139
|
-
this._summary = "";
|
|
140
|
-
this._argsDescription = undefined;
|
|
141
|
-
this._enablePositionalOptions = false;
|
|
142
|
-
this._passThroughOptions = false;
|
|
143
|
-
this._lifeCycleHooks = {};
|
|
144
|
-
this._showHelpAfterError = false;
|
|
145
|
-
this._showSuggestionAfterError = true;
|
|
146
|
-
this._savedState = null;
|
|
147
|
-
this._outputConfiguration = {
|
|
148
|
-
writeOut: (str) => process.stdout.write(str),
|
|
149
|
-
writeErr: (str) => process.stderr.write(str),
|
|
150
|
-
outputError: (str, write) => write(str),
|
|
151
|
-
getOutHelpWidth: () =>
|
|
152
|
-
process.stdout.isTTY ? process.stdout.columns : undefined,
|
|
153
|
-
getErrHelpWidth: () =>
|
|
154
|
-
process.stderr.isTTY ? process.stderr.columns : undefined,
|
|
155
|
-
getOutHasColors: () =>
|
|
156
|
-
useColor() ??
|
|
157
|
-
(process.stdout.isTTY && process.stdout.hasColors?.()),
|
|
158
|
-
getErrHasColors: () =>
|
|
159
|
-
useColor() ??
|
|
160
|
-
(process.stderr.isTTY && process.stderr.hasColors?.()),
|
|
161
|
-
stripColor: (str) => stripColor(str),
|
|
162
|
-
};
|
|
163
|
-
this._hidden = false;
|
|
164
|
-
this._helpOption = undefined;
|
|
165
|
-
this._addImplicitHelpCommand = undefined;
|
|
166
|
-
this._helpCommand = undefined;
|
|
167
|
-
this._helpConfiguration = {};
|
|
168
|
-
}
|
|
169
|
-
copyInheritedSettings(sourceCommand) {
|
|
170
|
-
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
171
|
-
this._helpOption = sourceCommand._helpOption;
|
|
172
|
-
this._helpCommand = sourceCommand._helpCommand;
|
|
173
|
-
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
174
|
-
this._exitCallback = sourceCommand._exitCallback;
|
|
175
|
-
this._storeOptionsAsProperties =
|
|
176
|
-
sourceCommand._storeOptionsAsProperties;
|
|
177
|
-
this._combineFlagAndOptionalValue =
|
|
178
|
-
sourceCommand._combineFlagAndOptionalValue;
|
|
179
|
-
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
180
|
-
this._enablePositionalOptions =
|
|
181
|
-
sourceCommand._enablePositionalOptions;
|
|
182
|
-
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
183
|
-
this._showSuggestionAfterError =
|
|
184
|
-
sourceCommand._showSuggestionAfterError;
|
|
185
|
-
return this;
|
|
186
|
-
}
|
|
187
|
-
_getCommandAndAncestors() {
|
|
188
|
-
const result = [];
|
|
189
|
-
for (let command = this; command; command = command.parent) {
|
|
190
|
-
result.push(command);
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
195
|
-
let desc = actionOptsOrExecDesc;
|
|
196
|
-
let opts = execOpts;
|
|
197
|
-
if (typeof desc === "object" && desc !== null) {
|
|
198
|
-
opts = desc;
|
|
199
|
-
desc = null;
|
|
200
|
-
}
|
|
201
|
-
opts = opts || {};
|
|
202
|
-
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
203
|
-
const cmd = this.createCommand(name);
|
|
204
|
-
if (desc) {
|
|
205
|
-
cmd.description(desc);
|
|
206
|
-
cmd._executableHandler = true;
|
|
207
|
-
}
|
|
208
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
209
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
210
|
-
cmd._executableFile = opts.executableFile || null;
|
|
211
|
-
if (args) cmd.arguments(args);
|
|
212
|
-
this._registerCommand(cmd);
|
|
213
|
-
cmd.parent = this;
|
|
214
|
-
cmd.copyInheritedSettings(this);
|
|
215
|
-
if (desc) return this;
|
|
216
|
-
return cmd;
|
|
217
|
-
}
|
|
218
|
-
createCommand(name) {
|
|
219
|
-
return new Command(name);
|
|
220
|
-
}
|
|
221
|
-
createHelp() {
|
|
222
|
-
return Object.assign(new Help(), this.configureHelp());
|
|
223
|
-
}
|
|
224
|
-
configureHelp(configuration) {
|
|
225
|
-
if (configuration === undefined) return this._helpConfiguration;
|
|
226
|
-
this._helpConfiguration = configuration;
|
|
227
|
-
return this;
|
|
228
|
-
}
|
|
229
|
-
configureOutput(configuration) {
|
|
230
|
-
if (configuration === undefined) return this._outputConfiguration;
|
|
231
|
-
Object.assign(this._outputConfiguration, configuration);
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
showHelpAfterError(displayHelp = true) {
|
|
235
|
-
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
236
|
-
this._showHelpAfterError = displayHelp;
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
showSuggestionAfterError(displaySuggestion = true) {
|
|
240
|
-
this._showSuggestionAfterError = !!displaySuggestion;
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
addCommand(cmd, opts) {
|
|
244
|
-
if (!cmd._name) {
|
|
245
|
-
throw new Error(
|
|
246
|
-
`Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()`,
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
opts = opts || {};
|
|
250
|
-
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
251
|
-
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
252
|
-
this._registerCommand(cmd);
|
|
253
|
-
cmd.parent = this;
|
|
254
|
-
cmd._checkForBrokenPassThrough();
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
createArgument(name, description) {
|
|
258
|
-
return new Argument(name, description);
|
|
259
|
-
}
|
|
260
|
-
argument(name, description, fn, defaultValue) {
|
|
261
|
-
const argument = this.createArgument(name, description);
|
|
262
|
-
if (typeof fn === "function") {
|
|
263
|
-
argument.default(defaultValue).argParser(fn);
|
|
264
|
-
} else {
|
|
265
|
-
argument.default(fn);
|
|
266
|
-
}
|
|
267
|
-
this.addArgument(argument);
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
arguments(names) {
|
|
271
|
-
names
|
|
272
|
-
.trim()
|
|
273
|
-
.split(/ +/)
|
|
274
|
-
.forEach((detail) => {
|
|
275
|
-
this.argument(detail);
|
|
276
|
-
});
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
addArgument(argument) {
|
|
280
|
-
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
281
|
-
if (previousArgument && previousArgument.variadic) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
`only the last argument can be variadic '${previousArgument.name()}'`,
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
if (
|
|
287
|
-
argument.required &&
|
|
288
|
-
argument.defaultValue !== undefined &&
|
|
289
|
-
argument.parseArg === undefined
|
|
290
|
-
) {
|
|
291
|
-
throw new Error(
|
|
292
|
-
`a default value for a required argument is never used: '${argument.name()}'`,
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
this.registeredArguments.push(argument);
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
298
|
-
helpCommand(enableOrNameAndArgs, description) {
|
|
299
|
-
if (typeof enableOrNameAndArgs === "boolean") {
|
|
300
|
-
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
301
|
-
return this;
|
|
302
|
-
}
|
|
303
|
-
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
304
|
-
const [, helpName, helpArgs] =
|
|
305
|
-
enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
306
|
-
const helpDescription = description ?? "display help for command";
|
|
307
|
-
const helpCommand = this.createCommand(helpName);
|
|
308
|
-
helpCommand.helpOption(false);
|
|
309
|
-
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
310
|
-
if (helpDescription) helpCommand.description(helpDescription);
|
|
311
|
-
this._addImplicitHelpCommand = true;
|
|
312
|
-
this._helpCommand = helpCommand;
|
|
313
|
-
return this;
|
|
314
|
-
}
|
|
315
|
-
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
316
|
-
if (typeof helpCommand !== "object") {
|
|
317
|
-
this.helpCommand(helpCommand, deprecatedDescription);
|
|
318
|
-
return this;
|
|
319
|
-
}
|
|
320
|
-
this._addImplicitHelpCommand = true;
|
|
321
|
-
this._helpCommand = helpCommand;
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
_getHelpCommand() {
|
|
325
|
-
const hasImplicitHelpCommand =
|
|
326
|
-
this._addImplicitHelpCommand ??
|
|
327
|
-
(this.commands.length &&
|
|
328
|
-
!this._actionHandler &&
|
|
329
|
-
!this._findCommand("help"));
|
|
330
|
-
if (hasImplicitHelpCommand) {
|
|
331
|
-
if (this._helpCommand === undefined) {
|
|
332
|
-
this.helpCommand(undefined, undefined);
|
|
333
|
-
}
|
|
334
|
-
return this._helpCommand;
|
|
335
|
-
}
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
hook(event, listener) {
|
|
339
|
-
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
340
|
-
if (!allowedValues.includes(event)) {
|
|
341
|
-
throw new Error(
|
|
342
|
-
`Unexpected value for event passed to hook : '${event}'.\nExpecting one of '${allowedValues.join("', '")}'`,
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
if (this._lifeCycleHooks[event]) {
|
|
346
|
-
this._lifeCycleHooks[event].push(listener);
|
|
347
|
-
} else {
|
|
348
|
-
this._lifeCycleHooks[event] = [listener];
|
|
349
|
-
}
|
|
350
|
-
return this;
|
|
351
|
-
}
|
|
352
|
-
exitOverride(fn) {
|
|
353
|
-
if (fn) {
|
|
354
|
-
this._exitCallback = fn;
|
|
355
|
-
} else {
|
|
356
|
-
this._exitCallback = (err) => {
|
|
357
|
-
if (err.code !== "commander.executeSubCommandAsync") {
|
|
358
|
-
throw err;
|
|
359
|
-
} else {
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
return this;
|
|
364
|
-
}
|
|
365
|
-
_exit(exitCode, code, message) {
|
|
366
|
-
if (this._exitCallback) {
|
|
367
|
-
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
368
|
-
}
|
|
369
|
-
process.exit(exitCode);
|
|
370
|
-
}
|
|
371
|
-
action(fn) {
|
|
372
|
-
const listener = (args) => {
|
|
373
|
-
const expectedArgsCount = this.registeredArguments.length;
|
|
374
|
-
const actionArgs = args.slice(0, expectedArgsCount);
|
|
375
|
-
if (this._storeOptionsAsProperties) {
|
|
376
|
-
actionArgs[expectedArgsCount] = this;
|
|
377
|
-
} else {
|
|
378
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
379
|
-
}
|
|
380
|
-
actionArgs.push(this);
|
|
381
|
-
return fn.apply(this, actionArgs);
|
|
382
|
-
};
|
|
383
|
-
this._actionHandler = listener;
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
createOption(flags, description) {
|
|
387
|
-
return new Option(flags, description);
|
|
388
|
-
}
|
|
389
|
-
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
390
|
-
try {
|
|
391
|
-
return target.parseArg(value, previous);
|
|
392
|
-
} catch (err) {
|
|
393
|
-
if (err.code === "commander.invalidArgument") {
|
|
394
|
-
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
395
|
-
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
396
|
-
}
|
|
397
|
-
throw err;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
_registerOption(option) {
|
|
401
|
-
const matchingOption =
|
|
402
|
-
(option.short && this._findOption(option.short)) ||
|
|
403
|
-
(option.long && this._findOption(option.long));
|
|
404
|
-
if (matchingOption) {
|
|
405
|
-
const matchingFlag =
|
|
406
|
-
option.long && this._findOption(option.long)
|
|
407
|
-
? option.long
|
|
408
|
-
: option.short;
|
|
409
|
-
throw new Error(
|
|
410
|
-
`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'\n- already used by option '${matchingOption.flags}'`,
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
this.options.push(option);
|
|
414
|
-
}
|
|
415
|
-
_registerCommand(command) {
|
|
416
|
-
const knownBy = (cmd) => [cmd.name()].concat(cmd.aliases());
|
|
417
|
-
const alreadyUsed = knownBy(command).find((name) =>
|
|
418
|
-
this._findCommand(name),
|
|
419
|
-
);
|
|
420
|
-
if (alreadyUsed) {
|
|
421
|
-
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join(
|
|
422
|
-
"|",
|
|
423
|
-
);
|
|
424
|
-
const newCmd = knownBy(command).join("|");
|
|
425
|
-
throw new Error(
|
|
426
|
-
`cannot add command '${newCmd}' as already have command '${existingCmd}'`,
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
this.commands.push(command);
|
|
430
|
-
}
|
|
431
|
-
addOption(option) {
|
|
432
|
-
this._registerOption(option);
|
|
433
|
-
const oname = option.name();
|
|
434
|
-
const name = option.attributeName();
|
|
435
|
-
if (option.negate) {
|
|
436
|
-
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
437
|
-
if (!this._findOption(positiveLongFlag)) {
|
|
438
|
-
this.setOptionValueWithSource(
|
|
439
|
-
name,
|
|
440
|
-
option.defaultValue === undefined ? true : option.defaultValue,
|
|
441
|
-
"default",
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
} else if (option.defaultValue !== undefined) {
|
|
445
|
-
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
446
|
-
}
|
|
447
|
-
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
448
|
-
if (val == null && option.presetArg !== undefined) {
|
|
449
|
-
val = option.presetArg;
|
|
450
|
-
}
|
|
451
|
-
const oldValue = this.getOptionValue(name);
|
|
452
|
-
if (val !== null && option.parseArg) {
|
|
453
|
-
val = this._callParseArg(
|
|
454
|
-
option,
|
|
455
|
-
val,
|
|
456
|
-
oldValue,
|
|
457
|
-
invalidValueMessage,
|
|
458
|
-
);
|
|
459
|
-
} else if (val !== null && option.variadic) {
|
|
460
|
-
val = option._concatValue(val, oldValue);
|
|
461
|
-
}
|
|
462
|
-
if (val == null) {
|
|
463
|
-
if (option.negate) {
|
|
464
|
-
val = false;
|
|
465
|
-
} else if (option.isBoolean() || option.optional) {
|
|
466
|
-
val = true;
|
|
467
|
-
} else {
|
|
468
|
-
val = "";
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
this.setOptionValueWithSource(name, val, valueSource);
|
|
472
|
-
};
|
|
473
|
-
this.on("option:" + oname, (val) => {
|
|
474
|
-
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
475
|
-
handleOptionValue(val, invalidValueMessage, "cli");
|
|
476
|
-
});
|
|
477
|
-
if (option.envVar) {
|
|
478
|
-
this.on("optionEnv:" + oname, (val) => {
|
|
479
|
-
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
480
|
-
handleOptionValue(val, invalidValueMessage, "env");
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
return this;
|
|
484
|
-
}
|
|
485
|
-
_optionEx(config, flags, description, fn, defaultValue) {
|
|
486
|
-
if (typeof flags === "object" && flags instanceof Option) {
|
|
487
|
-
throw new Error(
|
|
488
|
-
"To add an Option object use addOption() instead of option() or requiredOption()",
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
const option = this.createOption(flags, description);
|
|
492
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
493
|
-
if (typeof fn === "function") {
|
|
494
|
-
option.default(defaultValue).argParser(fn);
|
|
495
|
-
} else if (fn instanceof RegExp) {
|
|
496
|
-
const regex = fn;
|
|
497
|
-
fn = (val, def) => {
|
|
498
|
-
const m = regex.exec(val);
|
|
499
|
-
return m ? m[0] : def;
|
|
500
|
-
};
|
|
501
|
-
option.default(defaultValue).argParser(fn);
|
|
502
|
-
} else {
|
|
503
|
-
option.default(fn);
|
|
504
|
-
}
|
|
505
|
-
return this.addOption(option);
|
|
506
|
-
}
|
|
507
|
-
option(flags, description, parseArg, defaultValue) {
|
|
508
|
-
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
509
|
-
}
|
|
510
|
-
requiredOption(flags, description, parseArg, defaultValue) {
|
|
511
|
-
return this._optionEx(
|
|
512
|
-
{ mandatory: true },
|
|
513
|
-
flags,
|
|
514
|
-
description,
|
|
515
|
-
parseArg,
|
|
516
|
-
defaultValue,
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
combineFlagAndOptionalValue(combine = true) {
|
|
520
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
521
|
-
return this;
|
|
522
|
-
}
|
|
523
|
-
allowUnknownOption(allowUnknown = true) {
|
|
524
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
525
|
-
return this;
|
|
526
|
-
}
|
|
527
|
-
allowExcessArguments(allowExcess = true) {
|
|
528
|
-
this._allowExcessArguments = !!allowExcess;
|
|
529
|
-
return this;
|
|
530
|
-
}
|
|
531
|
-
enablePositionalOptions(positional = true) {
|
|
532
|
-
this._enablePositionalOptions = !!positional;
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
passThroughOptions(passThrough = true) {
|
|
536
|
-
this._passThroughOptions = !!passThrough;
|
|
537
|
-
this._checkForBrokenPassThrough();
|
|
538
|
-
return this;
|
|
539
|
-
}
|
|
540
|
-
_checkForBrokenPassThrough() {
|
|
541
|
-
if (
|
|
542
|
-
this.parent &&
|
|
543
|
-
this._passThroughOptions &&
|
|
544
|
-
!this.parent._enablePositionalOptions
|
|
545
|
-
) {
|
|
546
|
-
throw new Error(
|
|
547
|
-
`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`,
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
storeOptionsAsProperties(storeAsProperties = true) {
|
|
552
|
-
if (this.options.length) {
|
|
553
|
-
throw new Error(
|
|
554
|
-
"call .storeOptionsAsProperties() before adding options",
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
if (Object.keys(this._optionValues).length) {
|
|
558
|
-
throw new Error(
|
|
559
|
-
"call .storeOptionsAsProperties() before setting option values",
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
563
|
-
return this;
|
|
564
|
-
}
|
|
565
|
-
getOptionValue(key) {
|
|
566
|
-
if (this._storeOptionsAsProperties) {
|
|
567
|
-
return this[key];
|
|
568
|
-
}
|
|
569
|
-
return this._optionValues[key];
|
|
570
|
-
}
|
|
571
|
-
setOptionValue(key, value) {
|
|
572
|
-
return this.setOptionValueWithSource(key, value, undefined);
|
|
573
|
-
}
|
|
574
|
-
setOptionValueWithSource(key, value, source) {
|
|
575
|
-
if (this._storeOptionsAsProperties) {
|
|
576
|
-
this[key] = value;
|
|
577
|
-
} else {
|
|
578
|
-
this._optionValues[key] = value;
|
|
579
|
-
}
|
|
580
|
-
this._optionValueSources[key] = source;
|
|
581
|
-
return this;
|
|
582
|
-
}
|
|
583
|
-
getOptionValueSource(key) {
|
|
584
|
-
return this._optionValueSources[key];
|
|
585
|
-
}
|
|
586
|
-
getOptionValueSourceWithGlobals(key) {
|
|
587
|
-
let source;
|
|
588
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
589
|
-
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
590
|
-
source = cmd.getOptionValueSource(key);
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
return source;
|
|
594
|
-
}
|
|
595
|
-
_prepareUserArgs(argv, parseOptions) {
|
|
596
|
-
if (argv !== undefined && !Array.isArray(argv)) {
|
|
597
|
-
throw new Error(
|
|
598
|
-
"first parameter to parse must be array or undefined",
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
parseOptions = parseOptions || {};
|
|
602
|
-
if (argv === undefined && parseOptions.from === undefined) {
|
|
603
|
-
if (process.versions?.electron) {
|
|
604
|
-
parseOptions.from = "electron";
|
|
605
|
-
}
|
|
606
|
-
const execArgv = process.execArgv ?? [];
|
|
607
|
-
if (
|
|
608
|
-
execArgv.includes("-e") ||
|
|
609
|
-
execArgv.includes("--eval") ||
|
|
610
|
-
execArgv.includes("-p") ||
|
|
611
|
-
execArgv.includes("--print")
|
|
612
|
-
) {
|
|
613
|
-
parseOptions.from = "eval";
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
if (argv === undefined) {
|
|
617
|
-
argv = process.argv;
|
|
618
|
-
}
|
|
619
|
-
this.rawArgs = argv.slice();
|
|
620
|
-
let userArgs;
|
|
621
|
-
switch (parseOptions.from) {
|
|
622
|
-
case undefined:
|
|
623
|
-
case "node":
|
|
624
|
-
this._scriptPath = argv[1];
|
|
625
|
-
userArgs = argv.slice(2);
|
|
626
|
-
break;
|
|
627
|
-
case "electron":
|
|
628
|
-
if (process.defaultApp) {
|
|
629
|
-
this._scriptPath = argv[1];
|
|
630
|
-
userArgs = argv.slice(2);
|
|
631
|
-
} else {
|
|
632
|
-
userArgs = argv.slice(1);
|
|
633
|
-
}
|
|
634
|
-
break;
|
|
635
|
-
case "user":
|
|
636
|
-
userArgs = argv.slice(0);
|
|
637
|
-
break;
|
|
638
|
-
case "eval":
|
|
639
|
-
userArgs = argv.slice(1);
|
|
640
|
-
break;
|
|
641
|
-
default:
|
|
642
|
-
throw new Error(
|
|
643
|
-
`unexpected parse option { from: '${parseOptions.from}' }`,
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
if (!this._name && this._scriptPath)
|
|
647
|
-
this.nameFromFilename(this._scriptPath);
|
|
648
|
-
this._name = this._name || "program";
|
|
649
|
-
return userArgs;
|
|
650
|
-
}
|
|
651
|
-
parse(argv, parseOptions) {
|
|
652
|
-
this._prepareForParse();
|
|
653
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
654
|
-
this._parseCommand([], userArgs);
|
|
655
|
-
return this;
|
|
656
|
-
}
|
|
657
|
-
async parseAsync(argv, parseOptions) {
|
|
658
|
-
this._prepareForParse();
|
|
659
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
660
|
-
await this._parseCommand([], userArgs);
|
|
661
|
-
return this;
|
|
662
|
-
}
|
|
663
|
-
_prepareForParse() {
|
|
664
|
-
if (this._savedState === null) {
|
|
665
|
-
this.saveStateBeforeParse();
|
|
666
|
-
} else {
|
|
667
|
-
this.restoreStateBeforeParse();
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
saveStateBeforeParse() {
|
|
671
|
-
this._savedState = {
|
|
672
|
-
_name: this._name,
|
|
673
|
-
_optionValues: { ...this._optionValues },
|
|
674
|
-
_optionValueSources: { ...this._optionValueSources },
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
restoreStateBeforeParse() {
|
|
678
|
-
if (this._storeOptionsAsProperties)
|
|
679
|
-
throw new Error(
|
|
680
|
-
`Can not call parse again when storeOptionsAsProperties is true.\n- either make a new Command for each call to parse, or stop storing options as properties`,
|
|
681
|
-
);
|
|
682
|
-
this._name = this._savedState._name;
|
|
683
|
-
this._scriptPath = null;
|
|
684
|
-
this.rawArgs = [];
|
|
685
|
-
this._optionValues = { ...this._savedState._optionValues };
|
|
686
|
-
this._optionValueSources = {
|
|
687
|
-
...this._savedState._optionValueSources,
|
|
688
|
-
};
|
|
689
|
-
this.args = [];
|
|
690
|
-
this.processedArgs = [];
|
|
691
|
-
}
|
|
692
|
-
_checkForMissingExecutable(
|
|
693
|
-
executableFile,
|
|
694
|
-
executableDir,
|
|
695
|
-
subcommandName,
|
|
696
|
-
) {
|
|
697
|
-
if (fs.existsSync(executableFile)) return;
|
|
698
|
-
const executableDirMessage = executableDir
|
|
699
|
-
? `searched for local subcommand relative to directory '${executableDir}'`
|
|
700
|
-
: "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
701
|
-
const executableMissing = `'${executableFile}' does not exist\n - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${executableDirMessage}`;
|
|
702
|
-
throw new Error(executableMissing);
|
|
703
|
-
}
|
|
704
|
-
_executeSubCommand(subcommand, args) {
|
|
705
|
-
args = args.slice();
|
|
706
|
-
let launchWithNode = false;
|
|
707
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
708
|
-
function findFile(baseDir, baseName) {
|
|
709
|
-
const localBin = path.resolve(baseDir, baseName);
|
|
710
|
-
if (fs.existsSync(localBin)) return localBin;
|
|
711
|
-
if (sourceExt.includes(path.extname(baseName))) return undefined;
|
|
712
|
-
const foundExt = sourceExt.find((ext) =>
|
|
713
|
-
fs.existsSync(`${localBin}${ext}`),
|
|
714
|
-
);
|
|
715
|
-
if (foundExt) return `${localBin}${foundExt}`;
|
|
716
|
-
return undefined;
|
|
717
|
-
}
|
|
718
|
-
this._checkForMissingMandatoryOptions();
|
|
719
|
-
this._checkForConflictingOptions();
|
|
720
|
-
let executableFile =
|
|
721
|
-
subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
722
|
-
let executableDir = this._executableDir || "";
|
|
723
|
-
if (this._scriptPath) {
|
|
724
|
-
let resolvedScriptPath;
|
|
725
|
-
try {
|
|
726
|
-
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
727
|
-
} catch {
|
|
728
|
-
resolvedScriptPath = this._scriptPath;
|
|
729
|
-
}
|
|
730
|
-
executableDir = path.resolve(
|
|
731
|
-
path.dirname(resolvedScriptPath),
|
|
732
|
-
executableDir,
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
if (executableDir) {
|
|
736
|
-
let localFile = findFile(executableDir, executableFile);
|
|
737
|
-
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
738
|
-
const legacyName = path.basename(
|
|
739
|
-
this._scriptPath,
|
|
740
|
-
path.extname(this._scriptPath),
|
|
741
|
-
);
|
|
742
|
-
if (legacyName !== this._name) {
|
|
743
|
-
localFile = findFile(
|
|
744
|
-
executableDir,
|
|
745
|
-
`${legacyName}-${subcommand._name}`,
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
executableFile = localFile || executableFile;
|
|
750
|
-
}
|
|
751
|
-
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
752
|
-
let proc;
|
|
753
|
-
if (process.platform !== "win32") {
|
|
754
|
-
if (launchWithNode) {
|
|
755
|
-
args.unshift(executableFile);
|
|
756
|
-
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
757
|
-
proc = childProcess.spawn(process.argv[0], args, {
|
|
758
|
-
stdio: "inherit",
|
|
759
|
-
});
|
|
760
|
-
} else {
|
|
761
|
-
proc = childProcess.spawn(executableFile, args, {
|
|
762
|
-
stdio: "inherit",
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
} else {
|
|
766
|
-
this._checkForMissingExecutable(
|
|
767
|
-
executableFile,
|
|
768
|
-
executableDir,
|
|
769
|
-
subcommand._name,
|
|
770
|
-
);
|
|
771
|
-
args.unshift(executableFile);
|
|
772
|
-
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
773
|
-
proc = childProcess.spawn(process.execPath, args, {
|
|
774
|
-
stdio: "inherit",
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
if (!proc.killed) {
|
|
778
|
-
const signals = [
|
|
779
|
-
"SIGUSR1",
|
|
780
|
-
"SIGUSR2",
|
|
781
|
-
"SIGTERM",
|
|
782
|
-
"SIGINT",
|
|
783
|
-
"SIGHUP",
|
|
784
|
-
];
|
|
785
|
-
signals.forEach((signal) => {
|
|
786
|
-
process.on(signal, () => {
|
|
787
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
788
|
-
proc.kill(signal);
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
const exitCallback = this._exitCallback;
|
|
794
|
-
proc.on("close", (code) => {
|
|
795
|
-
code = code ?? 1;
|
|
796
|
-
if (!exitCallback) {
|
|
797
|
-
process.exit(code);
|
|
798
|
-
} else {
|
|
799
|
-
exitCallback(
|
|
800
|
-
new CommanderError(
|
|
801
|
-
code,
|
|
802
|
-
"commander.executeSubCommandAsync",
|
|
803
|
-
"(close)",
|
|
804
|
-
),
|
|
805
|
-
);
|
|
806
|
-
}
|
|
807
|
-
});
|
|
808
|
-
proc.on("error", (err) => {
|
|
809
|
-
if (err.code === "ENOENT") {
|
|
810
|
-
this._checkForMissingExecutable(
|
|
811
|
-
executableFile,
|
|
812
|
-
executableDir,
|
|
813
|
-
subcommand._name,
|
|
814
|
-
);
|
|
815
|
-
} else if (err.code === "EACCES") {
|
|
816
|
-
throw new Error(`'${executableFile}' not executable`);
|
|
817
|
-
}
|
|
818
|
-
if (!exitCallback) {
|
|
819
|
-
process.exit(1);
|
|
820
|
-
} else {
|
|
821
|
-
const wrappedError = new CommanderError(
|
|
822
|
-
1,
|
|
823
|
-
"commander.executeSubCommandAsync",
|
|
824
|
-
"(error)",
|
|
825
|
-
);
|
|
826
|
-
wrappedError.nestedError = err;
|
|
827
|
-
exitCallback(wrappedError);
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
this.runningCommand = proc;
|
|
831
|
-
}
|
|
832
|
-
_dispatchSubcommand(commandName, operands, unknown) {
|
|
833
|
-
const subCommand = this._findCommand(commandName);
|
|
834
|
-
if (!subCommand) this.help({ error: true });
|
|
835
|
-
subCommand._prepareForParse();
|
|
836
|
-
let promiseChain;
|
|
837
|
-
promiseChain = this._chainOrCallSubCommandHook(
|
|
838
|
-
promiseChain,
|
|
839
|
-
subCommand,
|
|
840
|
-
"preSubcommand",
|
|
841
|
-
);
|
|
842
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
843
|
-
if (subCommand._executableHandler) {
|
|
844
|
-
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
845
|
-
} else {
|
|
846
|
-
return subCommand._parseCommand(operands, unknown);
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
return promiseChain;
|
|
850
|
-
}
|
|
851
|
-
_dispatchHelpCommand(subcommandName) {
|
|
852
|
-
if (!subcommandName) {
|
|
853
|
-
this.help();
|
|
854
|
-
}
|
|
855
|
-
const subCommand = this._findCommand(subcommandName);
|
|
856
|
-
if (subCommand && !subCommand._executableHandler) {
|
|
857
|
-
subCommand.help();
|
|
858
|
-
}
|
|
859
|
-
return this._dispatchSubcommand(
|
|
860
|
-
subcommandName,
|
|
861
|
-
[],
|
|
862
|
-
[
|
|
863
|
-
this._getHelpOption()?.long ??
|
|
864
|
-
this._getHelpOption()?.short ??
|
|
865
|
-
"--help",
|
|
866
|
-
],
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
_checkNumberOfArguments() {
|
|
870
|
-
this.registeredArguments.forEach((arg, i) => {
|
|
871
|
-
if (arg.required && this.args[i] == null) {
|
|
872
|
-
this.missingArgument(arg.name());
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
if (
|
|
876
|
-
this.registeredArguments.length > 0 &&
|
|
877
|
-
this.registeredArguments[this.registeredArguments.length - 1]
|
|
878
|
-
.variadic
|
|
879
|
-
) {
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
if (this.args.length > this.registeredArguments.length) {
|
|
883
|
-
this._excessArguments(this.args);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
_processArguments() {
|
|
887
|
-
const myParseArg = (argument, value, previous) => {
|
|
888
|
-
let parsedValue = value;
|
|
889
|
-
if (value !== null && argument.parseArg) {
|
|
890
|
-
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
891
|
-
parsedValue = this._callParseArg(
|
|
892
|
-
argument,
|
|
893
|
-
value,
|
|
894
|
-
previous,
|
|
895
|
-
invalidValueMessage,
|
|
896
|
-
);
|
|
897
|
-
}
|
|
898
|
-
return parsedValue;
|
|
899
|
-
};
|
|
900
|
-
this._checkNumberOfArguments();
|
|
901
|
-
const processedArgs = [];
|
|
902
|
-
this.registeredArguments.forEach((declaredArg, index) => {
|
|
903
|
-
let value = declaredArg.defaultValue;
|
|
904
|
-
if (declaredArg.variadic) {
|
|
905
|
-
if (index < this.args.length) {
|
|
906
|
-
value = this.args.slice(index);
|
|
907
|
-
if (declaredArg.parseArg) {
|
|
908
|
-
value = value.reduce(
|
|
909
|
-
(processed, v) => myParseArg(declaredArg, v, processed),
|
|
910
|
-
declaredArg.defaultValue,
|
|
911
|
-
);
|
|
912
|
-
}
|
|
913
|
-
} else if (value === undefined) {
|
|
914
|
-
value = [];
|
|
915
|
-
}
|
|
916
|
-
} else if (index < this.args.length) {
|
|
917
|
-
value = this.args[index];
|
|
918
|
-
if (declaredArg.parseArg) {
|
|
919
|
-
value = myParseArg(
|
|
920
|
-
declaredArg,
|
|
921
|
-
value,
|
|
922
|
-
declaredArg.defaultValue,
|
|
923
|
-
);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
processedArgs[index] = value;
|
|
927
|
-
});
|
|
928
|
-
this.processedArgs = processedArgs;
|
|
929
|
-
}
|
|
930
|
-
_chainOrCall(promise, fn) {
|
|
931
|
-
if (promise && promise.then && typeof promise.then === "function") {
|
|
932
|
-
return promise.then(() => fn());
|
|
933
|
-
}
|
|
934
|
-
return fn();
|
|
935
|
-
}
|
|
936
|
-
_chainOrCallHooks(promise, event) {
|
|
937
|
-
let result = promise;
|
|
938
|
-
const hooks = [];
|
|
939
|
-
this._getCommandAndAncestors()
|
|
940
|
-
.reverse()
|
|
941
|
-
.filter((cmd) => cmd._lifeCycleHooks[event] !== undefined)
|
|
942
|
-
.forEach((hookedCommand) => {
|
|
943
|
-
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
944
|
-
hooks.push({ hookedCommand, callback });
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
if (event === "postAction") {
|
|
948
|
-
hooks.reverse();
|
|
949
|
-
}
|
|
950
|
-
hooks.forEach((hookDetail) => {
|
|
951
|
-
result = this._chainOrCall(result, () =>
|
|
952
|
-
hookDetail.callback(hookDetail.hookedCommand, this),
|
|
953
|
-
);
|
|
954
|
-
});
|
|
955
|
-
return result;
|
|
956
|
-
}
|
|
957
|
-
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
958
|
-
let result = promise;
|
|
959
|
-
if (this._lifeCycleHooks[event] !== undefined) {
|
|
960
|
-
this._lifeCycleHooks[event].forEach((hook) => {
|
|
961
|
-
result = this._chainOrCall(result, () => hook(this, subCommand));
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
return result;
|
|
965
|
-
}
|
|
966
|
-
_parseCommand(operands, unknown) {
|
|
967
|
-
const parsed = this.parseOptions(unknown);
|
|
968
|
-
this._parseOptionsEnv();
|
|
969
|
-
this._parseOptionsImplied();
|
|
970
|
-
operands = operands.concat(parsed.operands);
|
|
971
|
-
unknown = parsed.unknown;
|
|
972
|
-
this.args = operands.concat(unknown);
|
|
973
|
-
if (operands && this._findCommand(operands[0])) {
|
|
974
|
-
return this._dispatchSubcommand(
|
|
975
|
-
operands[0],
|
|
976
|
-
operands.slice(1),
|
|
977
|
-
unknown,
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
if (
|
|
981
|
-
this._getHelpCommand() &&
|
|
982
|
-
operands[0] === this._getHelpCommand().name()
|
|
983
|
-
) {
|
|
984
|
-
return this._dispatchHelpCommand(operands[1]);
|
|
985
|
-
}
|
|
986
|
-
if (this._defaultCommandName) {
|
|
987
|
-
this._outputHelpIfRequested(unknown);
|
|
988
|
-
return this._dispatchSubcommand(
|
|
989
|
-
this._defaultCommandName,
|
|
990
|
-
operands,
|
|
991
|
-
unknown,
|
|
992
|
-
);
|
|
993
|
-
}
|
|
994
|
-
if (
|
|
995
|
-
this.commands.length &&
|
|
996
|
-
this.args.length === 0 &&
|
|
997
|
-
!this._actionHandler &&
|
|
998
|
-
!this._defaultCommandName
|
|
999
|
-
) {
|
|
1000
|
-
this.help({ error: true });
|
|
1001
|
-
}
|
|
1002
|
-
this._outputHelpIfRequested(parsed.unknown);
|
|
1003
|
-
this._checkForMissingMandatoryOptions();
|
|
1004
|
-
this._checkForConflictingOptions();
|
|
1005
|
-
const checkForUnknownOptions = () => {
|
|
1006
|
-
if (parsed.unknown.length > 0) {
|
|
1007
|
-
this.unknownOption(parsed.unknown[0]);
|
|
1008
|
-
}
|
|
1009
|
-
};
|
|
1010
|
-
const commandEvent = `command:${this.name()}`;
|
|
1011
|
-
if (this._actionHandler) {
|
|
1012
|
-
checkForUnknownOptions();
|
|
1013
|
-
this._processArguments();
|
|
1014
|
-
let promiseChain;
|
|
1015
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1016
|
-
promiseChain = this._chainOrCall(promiseChain, () =>
|
|
1017
|
-
this._actionHandler(this.processedArgs),
|
|
1018
|
-
);
|
|
1019
|
-
if (this.parent) {
|
|
1020
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1021
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1025
|
-
return promiseChain;
|
|
1026
|
-
}
|
|
1027
|
-
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1028
|
-
checkForUnknownOptions();
|
|
1029
|
-
this._processArguments();
|
|
1030
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1031
|
-
} else if (operands.length) {
|
|
1032
|
-
if (this._findCommand("*")) {
|
|
1033
|
-
return this._dispatchSubcommand("*", operands, unknown);
|
|
1034
|
-
}
|
|
1035
|
-
if (this.listenerCount("command:*")) {
|
|
1036
|
-
this.emit("command:*", operands, unknown);
|
|
1037
|
-
} else if (this.commands.length) {
|
|
1038
|
-
this.unknownCommand();
|
|
1039
|
-
} else {
|
|
1040
|
-
checkForUnknownOptions();
|
|
1041
|
-
this._processArguments();
|
|
1042
|
-
}
|
|
1043
|
-
} else if (this.commands.length) {
|
|
1044
|
-
checkForUnknownOptions();
|
|
1045
|
-
this.help({ error: true });
|
|
1046
|
-
} else {
|
|
1047
|
-
checkForUnknownOptions();
|
|
1048
|
-
this._processArguments();
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
_findCommand(name) {
|
|
1052
|
-
if (!name) return undefined;
|
|
1053
|
-
return this.commands.find(
|
|
1054
|
-
(cmd) => cmd._name === name || cmd._aliases.includes(name),
|
|
1055
|
-
);
|
|
1056
|
-
}
|
|
1057
|
-
_findOption(arg) {
|
|
1058
|
-
return this.options.find((option) => option.is(arg));
|
|
1059
|
-
}
|
|
1060
|
-
_checkForMissingMandatoryOptions() {
|
|
1061
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1062
|
-
cmd.options.forEach((anOption) => {
|
|
1063
|
-
if (
|
|
1064
|
-
anOption.mandatory &&
|
|
1065
|
-
cmd.getOptionValue(anOption.attributeName()) === undefined
|
|
1066
|
-
) {
|
|
1067
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
_checkForConflictingLocalOptions() {
|
|
1073
|
-
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1074
|
-
const optionKey = option.attributeName();
|
|
1075
|
-
if (this.getOptionValue(optionKey) === undefined) {
|
|
1076
|
-
return false;
|
|
1077
|
-
}
|
|
1078
|
-
return this.getOptionValueSource(optionKey) !== "default";
|
|
1079
|
-
});
|
|
1080
|
-
const optionsWithConflicting = definedNonDefaultOptions.filter(
|
|
1081
|
-
(option) => option.conflictsWith.length > 0,
|
|
1082
|
-
);
|
|
1083
|
-
optionsWithConflicting.forEach((option) => {
|
|
1084
|
-
const conflictingAndDefined = definedNonDefaultOptions.find(
|
|
1085
|
-
(defined) =>
|
|
1086
|
-
option.conflictsWith.includes(defined.attributeName()),
|
|
1087
|
-
);
|
|
1088
|
-
if (conflictingAndDefined) {
|
|
1089
|
-
this._conflictingOption(option, conflictingAndDefined);
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
_checkForConflictingOptions() {
|
|
1094
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1095
|
-
cmd._checkForConflictingLocalOptions();
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
parseOptions(argv) {
|
|
1099
|
-
const operands = [];
|
|
1100
|
-
const unknown = [];
|
|
1101
|
-
let dest = operands;
|
|
1102
|
-
const args = argv.slice();
|
|
1103
|
-
function maybeOption(arg) {
|
|
1104
|
-
return arg.length > 1 && arg[0] === "-";
|
|
1105
|
-
}
|
|
1106
|
-
let activeVariadicOption = null;
|
|
1107
|
-
while (args.length) {
|
|
1108
|
-
const arg = args.shift();
|
|
1109
|
-
if (arg === "--") {
|
|
1110
|
-
if (dest === unknown) dest.push(arg);
|
|
1111
|
-
dest.push(...args);
|
|
1112
|
-
break;
|
|
1113
|
-
}
|
|
1114
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1115
|
-
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1116
|
-
continue;
|
|
1117
|
-
}
|
|
1118
|
-
activeVariadicOption = null;
|
|
1119
|
-
if (maybeOption(arg)) {
|
|
1120
|
-
const option = this._findOption(arg);
|
|
1121
|
-
if (option) {
|
|
1122
|
-
if (option.required) {
|
|
1123
|
-
const value = args.shift();
|
|
1124
|
-
if (value === undefined) this.optionMissingArgument(option);
|
|
1125
|
-
this.emit(`option:${option.name()}`, value);
|
|
1126
|
-
} else if (option.optional) {
|
|
1127
|
-
let value = null;
|
|
1128
|
-
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1129
|
-
value = args.shift();
|
|
1130
|
-
}
|
|
1131
|
-
this.emit(`option:${option.name()}`, value);
|
|
1132
|
-
} else {
|
|
1133
|
-
this.emit(`option:${option.name()}`);
|
|
1134
|
-
}
|
|
1135
|
-
activeVariadicOption = option.variadic ? option : null;
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1140
|
-
const option = this._findOption(`-${arg[1]}`);
|
|
1141
|
-
if (option) {
|
|
1142
|
-
if (
|
|
1143
|
-
option.required ||
|
|
1144
|
-
(option.optional && this._combineFlagAndOptionalValue)
|
|
1145
|
-
) {
|
|
1146
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1147
|
-
} else {
|
|
1148
|
-
this.emit(`option:${option.name()}`);
|
|
1149
|
-
args.unshift(`-${arg.slice(2)}`);
|
|
1150
|
-
}
|
|
1151
|
-
continue;
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
if (/^--[^=]+=/.test(arg)) {
|
|
1155
|
-
const index = arg.indexOf("=");
|
|
1156
|
-
const option = this._findOption(arg.slice(0, index));
|
|
1157
|
-
if (option && (option.required || option.optional)) {
|
|
1158
|
-
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
if (maybeOption(arg)) {
|
|
1163
|
-
dest = unknown;
|
|
1164
|
-
}
|
|
1165
|
-
if (
|
|
1166
|
-
(this._enablePositionalOptions || this._passThroughOptions) &&
|
|
1167
|
-
operands.length === 0 &&
|
|
1168
|
-
unknown.length === 0
|
|
1169
|
-
) {
|
|
1170
|
-
if (this._findCommand(arg)) {
|
|
1171
|
-
operands.push(arg);
|
|
1172
|
-
if (args.length > 0) unknown.push(...args);
|
|
1173
|
-
break;
|
|
1174
|
-
} else if (
|
|
1175
|
-
this._getHelpCommand() &&
|
|
1176
|
-
arg === this._getHelpCommand().name()
|
|
1177
|
-
) {
|
|
1178
|
-
operands.push(arg);
|
|
1179
|
-
if (args.length > 0) operands.push(...args);
|
|
1180
|
-
break;
|
|
1181
|
-
} else if (this._defaultCommandName) {
|
|
1182
|
-
unknown.push(arg);
|
|
1183
|
-
if (args.length > 0) unknown.push(...args);
|
|
1184
|
-
break;
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
if (this._passThroughOptions) {
|
|
1188
|
-
dest.push(arg);
|
|
1189
|
-
if (args.length > 0) dest.push(...args);
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
dest.push(arg);
|
|
1193
|
-
}
|
|
1194
|
-
return { operands, unknown };
|
|
1195
|
-
}
|
|
1196
|
-
opts() {
|
|
1197
|
-
if (this._storeOptionsAsProperties) {
|
|
1198
|
-
const result = {};
|
|
1199
|
-
const len = this.options.length;
|
|
1200
|
-
for (let i = 0; i < len; i++) {
|
|
1201
|
-
const key = this.options[i].attributeName();
|
|
1202
|
-
result[key] =
|
|
1203
|
-
key === this._versionOptionName ? this._version : this[key];
|
|
1204
|
-
}
|
|
1205
|
-
return result;
|
|
1206
|
-
}
|
|
1207
|
-
return this._optionValues;
|
|
1208
|
-
}
|
|
1209
|
-
optsWithGlobals() {
|
|
1210
|
-
return this._getCommandAndAncestors().reduce(
|
|
1211
|
-
(combinedOptions, cmd) =>
|
|
1212
|
-
Object.assign(combinedOptions, cmd.opts()),
|
|
1213
|
-
{},
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
error(message, errorOptions) {
|
|
1217
|
-
this._outputConfiguration.outputError(
|
|
1218
|
-
`${message}\n`,
|
|
1219
|
-
this._outputConfiguration.writeErr,
|
|
1220
|
-
);
|
|
1221
|
-
if (typeof this._showHelpAfterError === "string") {
|
|
1222
|
-
this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
|
|
1223
|
-
} else if (this._showHelpAfterError) {
|
|
1224
|
-
this._outputConfiguration.writeErr("\n");
|
|
1225
|
-
this.outputHelp({ error: true });
|
|
1226
|
-
}
|
|
1227
|
-
const config = errorOptions || {};
|
|
1228
|
-
const exitCode = config.exitCode || 1;
|
|
1229
|
-
const code = config.code || "commander.error";
|
|
1230
|
-
this._exit(exitCode, code, message);
|
|
1231
|
-
}
|
|
1232
|
-
_parseOptionsEnv() {
|
|
1233
|
-
this.options.forEach((option) => {
|
|
1234
|
-
if (option.envVar && option.envVar in process.env) {
|
|
1235
|
-
const optionKey = option.attributeName();
|
|
1236
|
-
if (
|
|
1237
|
-
this.getOptionValue(optionKey) === undefined ||
|
|
1238
|
-
["default", "config", "env"].includes(
|
|
1239
|
-
this.getOptionValueSource(optionKey),
|
|
1240
|
-
)
|
|
1241
|
-
) {
|
|
1242
|
-
if (option.required || option.optional) {
|
|
1243
|
-
this.emit(
|
|
1244
|
-
`optionEnv:${option.name()}`,
|
|
1245
|
-
process.env[option.envVar],
|
|
1246
|
-
);
|
|
1247
|
-
} else {
|
|
1248
|
-
this.emit(`optionEnv:${option.name()}`);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
_parseOptionsImplied() {
|
|
1255
|
-
const dualHelper = new DualOptions(this.options);
|
|
1256
|
-
const hasCustomOptionValue = (optionKey) =>
|
|
1257
|
-
this.getOptionValue(optionKey) !== undefined &&
|
|
1258
|
-
!["default", "implied"].includes(
|
|
1259
|
-
this.getOptionValueSource(optionKey),
|
|
1260
|
-
);
|
|
1261
|
-
this.options
|
|
1262
|
-
.filter(
|
|
1263
|
-
(option) =>
|
|
1264
|
-
option.implied !== undefined &&
|
|
1265
|
-
hasCustomOptionValue(option.attributeName()) &&
|
|
1266
|
-
dualHelper.valueFromOption(
|
|
1267
|
-
this.getOptionValue(option.attributeName()),
|
|
1268
|
-
option,
|
|
1269
|
-
),
|
|
1270
|
-
)
|
|
1271
|
-
.forEach((option) => {
|
|
1272
|
-
Object.keys(option.implied)
|
|
1273
|
-
.filter((impliedKey) => !hasCustomOptionValue(impliedKey))
|
|
1274
|
-
.forEach((impliedKey) => {
|
|
1275
|
-
this.setOptionValueWithSource(
|
|
1276
|
-
impliedKey,
|
|
1277
|
-
option.implied[impliedKey],
|
|
1278
|
-
"implied",
|
|
1279
|
-
);
|
|
1280
|
-
});
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
missingArgument(name) {
|
|
1284
|
-
const message = `error: missing required argument '${name}'`;
|
|
1285
|
-
this.error(message, { code: "commander.missingArgument" });
|
|
1286
|
-
}
|
|
1287
|
-
optionMissingArgument(option) {
|
|
1288
|
-
const message = `error: option '${option.flags}' argument missing`;
|
|
1289
|
-
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1290
|
-
}
|
|
1291
|
-
missingMandatoryOptionValue(option) {
|
|
1292
|
-
const message = `error: required option '${option.flags}' not specified`;
|
|
1293
|
-
this.error(message, {
|
|
1294
|
-
code: "commander.missingMandatoryOptionValue",
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
_conflictingOption(option, conflictingOption) {
|
|
1298
|
-
const findBestOptionFromValue = (option) => {
|
|
1299
|
-
const optionKey = option.attributeName();
|
|
1300
|
-
const optionValue = this.getOptionValue(optionKey);
|
|
1301
|
-
const negativeOption = this.options.find(
|
|
1302
|
-
(target) => target.negate && optionKey === target.attributeName(),
|
|
1303
|
-
);
|
|
1304
|
-
const positiveOption = this.options.find(
|
|
1305
|
-
(target) =>
|
|
1306
|
-
!target.negate && optionKey === target.attributeName(),
|
|
1307
|
-
);
|
|
1308
|
-
if (
|
|
1309
|
-
negativeOption &&
|
|
1310
|
-
((negativeOption.presetArg === undefined &&
|
|
1311
|
-
optionValue === false) ||
|
|
1312
|
-
(negativeOption.presetArg !== undefined &&
|
|
1313
|
-
optionValue === negativeOption.presetArg))
|
|
1314
|
-
) {
|
|
1315
|
-
return negativeOption;
|
|
1316
|
-
}
|
|
1317
|
-
return positiveOption || option;
|
|
1318
|
-
};
|
|
1319
|
-
const getErrorMessage = (option) => {
|
|
1320
|
-
const bestOption = findBestOptionFromValue(option);
|
|
1321
|
-
const optionKey = bestOption.attributeName();
|
|
1322
|
-
const source = this.getOptionValueSource(optionKey);
|
|
1323
|
-
if (source === "env") {
|
|
1324
|
-
return `environment variable '${bestOption.envVar}'`;
|
|
1325
|
-
}
|
|
1326
|
-
return `option '${bestOption.flags}'`;
|
|
1327
|
-
};
|
|
1328
|
-
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1329
|
-
this.error(message, { code: "commander.conflictingOption" });
|
|
1330
|
-
}
|
|
1331
|
-
unknownOption(flag) {
|
|
1332
|
-
if (this._allowUnknownOption) return;
|
|
1333
|
-
let suggestion = "";
|
|
1334
|
-
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1335
|
-
let candidateFlags = [];
|
|
1336
|
-
let command = this;
|
|
1337
|
-
do {
|
|
1338
|
-
const moreFlags = command
|
|
1339
|
-
.createHelp()
|
|
1340
|
-
.visibleOptions(command)
|
|
1341
|
-
.filter((option) => option.long)
|
|
1342
|
-
.map((option) => option.long);
|
|
1343
|
-
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1344
|
-
command = command.parent;
|
|
1345
|
-
} while (command && !command._enablePositionalOptions);
|
|
1346
|
-
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1347
|
-
}
|
|
1348
|
-
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1349
|
-
this.error(message, { code: "commander.unknownOption" });
|
|
1350
|
-
}
|
|
1351
|
-
_excessArguments(receivedArgs) {
|
|
1352
|
-
if (this._allowExcessArguments) return;
|
|
1353
|
-
const expected = this.registeredArguments.length;
|
|
1354
|
-
const s = expected === 1 ? "" : "s";
|
|
1355
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1356
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1357
|
-
this.error(message, { code: "commander.excessArguments" });
|
|
1358
|
-
}
|
|
1359
|
-
unknownCommand() {
|
|
1360
|
-
const unknownName = this.args[0];
|
|
1361
|
-
let suggestion = "";
|
|
1362
|
-
if (this._showSuggestionAfterError) {
|
|
1363
|
-
const candidateNames = [];
|
|
1364
|
-
this.createHelp()
|
|
1365
|
-
.visibleCommands(this)
|
|
1366
|
-
.forEach((command) => {
|
|
1367
|
-
candidateNames.push(command.name());
|
|
1368
|
-
if (command.alias()) candidateNames.push(command.alias());
|
|
1369
|
-
});
|
|
1370
|
-
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1371
|
-
}
|
|
1372
|
-
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1373
|
-
this.error(message, { code: "commander.unknownCommand" });
|
|
1374
|
-
}
|
|
1375
|
-
version(str, flags, description) {
|
|
1376
|
-
if (str === undefined) return this._version;
|
|
1377
|
-
this._version = str;
|
|
1378
|
-
flags = flags || "-V, --version";
|
|
1379
|
-
description = description || "output the version number";
|
|
1380
|
-
const versionOption = this.createOption(flags, description);
|
|
1381
|
-
this._versionOptionName = versionOption.attributeName();
|
|
1382
|
-
this._registerOption(versionOption);
|
|
1383
|
-
this.on("option:" + versionOption.name(), () => {
|
|
1384
|
-
this._outputConfiguration.writeOut(`${str}\n`);
|
|
1385
|
-
this._exit(0, "commander.version", str);
|
|
1386
|
-
});
|
|
1387
|
-
return this;
|
|
1388
|
-
}
|
|
1389
|
-
description(str, argsDescription) {
|
|
1390
|
-
if (str === undefined && argsDescription === undefined)
|
|
1391
|
-
return this._description;
|
|
1392
|
-
this._description = str;
|
|
1393
|
-
if (argsDescription) {
|
|
1394
|
-
this._argsDescription = argsDescription;
|
|
1395
|
-
}
|
|
1396
|
-
return this;
|
|
1397
|
-
}
|
|
1398
|
-
summary(str) {
|
|
1399
|
-
if (str === undefined) return this._summary;
|
|
1400
|
-
this._summary = str;
|
|
1401
|
-
return this;
|
|
1402
|
-
}
|
|
1403
|
-
alias(alias) {
|
|
1404
|
-
if (alias === undefined) return this._aliases[0];
|
|
1405
|
-
let command = this;
|
|
1406
|
-
if (
|
|
1407
|
-
this.commands.length !== 0 &&
|
|
1408
|
-
this.commands[this.commands.length - 1]._executableHandler
|
|
1409
|
-
) {
|
|
1410
|
-
command = this.commands[this.commands.length - 1];
|
|
1411
|
-
}
|
|
1412
|
-
if (alias === command._name)
|
|
1413
|
-
throw new Error("Command alias can't be the same as its name");
|
|
1414
|
-
const matchingCommand = this.parent?._findCommand(alias);
|
|
1415
|
-
if (matchingCommand) {
|
|
1416
|
-
const existingCmd = [matchingCommand.name()]
|
|
1417
|
-
.concat(matchingCommand.aliases())
|
|
1418
|
-
.join("|");
|
|
1419
|
-
throw new Error(
|
|
1420
|
-
`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`,
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
command._aliases.push(alias);
|
|
1424
|
-
return this;
|
|
1425
|
-
}
|
|
1426
|
-
aliases(aliases) {
|
|
1427
|
-
if (aliases === undefined) return this._aliases;
|
|
1428
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
1429
|
-
return this;
|
|
1430
|
-
}
|
|
1431
|
-
usage(str) {
|
|
1432
|
-
if (str === undefined) {
|
|
1433
|
-
if (this._usage) return this._usage;
|
|
1434
|
-
const args = this.registeredArguments.map((arg) =>
|
|
1435
|
-
humanReadableArgName(arg),
|
|
1436
|
-
);
|
|
1437
|
-
return []
|
|
1438
|
-
.concat(
|
|
1439
|
-
this.options.length || this._helpOption !== null
|
|
1440
|
-
? "[options]"
|
|
1441
|
-
: [],
|
|
1442
|
-
this.commands.length ? "[command]" : [],
|
|
1443
|
-
this.registeredArguments.length ? args : [],
|
|
1444
|
-
)
|
|
1445
|
-
.join(" ");
|
|
1446
|
-
}
|
|
1447
|
-
this._usage = str;
|
|
1448
|
-
return this;
|
|
1449
|
-
}
|
|
1450
|
-
name(str) {
|
|
1451
|
-
if (str === undefined) return this._name;
|
|
1452
|
-
this._name = str;
|
|
1453
|
-
return this;
|
|
1454
|
-
}
|
|
1455
|
-
nameFromFilename(filename) {
|
|
1456
|
-
this._name = path.basename(filename, path.extname(filename));
|
|
1457
|
-
return this;
|
|
1458
|
-
}
|
|
1459
|
-
executableDir(path) {
|
|
1460
|
-
if (path === undefined) return this._executableDir;
|
|
1461
|
-
this._executableDir = path;
|
|
1462
|
-
return this;
|
|
1463
|
-
}
|
|
1464
|
-
helpInformation(contextOptions) {
|
|
1465
|
-
const helper = this.createHelp();
|
|
1466
|
-
const context = this._getOutputContext(contextOptions);
|
|
1467
|
-
helper.prepareContext({
|
|
1468
|
-
error: context.error,
|
|
1469
|
-
helpWidth: context.helpWidth,
|
|
1470
|
-
outputHasColors: context.hasColors,
|
|
1471
|
-
});
|
|
1472
|
-
const text = helper.formatHelp(this, helper);
|
|
1473
|
-
if (context.hasColors) return text;
|
|
1474
|
-
return this._outputConfiguration.stripColor(text);
|
|
1475
|
-
}
|
|
1476
|
-
_getOutputContext(contextOptions) {
|
|
1477
|
-
contextOptions = contextOptions || {};
|
|
1478
|
-
const error = !!contextOptions.error;
|
|
1479
|
-
let baseWrite;
|
|
1480
|
-
let hasColors;
|
|
1481
|
-
let helpWidth;
|
|
1482
|
-
if (error) {
|
|
1483
|
-
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
1484
|
-
hasColors = this._outputConfiguration.getErrHasColors();
|
|
1485
|
-
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
1486
|
-
} else {
|
|
1487
|
-
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
1488
|
-
hasColors = this._outputConfiguration.getOutHasColors();
|
|
1489
|
-
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
1490
|
-
}
|
|
1491
|
-
const write = (str) => {
|
|
1492
|
-
if (!hasColors) str = this._outputConfiguration.stripColor(str);
|
|
1493
|
-
return baseWrite(str);
|
|
1494
|
-
};
|
|
1495
|
-
return { error, write, hasColors, helpWidth };
|
|
1496
|
-
}
|
|
1497
|
-
outputHelp(contextOptions) {
|
|
1498
|
-
let deprecatedCallback;
|
|
1499
|
-
if (typeof contextOptions === "function") {
|
|
1500
|
-
deprecatedCallback = contextOptions;
|
|
1501
|
-
contextOptions = undefined;
|
|
1502
|
-
}
|
|
1503
|
-
const outputContext = this._getOutputContext(contextOptions);
|
|
1504
|
-
const eventContext = {
|
|
1505
|
-
error: outputContext.error,
|
|
1506
|
-
write: outputContext.write,
|
|
1507
|
-
command: this,
|
|
1508
|
-
};
|
|
1509
|
-
this._getCommandAndAncestors()
|
|
1510
|
-
.reverse()
|
|
1511
|
-
.forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
1512
|
-
this.emit("beforeHelp", eventContext);
|
|
1513
|
-
let helpInformation = this.helpInformation({
|
|
1514
|
-
error: outputContext.error,
|
|
1515
|
-
});
|
|
1516
|
-
if (deprecatedCallback) {
|
|
1517
|
-
helpInformation = deprecatedCallback(helpInformation);
|
|
1518
|
-
if (
|
|
1519
|
-
typeof helpInformation !== "string" &&
|
|
1520
|
-
!Buffer.isBuffer(helpInformation)
|
|
1521
|
-
) {
|
|
1522
|
-
throw new Error(
|
|
1523
|
-
"outputHelp callback must return a string or a Buffer",
|
|
1524
|
-
);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
outputContext.write(helpInformation);
|
|
1528
|
-
if (this._getHelpOption()?.long) {
|
|
1529
|
-
this.emit(this._getHelpOption().long);
|
|
1530
|
-
}
|
|
1531
|
-
this.emit("afterHelp", eventContext);
|
|
1532
|
-
this._getCommandAndAncestors().forEach((command) =>
|
|
1533
|
-
command.emit("afterAllHelp", eventContext),
|
|
1534
|
-
);
|
|
1535
|
-
}
|
|
1536
|
-
helpOption(flags, description) {
|
|
1537
|
-
if (typeof flags === "boolean") {
|
|
1538
|
-
if (flags) {
|
|
1539
|
-
this._helpOption = this._helpOption ?? undefined;
|
|
1540
|
-
} else {
|
|
1541
|
-
this._helpOption = null;
|
|
1542
|
-
}
|
|
1543
|
-
return this;
|
|
1544
|
-
}
|
|
1545
|
-
flags = flags ?? "-h, --help";
|
|
1546
|
-
description = description ?? "display help for command";
|
|
1547
|
-
this._helpOption = this.createOption(flags, description);
|
|
1548
|
-
return this;
|
|
1549
|
-
}
|
|
1550
|
-
_getHelpOption() {
|
|
1551
|
-
if (this._helpOption === undefined) {
|
|
1552
|
-
this.helpOption(undefined, undefined);
|
|
1553
|
-
}
|
|
1554
|
-
return this._helpOption;
|
|
1555
|
-
}
|
|
1556
|
-
addHelpOption(option) {
|
|
1557
|
-
this._helpOption = option;
|
|
1558
|
-
return this;
|
|
1559
|
-
}
|
|
1560
|
-
help(contextOptions) {
|
|
1561
|
-
this.outputHelp(contextOptions);
|
|
1562
|
-
let exitCode = Number(process.exitCode ?? 0);
|
|
1563
|
-
if (
|
|
1564
|
-
exitCode === 0 &&
|
|
1565
|
-
contextOptions &&
|
|
1566
|
-
typeof contextOptions !== "function" &&
|
|
1567
|
-
contextOptions.error
|
|
1568
|
-
) {
|
|
1569
|
-
exitCode = 1;
|
|
1570
|
-
}
|
|
1571
|
-
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1572
|
-
}
|
|
1573
|
-
addHelpText(position, text) {
|
|
1574
|
-
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1575
|
-
if (!allowedValues.includes(position)) {
|
|
1576
|
-
throw new Error(
|
|
1577
|
-
`Unexpected value for position to addHelpText.\nExpecting one of '${allowedValues.join("', '")}'`,
|
|
1578
|
-
);
|
|
1579
|
-
}
|
|
1580
|
-
const helpEvent = `${position}Help`;
|
|
1581
|
-
this.on(helpEvent, (context) => {
|
|
1582
|
-
let helpStr;
|
|
1583
|
-
if (typeof text === "function") {
|
|
1584
|
-
helpStr = text({
|
|
1585
|
-
error: context.error,
|
|
1586
|
-
command: context.command,
|
|
1587
|
-
});
|
|
1588
|
-
} else {
|
|
1589
|
-
helpStr = text;
|
|
1590
|
-
}
|
|
1591
|
-
if (helpStr) {
|
|
1592
|
-
context.write(`${helpStr}\n`);
|
|
1593
|
-
}
|
|
1594
|
-
});
|
|
1595
|
-
return this;
|
|
1596
|
-
}
|
|
1597
|
-
_outputHelpIfRequested(args) {
|
|
1598
|
-
const helpOption = this._getHelpOption();
|
|
1599
|
-
const helpRequested =
|
|
1600
|
-
helpOption && args.find((arg) => helpOption.is(arg));
|
|
1601
|
-
if (helpRequested) {
|
|
1602
|
-
this.outputHelp();
|
|
1603
|
-
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
function incrementNodeInspectorPort(args) {
|
|
1608
|
-
return args.map((arg) => {
|
|
1609
|
-
if (!arg.startsWith("--inspect")) {
|
|
1610
|
-
return arg;
|
|
1611
|
-
}
|
|
1612
|
-
let debugOption;
|
|
1613
|
-
let debugHost = "127.0.0.1";
|
|
1614
|
-
let debugPort = "9229";
|
|
1615
|
-
let match;
|
|
1616
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1617
|
-
debugOption = match[1];
|
|
1618
|
-
} else if (
|
|
1619
|
-
(match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null
|
|
1620
|
-
) {
|
|
1621
|
-
debugOption = match[1];
|
|
1622
|
-
if (/^\d+$/.test(match[3])) {
|
|
1623
|
-
debugPort = match[3];
|
|
1624
|
-
} else {
|
|
1625
|
-
debugHost = match[3];
|
|
1626
|
-
}
|
|
1627
|
-
} else if (
|
|
1628
|
-
(match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !==
|
|
1629
|
-
null
|
|
1630
|
-
) {
|
|
1631
|
-
debugOption = match[1];
|
|
1632
|
-
debugHost = match[3];
|
|
1633
|
-
debugPort = match[4];
|
|
1634
|
-
}
|
|
1635
|
-
if (debugOption && debugPort !== "0") {
|
|
1636
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1637
|
-
}
|
|
1638
|
-
return arg;
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
function useColor() {
|
|
1642
|
-
if (
|
|
1643
|
-
process.env.NO_COLOR ||
|
|
1644
|
-
process.env.FORCE_COLOR === "0" ||
|
|
1645
|
-
process.env.FORCE_COLOR === "false"
|
|
1646
|
-
)
|
|
1647
|
-
return false;
|
|
1648
|
-
if (process.env.FORCE_COLOR || process.env.CLICOLOR_FORCE !== undefined)
|
|
1649
|
-
return true;
|
|
1650
|
-
return undefined;
|
|
1651
|
-
}
|
|
1652
|
-
exports.Command = Command;
|
|
1653
|
-
exports.useColor = useColor;
|
|
1654
|
-
},
|
|
1655
|
-
848: (__unused_webpack_module, exports) => {
|
|
1656
|
-
class CommanderError extends Error {
|
|
1657
|
-
constructor(exitCode, code, message) {
|
|
1658
|
-
super(message);
|
|
1659
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1660
|
-
this.name = this.constructor.name;
|
|
1661
|
-
this.code = code;
|
|
1662
|
-
this.exitCode = exitCode;
|
|
1663
|
-
this.nestedError = undefined;
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
class InvalidArgumentError extends CommanderError {
|
|
1667
|
-
constructor(message) {
|
|
1668
|
-
super(1, "commander.invalidArgument", message);
|
|
1669
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1670
|
-
this.name = this.constructor.name;
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
exports.CommanderError = CommanderError;
|
|
1674
|
-
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1675
|
-
},
|
|
1676
|
-
613: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
1677
|
-
const { humanReadableArgName } = __nccwpck_require__(429);
|
|
1678
|
-
class Help {
|
|
1679
|
-
constructor() {
|
|
1680
|
-
this.helpWidth = undefined;
|
|
1681
|
-
this.minWidthToWrap = 40;
|
|
1682
|
-
this.sortSubcommands = false;
|
|
1683
|
-
this.sortOptions = false;
|
|
1684
|
-
this.showGlobalOptions = false;
|
|
1685
|
-
}
|
|
1686
|
-
prepareContext(contextOptions) {
|
|
1687
|
-
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
1688
|
-
}
|
|
1689
|
-
visibleCommands(cmd) {
|
|
1690
|
-
const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
|
|
1691
|
-
const helpCommand = cmd._getHelpCommand();
|
|
1692
|
-
if (helpCommand && !helpCommand._hidden) {
|
|
1693
|
-
visibleCommands.push(helpCommand);
|
|
1694
|
-
}
|
|
1695
|
-
if (this.sortSubcommands) {
|
|
1696
|
-
visibleCommands.sort((a, b) => a.name().localeCompare(b.name()));
|
|
1697
|
-
}
|
|
1698
|
-
return visibleCommands;
|
|
1699
|
-
}
|
|
1700
|
-
compareOptions(a, b) {
|
|
1701
|
-
const getSortKey = (option) =>
|
|
1702
|
-
option.short
|
|
1703
|
-
? option.short.replace(/^-/, "")
|
|
1704
|
-
: option.long.replace(/^--/, "");
|
|
1705
|
-
return getSortKey(a).localeCompare(getSortKey(b));
|
|
1706
|
-
}
|
|
1707
|
-
visibleOptions(cmd) {
|
|
1708
|
-
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
1709
|
-
const helpOption = cmd._getHelpOption();
|
|
1710
|
-
if (helpOption && !helpOption.hidden) {
|
|
1711
|
-
const removeShort =
|
|
1712
|
-
helpOption.short && cmd._findOption(helpOption.short);
|
|
1713
|
-
const removeLong =
|
|
1714
|
-
helpOption.long && cmd._findOption(helpOption.long);
|
|
1715
|
-
if (!removeShort && !removeLong) {
|
|
1716
|
-
visibleOptions.push(helpOption);
|
|
1717
|
-
} else if (helpOption.long && !removeLong) {
|
|
1718
|
-
visibleOptions.push(
|
|
1719
|
-
cmd.createOption(helpOption.long, helpOption.description),
|
|
1720
|
-
);
|
|
1721
|
-
} else if (helpOption.short && !removeShort) {
|
|
1722
|
-
visibleOptions.push(
|
|
1723
|
-
cmd.createOption(helpOption.short, helpOption.description),
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
if (this.sortOptions) {
|
|
1728
|
-
visibleOptions.sort(this.compareOptions);
|
|
1729
|
-
}
|
|
1730
|
-
return visibleOptions;
|
|
1731
|
-
}
|
|
1732
|
-
visibleGlobalOptions(cmd) {
|
|
1733
|
-
if (!this.showGlobalOptions) return [];
|
|
1734
|
-
const globalOptions = [];
|
|
1735
|
-
for (
|
|
1736
|
-
let ancestorCmd = cmd.parent;
|
|
1737
|
-
ancestorCmd;
|
|
1738
|
-
ancestorCmd = ancestorCmd.parent
|
|
1739
|
-
) {
|
|
1740
|
-
const visibleOptions = ancestorCmd.options.filter(
|
|
1741
|
-
(option) => !option.hidden,
|
|
1742
|
-
);
|
|
1743
|
-
globalOptions.push(...visibleOptions);
|
|
1744
|
-
}
|
|
1745
|
-
if (this.sortOptions) {
|
|
1746
|
-
globalOptions.sort(this.compareOptions);
|
|
1747
|
-
}
|
|
1748
|
-
return globalOptions;
|
|
1749
|
-
}
|
|
1750
|
-
visibleArguments(cmd) {
|
|
1751
|
-
if (cmd._argsDescription) {
|
|
1752
|
-
cmd.registeredArguments.forEach((argument) => {
|
|
1753
|
-
argument.description =
|
|
1754
|
-
argument.description ||
|
|
1755
|
-
cmd._argsDescription[argument.name()] ||
|
|
1756
|
-
"";
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
if (
|
|
1760
|
-
cmd.registeredArguments.find((argument) => argument.description)
|
|
1761
|
-
) {
|
|
1762
|
-
return cmd.registeredArguments;
|
|
1763
|
-
}
|
|
1764
|
-
return [];
|
|
1765
|
-
}
|
|
1766
|
-
subcommandTerm(cmd) {
|
|
1767
|
-
const args = cmd.registeredArguments
|
|
1768
|
-
.map((arg) => humanReadableArgName(arg))
|
|
1769
|
-
.join(" ");
|
|
1770
|
-
return (
|
|
1771
|
-
cmd._name +
|
|
1772
|
-
(cmd._aliases[0] ? "|" + cmd._aliases[0] : "") +
|
|
1773
|
-
(cmd.options.length ? " [options]" : "") +
|
|
1774
|
-
(args ? " " + args : "")
|
|
1775
|
-
);
|
|
1776
|
-
}
|
|
1777
|
-
optionTerm(option) {
|
|
1778
|
-
return option.flags;
|
|
1779
|
-
}
|
|
1780
|
-
argumentTerm(argument) {
|
|
1781
|
-
return argument.name();
|
|
1782
|
-
}
|
|
1783
|
-
longestSubcommandTermLength(cmd, helper) {
|
|
1784
|
-
return helper
|
|
1785
|
-
.visibleCommands(cmd)
|
|
1786
|
-
.reduce(
|
|
1787
|
-
(max, command) =>
|
|
1788
|
-
Math.max(
|
|
1789
|
-
max,
|
|
1790
|
-
this.displayWidth(
|
|
1791
|
-
helper.styleSubcommandTerm(helper.subcommandTerm(command)),
|
|
1792
|
-
),
|
|
1793
|
-
),
|
|
1794
|
-
0,
|
|
1795
|
-
);
|
|
1796
|
-
}
|
|
1797
|
-
longestOptionTermLength(cmd, helper) {
|
|
1798
|
-
return helper
|
|
1799
|
-
.visibleOptions(cmd)
|
|
1800
|
-
.reduce(
|
|
1801
|
-
(max, option) =>
|
|
1802
|
-
Math.max(
|
|
1803
|
-
max,
|
|
1804
|
-
this.displayWidth(
|
|
1805
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1806
|
-
),
|
|
1807
|
-
),
|
|
1808
|
-
0,
|
|
1809
|
-
);
|
|
1810
|
-
}
|
|
1811
|
-
longestGlobalOptionTermLength(cmd, helper) {
|
|
1812
|
-
return helper
|
|
1813
|
-
.visibleGlobalOptions(cmd)
|
|
1814
|
-
.reduce(
|
|
1815
|
-
(max, option) =>
|
|
1816
|
-
Math.max(
|
|
1817
|
-
max,
|
|
1818
|
-
this.displayWidth(
|
|
1819
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1820
|
-
),
|
|
1821
|
-
),
|
|
1822
|
-
0,
|
|
1823
|
-
);
|
|
1824
|
-
}
|
|
1825
|
-
longestArgumentTermLength(cmd, helper) {
|
|
1826
|
-
return helper
|
|
1827
|
-
.visibleArguments(cmd)
|
|
1828
|
-
.reduce(
|
|
1829
|
-
(max, argument) =>
|
|
1830
|
-
Math.max(
|
|
1831
|
-
max,
|
|
1832
|
-
this.displayWidth(
|
|
1833
|
-
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
1834
|
-
),
|
|
1835
|
-
),
|
|
1836
|
-
0,
|
|
1837
|
-
);
|
|
1838
|
-
}
|
|
1839
|
-
commandUsage(cmd) {
|
|
1840
|
-
let cmdName = cmd._name;
|
|
1841
|
-
if (cmd._aliases[0]) {
|
|
1842
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
1843
|
-
}
|
|
1844
|
-
let ancestorCmdNames = "";
|
|
1845
|
-
for (
|
|
1846
|
-
let ancestorCmd = cmd.parent;
|
|
1847
|
-
ancestorCmd;
|
|
1848
|
-
ancestorCmd = ancestorCmd.parent
|
|
1849
|
-
) {
|
|
1850
|
-
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
1851
|
-
}
|
|
1852
|
-
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
1853
|
-
}
|
|
1854
|
-
commandDescription(cmd) {
|
|
1855
|
-
return cmd.description();
|
|
1856
|
-
}
|
|
1857
|
-
subcommandDescription(cmd) {
|
|
1858
|
-
return cmd.summary() || cmd.description();
|
|
1859
|
-
}
|
|
1860
|
-
optionDescription(option) {
|
|
1861
|
-
const extraInfo = [];
|
|
1862
|
-
if (option.argChoices) {
|
|
1863
|
-
extraInfo.push(
|
|
1864
|
-
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`,
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
if (option.defaultValue !== undefined) {
|
|
1868
|
-
const showDefault =
|
|
1869
|
-
option.required ||
|
|
1870
|
-
option.optional ||
|
|
1871
|
-
(option.isBoolean() && typeof option.defaultValue === "boolean");
|
|
1872
|
-
if (showDefault) {
|
|
1873
|
-
extraInfo.push(
|
|
1874
|
-
`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`,
|
|
1875
|
-
);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
if (option.presetArg !== undefined && option.optional) {
|
|
1879
|
-
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
1880
|
-
}
|
|
1881
|
-
if (option.envVar !== undefined) {
|
|
1882
|
-
extraInfo.push(`env: ${option.envVar}`);
|
|
1883
|
-
}
|
|
1884
|
-
if (extraInfo.length > 0) {
|
|
1885
|
-
return `${option.description} (${extraInfo.join(", ")})`;
|
|
1886
|
-
}
|
|
1887
|
-
return option.description;
|
|
1888
|
-
}
|
|
1889
|
-
argumentDescription(argument) {
|
|
1890
|
-
const extraInfo = [];
|
|
1891
|
-
if (argument.argChoices) {
|
|
1892
|
-
extraInfo.push(
|
|
1893
|
-
`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`,
|
|
1894
|
-
);
|
|
1895
|
-
}
|
|
1896
|
-
if (argument.defaultValue !== undefined) {
|
|
1897
|
-
extraInfo.push(
|
|
1898
|
-
`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`,
|
|
1899
|
-
);
|
|
1900
|
-
}
|
|
1901
|
-
if (extraInfo.length > 0) {
|
|
1902
|
-
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1903
|
-
if (argument.description) {
|
|
1904
|
-
return `${argument.description} ${extraDescription}`;
|
|
1905
|
-
}
|
|
1906
|
-
return extraDescription;
|
|
1907
|
-
}
|
|
1908
|
-
return argument.description;
|
|
1909
|
-
}
|
|
1910
|
-
formatHelp(cmd, helper) {
|
|
1911
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
1912
|
-
const helpWidth = helper.helpWidth ?? 80;
|
|
1913
|
-
function callFormatItem(term, description) {
|
|
1914
|
-
return helper.formatItem(term, termWidth, description, helper);
|
|
1915
|
-
}
|
|
1916
|
-
let output = [
|
|
1917
|
-
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
1918
|
-
"",
|
|
1919
|
-
];
|
|
1920
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
1921
|
-
if (commandDescription.length > 0) {
|
|
1922
|
-
output = output.concat([
|
|
1923
|
-
helper.boxWrap(
|
|
1924
|
-
helper.styleCommandDescription(commandDescription),
|
|
1925
|
-
helpWidth,
|
|
1926
|
-
),
|
|
1927
|
-
"",
|
|
1928
|
-
]);
|
|
1929
|
-
}
|
|
1930
|
-
const argumentList = helper
|
|
1931
|
-
.visibleArguments(cmd)
|
|
1932
|
-
.map((argument) =>
|
|
1933
|
-
callFormatItem(
|
|
1934
|
-
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
1935
|
-
helper.styleArgumentDescription(
|
|
1936
|
-
helper.argumentDescription(argument),
|
|
1937
|
-
),
|
|
1938
|
-
),
|
|
1939
|
-
);
|
|
1940
|
-
if (argumentList.length > 0) {
|
|
1941
|
-
output = output.concat([
|
|
1942
|
-
helper.styleTitle("Arguments:"),
|
|
1943
|
-
...argumentList,
|
|
1944
|
-
"",
|
|
1945
|
-
]);
|
|
1946
|
-
}
|
|
1947
|
-
const optionList = helper
|
|
1948
|
-
.visibleOptions(cmd)
|
|
1949
|
-
.map((option) =>
|
|
1950
|
-
callFormatItem(
|
|
1951
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1952
|
-
helper.styleOptionDescription(helper.optionDescription(option)),
|
|
1953
|
-
),
|
|
1954
|
-
);
|
|
1955
|
-
if (optionList.length > 0) {
|
|
1956
|
-
output = output.concat([
|
|
1957
|
-
helper.styleTitle("Options:"),
|
|
1958
|
-
...optionList,
|
|
1959
|
-
"",
|
|
1960
|
-
]);
|
|
1961
|
-
}
|
|
1962
|
-
if (helper.showGlobalOptions) {
|
|
1963
|
-
const globalOptionList = helper
|
|
1964
|
-
.visibleGlobalOptions(cmd)
|
|
1965
|
-
.map((option) =>
|
|
1966
|
-
callFormatItem(
|
|
1967
|
-
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
1968
|
-
helper.styleOptionDescription(
|
|
1969
|
-
helper.optionDescription(option),
|
|
1970
|
-
),
|
|
1971
|
-
),
|
|
1972
|
-
);
|
|
1973
|
-
if (globalOptionList.length > 0) {
|
|
1974
|
-
output = output.concat([
|
|
1975
|
-
helper.styleTitle("Global Options:"),
|
|
1976
|
-
...globalOptionList,
|
|
1977
|
-
"",
|
|
1978
|
-
]);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
const commandList = helper
|
|
1982
|
-
.visibleCommands(cmd)
|
|
1983
|
-
.map((cmd) =>
|
|
1984
|
-
callFormatItem(
|
|
1985
|
-
helper.styleSubcommandTerm(helper.subcommandTerm(cmd)),
|
|
1986
|
-
helper.styleSubcommandDescription(
|
|
1987
|
-
helper.subcommandDescription(cmd),
|
|
1988
|
-
),
|
|
1989
|
-
),
|
|
1990
|
-
);
|
|
1991
|
-
if (commandList.length > 0) {
|
|
1992
|
-
output = output.concat([
|
|
1993
|
-
helper.styleTitle("Commands:"),
|
|
1994
|
-
...commandList,
|
|
1995
|
-
"",
|
|
1996
|
-
]);
|
|
1997
|
-
}
|
|
1998
|
-
return output.join("\n");
|
|
1999
|
-
}
|
|
2000
|
-
displayWidth(str) {
|
|
2001
|
-
return stripColor(str).length;
|
|
2002
|
-
}
|
|
2003
|
-
styleTitle(str) {
|
|
2004
|
-
return str;
|
|
2005
|
-
}
|
|
2006
|
-
styleUsage(str) {
|
|
2007
|
-
return str
|
|
2008
|
-
.split(" ")
|
|
2009
|
-
.map((word) => {
|
|
2010
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
2011
|
-
if (word === "[command]") return this.styleSubcommandText(word);
|
|
2012
|
-
if (word[0] === "[" || word[0] === "<")
|
|
2013
|
-
return this.styleArgumentText(word);
|
|
2014
|
-
return this.styleCommandText(word);
|
|
2015
|
-
})
|
|
2016
|
-
.join(" ");
|
|
2017
|
-
}
|
|
2018
|
-
styleCommandDescription(str) {
|
|
2019
|
-
return this.styleDescriptionText(str);
|
|
2020
|
-
}
|
|
2021
|
-
styleOptionDescription(str) {
|
|
2022
|
-
return this.styleDescriptionText(str);
|
|
2023
|
-
}
|
|
2024
|
-
styleSubcommandDescription(str) {
|
|
2025
|
-
return this.styleDescriptionText(str);
|
|
2026
|
-
}
|
|
2027
|
-
styleArgumentDescription(str) {
|
|
2028
|
-
return this.styleDescriptionText(str);
|
|
2029
|
-
}
|
|
2030
|
-
styleDescriptionText(str) {
|
|
2031
|
-
return str;
|
|
2032
|
-
}
|
|
2033
|
-
styleOptionTerm(str) {
|
|
2034
|
-
return this.styleOptionText(str);
|
|
2035
|
-
}
|
|
2036
|
-
styleSubcommandTerm(str) {
|
|
2037
|
-
return str
|
|
2038
|
-
.split(" ")
|
|
2039
|
-
.map((word) => {
|
|
2040
|
-
if (word === "[options]") return this.styleOptionText(word);
|
|
2041
|
-
if (word[0] === "[" || word[0] === "<")
|
|
2042
|
-
return this.styleArgumentText(word);
|
|
2043
|
-
return this.styleSubcommandText(word);
|
|
2044
|
-
})
|
|
2045
|
-
.join(" ");
|
|
2046
|
-
}
|
|
2047
|
-
styleArgumentTerm(str) {
|
|
2048
|
-
return this.styleArgumentText(str);
|
|
2049
|
-
}
|
|
2050
|
-
styleOptionText(str) {
|
|
2051
|
-
return str;
|
|
2052
|
-
}
|
|
2053
|
-
styleArgumentText(str) {
|
|
2054
|
-
return str;
|
|
2055
|
-
}
|
|
2056
|
-
styleSubcommandText(str) {
|
|
2057
|
-
return str;
|
|
2058
|
-
}
|
|
2059
|
-
styleCommandText(str) {
|
|
2060
|
-
return str;
|
|
2061
|
-
}
|
|
2062
|
-
padWidth(cmd, helper) {
|
|
2063
|
-
return Math.max(
|
|
2064
|
-
helper.longestOptionTermLength(cmd, helper),
|
|
2065
|
-
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
2066
|
-
helper.longestSubcommandTermLength(cmd, helper),
|
|
2067
|
-
helper.longestArgumentTermLength(cmd, helper),
|
|
2068
|
-
);
|
|
2069
|
-
}
|
|
2070
|
-
preformatted(str) {
|
|
2071
|
-
return /\n[^\S\r\n]/.test(str);
|
|
2072
|
-
}
|
|
2073
|
-
formatItem(term, termWidth, description, helper) {
|
|
2074
|
-
const itemIndent = 2;
|
|
2075
|
-
const itemIndentStr = " ".repeat(itemIndent);
|
|
2076
|
-
if (!description) return itemIndentStr + term;
|
|
2077
|
-
const paddedTerm = term.padEnd(
|
|
2078
|
-
termWidth + term.length - helper.displayWidth(term),
|
|
2079
|
-
);
|
|
2080
|
-
const spacerWidth = 2;
|
|
2081
|
-
const helpWidth = this.helpWidth ?? 80;
|
|
2082
|
-
const remainingWidth =
|
|
2083
|
-
helpWidth - termWidth - spacerWidth - itemIndent;
|
|
2084
|
-
let formattedDescription;
|
|
2085
|
-
if (
|
|
2086
|
-
remainingWidth < this.minWidthToWrap ||
|
|
2087
|
-
helper.preformatted(description)
|
|
2088
|
-
) {
|
|
2089
|
-
formattedDescription = description;
|
|
2090
|
-
} else {
|
|
2091
|
-
const wrappedDescription = helper.boxWrap(
|
|
2092
|
-
description,
|
|
2093
|
-
remainingWidth,
|
|
2094
|
-
);
|
|
2095
|
-
formattedDescription = wrappedDescription.replace(
|
|
2096
|
-
/\n/g,
|
|
2097
|
-
"\n" + " ".repeat(termWidth + spacerWidth),
|
|
2098
|
-
);
|
|
2099
|
-
}
|
|
2100
|
-
return (
|
|
2101
|
-
itemIndentStr +
|
|
2102
|
-
paddedTerm +
|
|
2103
|
-
" ".repeat(spacerWidth) +
|
|
2104
|
-
formattedDescription.replace(/\n/g, `\n${itemIndentStr}`)
|
|
2105
|
-
);
|
|
2106
|
-
}
|
|
2107
|
-
boxWrap(str, width) {
|
|
2108
|
-
if (width < this.minWidthToWrap) return str;
|
|
2109
|
-
const rawLines = str.split(/\r\n|\n/);
|
|
2110
|
-
const chunkPattern = /[\s]*[^\s]+/g;
|
|
2111
|
-
const wrappedLines = [];
|
|
2112
|
-
rawLines.forEach((line) => {
|
|
2113
|
-
const chunks = line.match(chunkPattern);
|
|
2114
|
-
if (chunks === null) {
|
|
2115
|
-
wrappedLines.push("");
|
|
2116
|
-
return;
|
|
2117
|
-
}
|
|
2118
|
-
let sumChunks = [chunks.shift()];
|
|
2119
|
-
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
2120
|
-
chunks.forEach((chunk) => {
|
|
2121
|
-
const visibleWidth = this.displayWidth(chunk);
|
|
2122
|
-
if (sumWidth + visibleWidth <= width) {
|
|
2123
|
-
sumChunks.push(chunk);
|
|
2124
|
-
sumWidth += visibleWidth;
|
|
2125
|
-
return;
|
|
2126
|
-
}
|
|
2127
|
-
wrappedLines.push(sumChunks.join(""));
|
|
2128
|
-
const nextChunk = chunk.trimStart();
|
|
2129
|
-
sumChunks = [nextChunk];
|
|
2130
|
-
sumWidth = this.displayWidth(nextChunk);
|
|
2131
|
-
});
|
|
2132
|
-
wrappedLines.push(sumChunks.join(""));
|
|
2133
|
-
});
|
|
2134
|
-
return wrappedLines.join("\n");
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
function stripColor(str) {
|
|
2138
|
-
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
2139
|
-
return str.replace(sgrPattern, "");
|
|
2140
|
-
}
|
|
2141
|
-
exports.Help = Help;
|
|
2142
|
-
exports.stripColor = stripColor;
|
|
2143
|
-
},
|
|
2144
|
-
234: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
2145
|
-
const { InvalidArgumentError } = __nccwpck_require__(848);
|
|
2146
|
-
class Option {
|
|
2147
|
-
constructor(flags, description) {
|
|
2148
|
-
this.flags = flags;
|
|
2149
|
-
this.description = description || "";
|
|
2150
|
-
this.required = flags.includes("<");
|
|
2151
|
-
this.optional = flags.includes("[");
|
|
2152
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
2153
|
-
this.mandatory = false;
|
|
2154
|
-
const optionFlags = splitOptionFlags(flags);
|
|
2155
|
-
this.short = optionFlags.shortFlag;
|
|
2156
|
-
this.long = optionFlags.longFlag;
|
|
2157
|
-
this.negate = false;
|
|
2158
|
-
if (this.long) {
|
|
2159
|
-
this.negate = this.long.startsWith("--no-");
|
|
2160
|
-
}
|
|
2161
|
-
this.defaultValue = undefined;
|
|
2162
|
-
this.defaultValueDescription = undefined;
|
|
2163
|
-
this.presetArg = undefined;
|
|
2164
|
-
this.envVar = undefined;
|
|
2165
|
-
this.parseArg = undefined;
|
|
2166
|
-
this.hidden = false;
|
|
2167
|
-
this.argChoices = undefined;
|
|
2168
|
-
this.conflictsWith = [];
|
|
2169
|
-
this.implied = undefined;
|
|
2170
|
-
}
|
|
2171
|
-
default(value, description) {
|
|
2172
|
-
this.defaultValue = value;
|
|
2173
|
-
this.defaultValueDescription = description;
|
|
2174
|
-
return this;
|
|
2175
|
-
}
|
|
2176
|
-
preset(arg) {
|
|
2177
|
-
this.presetArg = arg;
|
|
2178
|
-
return this;
|
|
2179
|
-
}
|
|
2180
|
-
conflicts(names) {
|
|
2181
|
-
this.conflictsWith = this.conflictsWith.concat(names);
|
|
2182
|
-
return this;
|
|
2183
|
-
}
|
|
2184
|
-
implies(impliedOptionValues) {
|
|
2185
|
-
let newImplied = impliedOptionValues;
|
|
2186
|
-
if (typeof impliedOptionValues === "string") {
|
|
2187
|
-
newImplied = { [impliedOptionValues]: true };
|
|
2188
|
-
}
|
|
2189
|
-
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
2190
|
-
return this;
|
|
2191
|
-
}
|
|
2192
|
-
env(name) {
|
|
2193
|
-
this.envVar = name;
|
|
2194
|
-
return this;
|
|
2195
|
-
}
|
|
2196
|
-
argParser(fn) {
|
|
2197
|
-
this.parseArg = fn;
|
|
2198
|
-
return this;
|
|
2199
|
-
}
|
|
2200
|
-
makeOptionMandatory(mandatory = true) {
|
|
2201
|
-
this.mandatory = !!mandatory;
|
|
2202
|
-
return this;
|
|
2203
|
-
}
|
|
2204
|
-
hideHelp(hide = true) {
|
|
2205
|
-
this.hidden = !!hide;
|
|
2206
|
-
return this;
|
|
2207
|
-
}
|
|
2208
|
-
_concatValue(value, previous) {
|
|
2209
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
2210
|
-
return [value];
|
|
2211
|
-
}
|
|
2212
|
-
return previous.concat(value);
|
|
2213
|
-
}
|
|
2214
|
-
choices(values) {
|
|
2215
|
-
this.argChoices = values.slice();
|
|
2216
|
-
this.parseArg = (arg, previous) => {
|
|
2217
|
-
if (!this.argChoices.includes(arg)) {
|
|
2218
|
-
throw new InvalidArgumentError(
|
|
2219
|
-
`Allowed choices are ${this.argChoices.join(", ")}.`,
|
|
2220
|
-
);
|
|
2221
|
-
}
|
|
2222
|
-
if (this.variadic) {
|
|
2223
|
-
return this._concatValue(arg, previous);
|
|
2224
|
-
}
|
|
2225
|
-
return arg;
|
|
2226
|
-
};
|
|
2227
|
-
return this;
|
|
2228
|
-
}
|
|
2229
|
-
name() {
|
|
2230
|
-
if (this.long) {
|
|
2231
|
-
return this.long.replace(/^--/, "");
|
|
2232
|
-
}
|
|
2233
|
-
return this.short.replace(/^-/, "");
|
|
2234
|
-
}
|
|
2235
|
-
attributeName() {
|
|
2236
|
-
if (this.negate) {
|
|
2237
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
2238
|
-
}
|
|
2239
|
-
return camelcase(this.name());
|
|
2240
|
-
}
|
|
2241
|
-
is(arg) {
|
|
2242
|
-
return this.short === arg || this.long === arg;
|
|
2243
|
-
}
|
|
2244
|
-
isBoolean() {
|
|
2245
|
-
return !this.required && !this.optional && !this.negate;
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
class DualOptions {
|
|
2249
|
-
constructor(options) {
|
|
2250
|
-
this.positiveOptions = new Map();
|
|
2251
|
-
this.negativeOptions = new Map();
|
|
2252
|
-
this.dualOptions = new Set();
|
|
2253
|
-
options.forEach((option) => {
|
|
2254
|
-
if (option.negate) {
|
|
2255
|
-
this.negativeOptions.set(option.attributeName(), option);
|
|
2256
|
-
} else {
|
|
2257
|
-
this.positiveOptions.set(option.attributeName(), option);
|
|
2258
|
-
}
|
|
2259
|
-
});
|
|
2260
|
-
this.negativeOptions.forEach((value, key) => {
|
|
2261
|
-
if (this.positiveOptions.has(key)) {
|
|
2262
|
-
this.dualOptions.add(key);
|
|
2263
|
-
}
|
|
2264
|
-
});
|
|
2265
|
-
}
|
|
2266
|
-
valueFromOption(value, option) {
|
|
2267
|
-
const optionKey = option.attributeName();
|
|
2268
|
-
if (!this.dualOptions.has(optionKey)) return true;
|
|
2269
|
-
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
2270
|
-
const negativeValue = preset !== undefined ? preset : false;
|
|
2271
|
-
return option.negate === (negativeValue === value);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
function camelcase(str) {
|
|
2275
|
-
return str
|
|
2276
|
-
.split("-")
|
|
2277
|
-
.reduce((str, word) => str + word[0].toUpperCase() + word.slice(1));
|
|
2278
|
-
}
|
|
2279
|
-
function splitOptionFlags(flags) {
|
|
2280
|
-
let shortFlag;
|
|
2281
|
-
let longFlag;
|
|
2282
|
-
const shortFlagExp = /^-[^-]$/;
|
|
2283
|
-
const longFlagExp = /^--[^-]/;
|
|
2284
|
-
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
2285
|
-
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
2286
|
-
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
2287
|
-
if (/^-[^-][^-]/.test(flagParts[0]))
|
|
2288
|
-
throw new Error(
|
|
2289
|
-
`invalid Option flags, short option is dash and single character: '${flags}'`,
|
|
2290
|
-
);
|
|
2291
|
-
if (shortFlag && shortFlagExp.test(flagParts[0]))
|
|
2292
|
-
throw new Error(
|
|
2293
|
-
`invalid Option flags, more than one short flag: '${flags}'`,
|
|
2294
|
-
);
|
|
2295
|
-
if (longFlag && longFlagExp.test(flagParts[0]))
|
|
2296
|
-
throw new Error(
|
|
2297
|
-
`invalid Option flags, more than one long flag: '${flags}'`,
|
|
2298
|
-
);
|
|
2299
|
-
if (!(shortFlag || longFlag) || flagParts[0].startsWith("-"))
|
|
2300
|
-
throw new Error(`invalid Option flags: '${flags}'`);
|
|
2301
|
-
return { shortFlag, longFlag };
|
|
2302
|
-
}
|
|
2303
|
-
exports.Option = Option;
|
|
2304
|
-
exports.DualOptions = DualOptions;
|
|
2305
|
-
},
|
|
2306
|
-
824: (__unused_webpack_module, exports) => {
|
|
2307
|
-
const maxDistance = 3;
|
|
2308
|
-
function editDistance(a, b) {
|
|
2309
|
-
if (Math.abs(a.length - b.length) > maxDistance)
|
|
2310
|
-
return Math.max(a.length, b.length);
|
|
2311
|
-
const d = [];
|
|
2312
|
-
for (let i = 0; i <= a.length; i++) {
|
|
2313
|
-
d[i] = [i];
|
|
2314
|
-
}
|
|
2315
|
-
for (let j = 0; j <= b.length; j++) {
|
|
2316
|
-
d[0][j] = j;
|
|
2317
|
-
}
|
|
2318
|
-
for (let j = 1; j <= b.length; j++) {
|
|
2319
|
-
for (let i = 1; i <= a.length; i++) {
|
|
2320
|
-
let cost = 1;
|
|
2321
|
-
if (a[i - 1] === b[j - 1]) {
|
|
2322
|
-
cost = 0;
|
|
2323
|
-
} else {
|
|
2324
|
-
cost = 1;
|
|
2325
|
-
}
|
|
2326
|
-
d[i][j] = Math.min(
|
|
2327
|
-
d[i - 1][j] + 1,
|
|
2328
|
-
d[i][j - 1] + 1,
|
|
2329
|
-
d[i - 1][j - 1] + cost,
|
|
2330
|
-
);
|
|
2331
|
-
if (
|
|
2332
|
-
i > 1 &&
|
|
2333
|
-
j > 1 &&
|
|
2334
|
-
a[i - 1] === b[j - 2] &&
|
|
2335
|
-
a[i - 2] === b[j - 1]
|
|
2336
|
-
) {
|
|
2337
|
-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
return d[a.length][b.length];
|
|
2342
|
-
}
|
|
2343
|
-
function suggestSimilar(word, candidates) {
|
|
2344
|
-
if (!candidates || candidates.length === 0) return "";
|
|
2345
|
-
candidates = Array.from(new Set(candidates));
|
|
2346
|
-
const searchingOptions = word.startsWith("--");
|
|
2347
|
-
if (searchingOptions) {
|
|
2348
|
-
word = word.slice(2);
|
|
2349
|
-
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
2350
|
-
}
|
|
2351
|
-
let similar = [];
|
|
2352
|
-
let bestDistance = maxDistance;
|
|
2353
|
-
const minSimilarity = 0.4;
|
|
2354
|
-
candidates.forEach((candidate) => {
|
|
2355
|
-
if (candidate.length <= 1) return;
|
|
2356
|
-
const distance = editDistance(word, candidate);
|
|
2357
|
-
const length = Math.max(word.length, candidate.length);
|
|
2358
|
-
const similarity = (length - distance) / length;
|
|
2359
|
-
if (similarity > minSimilarity) {
|
|
2360
|
-
if (distance < bestDistance) {
|
|
2361
|
-
bestDistance = distance;
|
|
2362
|
-
similar = [candidate];
|
|
2363
|
-
} else if (distance === bestDistance) {
|
|
2364
|
-
similar.push(candidate);
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
});
|
|
2368
|
-
similar.sort((a, b) => a.localeCompare(b));
|
|
2369
|
-
if (searchingOptions) {
|
|
2370
|
-
similar = similar.map((candidate) => `--${candidate}`);
|
|
2371
|
-
}
|
|
2372
|
-
if (similar.length > 1) {
|
|
2373
|
-
return `\n(Did you mean one of ${similar.join(", ")}?)`;
|
|
2374
|
-
}
|
|
2375
|
-
if (similar.length === 1) {
|
|
2376
|
-
return `\n(Did you mean ${similar[0]}?)`;
|
|
2377
|
-
}
|
|
2378
|
-
return "";
|
|
2379
|
-
}
|
|
2380
|
-
exports.suggestSimilar = suggestSimilar;
|
|
2381
|
-
},
|
|
2382
|
-
};
|
|
2383
|
-
var __webpack_module_cache__ = {};
|
|
2384
|
-
function __nccwpck_require__(moduleId) {
|
|
2385
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
2386
|
-
if (cachedModule !== undefined) {
|
|
2387
|
-
return cachedModule.exports;
|
|
2388
|
-
}
|
|
2389
|
-
var module = (__webpack_module_cache__[moduleId] = { exports: {} });
|
|
2390
|
-
var threw = true;
|
|
2391
|
-
try {
|
|
2392
|
-
__webpack_modules__[moduleId](
|
|
2393
|
-
module,
|
|
2394
|
-
module.exports,
|
|
2395
|
-
__nccwpck_require__,
|
|
2396
|
-
);
|
|
2397
|
-
threw = false;
|
|
2398
|
-
} finally {
|
|
2399
|
-
if (threw) delete __webpack_module_cache__[moduleId];
|
|
2400
|
-
}
|
|
2401
|
-
return module.exports;
|
|
2402
|
-
}
|
|
2403
|
-
if (typeof __nccwpck_require__ !== "undefined")
|
|
2404
|
-
__nccwpck_require__.ab = __dirname + "/";
|
|
2405
|
-
var __webpack_exports__ = {};
|
|
2406
|
-
(() => {
|
|
2407
|
-
var exports = __webpack_exports__;
|
|
2408
|
-
const { Argument } = __nccwpck_require__(429);
|
|
2409
|
-
const { Command } = __nccwpck_require__(745);
|
|
2410
|
-
const { CommanderError, InvalidArgumentError } = __nccwpck_require__(848);
|
|
2411
|
-
const { Help } = __nccwpck_require__(613);
|
|
2412
|
-
const { Option } = __nccwpck_require__(234);
|
|
2413
|
-
exports.program = new Command();
|
|
2414
|
-
exports.createCommand = (name) => new Command(name);
|
|
2415
|
-
exports.createOption = (flags, description) =>
|
|
2416
|
-
new Option(flags, description);
|
|
2417
|
-
exports.createArgument = (name, description) =>
|
|
2418
|
-
new Argument(name, description);
|
|
2419
|
-
exports.Command = Command;
|
|
2420
|
-
exports.Option = Option;
|
|
2421
|
-
exports.Argument = Argument;
|
|
2422
|
-
exports.Help = Help;
|
|
2423
|
-
exports.CommanderError = CommanderError;
|
|
2424
|
-
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2425
|
-
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2426
|
-
})();
|
|
2427
|
-
module.exports = __webpack_exports__;
|
|
2428
|
-
})();
|