hebrew-transliteration 2.0.2 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1696 -0
- package/dist/index.esm.js +5 -3
- package/dist/index.js +13 -16
- package/package.json +15 -15
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1696 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
|
|
21
|
+
// node_modules/commander/lib/error.js
|
|
22
|
+
var require_error = __commonJS({
|
|
23
|
+
"node_modules/commander/lib/error.js"(exports) {
|
|
24
|
+
var CommanderError2 = class extends Error {
|
|
25
|
+
constructor(exitCode, code, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
Error.captureStackTrace(this, this.constructor);
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.exitCode = exitCode;
|
|
31
|
+
this.nestedError = void 0;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var InvalidArgumentError2 = class extends CommanderError2 {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(1, "commander.invalidArgument", message);
|
|
37
|
+
Error.captureStackTrace(this, this.constructor);
|
|
38
|
+
this.name = this.constructor.name;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.CommanderError = CommanderError2;
|
|
42
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// node_modules/commander/lib/argument.js
|
|
47
|
+
var require_argument = __commonJS({
|
|
48
|
+
"node_modules/commander/lib/argument.js"(exports) {
|
|
49
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
50
|
+
var Argument2 = class {
|
|
51
|
+
constructor(name, description) {
|
|
52
|
+
this.description = description || "";
|
|
53
|
+
this.variadic = false;
|
|
54
|
+
this.parseArg = void 0;
|
|
55
|
+
this.defaultValue = void 0;
|
|
56
|
+
this.defaultValueDescription = void 0;
|
|
57
|
+
this.argChoices = void 0;
|
|
58
|
+
switch (name[0]) {
|
|
59
|
+
case "<":
|
|
60
|
+
this.required = true;
|
|
61
|
+
this._name = name.slice(1, -1);
|
|
62
|
+
break;
|
|
63
|
+
case "[":
|
|
64
|
+
this.required = false;
|
|
65
|
+
this._name = name.slice(1, -1);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
this.required = true;
|
|
69
|
+
this._name = name;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
73
|
+
this.variadic = true;
|
|
74
|
+
this._name = this._name.slice(0, -3);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
name() {
|
|
78
|
+
return this._name;
|
|
79
|
+
}
|
|
80
|
+
_concatValue(value, previous) {
|
|
81
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
82
|
+
return [value];
|
|
83
|
+
}
|
|
84
|
+
return previous.concat(value);
|
|
85
|
+
}
|
|
86
|
+
default(value, description) {
|
|
87
|
+
this.defaultValue = value;
|
|
88
|
+
this.defaultValueDescription = description;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
argParser(fn) {
|
|
92
|
+
this.parseArg = fn;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
choices(values) {
|
|
96
|
+
this.argChoices = values.slice();
|
|
97
|
+
this.parseArg = (arg, previous) => {
|
|
98
|
+
if (!this.argChoices.includes(arg)) {
|
|
99
|
+
throw new InvalidArgumentError2(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
100
|
+
}
|
|
101
|
+
if (this.variadic) {
|
|
102
|
+
return this._concatValue(arg, previous);
|
|
103
|
+
}
|
|
104
|
+
return arg;
|
|
105
|
+
};
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
argRequired() {
|
|
109
|
+
this.required = true;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
argOptional() {
|
|
113
|
+
this.required = false;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function humanReadableArgName(arg) {
|
|
118
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
119
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
120
|
+
}
|
|
121
|
+
exports.Argument = Argument2;
|
|
122
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// node_modules/commander/lib/help.js
|
|
127
|
+
var require_help = __commonJS({
|
|
128
|
+
"node_modules/commander/lib/help.js"(exports) {
|
|
129
|
+
var { humanReadableArgName } = require_argument();
|
|
130
|
+
var Help2 = class {
|
|
131
|
+
constructor() {
|
|
132
|
+
this.helpWidth = void 0;
|
|
133
|
+
this.sortSubcommands = false;
|
|
134
|
+
this.sortOptions = false;
|
|
135
|
+
}
|
|
136
|
+
visibleCommands(cmd) {
|
|
137
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
138
|
+
if (cmd._hasImplicitHelpCommand()) {
|
|
139
|
+
const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
|
|
140
|
+
const helpCommand = cmd.createCommand(helpName).helpOption(false);
|
|
141
|
+
helpCommand.description(cmd._helpCommandDescription);
|
|
142
|
+
if (helpArgs)
|
|
143
|
+
helpCommand.arguments(helpArgs);
|
|
144
|
+
visibleCommands.push(helpCommand);
|
|
145
|
+
}
|
|
146
|
+
if (this.sortSubcommands) {
|
|
147
|
+
visibleCommands.sort((a, b) => {
|
|
148
|
+
return a.name().localeCompare(b.name());
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return visibleCommands;
|
|
152
|
+
}
|
|
153
|
+
visibleOptions(cmd) {
|
|
154
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
155
|
+
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
|
|
156
|
+
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
|
|
157
|
+
if (showShortHelpFlag || showLongHelpFlag) {
|
|
158
|
+
let helpOption;
|
|
159
|
+
if (!showShortHelpFlag) {
|
|
160
|
+
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
|
|
161
|
+
} else if (!showLongHelpFlag) {
|
|
162
|
+
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
|
|
163
|
+
} else {
|
|
164
|
+
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
|
|
165
|
+
}
|
|
166
|
+
visibleOptions.push(helpOption);
|
|
167
|
+
}
|
|
168
|
+
if (this.sortOptions) {
|
|
169
|
+
const getSortKey = (option) => {
|
|
170
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
171
|
+
};
|
|
172
|
+
visibleOptions.sort((a, b) => {
|
|
173
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return visibleOptions;
|
|
177
|
+
}
|
|
178
|
+
visibleArguments(cmd) {
|
|
179
|
+
if (cmd._argsDescription) {
|
|
180
|
+
cmd._args.forEach((argument) => {
|
|
181
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (cmd._args.find((argument) => argument.description)) {
|
|
185
|
+
return cmd._args;
|
|
186
|
+
}
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
subcommandTerm(cmd) {
|
|
190
|
+
const args = cmd._args.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
191
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
192
|
+
}
|
|
193
|
+
optionTerm(option) {
|
|
194
|
+
return option.flags;
|
|
195
|
+
}
|
|
196
|
+
argumentTerm(argument) {
|
|
197
|
+
return argument.name();
|
|
198
|
+
}
|
|
199
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
200
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
201
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
202
|
+
}, 0);
|
|
203
|
+
}
|
|
204
|
+
longestOptionTermLength(cmd, helper) {
|
|
205
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
206
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
207
|
+
}, 0);
|
|
208
|
+
}
|
|
209
|
+
longestArgumentTermLength(cmd, helper) {
|
|
210
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
211
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
212
|
+
}, 0);
|
|
213
|
+
}
|
|
214
|
+
commandUsage(cmd) {
|
|
215
|
+
let cmdName = cmd._name;
|
|
216
|
+
if (cmd._aliases[0]) {
|
|
217
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
218
|
+
}
|
|
219
|
+
let parentCmdNames = "";
|
|
220
|
+
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
|
|
221
|
+
parentCmdNames = parentCmd.name() + " " + parentCmdNames;
|
|
222
|
+
}
|
|
223
|
+
return parentCmdNames + cmdName + " " + cmd.usage();
|
|
224
|
+
}
|
|
225
|
+
commandDescription(cmd) {
|
|
226
|
+
return cmd.description();
|
|
227
|
+
}
|
|
228
|
+
subcommandDescription(cmd) {
|
|
229
|
+
return cmd.description();
|
|
230
|
+
}
|
|
231
|
+
optionDescription(option) {
|
|
232
|
+
const extraInfo = [];
|
|
233
|
+
if (option.argChoices) {
|
|
234
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
235
|
+
}
|
|
236
|
+
if (option.defaultValue !== void 0) {
|
|
237
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
238
|
+
if (showDefault) {
|
|
239
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (option.presetArg !== void 0 && option.optional) {
|
|
243
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
244
|
+
}
|
|
245
|
+
if (option.envVar !== void 0) {
|
|
246
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
247
|
+
}
|
|
248
|
+
if (extraInfo.length > 0) {
|
|
249
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
250
|
+
}
|
|
251
|
+
return option.description;
|
|
252
|
+
}
|
|
253
|
+
argumentDescription(argument) {
|
|
254
|
+
const extraInfo = [];
|
|
255
|
+
if (argument.argChoices) {
|
|
256
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
257
|
+
}
|
|
258
|
+
if (argument.defaultValue !== void 0) {
|
|
259
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
260
|
+
}
|
|
261
|
+
if (extraInfo.length > 0) {
|
|
262
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
263
|
+
if (argument.description) {
|
|
264
|
+
return `${argument.description} ${extraDescripton}`;
|
|
265
|
+
}
|
|
266
|
+
return extraDescripton;
|
|
267
|
+
}
|
|
268
|
+
return argument.description;
|
|
269
|
+
}
|
|
270
|
+
formatHelp(cmd, helper) {
|
|
271
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
272
|
+
const helpWidth = helper.helpWidth || 80;
|
|
273
|
+
const itemIndentWidth = 2;
|
|
274
|
+
const itemSeparatorWidth = 2;
|
|
275
|
+
function formatItem(term, description) {
|
|
276
|
+
if (description) {
|
|
277
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
278
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
279
|
+
}
|
|
280
|
+
return term;
|
|
281
|
+
}
|
|
282
|
+
function formatList(textArray) {
|
|
283
|
+
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
284
|
+
}
|
|
285
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
286
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
287
|
+
if (commandDescription.length > 0) {
|
|
288
|
+
output = output.concat([commandDescription, ""]);
|
|
289
|
+
}
|
|
290
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
291
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
292
|
+
});
|
|
293
|
+
if (argumentList.length > 0) {
|
|
294
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
295
|
+
}
|
|
296
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
297
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
298
|
+
});
|
|
299
|
+
if (optionList.length > 0) {
|
|
300
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
301
|
+
}
|
|
302
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
303
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
304
|
+
});
|
|
305
|
+
if (commandList.length > 0) {
|
|
306
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
307
|
+
}
|
|
308
|
+
return output.join("\n");
|
|
309
|
+
}
|
|
310
|
+
padWidth(cmd, helper) {
|
|
311
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
312
|
+
}
|
|
313
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
314
|
+
if (str.match(/[\n]\s+/))
|
|
315
|
+
return str;
|
|
316
|
+
const columnWidth = width - indent;
|
|
317
|
+
if (columnWidth < minColumnWidth)
|
|
318
|
+
return str;
|
|
319
|
+
const leadingStr = str.slice(0, indent);
|
|
320
|
+
const columnText = str.slice(indent);
|
|
321
|
+
const indentString = " ".repeat(indent);
|
|
322
|
+
const regex = new RegExp(".{1," + (columnWidth - 1) + "}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)", "g");
|
|
323
|
+
const lines = columnText.match(regex) || [];
|
|
324
|
+
return leadingStr + lines.map((line, i) => {
|
|
325
|
+
if (line.slice(-1) === "\n") {
|
|
326
|
+
line = line.slice(0, line.length - 1);
|
|
327
|
+
}
|
|
328
|
+
return (i > 0 ? indentString : "") + line.trimRight();
|
|
329
|
+
}).join("\n");
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
exports.Help = Help2;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// node_modules/commander/lib/option.js
|
|
337
|
+
var require_option = __commonJS({
|
|
338
|
+
"node_modules/commander/lib/option.js"(exports) {
|
|
339
|
+
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
340
|
+
var Option2 = class {
|
|
341
|
+
constructor(flags, description) {
|
|
342
|
+
this.flags = flags;
|
|
343
|
+
this.description = description || "";
|
|
344
|
+
this.required = flags.includes("<");
|
|
345
|
+
this.optional = flags.includes("[");
|
|
346
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
347
|
+
this.mandatory = false;
|
|
348
|
+
const optionFlags = splitOptionFlags(flags);
|
|
349
|
+
this.short = optionFlags.shortFlag;
|
|
350
|
+
this.long = optionFlags.longFlag;
|
|
351
|
+
this.negate = false;
|
|
352
|
+
if (this.long) {
|
|
353
|
+
this.negate = this.long.startsWith("--no-");
|
|
354
|
+
}
|
|
355
|
+
this.defaultValue = void 0;
|
|
356
|
+
this.defaultValueDescription = void 0;
|
|
357
|
+
this.presetArg = void 0;
|
|
358
|
+
this.envVar = void 0;
|
|
359
|
+
this.parseArg = void 0;
|
|
360
|
+
this.hidden = false;
|
|
361
|
+
this.argChoices = void 0;
|
|
362
|
+
this.conflictsWith = [];
|
|
363
|
+
}
|
|
364
|
+
default(value, description) {
|
|
365
|
+
this.defaultValue = value;
|
|
366
|
+
this.defaultValueDescription = description;
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
preset(arg) {
|
|
370
|
+
this.presetArg = arg;
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
conflicts(names) {
|
|
374
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
377
|
+
env(name) {
|
|
378
|
+
this.envVar = name;
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
argParser(fn) {
|
|
382
|
+
this.parseArg = fn;
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
makeOptionMandatory(mandatory = true) {
|
|
386
|
+
this.mandatory = !!mandatory;
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
hideHelp(hide = true) {
|
|
390
|
+
this.hidden = !!hide;
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
_concatValue(value, previous) {
|
|
394
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
395
|
+
return [value];
|
|
396
|
+
}
|
|
397
|
+
return previous.concat(value);
|
|
398
|
+
}
|
|
399
|
+
choices(values) {
|
|
400
|
+
this.argChoices = values.slice();
|
|
401
|
+
this.parseArg = (arg, previous) => {
|
|
402
|
+
if (!this.argChoices.includes(arg)) {
|
|
403
|
+
throw new InvalidArgumentError2(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
404
|
+
}
|
|
405
|
+
if (this.variadic) {
|
|
406
|
+
return this._concatValue(arg, previous);
|
|
407
|
+
}
|
|
408
|
+
return arg;
|
|
409
|
+
};
|
|
410
|
+
return this;
|
|
411
|
+
}
|
|
412
|
+
name() {
|
|
413
|
+
if (this.long) {
|
|
414
|
+
return this.long.replace(/^--/, "");
|
|
415
|
+
}
|
|
416
|
+
return this.short.replace(/^-/, "");
|
|
417
|
+
}
|
|
418
|
+
attributeName() {
|
|
419
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
420
|
+
}
|
|
421
|
+
is(arg) {
|
|
422
|
+
return this.short === arg || this.long === arg;
|
|
423
|
+
}
|
|
424
|
+
isBoolean() {
|
|
425
|
+
return !this.required && !this.optional && !this.negate;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
function camelcase(str) {
|
|
429
|
+
return str.split("-").reduce((str2, word) => {
|
|
430
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function splitOptionFlags(flags) {
|
|
434
|
+
let shortFlag;
|
|
435
|
+
let longFlag;
|
|
436
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
437
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
438
|
+
shortFlag = flagParts.shift();
|
|
439
|
+
longFlag = flagParts.shift();
|
|
440
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
441
|
+
shortFlag = longFlag;
|
|
442
|
+
longFlag = void 0;
|
|
443
|
+
}
|
|
444
|
+
return { shortFlag, longFlag };
|
|
445
|
+
}
|
|
446
|
+
exports.Option = Option2;
|
|
447
|
+
exports.splitOptionFlags = splitOptionFlags;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
452
|
+
var require_suggestSimilar = __commonJS({
|
|
453
|
+
"node_modules/commander/lib/suggestSimilar.js"(exports) {
|
|
454
|
+
var maxDistance = 3;
|
|
455
|
+
function editDistance(a, b) {
|
|
456
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
457
|
+
return Math.max(a.length, b.length);
|
|
458
|
+
const d = [];
|
|
459
|
+
for (let i = 0; i <= a.length; i++) {
|
|
460
|
+
d[i] = [i];
|
|
461
|
+
}
|
|
462
|
+
for (let j = 0; j <= b.length; j++) {
|
|
463
|
+
d[0][j] = j;
|
|
464
|
+
}
|
|
465
|
+
for (let j = 1; j <= b.length; j++) {
|
|
466
|
+
for (let i = 1; i <= a.length; i++) {
|
|
467
|
+
let cost = 1;
|
|
468
|
+
if (a[i - 1] === b[j - 1]) {
|
|
469
|
+
cost = 0;
|
|
470
|
+
} else {
|
|
471
|
+
cost = 1;
|
|
472
|
+
}
|
|
473
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
474
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
475
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return d[a.length][b.length];
|
|
480
|
+
}
|
|
481
|
+
function suggestSimilar(word, candidates) {
|
|
482
|
+
if (!candidates || candidates.length === 0)
|
|
483
|
+
return "";
|
|
484
|
+
candidates = Array.from(new Set(candidates));
|
|
485
|
+
const searchingOptions = word.startsWith("--");
|
|
486
|
+
if (searchingOptions) {
|
|
487
|
+
word = word.slice(2);
|
|
488
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
489
|
+
}
|
|
490
|
+
let similar = [];
|
|
491
|
+
let bestDistance = maxDistance;
|
|
492
|
+
const minSimilarity = 0.4;
|
|
493
|
+
candidates.forEach((candidate) => {
|
|
494
|
+
if (candidate.length <= 1)
|
|
495
|
+
return;
|
|
496
|
+
const distance = editDistance(word, candidate);
|
|
497
|
+
const length = Math.max(word.length, candidate.length);
|
|
498
|
+
const similarity = (length - distance) / length;
|
|
499
|
+
if (similarity > minSimilarity) {
|
|
500
|
+
if (distance < bestDistance) {
|
|
501
|
+
bestDistance = distance;
|
|
502
|
+
similar = [candidate];
|
|
503
|
+
} else if (distance === bestDistance) {
|
|
504
|
+
similar.push(candidate);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
509
|
+
if (searchingOptions) {
|
|
510
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
511
|
+
}
|
|
512
|
+
if (similar.length > 1) {
|
|
513
|
+
return `
|
|
514
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
515
|
+
}
|
|
516
|
+
if (similar.length === 1) {
|
|
517
|
+
return `
|
|
518
|
+
(Did you mean ${similar[0]}?)`;
|
|
519
|
+
}
|
|
520
|
+
return "";
|
|
521
|
+
}
|
|
522
|
+
exports.suggestSimilar = suggestSimilar;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// node_modules/commander/lib/command.js
|
|
527
|
+
var require_command = __commonJS({
|
|
528
|
+
"node_modules/commander/lib/command.js"(exports) {
|
|
529
|
+
var EventEmitter = require("events").EventEmitter;
|
|
530
|
+
var childProcess = require("child_process");
|
|
531
|
+
var path = require("path");
|
|
532
|
+
var fs = require("fs");
|
|
533
|
+
var process = require("process");
|
|
534
|
+
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
535
|
+
var { CommanderError: CommanderError2 } = require_error();
|
|
536
|
+
var { Help: Help2 } = require_help();
|
|
537
|
+
var { Option: Option2, splitOptionFlags } = require_option();
|
|
538
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
539
|
+
var Command2 = class extends EventEmitter {
|
|
540
|
+
constructor(name) {
|
|
541
|
+
super();
|
|
542
|
+
this.commands = [];
|
|
543
|
+
this.options = [];
|
|
544
|
+
this.parent = null;
|
|
545
|
+
this._allowUnknownOption = false;
|
|
546
|
+
this._allowExcessArguments = true;
|
|
547
|
+
this._args = [];
|
|
548
|
+
this.args = [];
|
|
549
|
+
this.rawArgs = [];
|
|
550
|
+
this.processedArgs = [];
|
|
551
|
+
this._scriptPath = null;
|
|
552
|
+
this._name = name || "";
|
|
553
|
+
this._optionValues = {};
|
|
554
|
+
this._optionValueSources = {};
|
|
555
|
+
this._storeOptionsAsProperties = false;
|
|
556
|
+
this._actionHandler = null;
|
|
557
|
+
this._executableHandler = false;
|
|
558
|
+
this._executableFile = null;
|
|
559
|
+
this._executableDir = null;
|
|
560
|
+
this._defaultCommandName = null;
|
|
561
|
+
this._exitCallback = null;
|
|
562
|
+
this._aliases = [];
|
|
563
|
+
this._combineFlagAndOptionalValue = true;
|
|
564
|
+
this._description = "";
|
|
565
|
+
this._argsDescription = void 0;
|
|
566
|
+
this._enablePositionalOptions = false;
|
|
567
|
+
this._passThroughOptions = false;
|
|
568
|
+
this._lifeCycleHooks = {};
|
|
569
|
+
this._showHelpAfterError = false;
|
|
570
|
+
this._showSuggestionAfterError = true;
|
|
571
|
+
this._outputConfiguration = {
|
|
572
|
+
writeOut: (str) => process.stdout.write(str),
|
|
573
|
+
writeErr: (str) => process.stderr.write(str),
|
|
574
|
+
getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : void 0,
|
|
575
|
+
getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : void 0,
|
|
576
|
+
outputError: (str, write) => write(str)
|
|
577
|
+
};
|
|
578
|
+
this._hidden = false;
|
|
579
|
+
this._hasHelpOption = true;
|
|
580
|
+
this._helpFlags = "-h, --help";
|
|
581
|
+
this._helpDescription = "display help for command";
|
|
582
|
+
this._helpShortFlag = "-h";
|
|
583
|
+
this._helpLongFlag = "--help";
|
|
584
|
+
this._addImplicitHelpCommand = void 0;
|
|
585
|
+
this._helpCommandName = "help";
|
|
586
|
+
this._helpCommandnameAndArgs = "help [command]";
|
|
587
|
+
this._helpCommandDescription = "display help for command";
|
|
588
|
+
this._helpConfiguration = {};
|
|
589
|
+
}
|
|
590
|
+
copyInheritedSettings(sourceCommand) {
|
|
591
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
592
|
+
this._hasHelpOption = sourceCommand._hasHelpOption;
|
|
593
|
+
this._helpFlags = sourceCommand._helpFlags;
|
|
594
|
+
this._helpDescription = sourceCommand._helpDescription;
|
|
595
|
+
this._helpShortFlag = sourceCommand._helpShortFlag;
|
|
596
|
+
this._helpLongFlag = sourceCommand._helpLongFlag;
|
|
597
|
+
this._helpCommandName = sourceCommand._helpCommandName;
|
|
598
|
+
this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
|
|
599
|
+
this._helpCommandDescription = sourceCommand._helpCommandDescription;
|
|
600
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
601
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
602
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
603
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
604
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
605
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
606
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
607
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
611
|
+
let desc = actionOptsOrExecDesc;
|
|
612
|
+
let opts = execOpts;
|
|
613
|
+
if (typeof desc === "object" && desc !== null) {
|
|
614
|
+
opts = desc;
|
|
615
|
+
desc = null;
|
|
616
|
+
}
|
|
617
|
+
opts = opts || {};
|
|
618
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
619
|
+
const cmd = this.createCommand(name);
|
|
620
|
+
if (desc) {
|
|
621
|
+
cmd.description(desc);
|
|
622
|
+
cmd._executableHandler = true;
|
|
623
|
+
}
|
|
624
|
+
if (opts.isDefault)
|
|
625
|
+
this._defaultCommandName = cmd._name;
|
|
626
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
627
|
+
cmd._executableFile = opts.executableFile || null;
|
|
628
|
+
if (args)
|
|
629
|
+
cmd.arguments(args);
|
|
630
|
+
this.commands.push(cmd);
|
|
631
|
+
cmd.parent = this;
|
|
632
|
+
cmd.copyInheritedSettings(this);
|
|
633
|
+
if (desc)
|
|
634
|
+
return this;
|
|
635
|
+
return cmd;
|
|
636
|
+
}
|
|
637
|
+
createCommand(name) {
|
|
638
|
+
return new Command2(name);
|
|
639
|
+
}
|
|
640
|
+
createHelp() {
|
|
641
|
+
return Object.assign(new Help2(), this.configureHelp());
|
|
642
|
+
}
|
|
643
|
+
configureHelp(configuration) {
|
|
644
|
+
if (configuration === void 0)
|
|
645
|
+
return this._helpConfiguration;
|
|
646
|
+
this._helpConfiguration = configuration;
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
configureOutput(configuration) {
|
|
650
|
+
if (configuration === void 0)
|
|
651
|
+
return this._outputConfiguration;
|
|
652
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
653
|
+
return this;
|
|
654
|
+
}
|
|
655
|
+
showHelpAfterError(displayHelp = true) {
|
|
656
|
+
if (typeof displayHelp !== "string")
|
|
657
|
+
displayHelp = !!displayHelp;
|
|
658
|
+
this._showHelpAfterError = displayHelp;
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
662
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
663
|
+
return this;
|
|
664
|
+
}
|
|
665
|
+
addCommand(cmd, opts) {
|
|
666
|
+
if (!cmd._name) {
|
|
667
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
668
|
+
- specify the name in Command constructor or using .name()`);
|
|
669
|
+
}
|
|
670
|
+
opts = opts || {};
|
|
671
|
+
if (opts.isDefault)
|
|
672
|
+
this._defaultCommandName = cmd._name;
|
|
673
|
+
if (opts.noHelp || opts.hidden)
|
|
674
|
+
cmd._hidden = true;
|
|
675
|
+
this.commands.push(cmd);
|
|
676
|
+
cmd.parent = this;
|
|
677
|
+
return this;
|
|
678
|
+
}
|
|
679
|
+
createArgument(name, description) {
|
|
680
|
+
return new Argument2(name, description);
|
|
681
|
+
}
|
|
682
|
+
argument(name, description, fn, defaultValue) {
|
|
683
|
+
const argument = this.createArgument(name, description);
|
|
684
|
+
if (typeof fn === "function") {
|
|
685
|
+
argument.default(defaultValue).argParser(fn);
|
|
686
|
+
} else {
|
|
687
|
+
argument.default(fn);
|
|
688
|
+
}
|
|
689
|
+
this.addArgument(argument);
|
|
690
|
+
return this;
|
|
691
|
+
}
|
|
692
|
+
arguments(names) {
|
|
693
|
+
names.split(/ +/).forEach((detail) => {
|
|
694
|
+
this.argument(detail);
|
|
695
|
+
});
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
addArgument(argument) {
|
|
699
|
+
const previousArgument = this._args.slice(-1)[0];
|
|
700
|
+
if (previousArgument && previousArgument.variadic) {
|
|
701
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
702
|
+
}
|
|
703
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
|
|
704
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
705
|
+
}
|
|
706
|
+
this._args.push(argument);
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
addHelpCommand(enableOrNameAndArgs, description) {
|
|
710
|
+
if (enableOrNameAndArgs === false) {
|
|
711
|
+
this._addImplicitHelpCommand = false;
|
|
712
|
+
} else {
|
|
713
|
+
this._addImplicitHelpCommand = true;
|
|
714
|
+
if (typeof enableOrNameAndArgs === "string") {
|
|
715
|
+
this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
|
|
716
|
+
this._helpCommandnameAndArgs = enableOrNameAndArgs;
|
|
717
|
+
}
|
|
718
|
+
this._helpCommandDescription = description || this._helpCommandDescription;
|
|
719
|
+
}
|
|
720
|
+
return this;
|
|
721
|
+
}
|
|
722
|
+
_hasImplicitHelpCommand() {
|
|
723
|
+
if (this._addImplicitHelpCommand === void 0) {
|
|
724
|
+
return this.commands.length && !this._actionHandler && !this._findCommand("help");
|
|
725
|
+
}
|
|
726
|
+
return this._addImplicitHelpCommand;
|
|
727
|
+
}
|
|
728
|
+
hook(event, listener) {
|
|
729
|
+
const allowedValues = ["preAction", "postAction"];
|
|
730
|
+
if (!allowedValues.includes(event)) {
|
|
731
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
732
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
733
|
+
}
|
|
734
|
+
if (this._lifeCycleHooks[event]) {
|
|
735
|
+
this._lifeCycleHooks[event].push(listener);
|
|
736
|
+
} else {
|
|
737
|
+
this._lifeCycleHooks[event] = [listener];
|
|
738
|
+
}
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
exitOverride(fn) {
|
|
742
|
+
if (fn) {
|
|
743
|
+
this._exitCallback = fn;
|
|
744
|
+
} else {
|
|
745
|
+
this._exitCallback = (err) => {
|
|
746
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
747
|
+
throw err;
|
|
748
|
+
} else {
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
_exit(exitCode, code, message) {
|
|
755
|
+
if (this._exitCallback) {
|
|
756
|
+
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
757
|
+
}
|
|
758
|
+
process.exit(exitCode);
|
|
759
|
+
}
|
|
760
|
+
action(fn) {
|
|
761
|
+
const listener = (args) => {
|
|
762
|
+
const expectedArgsCount = this._args.length;
|
|
763
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
764
|
+
if (this._storeOptionsAsProperties) {
|
|
765
|
+
actionArgs[expectedArgsCount] = this;
|
|
766
|
+
} else {
|
|
767
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
768
|
+
}
|
|
769
|
+
actionArgs.push(this);
|
|
770
|
+
return fn.apply(this, actionArgs);
|
|
771
|
+
};
|
|
772
|
+
this._actionHandler = listener;
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
createOption(flags, description) {
|
|
776
|
+
return new Option2(flags, description);
|
|
777
|
+
}
|
|
778
|
+
addOption(option) {
|
|
779
|
+
const oname = option.name();
|
|
780
|
+
const name = option.attributeName();
|
|
781
|
+
if (option.negate) {
|
|
782
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
783
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
784
|
+
this.setOptionValueWithSource(name, option.defaultValue === void 0 ? true : option.defaultValue, "default");
|
|
785
|
+
}
|
|
786
|
+
} else if (option.defaultValue !== void 0) {
|
|
787
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
788
|
+
}
|
|
789
|
+
this.options.push(option);
|
|
790
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
791
|
+
if (val == null && option.presetArg !== void 0) {
|
|
792
|
+
val = option.presetArg;
|
|
793
|
+
}
|
|
794
|
+
const oldValue = this.getOptionValue(name);
|
|
795
|
+
if (val !== null && option.parseArg) {
|
|
796
|
+
try {
|
|
797
|
+
val = option.parseArg(val, oldValue);
|
|
798
|
+
} catch (err) {
|
|
799
|
+
if (err.code === "commander.invalidArgument") {
|
|
800
|
+
const message = `${invalidValueMessage} ${err.message}`;
|
|
801
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
802
|
+
}
|
|
803
|
+
throw err;
|
|
804
|
+
}
|
|
805
|
+
} else if (val !== null && option.variadic) {
|
|
806
|
+
val = option._concatValue(val, oldValue);
|
|
807
|
+
}
|
|
808
|
+
if (val == null) {
|
|
809
|
+
if (option.negate) {
|
|
810
|
+
val = false;
|
|
811
|
+
} else if (option.isBoolean() || option.optional) {
|
|
812
|
+
val = true;
|
|
813
|
+
} else {
|
|
814
|
+
val = "";
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
818
|
+
};
|
|
819
|
+
this.on("option:" + oname, (val) => {
|
|
820
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
821
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
822
|
+
});
|
|
823
|
+
if (option.envVar) {
|
|
824
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
825
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
826
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
return this;
|
|
830
|
+
}
|
|
831
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
832
|
+
if (typeof flags === "object" && flags instanceof Option2) {
|
|
833
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
834
|
+
}
|
|
835
|
+
const option = this.createOption(flags, description);
|
|
836
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
837
|
+
if (typeof fn === "function") {
|
|
838
|
+
option.default(defaultValue).argParser(fn);
|
|
839
|
+
} else if (fn instanceof RegExp) {
|
|
840
|
+
const regex = fn;
|
|
841
|
+
fn = (val, def) => {
|
|
842
|
+
const m = regex.exec(val);
|
|
843
|
+
return m ? m[0] : def;
|
|
844
|
+
};
|
|
845
|
+
option.default(defaultValue).argParser(fn);
|
|
846
|
+
} else {
|
|
847
|
+
option.default(fn);
|
|
848
|
+
}
|
|
849
|
+
return this.addOption(option);
|
|
850
|
+
}
|
|
851
|
+
option(flags, description, fn, defaultValue) {
|
|
852
|
+
return this._optionEx({}, flags, description, fn, defaultValue);
|
|
853
|
+
}
|
|
854
|
+
requiredOption(flags, description, fn, defaultValue) {
|
|
855
|
+
return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
|
|
856
|
+
}
|
|
857
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
858
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
859
|
+
return this;
|
|
860
|
+
}
|
|
861
|
+
allowUnknownOption(allowUnknown = true) {
|
|
862
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
863
|
+
return this;
|
|
864
|
+
}
|
|
865
|
+
allowExcessArguments(allowExcess = true) {
|
|
866
|
+
this._allowExcessArguments = !!allowExcess;
|
|
867
|
+
return this;
|
|
868
|
+
}
|
|
869
|
+
enablePositionalOptions(positional = true) {
|
|
870
|
+
this._enablePositionalOptions = !!positional;
|
|
871
|
+
return this;
|
|
872
|
+
}
|
|
873
|
+
passThroughOptions(passThrough = true) {
|
|
874
|
+
this._passThroughOptions = !!passThrough;
|
|
875
|
+
if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
|
|
876
|
+
throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
|
|
877
|
+
}
|
|
878
|
+
return this;
|
|
879
|
+
}
|
|
880
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
881
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
882
|
+
if (this.options.length) {
|
|
883
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
884
|
+
}
|
|
885
|
+
return this;
|
|
886
|
+
}
|
|
887
|
+
getOptionValue(key) {
|
|
888
|
+
if (this._storeOptionsAsProperties) {
|
|
889
|
+
return this[key];
|
|
890
|
+
}
|
|
891
|
+
return this._optionValues[key];
|
|
892
|
+
}
|
|
893
|
+
setOptionValue(key, value) {
|
|
894
|
+
if (this._storeOptionsAsProperties) {
|
|
895
|
+
this[key] = value;
|
|
896
|
+
} else {
|
|
897
|
+
this._optionValues[key] = value;
|
|
898
|
+
}
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
setOptionValueWithSource(key, value, source) {
|
|
902
|
+
this.setOptionValue(key, value);
|
|
903
|
+
this._optionValueSources[key] = source;
|
|
904
|
+
return this;
|
|
905
|
+
}
|
|
906
|
+
getOptionValueSource(key) {
|
|
907
|
+
return this._optionValueSources[key];
|
|
908
|
+
}
|
|
909
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
910
|
+
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
911
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
912
|
+
}
|
|
913
|
+
parseOptions = parseOptions || {};
|
|
914
|
+
if (argv === void 0) {
|
|
915
|
+
argv = process.argv;
|
|
916
|
+
if (process.versions && process.versions.electron) {
|
|
917
|
+
parseOptions.from = "electron";
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
this.rawArgs = argv.slice();
|
|
921
|
+
let userArgs;
|
|
922
|
+
switch (parseOptions.from) {
|
|
923
|
+
case void 0:
|
|
924
|
+
case "node":
|
|
925
|
+
this._scriptPath = argv[1];
|
|
926
|
+
userArgs = argv.slice(2);
|
|
927
|
+
break;
|
|
928
|
+
case "electron":
|
|
929
|
+
if (process.defaultApp) {
|
|
930
|
+
this._scriptPath = argv[1];
|
|
931
|
+
userArgs = argv.slice(2);
|
|
932
|
+
} else {
|
|
933
|
+
userArgs = argv.slice(1);
|
|
934
|
+
}
|
|
935
|
+
break;
|
|
936
|
+
case "user":
|
|
937
|
+
userArgs = argv.slice(0);
|
|
938
|
+
break;
|
|
939
|
+
default:
|
|
940
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
941
|
+
}
|
|
942
|
+
if (!this._name && this._scriptPath)
|
|
943
|
+
this.nameFromFilename(this._scriptPath);
|
|
944
|
+
this._name = this._name || "program";
|
|
945
|
+
return userArgs;
|
|
946
|
+
}
|
|
947
|
+
parse(argv, parseOptions) {
|
|
948
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
949
|
+
this._parseCommand([], userArgs);
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
async parseAsync(argv, parseOptions) {
|
|
953
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
954
|
+
await this._parseCommand([], userArgs);
|
|
955
|
+
return this;
|
|
956
|
+
}
|
|
957
|
+
_executeSubCommand(subcommand, args) {
|
|
958
|
+
args = args.slice();
|
|
959
|
+
let launchWithNode = false;
|
|
960
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
961
|
+
function findFile(baseDir, baseName) {
|
|
962
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
963
|
+
if (fs.existsSync(localBin))
|
|
964
|
+
return localBin;
|
|
965
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
966
|
+
return void 0;
|
|
967
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
968
|
+
if (foundExt)
|
|
969
|
+
return `${localBin}${foundExt}`;
|
|
970
|
+
return void 0;
|
|
971
|
+
}
|
|
972
|
+
this._checkForMissingMandatoryOptions();
|
|
973
|
+
this._checkForConflictingOptions();
|
|
974
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
975
|
+
let executableDir = this._executableDir || "";
|
|
976
|
+
if (this._scriptPath) {
|
|
977
|
+
let resolvedScriptPath;
|
|
978
|
+
try {
|
|
979
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
980
|
+
} catch (err) {
|
|
981
|
+
resolvedScriptPath = this._scriptPath;
|
|
982
|
+
}
|
|
983
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
984
|
+
}
|
|
985
|
+
if (executableDir) {
|
|
986
|
+
let localFile = findFile(executableDir, executableFile);
|
|
987
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
988
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
989
|
+
if (legacyName !== this._name) {
|
|
990
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
executableFile = localFile || executableFile;
|
|
994
|
+
}
|
|
995
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
996
|
+
let proc;
|
|
997
|
+
if (process.platform !== "win32") {
|
|
998
|
+
if (launchWithNode) {
|
|
999
|
+
args.unshift(executableFile);
|
|
1000
|
+
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
1001
|
+
proc = childProcess.spawn(process.argv[0], args, { stdio: "inherit" });
|
|
1002
|
+
} else {
|
|
1003
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1004
|
+
}
|
|
1005
|
+
} else {
|
|
1006
|
+
args.unshift(executableFile);
|
|
1007
|
+
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
1008
|
+
proc = childProcess.spawn(process.execPath, args, { stdio: "inherit" });
|
|
1009
|
+
}
|
|
1010
|
+
if (!proc.killed) {
|
|
1011
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1012
|
+
signals.forEach((signal) => {
|
|
1013
|
+
process.on(signal, () => {
|
|
1014
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1015
|
+
proc.kill(signal);
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
const exitCallback = this._exitCallback;
|
|
1021
|
+
if (!exitCallback) {
|
|
1022
|
+
proc.on("close", process.exit.bind(process));
|
|
1023
|
+
} else {
|
|
1024
|
+
proc.on("close", () => {
|
|
1025
|
+
exitCallback(new CommanderError2(process.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
proc.on("error", (err) => {
|
|
1029
|
+
if (err.code === "ENOENT") {
|
|
1030
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1031
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1032
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1033
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1034
|
+
- ${executableDirMessage}`;
|
|
1035
|
+
throw new Error(executableMissing);
|
|
1036
|
+
} else if (err.code === "EACCES") {
|
|
1037
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1038
|
+
}
|
|
1039
|
+
if (!exitCallback) {
|
|
1040
|
+
process.exit(1);
|
|
1041
|
+
} else {
|
|
1042
|
+
const wrappedError = new CommanderError2(1, "commander.executeSubCommandAsync", "(error)");
|
|
1043
|
+
wrappedError.nestedError = err;
|
|
1044
|
+
exitCallback(wrappedError);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
this.runningCommand = proc;
|
|
1048
|
+
}
|
|
1049
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1050
|
+
const subCommand = this._findCommand(commandName);
|
|
1051
|
+
if (!subCommand)
|
|
1052
|
+
this.help({ error: true });
|
|
1053
|
+
if (subCommand._executableHandler) {
|
|
1054
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1055
|
+
} else {
|
|
1056
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
_checkNumberOfArguments() {
|
|
1060
|
+
this._args.forEach((arg, i) => {
|
|
1061
|
+
if (arg.required && this.args[i] == null) {
|
|
1062
|
+
this.missingArgument(arg.name());
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
if (this._args.length > 0 && this._args[this._args.length - 1].variadic) {
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (this.args.length > this._args.length) {
|
|
1069
|
+
this._excessArguments(this.args);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
_processArguments() {
|
|
1073
|
+
const myParseArg = (argument, value, previous) => {
|
|
1074
|
+
let parsedValue = value;
|
|
1075
|
+
if (value !== null && argument.parseArg) {
|
|
1076
|
+
try {
|
|
1077
|
+
parsedValue = argument.parseArg(value, previous);
|
|
1078
|
+
} catch (err) {
|
|
1079
|
+
if (err.code === "commander.invalidArgument") {
|
|
1080
|
+
const message = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'. ${err.message}`;
|
|
1081
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1082
|
+
}
|
|
1083
|
+
throw err;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
return parsedValue;
|
|
1087
|
+
};
|
|
1088
|
+
this._checkNumberOfArguments();
|
|
1089
|
+
const processedArgs = [];
|
|
1090
|
+
this._args.forEach((declaredArg, index) => {
|
|
1091
|
+
let value = declaredArg.defaultValue;
|
|
1092
|
+
if (declaredArg.variadic) {
|
|
1093
|
+
if (index < this.args.length) {
|
|
1094
|
+
value = this.args.slice(index);
|
|
1095
|
+
if (declaredArg.parseArg) {
|
|
1096
|
+
value = value.reduce((processed, v) => {
|
|
1097
|
+
return myParseArg(declaredArg, v, processed);
|
|
1098
|
+
}, declaredArg.defaultValue);
|
|
1099
|
+
}
|
|
1100
|
+
} else if (value === void 0) {
|
|
1101
|
+
value = [];
|
|
1102
|
+
}
|
|
1103
|
+
} else if (index < this.args.length) {
|
|
1104
|
+
value = this.args[index];
|
|
1105
|
+
if (declaredArg.parseArg) {
|
|
1106
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
processedArgs[index] = value;
|
|
1110
|
+
});
|
|
1111
|
+
this.processedArgs = processedArgs;
|
|
1112
|
+
}
|
|
1113
|
+
_chainOrCall(promise, fn) {
|
|
1114
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1115
|
+
return promise.then(() => fn());
|
|
1116
|
+
}
|
|
1117
|
+
return fn();
|
|
1118
|
+
}
|
|
1119
|
+
_chainOrCallHooks(promise, event) {
|
|
1120
|
+
let result = promise;
|
|
1121
|
+
const hooks = [];
|
|
1122
|
+
getCommandAndParents(this).reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
1123
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1124
|
+
hooks.push({ hookedCommand, callback });
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1127
|
+
if (event === "postAction") {
|
|
1128
|
+
hooks.reverse();
|
|
1129
|
+
}
|
|
1130
|
+
hooks.forEach((hookDetail) => {
|
|
1131
|
+
result = this._chainOrCall(result, () => {
|
|
1132
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1133
|
+
});
|
|
1134
|
+
});
|
|
1135
|
+
return result;
|
|
1136
|
+
}
|
|
1137
|
+
_parseCommand(operands, unknown) {
|
|
1138
|
+
const parsed = this.parseOptions(unknown);
|
|
1139
|
+
this._parseOptionsEnv();
|
|
1140
|
+
operands = operands.concat(parsed.operands);
|
|
1141
|
+
unknown = parsed.unknown;
|
|
1142
|
+
this.args = operands.concat(unknown);
|
|
1143
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1144
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1145
|
+
}
|
|
1146
|
+
if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
|
|
1147
|
+
if (operands.length === 1) {
|
|
1148
|
+
this.help();
|
|
1149
|
+
}
|
|
1150
|
+
return this._dispatchSubcommand(operands[1], [], [this._helpLongFlag]);
|
|
1151
|
+
}
|
|
1152
|
+
if (this._defaultCommandName) {
|
|
1153
|
+
outputHelpIfRequested(this, unknown);
|
|
1154
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1155
|
+
}
|
|
1156
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1157
|
+
this.help({ error: true });
|
|
1158
|
+
}
|
|
1159
|
+
outputHelpIfRequested(this, parsed.unknown);
|
|
1160
|
+
this._checkForMissingMandatoryOptions();
|
|
1161
|
+
this._checkForConflictingOptions();
|
|
1162
|
+
const checkForUnknownOptions = () => {
|
|
1163
|
+
if (parsed.unknown.length > 0) {
|
|
1164
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
const commandEvent = `command:${this.name()}`;
|
|
1168
|
+
if (this._actionHandler) {
|
|
1169
|
+
checkForUnknownOptions();
|
|
1170
|
+
this._processArguments();
|
|
1171
|
+
let actionResult;
|
|
1172
|
+
actionResult = this._chainOrCallHooks(actionResult, "preAction");
|
|
1173
|
+
actionResult = this._chainOrCall(actionResult, () => this._actionHandler(this.processedArgs));
|
|
1174
|
+
if (this.parent) {
|
|
1175
|
+
actionResult = this._chainOrCall(actionResult, () => {
|
|
1176
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
actionResult = this._chainOrCallHooks(actionResult, "postAction");
|
|
1180
|
+
return actionResult;
|
|
1181
|
+
}
|
|
1182
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1183
|
+
checkForUnknownOptions();
|
|
1184
|
+
this._processArguments();
|
|
1185
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1186
|
+
} else if (operands.length) {
|
|
1187
|
+
if (this._findCommand("*")) {
|
|
1188
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1189
|
+
}
|
|
1190
|
+
if (this.listenerCount("command:*")) {
|
|
1191
|
+
this.emit("command:*", operands, unknown);
|
|
1192
|
+
} else if (this.commands.length) {
|
|
1193
|
+
this.unknownCommand();
|
|
1194
|
+
} else {
|
|
1195
|
+
checkForUnknownOptions();
|
|
1196
|
+
this._processArguments();
|
|
1197
|
+
}
|
|
1198
|
+
} else if (this.commands.length) {
|
|
1199
|
+
checkForUnknownOptions();
|
|
1200
|
+
this.help({ error: true });
|
|
1201
|
+
} else {
|
|
1202
|
+
checkForUnknownOptions();
|
|
1203
|
+
this._processArguments();
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
_findCommand(name) {
|
|
1207
|
+
if (!name)
|
|
1208
|
+
return void 0;
|
|
1209
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1210
|
+
}
|
|
1211
|
+
_findOption(arg) {
|
|
1212
|
+
return this.options.find((option) => option.is(arg));
|
|
1213
|
+
}
|
|
1214
|
+
_checkForMissingMandatoryOptions() {
|
|
1215
|
+
for (let cmd = this; cmd; cmd = cmd.parent) {
|
|
1216
|
+
cmd.options.forEach((anOption) => {
|
|
1217
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
|
|
1218
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
_checkForConflictingLocalOptions() {
|
|
1224
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1225
|
+
const optionKey = option.attributeName();
|
|
1226
|
+
if (this.getOptionValue(optionKey) === void 0) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1230
|
+
});
|
|
1231
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1232
|
+
optionsWithConflicting.forEach((option) => {
|
|
1233
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1234
|
+
if (conflictingAndDefined) {
|
|
1235
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
_checkForConflictingOptions() {
|
|
1240
|
+
for (let cmd = this; cmd; cmd = cmd.parent) {
|
|
1241
|
+
cmd._checkForConflictingLocalOptions();
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
parseOptions(argv) {
|
|
1245
|
+
const operands = [];
|
|
1246
|
+
const unknown = [];
|
|
1247
|
+
let dest = operands;
|
|
1248
|
+
const args = argv.slice();
|
|
1249
|
+
function maybeOption(arg) {
|
|
1250
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1251
|
+
}
|
|
1252
|
+
let activeVariadicOption = null;
|
|
1253
|
+
while (args.length) {
|
|
1254
|
+
const arg = args.shift();
|
|
1255
|
+
if (arg === "--") {
|
|
1256
|
+
if (dest === unknown)
|
|
1257
|
+
dest.push(arg);
|
|
1258
|
+
dest.push(...args);
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1262
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
activeVariadicOption = null;
|
|
1266
|
+
if (maybeOption(arg)) {
|
|
1267
|
+
const option = this._findOption(arg);
|
|
1268
|
+
if (option) {
|
|
1269
|
+
if (option.required) {
|
|
1270
|
+
const value = args.shift();
|
|
1271
|
+
if (value === void 0)
|
|
1272
|
+
this.optionMissingArgument(option);
|
|
1273
|
+
this.emit(`option:${option.name()}`, value);
|
|
1274
|
+
} else if (option.optional) {
|
|
1275
|
+
let value = null;
|
|
1276
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1277
|
+
value = args.shift();
|
|
1278
|
+
}
|
|
1279
|
+
this.emit(`option:${option.name()}`, value);
|
|
1280
|
+
} else {
|
|
1281
|
+
this.emit(`option:${option.name()}`);
|
|
1282
|
+
}
|
|
1283
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1288
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1289
|
+
if (option) {
|
|
1290
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1291
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1292
|
+
} else {
|
|
1293
|
+
this.emit(`option:${option.name()}`);
|
|
1294
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1295
|
+
}
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1300
|
+
const index = arg.indexOf("=");
|
|
1301
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1302
|
+
if (option && (option.required || option.optional)) {
|
|
1303
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
if (maybeOption(arg)) {
|
|
1308
|
+
dest = unknown;
|
|
1309
|
+
}
|
|
1310
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1311
|
+
if (this._findCommand(arg)) {
|
|
1312
|
+
operands.push(arg);
|
|
1313
|
+
if (args.length > 0)
|
|
1314
|
+
unknown.push(...args);
|
|
1315
|
+
break;
|
|
1316
|
+
} else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
|
|
1317
|
+
operands.push(arg);
|
|
1318
|
+
if (args.length > 0)
|
|
1319
|
+
operands.push(...args);
|
|
1320
|
+
break;
|
|
1321
|
+
} else if (this._defaultCommandName) {
|
|
1322
|
+
unknown.push(arg);
|
|
1323
|
+
if (args.length > 0)
|
|
1324
|
+
unknown.push(...args);
|
|
1325
|
+
break;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (this._passThroughOptions) {
|
|
1329
|
+
dest.push(arg);
|
|
1330
|
+
if (args.length > 0)
|
|
1331
|
+
dest.push(...args);
|
|
1332
|
+
break;
|
|
1333
|
+
}
|
|
1334
|
+
dest.push(arg);
|
|
1335
|
+
}
|
|
1336
|
+
return { operands, unknown };
|
|
1337
|
+
}
|
|
1338
|
+
opts() {
|
|
1339
|
+
if (this._storeOptionsAsProperties) {
|
|
1340
|
+
const result = {};
|
|
1341
|
+
const len = this.options.length;
|
|
1342
|
+
for (let i = 0; i < len; i++) {
|
|
1343
|
+
const key = this.options[i].attributeName();
|
|
1344
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1345
|
+
}
|
|
1346
|
+
return result;
|
|
1347
|
+
}
|
|
1348
|
+
return this._optionValues;
|
|
1349
|
+
}
|
|
1350
|
+
optsWithGlobals() {
|
|
1351
|
+
return getCommandAndParents(this).reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1352
|
+
}
|
|
1353
|
+
error(message, errorOptions) {
|
|
1354
|
+
this._outputConfiguration.outputError(`${message}
|
|
1355
|
+
`, this._outputConfiguration.writeErr);
|
|
1356
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1357
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1358
|
+
`);
|
|
1359
|
+
} else if (this._showHelpAfterError) {
|
|
1360
|
+
this._outputConfiguration.writeErr("\n");
|
|
1361
|
+
this.outputHelp({ error: true });
|
|
1362
|
+
}
|
|
1363
|
+
const config = errorOptions || {};
|
|
1364
|
+
const exitCode = config.exitCode || 1;
|
|
1365
|
+
const code = config.code || "commander.error";
|
|
1366
|
+
this._exit(exitCode, code, message);
|
|
1367
|
+
}
|
|
1368
|
+
_parseOptionsEnv() {
|
|
1369
|
+
this.options.forEach((option) => {
|
|
1370
|
+
if (option.envVar && option.envVar in process.env) {
|
|
1371
|
+
const optionKey = option.attributeName();
|
|
1372
|
+
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1373
|
+
if (option.required || option.optional) {
|
|
1374
|
+
this.emit(`optionEnv:${option.name()}`, process.env[option.envVar]);
|
|
1375
|
+
} else {
|
|
1376
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
missingArgument(name) {
|
|
1383
|
+
const message = `error: missing required argument '${name}'`;
|
|
1384
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1385
|
+
}
|
|
1386
|
+
optionMissingArgument(option) {
|
|
1387
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1388
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1389
|
+
}
|
|
1390
|
+
missingMandatoryOptionValue(option) {
|
|
1391
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1392
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1393
|
+
}
|
|
1394
|
+
_conflictingOption(option, conflictingOption) {
|
|
1395
|
+
const findBestOptionFromValue = (option2) => {
|
|
1396
|
+
const optionKey = option2.attributeName();
|
|
1397
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1398
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1399
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1400
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) {
|
|
1401
|
+
return negativeOption;
|
|
1402
|
+
}
|
|
1403
|
+
return positiveOption || option2;
|
|
1404
|
+
};
|
|
1405
|
+
const getErrorMessage = (option2) => {
|
|
1406
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1407
|
+
const optionKey = bestOption.attributeName();
|
|
1408
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1409
|
+
if (source === "env") {
|
|
1410
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1411
|
+
}
|
|
1412
|
+
return `option '${bestOption.flags}'`;
|
|
1413
|
+
};
|
|
1414
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1415
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1416
|
+
}
|
|
1417
|
+
unknownOption(flag) {
|
|
1418
|
+
if (this._allowUnknownOption)
|
|
1419
|
+
return;
|
|
1420
|
+
let suggestion = "";
|
|
1421
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1422
|
+
let candidateFlags = [];
|
|
1423
|
+
let command = this;
|
|
1424
|
+
do {
|
|
1425
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1426
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1427
|
+
command = command.parent;
|
|
1428
|
+
} while (command && !command._enablePositionalOptions);
|
|
1429
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1430
|
+
}
|
|
1431
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1432
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1433
|
+
}
|
|
1434
|
+
_excessArguments(receivedArgs) {
|
|
1435
|
+
if (this._allowExcessArguments)
|
|
1436
|
+
return;
|
|
1437
|
+
const expected = this._args.length;
|
|
1438
|
+
const s = expected === 1 ? "" : "s";
|
|
1439
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1440
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1441
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1442
|
+
}
|
|
1443
|
+
unknownCommand() {
|
|
1444
|
+
const unknownName = this.args[0];
|
|
1445
|
+
let suggestion = "";
|
|
1446
|
+
if (this._showSuggestionAfterError) {
|
|
1447
|
+
const candidateNames = [];
|
|
1448
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1449
|
+
candidateNames.push(command.name());
|
|
1450
|
+
if (command.alias())
|
|
1451
|
+
candidateNames.push(command.alias());
|
|
1452
|
+
});
|
|
1453
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1454
|
+
}
|
|
1455
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1456
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1457
|
+
}
|
|
1458
|
+
version(str, flags, description) {
|
|
1459
|
+
if (str === void 0)
|
|
1460
|
+
return this._version;
|
|
1461
|
+
this._version = str;
|
|
1462
|
+
flags = flags || "-V, --version";
|
|
1463
|
+
description = description || "output the version number";
|
|
1464
|
+
const versionOption = this.createOption(flags, description);
|
|
1465
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1466
|
+
this.options.push(versionOption);
|
|
1467
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1468
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1469
|
+
`);
|
|
1470
|
+
this._exit(0, "commander.version", str);
|
|
1471
|
+
});
|
|
1472
|
+
return this;
|
|
1473
|
+
}
|
|
1474
|
+
description(str, argsDescription) {
|
|
1475
|
+
if (str === void 0 && argsDescription === void 0)
|
|
1476
|
+
return this._description;
|
|
1477
|
+
this._description = str;
|
|
1478
|
+
if (argsDescription) {
|
|
1479
|
+
this._argsDescription = argsDescription;
|
|
1480
|
+
}
|
|
1481
|
+
return this;
|
|
1482
|
+
}
|
|
1483
|
+
alias(alias) {
|
|
1484
|
+
if (alias === void 0)
|
|
1485
|
+
return this._aliases[0];
|
|
1486
|
+
let command = this;
|
|
1487
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1488
|
+
command = this.commands[this.commands.length - 1];
|
|
1489
|
+
}
|
|
1490
|
+
if (alias === command._name)
|
|
1491
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1492
|
+
command._aliases.push(alias);
|
|
1493
|
+
return this;
|
|
1494
|
+
}
|
|
1495
|
+
aliases(aliases) {
|
|
1496
|
+
if (aliases === void 0)
|
|
1497
|
+
return this._aliases;
|
|
1498
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1499
|
+
return this;
|
|
1500
|
+
}
|
|
1501
|
+
usage(str) {
|
|
1502
|
+
if (str === void 0) {
|
|
1503
|
+
if (this._usage)
|
|
1504
|
+
return this._usage;
|
|
1505
|
+
const args = this._args.map((arg) => {
|
|
1506
|
+
return humanReadableArgName(arg);
|
|
1507
|
+
});
|
|
1508
|
+
return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this._args.length ? args : []).join(" ");
|
|
1509
|
+
}
|
|
1510
|
+
this._usage = str;
|
|
1511
|
+
return this;
|
|
1512
|
+
}
|
|
1513
|
+
name(str) {
|
|
1514
|
+
if (str === void 0)
|
|
1515
|
+
return this._name;
|
|
1516
|
+
this._name = str;
|
|
1517
|
+
return this;
|
|
1518
|
+
}
|
|
1519
|
+
nameFromFilename(filename) {
|
|
1520
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1521
|
+
return this;
|
|
1522
|
+
}
|
|
1523
|
+
executableDir(path2) {
|
|
1524
|
+
if (path2 === void 0)
|
|
1525
|
+
return this._executableDir;
|
|
1526
|
+
this._executableDir = path2;
|
|
1527
|
+
return this;
|
|
1528
|
+
}
|
|
1529
|
+
helpInformation(contextOptions) {
|
|
1530
|
+
const helper = this.createHelp();
|
|
1531
|
+
if (helper.helpWidth === void 0) {
|
|
1532
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1533
|
+
}
|
|
1534
|
+
return helper.formatHelp(this, helper);
|
|
1535
|
+
}
|
|
1536
|
+
_getHelpContext(contextOptions) {
|
|
1537
|
+
contextOptions = contextOptions || {};
|
|
1538
|
+
const context = { error: !!contextOptions.error };
|
|
1539
|
+
let write;
|
|
1540
|
+
if (context.error) {
|
|
1541
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1542
|
+
} else {
|
|
1543
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1544
|
+
}
|
|
1545
|
+
context.write = contextOptions.write || write;
|
|
1546
|
+
context.command = this;
|
|
1547
|
+
return context;
|
|
1548
|
+
}
|
|
1549
|
+
outputHelp(contextOptions) {
|
|
1550
|
+
let deprecatedCallback;
|
|
1551
|
+
if (typeof contextOptions === "function") {
|
|
1552
|
+
deprecatedCallback = contextOptions;
|
|
1553
|
+
contextOptions = void 0;
|
|
1554
|
+
}
|
|
1555
|
+
const context = this._getHelpContext(contextOptions);
|
|
1556
|
+
getCommandAndParents(this).reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1557
|
+
this.emit("beforeHelp", context);
|
|
1558
|
+
let helpInformation = this.helpInformation(context);
|
|
1559
|
+
if (deprecatedCallback) {
|
|
1560
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1561
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1562
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
context.write(helpInformation);
|
|
1566
|
+
this.emit(this._helpLongFlag);
|
|
1567
|
+
this.emit("afterHelp", context);
|
|
1568
|
+
getCommandAndParents(this).forEach((command) => command.emit("afterAllHelp", context));
|
|
1569
|
+
}
|
|
1570
|
+
helpOption(flags, description) {
|
|
1571
|
+
if (typeof flags === "boolean") {
|
|
1572
|
+
this._hasHelpOption = flags;
|
|
1573
|
+
return this;
|
|
1574
|
+
}
|
|
1575
|
+
this._helpFlags = flags || this._helpFlags;
|
|
1576
|
+
this._helpDescription = description || this._helpDescription;
|
|
1577
|
+
const helpFlags = splitOptionFlags(this._helpFlags);
|
|
1578
|
+
this._helpShortFlag = helpFlags.shortFlag;
|
|
1579
|
+
this._helpLongFlag = helpFlags.longFlag;
|
|
1580
|
+
return this;
|
|
1581
|
+
}
|
|
1582
|
+
help(contextOptions) {
|
|
1583
|
+
this.outputHelp(contextOptions);
|
|
1584
|
+
let exitCode = process.exitCode || 0;
|
|
1585
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1586
|
+
exitCode = 1;
|
|
1587
|
+
}
|
|
1588
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1589
|
+
}
|
|
1590
|
+
addHelpText(position, text) {
|
|
1591
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1592
|
+
if (!allowedValues.includes(position)) {
|
|
1593
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1594
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1595
|
+
}
|
|
1596
|
+
const helpEvent = `${position}Help`;
|
|
1597
|
+
this.on(helpEvent, (context) => {
|
|
1598
|
+
let helpStr;
|
|
1599
|
+
if (typeof text === "function") {
|
|
1600
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1601
|
+
} else {
|
|
1602
|
+
helpStr = text;
|
|
1603
|
+
}
|
|
1604
|
+
if (helpStr) {
|
|
1605
|
+
context.write(`${helpStr}
|
|
1606
|
+
`);
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
return this;
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
function outputHelpIfRequested(cmd, args) {
|
|
1613
|
+
const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
|
|
1614
|
+
if (helpOption) {
|
|
1615
|
+
cmd.outputHelp();
|
|
1616
|
+
cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
function incrementNodeInspectorPort(args) {
|
|
1620
|
+
return args.map((arg) => {
|
|
1621
|
+
if (!arg.startsWith("--inspect")) {
|
|
1622
|
+
return arg;
|
|
1623
|
+
}
|
|
1624
|
+
let debugOption;
|
|
1625
|
+
let debugHost = "127.0.0.1";
|
|
1626
|
+
let debugPort = "9229";
|
|
1627
|
+
let match;
|
|
1628
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1629
|
+
debugOption = match[1];
|
|
1630
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1631
|
+
debugOption = match[1];
|
|
1632
|
+
if (/^\d+$/.test(match[3])) {
|
|
1633
|
+
debugPort = match[3];
|
|
1634
|
+
} else {
|
|
1635
|
+
debugHost = match[3];
|
|
1636
|
+
}
|
|
1637
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1638
|
+
debugOption = match[1];
|
|
1639
|
+
debugHost = match[3];
|
|
1640
|
+
debugPort = match[4];
|
|
1641
|
+
}
|
|
1642
|
+
if (debugOption && debugPort !== "0") {
|
|
1643
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1644
|
+
}
|
|
1645
|
+
return arg;
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
function getCommandAndParents(startCommand) {
|
|
1649
|
+
const result = [];
|
|
1650
|
+
for (let command = startCommand; command; command = command.parent) {
|
|
1651
|
+
result.push(command);
|
|
1652
|
+
}
|
|
1653
|
+
return result;
|
|
1654
|
+
}
|
|
1655
|
+
exports.Command = Command2;
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
// node_modules/commander/index.js
|
|
1660
|
+
var require_commander = __commonJS({
|
|
1661
|
+
"node_modules/commander/index.js"(exports, module2) {
|
|
1662
|
+
var { Argument: Argument2 } = require_argument();
|
|
1663
|
+
var { Command: Command2 } = require_command();
|
|
1664
|
+
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
1665
|
+
var { Help: Help2 } = require_help();
|
|
1666
|
+
var { Option: Option2 } = require_option();
|
|
1667
|
+
exports = module2.exports = new Command2();
|
|
1668
|
+
exports.program = exports;
|
|
1669
|
+
exports.Argument = Argument2;
|
|
1670
|
+
exports.Command = Command2;
|
|
1671
|
+
exports.CommanderError = CommanderError2;
|
|
1672
|
+
exports.Help = Help2;
|
|
1673
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
1674
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
1675
|
+
exports.Option = Option2;
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
// node_modules/commander/esm.mjs
|
|
1680
|
+
var import_index = __toESM(require_commander(), 1);
|
|
1681
|
+
var {
|
|
1682
|
+
program,
|
|
1683
|
+
createCommand,
|
|
1684
|
+
createArgument,
|
|
1685
|
+
createOption,
|
|
1686
|
+
CommanderError,
|
|
1687
|
+
InvalidArgumentError,
|
|
1688
|
+
Command,
|
|
1689
|
+
Argument,
|
|
1690
|
+
Option,
|
|
1691
|
+
Help
|
|
1692
|
+
} = import_index.default;
|
|
1693
|
+
|
|
1694
|
+
// src/cli.ts
|
|
1695
|
+
program.name("string-util").description("CLI to some JavaScript string utilities").version("0.8.0");
|
|
1696
|
+
program.parse();
|