aurochs 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +330 -1879
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -15088,1845 +15088,6 @@ $RC=function(a,b){if(b=document.getElementById(b))(a=document.getElementById(a))
|
|
|
15088
15088
|
})();
|
|
15089
15089
|
});
|
|
15090
15090
|
|
|
15091
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/error.js
|
|
15092
|
-
var require_error2 = __commonJS((exports) => {
|
|
15093
|
-
class CommanderError2 extends Error {
|
|
15094
|
-
constructor(exitCode, code, message) {
|
|
15095
|
-
super(message);
|
|
15096
|
-
Error.captureStackTrace(this, this.constructor);
|
|
15097
|
-
this.name = this.constructor.name;
|
|
15098
|
-
this.code = code;
|
|
15099
|
-
this.exitCode = exitCode;
|
|
15100
|
-
this.nestedError = undefined;
|
|
15101
|
-
}
|
|
15102
|
-
}
|
|
15103
|
-
|
|
15104
|
-
class InvalidArgumentError2 extends CommanderError2 {
|
|
15105
|
-
constructor(message) {
|
|
15106
|
-
super(1, "commander.invalidArgument", message);
|
|
15107
|
-
Error.captureStackTrace(this, this.constructor);
|
|
15108
|
-
this.name = this.constructor.name;
|
|
15109
|
-
}
|
|
15110
|
-
}
|
|
15111
|
-
exports.CommanderError = CommanderError2;
|
|
15112
|
-
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
15113
|
-
});
|
|
15114
|
-
|
|
15115
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/argument.js
|
|
15116
|
-
var require_argument2 = __commonJS((exports) => {
|
|
15117
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error2();
|
|
15118
|
-
|
|
15119
|
-
class Argument2 {
|
|
15120
|
-
constructor(name, description) {
|
|
15121
|
-
this.description = description || "";
|
|
15122
|
-
this.variadic = false;
|
|
15123
|
-
this.parseArg = undefined;
|
|
15124
|
-
this.defaultValue = undefined;
|
|
15125
|
-
this.defaultValueDescription = undefined;
|
|
15126
|
-
this.argChoices = undefined;
|
|
15127
|
-
switch (name[0]) {
|
|
15128
|
-
case "<":
|
|
15129
|
-
this.required = true;
|
|
15130
|
-
this._name = name.slice(1, -1);
|
|
15131
|
-
break;
|
|
15132
|
-
case "[":
|
|
15133
|
-
this.required = false;
|
|
15134
|
-
this._name = name.slice(1, -1);
|
|
15135
|
-
break;
|
|
15136
|
-
default:
|
|
15137
|
-
this.required = true;
|
|
15138
|
-
this._name = name;
|
|
15139
|
-
break;
|
|
15140
|
-
}
|
|
15141
|
-
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
15142
|
-
this.variadic = true;
|
|
15143
|
-
this._name = this._name.slice(0, -3);
|
|
15144
|
-
}
|
|
15145
|
-
}
|
|
15146
|
-
name() {
|
|
15147
|
-
return this._name;
|
|
15148
|
-
}
|
|
15149
|
-
_concatValue(value, previous) {
|
|
15150
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
15151
|
-
return [value];
|
|
15152
|
-
}
|
|
15153
|
-
return previous.concat(value);
|
|
15154
|
-
}
|
|
15155
|
-
default(value, description) {
|
|
15156
|
-
this.defaultValue = value;
|
|
15157
|
-
this.defaultValueDescription = description;
|
|
15158
|
-
return this;
|
|
15159
|
-
}
|
|
15160
|
-
argParser(fn) {
|
|
15161
|
-
this.parseArg = fn;
|
|
15162
|
-
return this;
|
|
15163
|
-
}
|
|
15164
|
-
choices(values) {
|
|
15165
|
-
this.argChoices = values.slice();
|
|
15166
|
-
this.parseArg = (arg, previous) => {
|
|
15167
|
-
if (!this.argChoices.includes(arg)) {
|
|
15168
|
-
throw new InvalidArgumentError2(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
15169
|
-
}
|
|
15170
|
-
if (this.variadic) {
|
|
15171
|
-
return this._concatValue(arg, previous);
|
|
15172
|
-
}
|
|
15173
|
-
return arg;
|
|
15174
|
-
};
|
|
15175
|
-
return this;
|
|
15176
|
-
}
|
|
15177
|
-
argRequired() {
|
|
15178
|
-
this.required = true;
|
|
15179
|
-
return this;
|
|
15180
|
-
}
|
|
15181
|
-
argOptional() {
|
|
15182
|
-
this.required = false;
|
|
15183
|
-
return this;
|
|
15184
|
-
}
|
|
15185
|
-
}
|
|
15186
|
-
function humanReadableArgName(arg) {
|
|
15187
|
-
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
15188
|
-
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
15189
|
-
}
|
|
15190
|
-
exports.Argument = Argument2;
|
|
15191
|
-
exports.humanReadableArgName = humanReadableArgName;
|
|
15192
|
-
});
|
|
15193
|
-
|
|
15194
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/help.js
|
|
15195
|
-
var require_help2 = __commonJS((exports) => {
|
|
15196
|
-
var { humanReadableArgName } = require_argument2();
|
|
15197
|
-
|
|
15198
|
-
class Help2 {
|
|
15199
|
-
constructor() {
|
|
15200
|
-
this.helpWidth = undefined;
|
|
15201
|
-
this.sortSubcommands = false;
|
|
15202
|
-
this.sortOptions = false;
|
|
15203
|
-
this.showGlobalOptions = false;
|
|
15204
|
-
}
|
|
15205
|
-
visibleCommands(cmd) {
|
|
15206
|
-
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
15207
|
-
const helpCommand = cmd._getHelpCommand();
|
|
15208
|
-
if (helpCommand && !helpCommand._hidden) {
|
|
15209
|
-
visibleCommands.push(helpCommand);
|
|
15210
|
-
}
|
|
15211
|
-
if (this.sortSubcommands) {
|
|
15212
|
-
visibleCommands.sort((a, b) => {
|
|
15213
|
-
return a.name().localeCompare(b.name());
|
|
15214
|
-
});
|
|
15215
|
-
}
|
|
15216
|
-
return visibleCommands;
|
|
15217
|
-
}
|
|
15218
|
-
compareOptions(a, b) {
|
|
15219
|
-
const getSortKey = (option) => {
|
|
15220
|
-
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
15221
|
-
};
|
|
15222
|
-
return getSortKey(a).localeCompare(getSortKey(b));
|
|
15223
|
-
}
|
|
15224
|
-
visibleOptions(cmd) {
|
|
15225
|
-
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
15226
|
-
const helpOption = cmd._getHelpOption();
|
|
15227
|
-
if (helpOption && !helpOption.hidden) {
|
|
15228
|
-
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
15229
|
-
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
15230
|
-
if (!removeShort && !removeLong) {
|
|
15231
|
-
visibleOptions.push(helpOption);
|
|
15232
|
-
} else if (helpOption.long && !removeLong) {
|
|
15233
|
-
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
15234
|
-
} else if (helpOption.short && !removeShort) {
|
|
15235
|
-
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
15236
|
-
}
|
|
15237
|
-
}
|
|
15238
|
-
if (this.sortOptions) {
|
|
15239
|
-
visibleOptions.sort(this.compareOptions);
|
|
15240
|
-
}
|
|
15241
|
-
return visibleOptions;
|
|
15242
|
-
}
|
|
15243
|
-
visibleGlobalOptions(cmd) {
|
|
15244
|
-
if (!this.showGlobalOptions)
|
|
15245
|
-
return [];
|
|
15246
|
-
const globalOptions = [];
|
|
15247
|
-
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
15248
|
-
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
15249
|
-
globalOptions.push(...visibleOptions);
|
|
15250
|
-
}
|
|
15251
|
-
if (this.sortOptions) {
|
|
15252
|
-
globalOptions.sort(this.compareOptions);
|
|
15253
|
-
}
|
|
15254
|
-
return globalOptions;
|
|
15255
|
-
}
|
|
15256
|
-
visibleArguments(cmd) {
|
|
15257
|
-
if (cmd._argsDescription) {
|
|
15258
|
-
cmd.registeredArguments.forEach((argument) => {
|
|
15259
|
-
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
15260
|
-
});
|
|
15261
|
-
}
|
|
15262
|
-
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
15263
|
-
return cmd.registeredArguments;
|
|
15264
|
-
}
|
|
15265
|
-
return [];
|
|
15266
|
-
}
|
|
15267
|
-
subcommandTerm(cmd) {
|
|
15268
|
-
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
15269
|
-
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
15270
|
-
}
|
|
15271
|
-
optionTerm(option) {
|
|
15272
|
-
return option.flags;
|
|
15273
|
-
}
|
|
15274
|
-
argumentTerm(argument) {
|
|
15275
|
-
return argument.name();
|
|
15276
|
-
}
|
|
15277
|
-
longestSubcommandTermLength(cmd, helper) {
|
|
15278
|
-
return helper.visibleCommands(cmd).reduce((max2, command) => {
|
|
15279
|
-
return Math.max(max2, helper.subcommandTerm(command).length);
|
|
15280
|
-
}, 0);
|
|
15281
|
-
}
|
|
15282
|
-
longestOptionTermLength(cmd, helper) {
|
|
15283
|
-
return helper.visibleOptions(cmd).reduce((max2, option) => {
|
|
15284
|
-
return Math.max(max2, helper.optionTerm(option).length);
|
|
15285
|
-
}, 0);
|
|
15286
|
-
}
|
|
15287
|
-
longestGlobalOptionTermLength(cmd, helper) {
|
|
15288
|
-
return helper.visibleGlobalOptions(cmd).reduce((max2, option) => {
|
|
15289
|
-
return Math.max(max2, helper.optionTerm(option).length);
|
|
15290
|
-
}, 0);
|
|
15291
|
-
}
|
|
15292
|
-
longestArgumentTermLength(cmd, helper) {
|
|
15293
|
-
return helper.visibleArguments(cmd).reduce((max2, argument) => {
|
|
15294
|
-
return Math.max(max2, helper.argumentTerm(argument).length);
|
|
15295
|
-
}, 0);
|
|
15296
|
-
}
|
|
15297
|
-
commandUsage(cmd) {
|
|
15298
|
-
let cmdName = cmd._name;
|
|
15299
|
-
if (cmd._aliases[0]) {
|
|
15300
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
15301
|
-
}
|
|
15302
|
-
let ancestorCmdNames = "";
|
|
15303
|
-
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
15304
|
-
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
15305
|
-
}
|
|
15306
|
-
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
15307
|
-
}
|
|
15308
|
-
commandDescription(cmd) {
|
|
15309
|
-
return cmd.description();
|
|
15310
|
-
}
|
|
15311
|
-
subcommandDescription(cmd) {
|
|
15312
|
-
return cmd.summary() || cmd.description();
|
|
15313
|
-
}
|
|
15314
|
-
optionDescription(option) {
|
|
15315
|
-
const extraInfo = [];
|
|
15316
|
-
if (option.argChoices) {
|
|
15317
|
-
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
15318
|
-
}
|
|
15319
|
-
if (option.defaultValue !== undefined) {
|
|
15320
|
-
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
15321
|
-
if (showDefault) {
|
|
15322
|
-
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
15323
|
-
}
|
|
15324
|
-
}
|
|
15325
|
-
if (option.presetArg !== undefined && option.optional) {
|
|
15326
|
-
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
15327
|
-
}
|
|
15328
|
-
if (option.envVar !== undefined) {
|
|
15329
|
-
extraInfo.push(`env: ${option.envVar}`);
|
|
15330
|
-
}
|
|
15331
|
-
if (extraInfo.length > 0) {
|
|
15332
|
-
return `${option.description} (${extraInfo.join(", ")})`;
|
|
15333
|
-
}
|
|
15334
|
-
return option.description;
|
|
15335
|
-
}
|
|
15336
|
-
argumentDescription(argument) {
|
|
15337
|
-
const extraInfo = [];
|
|
15338
|
-
if (argument.argChoices) {
|
|
15339
|
-
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
15340
|
-
}
|
|
15341
|
-
if (argument.defaultValue !== undefined) {
|
|
15342
|
-
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
15343
|
-
}
|
|
15344
|
-
if (extraInfo.length > 0) {
|
|
15345
|
-
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
15346
|
-
if (argument.description) {
|
|
15347
|
-
return `${argument.description} ${extraDescripton}`;
|
|
15348
|
-
}
|
|
15349
|
-
return extraDescripton;
|
|
15350
|
-
}
|
|
15351
|
-
return argument.description;
|
|
15352
|
-
}
|
|
15353
|
-
formatHelp(cmd, helper) {
|
|
15354
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
15355
|
-
const helpWidth = helper.helpWidth || 80;
|
|
15356
|
-
const itemIndentWidth = 2;
|
|
15357
|
-
const itemSeparatorWidth = 2;
|
|
15358
|
-
function formatItem(term, description) {
|
|
15359
|
-
if (description) {
|
|
15360
|
-
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
15361
|
-
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
15362
|
-
}
|
|
15363
|
-
return term;
|
|
15364
|
-
}
|
|
15365
|
-
function formatList(textArray) {
|
|
15366
|
-
return textArray.join(`
|
|
15367
|
-
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
15368
|
-
}
|
|
15369
|
-
let output2 = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
15370
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
15371
|
-
if (commandDescription.length > 0) {
|
|
15372
|
-
output2 = output2.concat([
|
|
15373
|
-
helper.wrap(commandDescription, helpWidth, 0),
|
|
15374
|
-
""
|
|
15375
|
-
]);
|
|
15376
|
-
}
|
|
15377
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
15378
|
-
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
15379
|
-
});
|
|
15380
|
-
if (argumentList.length > 0) {
|
|
15381
|
-
output2 = output2.concat(["Arguments:", formatList(argumentList), ""]);
|
|
15382
|
-
}
|
|
15383
|
-
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
15384
|
-
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
15385
|
-
});
|
|
15386
|
-
if (optionList.length > 0) {
|
|
15387
|
-
output2 = output2.concat(["Options:", formatList(optionList), ""]);
|
|
15388
|
-
}
|
|
15389
|
-
if (this.showGlobalOptions) {
|
|
15390
|
-
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
15391
|
-
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
15392
|
-
});
|
|
15393
|
-
if (globalOptionList.length > 0) {
|
|
15394
|
-
output2 = output2.concat([
|
|
15395
|
-
"Global Options:",
|
|
15396
|
-
formatList(globalOptionList),
|
|
15397
|
-
""
|
|
15398
|
-
]);
|
|
15399
|
-
}
|
|
15400
|
-
}
|
|
15401
|
-
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
15402
|
-
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
15403
|
-
});
|
|
15404
|
-
if (commandList.length > 0) {
|
|
15405
|
-
output2 = output2.concat(["Commands:", formatList(commandList), ""]);
|
|
15406
|
-
}
|
|
15407
|
-
return output2.join(`
|
|
15408
|
-
`);
|
|
15409
|
-
}
|
|
15410
|
-
padWidth(cmd, helper) {
|
|
15411
|
-
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
15412
|
-
}
|
|
15413
|
-
wrap(str, width, indent, minColumnWidth = 40) {
|
|
15414
|
-
const indents = " \\f\\t\\v - \uFEFF";
|
|
15415
|
-
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
15416
|
-
if (str.match(manualIndent))
|
|
15417
|
-
return str;
|
|
15418
|
-
const columnWidth = width - indent;
|
|
15419
|
-
if (columnWidth < minColumnWidth)
|
|
15420
|
-
return str;
|
|
15421
|
-
const leadingStr = str.slice(0, indent);
|
|
15422
|
-
const columnText = str.slice(indent).replace(`\r
|
|
15423
|
-
`, `
|
|
15424
|
-
`);
|
|
15425
|
-
const indentString = " ".repeat(indent);
|
|
15426
|
-
const zeroWidthSpace = "";
|
|
15427
|
-
const breaks = `\\s${zeroWidthSpace}`;
|
|
15428
|
-
const regex = new RegExp(`
|
|
15429
|
-
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
15430
|
-
const lines = columnText.match(regex) || [];
|
|
15431
|
-
return leadingStr + lines.map((line2, i2) => {
|
|
15432
|
-
if (line2 === `
|
|
15433
|
-
`)
|
|
15434
|
-
return "";
|
|
15435
|
-
return (i2 > 0 ? indentString : "") + line2.trimEnd();
|
|
15436
|
-
}).join(`
|
|
15437
|
-
`);
|
|
15438
|
-
}
|
|
15439
|
-
}
|
|
15440
|
-
exports.Help = Help2;
|
|
15441
|
-
});
|
|
15442
|
-
|
|
15443
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/option.js
|
|
15444
|
-
var require_option2 = __commonJS((exports) => {
|
|
15445
|
-
var { InvalidArgumentError: InvalidArgumentError2 } = require_error2();
|
|
15446
|
-
|
|
15447
|
-
class Option2 {
|
|
15448
|
-
constructor(flags, description) {
|
|
15449
|
-
this.flags = flags;
|
|
15450
|
-
this.description = description || "";
|
|
15451
|
-
this.required = flags.includes("<");
|
|
15452
|
-
this.optional = flags.includes("[");
|
|
15453
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
15454
|
-
this.mandatory = false;
|
|
15455
|
-
const optionFlags = splitOptionFlags(flags);
|
|
15456
|
-
this.short = optionFlags.shortFlag;
|
|
15457
|
-
this.long = optionFlags.longFlag;
|
|
15458
|
-
this.negate = false;
|
|
15459
|
-
if (this.long) {
|
|
15460
|
-
this.negate = this.long.startsWith("--no-");
|
|
15461
|
-
}
|
|
15462
|
-
this.defaultValue = undefined;
|
|
15463
|
-
this.defaultValueDescription = undefined;
|
|
15464
|
-
this.presetArg = undefined;
|
|
15465
|
-
this.envVar = undefined;
|
|
15466
|
-
this.parseArg = undefined;
|
|
15467
|
-
this.hidden = false;
|
|
15468
|
-
this.argChoices = undefined;
|
|
15469
|
-
this.conflictsWith = [];
|
|
15470
|
-
this.implied = undefined;
|
|
15471
|
-
}
|
|
15472
|
-
default(value, description) {
|
|
15473
|
-
this.defaultValue = value;
|
|
15474
|
-
this.defaultValueDescription = description;
|
|
15475
|
-
return this;
|
|
15476
|
-
}
|
|
15477
|
-
preset(arg) {
|
|
15478
|
-
this.presetArg = arg;
|
|
15479
|
-
return this;
|
|
15480
|
-
}
|
|
15481
|
-
conflicts(names) {
|
|
15482
|
-
this.conflictsWith = this.conflictsWith.concat(names);
|
|
15483
|
-
return this;
|
|
15484
|
-
}
|
|
15485
|
-
implies(impliedOptionValues) {
|
|
15486
|
-
let newImplied = impliedOptionValues;
|
|
15487
|
-
if (typeof impliedOptionValues === "string") {
|
|
15488
|
-
newImplied = { [impliedOptionValues]: true };
|
|
15489
|
-
}
|
|
15490
|
-
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
15491
|
-
return this;
|
|
15492
|
-
}
|
|
15493
|
-
env(name) {
|
|
15494
|
-
this.envVar = name;
|
|
15495
|
-
return this;
|
|
15496
|
-
}
|
|
15497
|
-
argParser(fn) {
|
|
15498
|
-
this.parseArg = fn;
|
|
15499
|
-
return this;
|
|
15500
|
-
}
|
|
15501
|
-
makeOptionMandatory(mandatory = true) {
|
|
15502
|
-
this.mandatory = !!mandatory;
|
|
15503
|
-
return this;
|
|
15504
|
-
}
|
|
15505
|
-
hideHelp(hide = true) {
|
|
15506
|
-
this.hidden = !!hide;
|
|
15507
|
-
return this;
|
|
15508
|
-
}
|
|
15509
|
-
_concatValue(value, previous) {
|
|
15510
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
15511
|
-
return [value];
|
|
15512
|
-
}
|
|
15513
|
-
return previous.concat(value);
|
|
15514
|
-
}
|
|
15515
|
-
choices(values) {
|
|
15516
|
-
this.argChoices = values.slice();
|
|
15517
|
-
this.parseArg = (arg, previous) => {
|
|
15518
|
-
if (!this.argChoices.includes(arg)) {
|
|
15519
|
-
throw new InvalidArgumentError2(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
15520
|
-
}
|
|
15521
|
-
if (this.variadic) {
|
|
15522
|
-
return this._concatValue(arg, previous);
|
|
15523
|
-
}
|
|
15524
|
-
return arg;
|
|
15525
|
-
};
|
|
15526
|
-
return this;
|
|
15527
|
-
}
|
|
15528
|
-
name() {
|
|
15529
|
-
if (this.long) {
|
|
15530
|
-
return this.long.replace(/^--/, "");
|
|
15531
|
-
}
|
|
15532
|
-
return this.short.replace(/^-/, "");
|
|
15533
|
-
}
|
|
15534
|
-
attributeName() {
|
|
15535
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
15536
|
-
}
|
|
15537
|
-
is(arg) {
|
|
15538
|
-
return this.short === arg || this.long === arg;
|
|
15539
|
-
}
|
|
15540
|
-
isBoolean() {
|
|
15541
|
-
return !this.required && !this.optional && !this.negate;
|
|
15542
|
-
}
|
|
15543
|
-
}
|
|
15544
|
-
|
|
15545
|
-
class DualOptions {
|
|
15546
|
-
constructor(options) {
|
|
15547
|
-
this.positiveOptions = new Map;
|
|
15548
|
-
this.negativeOptions = new Map;
|
|
15549
|
-
this.dualOptions = new Set;
|
|
15550
|
-
options.forEach((option) => {
|
|
15551
|
-
if (option.negate) {
|
|
15552
|
-
this.negativeOptions.set(option.attributeName(), option);
|
|
15553
|
-
} else {
|
|
15554
|
-
this.positiveOptions.set(option.attributeName(), option);
|
|
15555
|
-
}
|
|
15556
|
-
});
|
|
15557
|
-
this.negativeOptions.forEach((value, key) => {
|
|
15558
|
-
if (this.positiveOptions.has(key)) {
|
|
15559
|
-
this.dualOptions.add(key);
|
|
15560
|
-
}
|
|
15561
|
-
});
|
|
15562
|
-
}
|
|
15563
|
-
valueFromOption(value, option) {
|
|
15564
|
-
const optionKey = option.attributeName();
|
|
15565
|
-
if (!this.dualOptions.has(optionKey))
|
|
15566
|
-
return true;
|
|
15567
|
-
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
15568
|
-
const negativeValue = preset !== undefined ? preset : false;
|
|
15569
|
-
return option.negate === (negativeValue === value);
|
|
15570
|
-
}
|
|
15571
|
-
}
|
|
15572
|
-
function camelcase(str) {
|
|
15573
|
-
return str.split("-").reduce((str2, word) => {
|
|
15574
|
-
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
15575
|
-
});
|
|
15576
|
-
}
|
|
15577
|
-
function splitOptionFlags(flags) {
|
|
15578
|
-
let shortFlag;
|
|
15579
|
-
let longFlag;
|
|
15580
|
-
const flagParts = flags.split(/[ |,]+/);
|
|
15581
|
-
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
15582
|
-
shortFlag = flagParts.shift();
|
|
15583
|
-
longFlag = flagParts.shift();
|
|
15584
|
-
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
15585
|
-
shortFlag = longFlag;
|
|
15586
|
-
longFlag = undefined;
|
|
15587
|
-
}
|
|
15588
|
-
return { shortFlag, longFlag };
|
|
15589
|
-
}
|
|
15590
|
-
exports.Option = Option2;
|
|
15591
|
-
exports.DualOptions = DualOptions;
|
|
15592
|
-
});
|
|
15593
|
-
|
|
15594
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/suggestSimilar.js
|
|
15595
|
-
var require_suggestSimilar2 = __commonJS((exports) => {
|
|
15596
|
-
var maxDistance = 3;
|
|
15597
|
-
function editDistance(a, b) {
|
|
15598
|
-
if (Math.abs(a.length - b.length) > maxDistance)
|
|
15599
|
-
return Math.max(a.length, b.length);
|
|
15600
|
-
const d = [];
|
|
15601
|
-
for (let i2 = 0;i2 <= a.length; i2++) {
|
|
15602
|
-
d[i2] = [i2];
|
|
15603
|
-
}
|
|
15604
|
-
for (let j = 0;j <= b.length; j++) {
|
|
15605
|
-
d[0][j] = j;
|
|
15606
|
-
}
|
|
15607
|
-
for (let j = 1;j <= b.length; j++) {
|
|
15608
|
-
for (let i2 = 1;i2 <= a.length; i2++) {
|
|
15609
|
-
let cost = 1;
|
|
15610
|
-
if (a[i2 - 1] === b[j - 1]) {
|
|
15611
|
-
cost = 0;
|
|
15612
|
-
} else {
|
|
15613
|
-
cost = 1;
|
|
15614
|
-
}
|
|
15615
|
-
d[i2][j] = Math.min(d[i2 - 1][j] + 1, d[i2][j - 1] + 1, d[i2 - 1][j - 1] + cost);
|
|
15616
|
-
if (i2 > 1 && j > 1 && a[i2 - 1] === b[j - 2] && a[i2 - 2] === b[j - 1]) {
|
|
15617
|
-
d[i2][j] = Math.min(d[i2][j], d[i2 - 2][j - 2] + 1);
|
|
15618
|
-
}
|
|
15619
|
-
}
|
|
15620
|
-
}
|
|
15621
|
-
return d[a.length][b.length];
|
|
15622
|
-
}
|
|
15623
|
-
function suggestSimilar(word, candidates) {
|
|
15624
|
-
if (!candidates || candidates.length === 0)
|
|
15625
|
-
return "";
|
|
15626
|
-
candidates = Array.from(new Set(candidates));
|
|
15627
|
-
const searchingOptions = word.startsWith("--");
|
|
15628
|
-
if (searchingOptions) {
|
|
15629
|
-
word = word.slice(2);
|
|
15630
|
-
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
15631
|
-
}
|
|
15632
|
-
let similar = [];
|
|
15633
|
-
let bestDistance = maxDistance;
|
|
15634
|
-
const minSimilarity = 0.4;
|
|
15635
|
-
candidates.forEach((candidate) => {
|
|
15636
|
-
if (candidate.length <= 1)
|
|
15637
|
-
return;
|
|
15638
|
-
const distance = editDistance(word, candidate);
|
|
15639
|
-
const length = Math.max(word.length, candidate.length);
|
|
15640
|
-
const similarity = (length - distance) / length;
|
|
15641
|
-
if (similarity > minSimilarity) {
|
|
15642
|
-
if (distance < bestDistance) {
|
|
15643
|
-
bestDistance = distance;
|
|
15644
|
-
similar = [candidate];
|
|
15645
|
-
} else if (distance === bestDistance) {
|
|
15646
|
-
similar.push(candidate);
|
|
15647
|
-
}
|
|
15648
|
-
}
|
|
15649
|
-
});
|
|
15650
|
-
similar.sort((a, b) => a.localeCompare(b));
|
|
15651
|
-
if (searchingOptions) {
|
|
15652
|
-
similar = similar.map((candidate) => `--${candidate}`);
|
|
15653
|
-
}
|
|
15654
|
-
if (similar.length > 1) {
|
|
15655
|
-
return `
|
|
15656
|
-
(Did you mean one of ${similar.join(", ")}?)`;
|
|
15657
|
-
}
|
|
15658
|
-
if (similar.length === 1) {
|
|
15659
|
-
return `
|
|
15660
|
-
(Did you mean ${similar[0]}?)`;
|
|
15661
|
-
}
|
|
15662
|
-
return "";
|
|
15663
|
-
}
|
|
15664
|
-
exports.suggestSimilar = suggestSimilar;
|
|
15665
|
-
});
|
|
15666
|
-
|
|
15667
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/lib/command.js
|
|
15668
|
-
var require_command2 = __commonJS((exports) => {
|
|
15669
|
-
var EventEmitter = __require("node:events").EventEmitter;
|
|
15670
|
-
var childProcess = __require("node:child_process");
|
|
15671
|
-
var path11 = __require("node:path");
|
|
15672
|
-
var fs12 = __require("node:fs");
|
|
15673
|
-
var process2 = __require("node:process");
|
|
15674
|
-
var { Argument: Argument2, humanReadableArgName } = require_argument2();
|
|
15675
|
-
var { CommanderError: CommanderError2 } = require_error2();
|
|
15676
|
-
var { Help: Help2 } = require_help2();
|
|
15677
|
-
var { Option: Option2, DualOptions } = require_option2();
|
|
15678
|
-
var { suggestSimilar } = require_suggestSimilar2();
|
|
15679
|
-
|
|
15680
|
-
class Command2 extends EventEmitter {
|
|
15681
|
-
constructor(name) {
|
|
15682
|
-
super();
|
|
15683
|
-
this.commands = [];
|
|
15684
|
-
this.options = [];
|
|
15685
|
-
this.parent = null;
|
|
15686
|
-
this._allowUnknownOption = false;
|
|
15687
|
-
this._allowExcessArguments = true;
|
|
15688
|
-
this.registeredArguments = [];
|
|
15689
|
-
this._args = this.registeredArguments;
|
|
15690
|
-
this.args = [];
|
|
15691
|
-
this.rawArgs = [];
|
|
15692
|
-
this.processedArgs = [];
|
|
15693
|
-
this._scriptPath = null;
|
|
15694
|
-
this._name = name || "";
|
|
15695
|
-
this._optionValues = {};
|
|
15696
|
-
this._optionValueSources = {};
|
|
15697
|
-
this._storeOptionsAsProperties = false;
|
|
15698
|
-
this._actionHandler = null;
|
|
15699
|
-
this._executableHandler = false;
|
|
15700
|
-
this._executableFile = null;
|
|
15701
|
-
this._executableDir = null;
|
|
15702
|
-
this._defaultCommandName = null;
|
|
15703
|
-
this._exitCallback = null;
|
|
15704
|
-
this._aliases = [];
|
|
15705
|
-
this._combineFlagAndOptionalValue = true;
|
|
15706
|
-
this._description = "";
|
|
15707
|
-
this._summary = "";
|
|
15708
|
-
this._argsDescription = undefined;
|
|
15709
|
-
this._enablePositionalOptions = false;
|
|
15710
|
-
this._passThroughOptions = false;
|
|
15711
|
-
this._lifeCycleHooks = {};
|
|
15712
|
-
this._showHelpAfterError = false;
|
|
15713
|
-
this._showSuggestionAfterError = true;
|
|
15714
|
-
this._outputConfiguration = {
|
|
15715
|
-
writeOut: (str) => process2.stdout.write(str),
|
|
15716
|
-
writeErr: (str) => process2.stderr.write(str),
|
|
15717
|
-
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
15718
|
-
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
15719
|
-
outputError: (str, write) => write(str)
|
|
15720
|
-
};
|
|
15721
|
-
this._hidden = false;
|
|
15722
|
-
this._helpOption = undefined;
|
|
15723
|
-
this._addImplicitHelpCommand = undefined;
|
|
15724
|
-
this._helpCommand = undefined;
|
|
15725
|
-
this._helpConfiguration = {};
|
|
15726
|
-
}
|
|
15727
|
-
copyInheritedSettings(sourceCommand) {
|
|
15728
|
-
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
15729
|
-
this._helpOption = sourceCommand._helpOption;
|
|
15730
|
-
this._helpCommand = sourceCommand._helpCommand;
|
|
15731
|
-
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
15732
|
-
this._exitCallback = sourceCommand._exitCallback;
|
|
15733
|
-
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
15734
|
-
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
15735
|
-
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
15736
|
-
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
15737
|
-
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
15738
|
-
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
15739
|
-
return this;
|
|
15740
|
-
}
|
|
15741
|
-
_getCommandAndAncestors() {
|
|
15742
|
-
const result = [];
|
|
15743
|
-
for (let command = this;command; command = command.parent) {
|
|
15744
|
-
result.push(command);
|
|
15745
|
-
}
|
|
15746
|
-
return result;
|
|
15747
|
-
}
|
|
15748
|
-
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
15749
|
-
let desc = actionOptsOrExecDesc;
|
|
15750
|
-
let opts = execOpts;
|
|
15751
|
-
if (typeof desc === "object" && desc !== null) {
|
|
15752
|
-
opts = desc;
|
|
15753
|
-
desc = null;
|
|
15754
|
-
}
|
|
15755
|
-
opts = opts || {};
|
|
15756
|
-
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
15757
|
-
const cmd = this.createCommand(name);
|
|
15758
|
-
if (desc) {
|
|
15759
|
-
cmd.description(desc);
|
|
15760
|
-
cmd._executableHandler = true;
|
|
15761
|
-
}
|
|
15762
|
-
if (opts.isDefault)
|
|
15763
|
-
this._defaultCommandName = cmd._name;
|
|
15764
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
15765
|
-
cmd._executableFile = opts.executableFile || null;
|
|
15766
|
-
if (args)
|
|
15767
|
-
cmd.arguments(args);
|
|
15768
|
-
this._registerCommand(cmd);
|
|
15769
|
-
cmd.parent = this;
|
|
15770
|
-
cmd.copyInheritedSettings(this);
|
|
15771
|
-
if (desc)
|
|
15772
|
-
return this;
|
|
15773
|
-
return cmd;
|
|
15774
|
-
}
|
|
15775
|
-
createCommand(name) {
|
|
15776
|
-
return new Command2(name);
|
|
15777
|
-
}
|
|
15778
|
-
createHelp() {
|
|
15779
|
-
return Object.assign(new Help2, this.configureHelp());
|
|
15780
|
-
}
|
|
15781
|
-
configureHelp(configuration) {
|
|
15782
|
-
if (configuration === undefined)
|
|
15783
|
-
return this._helpConfiguration;
|
|
15784
|
-
this._helpConfiguration = configuration;
|
|
15785
|
-
return this;
|
|
15786
|
-
}
|
|
15787
|
-
configureOutput(configuration) {
|
|
15788
|
-
if (configuration === undefined)
|
|
15789
|
-
return this._outputConfiguration;
|
|
15790
|
-
Object.assign(this._outputConfiguration, configuration);
|
|
15791
|
-
return this;
|
|
15792
|
-
}
|
|
15793
|
-
showHelpAfterError(displayHelp = true) {
|
|
15794
|
-
if (typeof displayHelp !== "string")
|
|
15795
|
-
displayHelp = !!displayHelp;
|
|
15796
|
-
this._showHelpAfterError = displayHelp;
|
|
15797
|
-
return this;
|
|
15798
|
-
}
|
|
15799
|
-
showSuggestionAfterError(displaySuggestion = true) {
|
|
15800
|
-
this._showSuggestionAfterError = !!displaySuggestion;
|
|
15801
|
-
return this;
|
|
15802
|
-
}
|
|
15803
|
-
addCommand(cmd, opts) {
|
|
15804
|
-
if (!cmd._name) {
|
|
15805
|
-
throw new Error(`Command passed to .addCommand() must have a name
|
|
15806
|
-
- specify the name in Command constructor or using .name()`);
|
|
15807
|
-
}
|
|
15808
|
-
opts = opts || {};
|
|
15809
|
-
if (opts.isDefault)
|
|
15810
|
-
this._defaultCommandName = cmd._name;
|
|
15811
|
-
if (opts.noHelp || opts.hidden)
|
|
15812
|
-
cmd._hidden = true;
|
|
15813
|
-
this._registerCommand(cmd);
|
|
15814
|
-
cmd.parent = this;
|
|
15815
|
-
cmd._checkForBrokenPassThrough();
|
|
15816
|
-
return this;
|
|
15817
|
-
}
|
|
15818
|
-
createArgument(name, description) {
|
|
15819
|
-
return new Argument2(name, description);
|
|
15820
|
-
}
|
|
15821
|
-
argument(name, description, fn, defaultValue) {
|
|
15822
|
-
const argument = this.createArgument(name, description);
|
|
15823
|
-
if (typeof fn === "function") {
|
|
15824
|
-
argument.default(defaultValue).argParser(fn);
|
|
15825
|
-
} else {
|
|
15826
|
-
argument.default(fn);
|
|
15827
|
-
}
|
|
15828
|
-
this.addArgument(argument);
|
|
15829
|
-
return this;
|
|
15830
|
-
}
|
|
15831
|
-
arguments(names) {
|
|
15832
|
-
names.trim().split(/ +/).forEach((detail) => {
|
|
15833
|
-
this.argument(detail);
|
|
15834
|
-
});
|
|
15835
|
-
return this;
|
|
15836
|
-
}
|
|
15837
|
-
addArgument(argument) {
|
|
15838
|
-
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
15839
|
-
if (previousArgument && previousArgument.variadic) {
|
|
15840
|
-
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
15841
|
-
}
|
|
15842
|
-
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
15843
|
-
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
15844
|
-
}
|
|
15845
|
-
this.registeredArguments.push(argument);
|
|
15846
|
-
return this;
|
|
15847
|
-
}
|
|
15848
|
-
helpCommand(enableOrNameAndArgs, description) {
|
|
15849
|
-
if (typeof enableOrNameAndArgs === "boolean") {
|
|
15850
|
-
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
15851
|
-
return this;
|
|
15852
|
-
}
|
|
15853
|
-
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
15854
|
-
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
15855
|
-
const helpDescription = description ?? "display help for command";
|
|
15856
|
-
const helpCommand = this.createCommand(helpName);
|
|
15857
|
-
helpCommand.helpOption(false);
|
|
15858
|
-
if (helpArgs)
|
|
15859
|
-
helpCommand.arguments(helpArgs);
|
|
15860
|
-
if (helpDescription)
|
|
15861
|
-
helpCommand.description(helpDescription);
|
|
15862
|
-
this._addImplicitHelpCommand = true;
|
|
15863
|
-
this._helpCommand = helpCommand;
|
|
15864
|
-
return this;
|
|
15865
|
-
}
|
|
15866
|
-
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
15867
|
-
if (typeof helpCommand !== "object") {
|
|
15868
|
-
this.helpCommand(helpCommand, deprecatedDescription);
|
|
15869
|
-
return this;
|
|
15870
|
-
}
|
|
15871
|
-
this._addImplicitHelpCommand = true;
|
|
15872
|
-
this._helpCommand = helpCommand;
|
|
15873
|
-
return this;
|
|
15874
|
-
}
|
|
15875
|
-
_getHelpCommand() {
|
|
15876
|
-
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
15877
|
-
if (hasImplicitHelpCommand) {
|
|
15878
|
-
if (this._helpCommand === undefined) {
|
|
15879
|
-
this.helpCommand(undefined, undefined);
|
|
15880
|
-
}
|
|
15881
|
-
return this._helpCommand;
|
|
15882
|
-
}
|
|
15883
|
-
return null;
|
|
15884
|
-
}
|
|
15885
|
-
hook(event, listener) {
|
|
15886
|
-
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
15887
|
-
if (!allowedValues.includes(event)) {
|
|
15888
|
-
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
15889
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
15890
|
-
}
|
|
15891
|
-
if (this._lifeCycleHooks[event]) {
|
|
15892
|
-
this._lifeCycleHooks[event].push(listener);
|
|
15893
|
-
} else {
|
|
15894
|
-
this._lifeCycleHooks[event] = [listener];
|
|
15895
|
-
}
|
|
15896
|
-
return this;
|
|
15897
|
-
}
|
|
15898
|
-
exitOverride(fn) {
|
|
15899
|
-
if (fn) {
|
|
15900
|
-
this._exitCallback = fn;
|
|
15901
|
-
} else {
|
|
15902
|
-
this._exitCallback = (err2) => {
|
|
15903
|
-
if (err2.code !== "commander.executeSubCommandAsync") {
|
|
15904
|
-
throw err2;
|
|
15905
|
-
} else {}
|
|
15906
|
-
};
|
|
15907
|
-
}
|
|
15908
|
-
return this;
|
|
15909
|
-
}
|
|
15910
|
-
_exit(exitCode, code, message) {
|
|
15911
|
-
if (this._exitCallback) {
|
|
15912
|
-
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
15913
|
-
}
|
|
15914
|
-
process2.exit(exitCode);
|
|
15915
|
-
}
|
|
15916
|
-
action(fn) {
|
|
15917
|
-
const listener = (args) => {
|
|
15918
|
-
const expectedArgsCount = this.registeredArguments.length;
|
|
15919
|
-
const actionArgs = args.slice(0, expectedArgsCount);
|
|
15920
|
-
if (this._storeOptionsAsProperties) {
|
|
15921
|
-
actionArgs[expectedArgsCount] = this;
|
|
15922
|
-
} else {
|
|
15923
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
15924
|
-
}
|
|
15925
|
-
actionArgs.push(this);
|
|
15926
|
-
return fn.apply(this, actionArgs);
|
|
15927
|
-
};
|
|
15928
|
-
this._actionHandler = listener;
|
|
15929
|
-
return this;
|
|
15930
|
-
}
|
|
15931
|
-
createOption(flags, description) {
|
|
15932
|
-
return new Option2(flags, description);
|
|
15933
|
-
}
|
|
15934
|
-
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
15935
|
-
try {
|
|
15936
|
-
return target.parseArg(value, previous);
|
|
15937
|
-
} catch (err2) {
|
|
15938
|
-
if (err2.code === "commander.invalidArgument") {
|
|
15939
|
-
const message = `${invalidArgumentMessage} ${err2.message}`;
|
|
15940
|
-
this.error(message, { exitCode: err2.exitCode, code: err2.code });
|
|
15941
|
-
}
|
|
15942
|
-
throw err2;
|
|
15943
|
-
}
|
|
15944
|
-
}
|
|
15945
|
-
_registerOption(option) {
|
|
15946
|
-
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
15947
|
-
if (matchingOption) {
|
|
15948
|
-
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
15949
|
-
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
15950
|
-
- already used by option '${matchingOption.flags}'`);
|
|
15951
|
-
}
|
|
15952
|
-
this.options.push(option);
|
|
15953
|
-
}
|
|
15954
|
-
_registerCommand(command) {
|
|
15955
|
-
const knownBy = (cmd) => {
|
|
15956
|
-
return [cmd.name()].concat(cmd.aliases());
|
|
15957
|
-
};
|
|
15958
|
-
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
15959
|
-
if (alreadyUsed) {
|
|
15960
|
-
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
15961
|
-
const newCmd = knownBy(command).join("|");
|
|
15962
|
-
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
15963
|
-
}
|
|
15964
|
-
this.commands.push(command);
|
|
15965
|
-
}
|
|
15966
|
-
addOption(option) {
|
|
15967
|
-
this._registerOption(option);
|
|
15968
|
-
const oname = option.name();
|
|
15969
|
-
const name = option.attributeName();
|
|
15970
|
-
if (option.negate) {
|
|
15971
|
-
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
15972
|
-
if (!this._findOption(positiveLongFlag)) {
|
|
15973
|
-
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
15974
|
-
}
|
|
15975
|
-
} else if (option.defaultValue !== undefined) {
|
|
15976
|
-
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
15977
|
-
}
|
|
15978
|
-
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
15979
|
-
if (val == null && option.presetArg !== undefined) {
|
|
15980
|
-
val = option.presetArg;
|
|
15981
|
-
}
|
|
15982
|
-
const oldValue = this.getOptionValue(name);
|
|
15983
|
-
if (val !== null && option.parseArg) {
|
|
15984
|
-
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
15985
|
-
} else if (val !== null && option.variadic) {
|
|
15986
|
-
val = option._concatValue(val, oldValue);
|
|
15987
|
-
}
|
|
15988
|
-
if (val == null) {
|
|
15989
|
-
if (option.negate) {
|
|
15990
|
-
val = false;
|
|
15991
|
-
} else if (option.isBoolean() || option.optional) {
|
|
15992
|
-
val = true;
|
|
15993
|
-
} else {
|
|
15994
|
-
val = "";
|
|
15995
|
-
}
|
|
15996
|
-
}
|
|
15997
|
-
this.setOptionValueWithSource(name, val, valueSource);
|
|
15998
|
-
};
|
|
15999
|
-
this.on("option:" + oname, (val) => {
|
|
16000
|
-
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
16001
|
-
handleOptionValue(val, invalidValueMessage, "cli");
|
|
16002
|
-
});
|
|
16003
|
-
if (option.envVar) {
|
|
16004
|
-
this.on("optionEnv:" + oname, (val) => {
|
|
16005
|
-
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
16006
|
-
handleOptionValue(val, invalidValueMessage, "env");
|
|
16007
|
-
});
|
|
16008
|
-
}
|
|
16009
|
-
return this;
|
|
16010
|
-
}
|
|
16011
|
-
_optionEx(config, flags, description, fn, defaultValue) {
|
|
16012
|
-
if (typeof flags === "object" && flags instanceof Option2) {
|
|
16013
|
-
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
16014
|
-
}
|
|
16015
|
-
const option = this.createOption(flags, description);
|
|
16016
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
16017
|
-
if (typeof fn === "function") {
|
|
16018
|
-
option.default(defaultValue).argParser(fn);
|
|
16019
|
-
} else if (fn instanceof RegExp) {
|
|
16020
|
-
const regex = fn;
|
|
16021
|
-
fn = (val, def) => {
|
|
16022
|
-
const m = regex.exec(val);
|
|
16023
|
-
return m ? m[0] : def;
|
|
16024
|
-
};
|
|
16025
|
-
option.default(defaultValue).argParser(fn);
|
|
16026
|
-
} else {
|
|
16027
|
-
option.default(fn);
|
|
16028
|
-
}
|
|
16029
|
-
return this.addOption(option);
|
|
16030
|
-
}
|
|
16031
|
-
option(flags, description, parseArg, defaultValue) {
|
|
16032
|
-
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
16033
|
-
}
|
|
16034
|
-
requiredOption(flags, description, parseArg, defaultValue) {
|
|
16035
|
-
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
16036
|
-
}
|
|
16037
|
-
combineFlagAndOptionalValue(combine = true) {
|
|
16038
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
16039
|
-
return this;
|
|
16040
|
-
}
|
|
16041
|
-
allowUnknownOption(allowUnknown = true) {
|
|
16042
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
16043
|
-
return this;
|
|
16044
|
-
}
|
|
16045
|
-
allowExcessArguments(allowExcess = true) {
|
|
16046
|
-
this._allowExcessArguments = !!allowExcess;
|
|
16047
|
-
return this;
|
|
16048
|
-
}
|
|
16049
|
-
enablePositionalOptions(positional = true) {
|
|
16050
|
-
this._enablePositionalOptions = !!positional;
|
|
16051
|
-
return this;
|
|
16052
|
-
}
|
|
16053
|
-
passThroughOptions(passThrough = true) {
|
|
16054
|
-
this._passThroughOptions = !!passThrough;
|
|
16055
|
-
this._checkForBrokenPassThrough();
|
|
16056
|
-
return this;
|
|
16057
|
-
}
|
|
16058
|
-
_checkForBrokenPassThrough() {
|
|
16059
|
-
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
16060
|
-
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
16061
|
-
}
|
|
16062
|
-
}
|
|
16063
|
-
storeOptionsAsProperties(storeAsProperties = true) {
|
|
16064
|
-
if (this.options.length) {
|
|
16065
|
-
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
16066
|
-
}
|
|
16067
|
-
if (Object.keys(this._optionValues).length) {
|
|
16068
|
-
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
16069
|
-
}
|
|
16070
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
16071
|
-
return this;
|
|
16072
|
-
}
|
|
16073
|
-
getOptionValue(key) {
|
|
16074
|
-
if (this._storeOptionsAsProperties) {
|
|
16075
|
-
return this[key];
|
|
16076
|
-
}
|
|
16077
|
-
return this._optionValues[key];
|
|
16078
|
-
}
|
|
16079
|
-
setOptionValue(key, value) {
|
|
16080
|
-
return this.setOptionValueWithSource(key, value, undefined);
|
|
16081
|
-
}
|
|
16082
|
-
setOptionValueWithSource(key, value, source) {
|
|
16083
|
-
if (this._storeOptionsAsProperties) {
|
|
16084
|
-
this[key] = value;
|
|
16085
|
-
} else {
|
|
16086
|
-
this._optionValues[key] = value;
|
|
16087
|
-
}
|
|
16088
|
-
this._optionValueSources[key] = source;
|
|
16089
|
-
return this;
|
|
16090
|
-
}
|
|
16091
|
-
getOptionValueSource(key) {
|
|
16092
|
-
return this._optionValueSources[key];
|
|
16093
|
-
}
|
|
16094
|
-
getOptionValueSourceWithGlobals(key) {
|
|
16095
|
-
let source;
|
|
16096
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
16097
|
-
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
16098
|
-
source = cmd.getOptionValueSource(key);
|
|
16099
|
-
}
|
|
16100
|
-
});
|
|
16101
|
-
return source;
|
|
16102
|
-
}
|
|
16103
|
-
_prepareUserArgs(argv, parseOptions) {
|
|
16104
|
-
if (argv !== undefined && !Array.isArray(argv)) {
|
|
16105
|
-
throw new Error("first parameter to parse must be array or undefined");
|
|
16106
|
-
}
|
|
16107
|
-
parseOptions = parseOptions || {};
|
|
16108
|
-
if (argv === undefined && parseOptions.from === undefined) {
|
|
16109
|
-
if (process2.versions?.electron) {
|
|
16110
|
-
parseOptions.from = "electron";
|
|
16111
|
-
}
|
|
16112
|
-
const execArgv = process2.execArgv ?? [];
|
|
16113
|
-
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
16114
|
-
parseOptions.from = "eval";
|
|
16115
|
-
}
|
|
16116
|
-
}
|
|
16117
|
-
if (argv === undefined) {
|
|
16118
|
-
argv = process2.argv;
|
|
16119
|
-
}
|
|
16120
|
-
this.rawArgs = argv.slice();
|
|
16121
|
-
let userArgs;
|
|
16122
|
-
switch (parseOptions.from) {
|
|
16123
|
-
case undefined:
|
|
16124
|
-
case "node":
|
|
16125
|
-
this._scriptPath = argv[1];
|
|
16126
|
-
userArgs = argv.slice(2);
|
|
16127
|
-
break;
|
|
16128
|
-
case "electron":
|
|
16129
|
-
if (process2.defaultApp) {
|
|
16130
|
-
this._scriptPath = argv[1];
|
|
16131
|
-
userArgs = argv.slice(2);
|
|
16132
|
-
} else {
|
|
16133
|
-
userArgs = argv.slice(1);
|
|
16134
|
-
}
|
|
16135
|
-
break;
|
|
16136
|
-
case "user":
|
|
16137
|
-
userArgs = argv.slice(0);
|
|
16138
|
-
break;
|
|
16139
|
-
case "eval":
|
|
16140
|
-
userArgs = argv.slice(1);
|
|
16141
|
-
break;
|
|
16142
|
-
default:
|
|
16143
|
-
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
16144
|
-
}
|
|
16145
|
-
if (!this._name && this._scriptPath)
|
|
16146
|
-
this.nameFromFilename(this._scriptPath);
|
|
16147
|
-
this._name = this._name || "program";
|
|
16148
|
-
return userArgs;
|
|
16149
|
-
}
|
|
16150
|
-
parse(argv, parseOptions) {
|
|
16151
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
16152
|
-
this._parseCommand([], userArgs);
|
|
16153
|
-
return this;
|
|
16154
|
-
}
|
|
16155
|
-
async parseAsync(argv, parseOptions) {
|
|
16156
|
-
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
16157
|
-
await this._parseCommand([], userArgs);
|
|
16158
|
-
return this;
|
|
16159
|
-
}
|
|
16160
|
-
_executeSubCommand(subcommand, args) {
|
|
16161
|
-
args = args.slice();
|
|
16162
|
-
let launchWithNode = false;
|
|
16163
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
16164
|
-
function findFile(baseDir, baseName) {
|
|
16165
|
-
const localBin = path11.resolve(baseDir, baseName);
|
|
16166
|
-
if (fs12.existsSync(localBin))
|
|
16167
|
-
return localBin;
|
|
16168
|
-
if (sourceExt.includes(path11.extname(baseName)))
|
|
16169
|
-
return;
|
|
16170
|
-
const foundExt = sourceExt.find((ext) => fs12.existsSync(`${localBin}${ext}`));
|
|
16171
|
-
if (foundExt)
|
|
16172
|
-
return `${localBin}${foundExt}`;
|
|
16173
|
-
return;
|
|
16174
|
-
}
|
|
16175
|
-
this._checkForMissingMandatoryOptions();
|
|
16176
|
-
this._checkForConflictingOptions();
|
|
16177
|
-
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
16178
|
-
let executableDir = this._executableDir || "";
|
|
16179
|
-
if (this._scriptPath) {
|
|
16180
|
-
let resolvedScriptPath;
|
|
16181
|
-
try {
|
|
16182
|
-
resolvedScriptPath = fs12.realpathSync(this._scriptPath);
|
|
16183
|
-
} catch (err2) {
|
|
16184
|
-
resolvedScriptPath = this._scriptPath;
|
|
16185
|
-
}
|
|
16186
|
-
executableDir = path11.resolve(path11.dirname(resolvedScriptPath), executableDir);
|
|
16187
|
-
}
|
|
16188
|
-
if (executableDir) {
|
|
16189
|
-
let localFile = findFile(executableDir, executableFile);
|
|
16190
|
-
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
16191
|
-
const legacyName = path11.basename(this._scriptPath, path11.extname(this._scriptPath));
|
|
16192
|
-
if (legacyName !== this._name) {
|
|
16193
|
-
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
16194
|
-
}
|
|
16195
|
-
}
|
|
16196
|
-
executableFile = localFile || executableFile;
|
|
16197
|
-
}
|
|
16198
|
-
launchWithNode = sourceExt.includes(path11.extname(executableFile));
|
|
16199
|
-
let proc;
|
|
16200
|
-
if (process2.platform !== "win32") {
|
|
16201
|
-
if (launchWithNode) {
|
|
16202
|
-
args.unshift(executableFile);
|
|
16203
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
16204
|
-
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
16205
|
-
} else {
|
|
16206
|
-
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
16207
|
-
}
|
|
16208
|
-
} else {
|
|
16209
|
-
args.unshift(executableFile);
|
|
16210
|
-
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
16211
|
-
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
16212
|
-
}
|
|
16213
|
-
if (!proc.killed) {
|
|
16214
|
-
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
16215
|
-
signals.forEach((signal) => {
|
|
16216
|
-
process2.on(signal, () => {
|
|
16217
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
16218
|
-
proc.kill(signal);
|
|
16219
|
-
}
|
|
16220
|
-
});
|
|
16221
|
-
});
|
|
16222
|
-
}
|
|
16223
|
-
const exitCallback = this._exitCallback;
|
|
16224
|
-
proc.on("close", (code) => {
|
|
16225
|
-
code = code ?? 1;
|
|
16226
|
-
if (!exitCallback) {
|
|
16227
|
-
process2.exit(code);
|
|
16228
|
-
} else {
|
|
16229
|
-
exitCallback(new CommanderError2(code, "commander.executeSubCommandAsync", "(close)"));
|
|
16230
|
-
}
|
|
16231
|
-
});
|
|
16232
|
-
proc.on("error", (err2) => {
|
|
16233
|
-
if (err2.code === "ENOENT") {
|
|
16234
|
-
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";
|
|
16235
|
-
const executableMissing = `'${executableFile}' does not exist
|
|
16236
|
-
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16237
|
-
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
16238
|
-
- ${executableDirMessage}`;
|
|
16239
|
-
throw new Error(executableMissing);
|
|
16240
|
-
} else if (err2.code === "EACCES") {
|
|
16241
|
-
throw new Error(`'${executableFile}' not executable`);
|
|
16242
|
-
}
|
|
16243
|
-
if (!exitCallback) {
|
|
16244
|
-
process2.exit(1);
|
|
16245
|
-
} else {
|
|
16246
|
-
const wrappedError = new CommanderError2(1, "commander.executeSubCommandAsync", "(error)");
|
|
16247
|
-
wrappedError.nestedError = err2;
|
|
16248
|
-
exitCallback(wrappedError);
|
|
16249
|
-
}
|
|
16250
|
-
});
|
|
16251
|
-
this.runningCommand = proc;
|
|
16252
|
-
}
|
|
16253
|
-
_dispatchSubcommand(commandName, operands, unknown) {
|
|
16254
|
-
const subCommand = this._findCommand(commandName);
|
|
16255
|
-
if (!subCommand)
|
|
16256
|
-
this.help({ error: true });
|
|
16257
|
-
let promiseChain;
|
|
16258
|
-
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
16259
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
16260
|
-
if (subCommand._executableHandler) {
|
|
16261
|
-
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
16262
|
-
} else {
|
|
16263
|
-
return subCommand._parseCommand(operands, unknown);
|
|
16264
|
-
}
|
|
16265
|
-
});
|
|
16266
|
-
return promiseChain;
|
|
16267
|
-
}
|
|
16268
|
-
_dispatchHelpCommand(subcommandName) {
|
|
16269
|
-
if (!subcommandName) {
|
|
16270
|
-
this.help();
|
|
16271
|
-
}
|
|
16272
|
-
const subCommand = this._findCommand(subcommandName);
|
|
16273
|
-
if (subCommand && !subCommand._executableHandler) {
|
|
16274
|
-
subCommand.help();
|
|
16275
|
-
}
|
|
16276
|
-
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
16277
|
-
}
|
|
16278
|
-
_checkNumberOfArguments() {
|
|
16279
|
-
this.registeredArguments.forEach((arg, i2) => {
|
|
16280
|
-
if (arg.required && this.args[i2] == null) {
|
|
16281
|
-
this.missingArgument(arg.name());
|
|
16282
|
-
}
|
|
16283
|
-
});
|
|
16284
|
-
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
16285
|
-
return;
|
|
16286
|
-
}
|
|
16287
|
-
if (this.args.length > this.registeredArguments.length) {
|
|
16288
|
-
this._excessArguments(this.args);
|
|
16289
|
-
}
|
|
16290
|
-
}
|
|
16291
|
-
_processArguments() {
|
|
16292
|
-
const myParseArg = (argument, value, previous) => {
|
|
16293
|
-
let parsedValue = value;
|
|
16294
|
-
if (value !== null && argument.parseArg) {
|
|
16295
|
-
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
16296
|
-
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
16297
|
-
}
|
|
16298
|
-
return parsedValue;
|
|
16299
|
-
};
|
|
16300
|
-
this._checkNumberOfArguments();
|
|
16301
|
-
const processedArgs = [];
|
|
16302
|
-
this.registeredArguments.forEach((declaredArg, index) => {
|
|
16303
|
-
let value = declaredArg.defaultValue;
|
|
16304
|
-
if (declaredArg.variadic) {
|
|
16305
|
-
if (index < this.args.length) {
|
|
16306
|
-
value = this.args.slice(index);
|
|
16307
|
-
if (declaredArg.parseArg) {
|
|
16308
|
-
value = value.reduce((processed, v) => {
|
|
16309
|
-
return myParseArg(declaredArg, v, processed);
|
|
16310
|
-
}, declaredArg.defaultValue);
|
|
16311
|
-
}
|
|
16312
|
-
} else if (value === undefined) {
|
|
16313
|
-
value = [];
|
|
16314
|
-
}
|
|
16315
|
-
} else if (index < this.args.length) {
|
|
16316
|
-
value = this.args[index];
|
|
16317
|
-
if (declaredArg.parseArg) {
|
|
16318
|
-
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
16319
|
-
}
|
|
16320
|
-
}
|
|
16321
|
-
processedArgs[index] = value;
|
|
16322
|
-
});
|
|
16323
|
-
this.processedArgs = processedArgs;
|
|
16324
|
-
}
|
|
16325
|
-
_chainOrCall(promise, fn) {
|
|
16326
|
-
if (promise && promise.then && typeof promise.then === "function") {
|
|
16327
|
-
return promise.then(() => fn());
|
|
16328
|
-
}
|
|
16329
|
-
return fn();
|
|
16330
|
-
}
|
|
16331
|
-
_chainOrCallHooks(promise, event) {
|
|
16332
|
-
let result = promise;
|
|
16333
|
-
const hooks = [];
|
|
16334
|
-
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
16335
|
-
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
16336
|
-
hooks.push({ hookedCommand, callback });
|
|
16337
|
-
});
|
|
16338
|
-
});
|
|
16339
|
-
if (event === "postAction") {
|
|
16340
|
-
hooks.reverse();
|
|
16341
|
-
}
|
|
16342
|
-
hooks.forEach((hookDetail) => {
|
|
16343
|
-
result = this._chainOrCall(result, () => {
|
|
16344
|
-
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
16345
|
-
});
|
|
16346
|
-
});
|
|
16347
|
-
return result;
|
|
16348
|
-
}
|
|
16349
|
-
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
16350
|
-
let result = promise;
|
|
16351
|
-
if (this._lifeCycleHooks[event] !== undefined) {
|
|
16352
|
-
this._lifeCycleHooks[event].forEach((hook) => {
|
|
16353
|
-
result = this._chainOrCall(result, () => {
|
|
16354
|
-
return hook(this, subCommand);
|
|
16355
|
-
});
|
|
16356
|
-
});
|
|
16357
|
-
}
|
|
16358
|
-
return result;
|
|
16359
|
-
}
|
|
16360
|
-
_parseCommand(operands, unknown) {
|
|
16361
|
-
const parsed = this.parseOptions(unknown);
|
|
16362
|
-
this._parseOptionsEnv();
|
|
16363
|
-
this._parseOptionsImplied();
|
|
16364
|
-
operands = operands.concat(parsed.operands);
|
|
16365
|
-
unknown = parsed.unknown;
|
|
16366
|
-
this.args = operands.concat(unknown);
|
|
16367
|
-
if (operands && this._findCommand(operands[0])) {
|
|
16368
|
-
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
16369
|
-
}
|
|
16370
|
-
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
16371
|
-
return this._dispatchHelpCommand(operands[1]);
|
|
16372
|
-
}
|
|
16373
|
-
if (this._defaultCommandName) {
|
|
16374
|
-
this._outputHelpIfRequested(unknown);
|
|
16375
|
-
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
16376
|
-
}
|
|
16377
|
-
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
16378
|
-
this.help({ error: true });
|
|
16379
|
-
}
|
|
16380
|
-
this._outputHelpIfRequested(parsed.unknown);
|
|
16381
|
-
this._checkForMissingMandatoryOptions();
|
|
16382
|
-
this._checkForConflictingOptions();
|
|
16383
|
-
const checkForUnknownOptions = () => {
|
|
16384
|
-
if (parsed.unknown.length > 0) {
|
|
16385
|
-
this.unknownOption(parsed.unknown[0]);
|
|
16386
|
-
}
|
|
16387
|
-
};
|
|
16388
|
-
const commandEvent = `command:${this.name()}`;
|
|
16389
|
-
if (this._actionHandler) {
|
|
16390
|
-
checkForUnknownOptions();
|
|
16391
|
-
this._processArguments();
|
|
16392
|
-
let promiseChain;
|
|
16393
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
16394
|
-
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
16395
|
-
if (this.parent) {
|
|
16396
|
-
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
16397
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
16398
|
-
});
|
|
16399
|
-
}
|
|
16400
|
-
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
16401
|
-
return promiseChain;
|
|
16402
|
-
}
|
|
16403
|
-
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
16404
|
-
checkForUnknownOptions();
|
|
16405
|
-
this._processArguments();
|
|
16406
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
16407
|
-
} else if (operands.length) {
|
|
16408
|
-
if (this._findCommand("*")) {
|
|
16409
|
-
return this._dispatchSubcommand("*", operands, unknown);
|
|
16410
|
-
}
|
|
16411
|
-
if (this.listenerCount("command:*")) {
|
|
16412
|
-
this.emit("command:*", operands, unknown);
|
|
16413
|
-
} else if (this.commands.length) {
|
|
16414
|
-
this.unknownCommand();
|
|
16415
|
-
} else {
|
|
16416
|
-
checkForUnknownOptions();
|
|
16417
|
-
this._processArguments();
|
|
16418
|
-
}
|
|
16419
|
-
} else if (this.commands.length) {
|
|
16420
|
-
checkForUnknownOptions();
|
|
16421
|
-
this.help({ error: true });
|
|
16422
|
-
} else {
|
|
16423
|
-
checkForUnknownOptions();
|
|
16424
|
-
this._processArguments();
|
|
16425
|
-
}
|
|
16426
|
-
}
|
|
16427
|
-
_findCommand(name) {
|
|
16428
|
-
if (!name)
|
|
16429
|
-
return;
|
|
16430
|
-
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
16431
|
-
}
|
|
16432
|
-
_findOption(arg) {
|
|
16433
|
-
return this.options.find((option) => option.is(arg));
|
|
16434
|
-
}
|
|
16435
|
-
_checkForMissingMandatoryOptions() {
|
|
16436
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
16437
|
-
cmd.options.forEach((anOption) => {
|
|
16438
|
-
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
16439
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
16440
|
-
}
|
|
16441
|
-
});
|
|
16442
|
-
});
|
|
16443
|
-
}
|
|
16444
|
-
_checkForConflictingLocalOptions() {
|
|
16445
|
-
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
16446
|
-
const optionKey = option.attributeName();
|
|
16447
|
-
if (this.getOptionValue(optionKey) === undefined) {
|
|
16448
|
-
return false;
|
|
16449
|
-
}
|
|
16450
|
-
return this.getOptionValueSource(optionKey) !== "default";
|
|
16451
|
-
});
|
|
16452
|
-
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
16453
|
-
optionsWithConflicting.forEach((option) => {
|
|
16454
|
-
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
16455
|
-
if (conflictingAndDefined) {
|
|
16456
|
-
this._conflictingOption(option, conflictingAndDefined);
|
|
16457
|
-
}
|
|
16458
|
-
});
|
|
16459
|
-
}
|
|
16460
|
-
_checkForConflictingOptions() {
|
|
16461
|
-
this._getCommandAndAncestors().forEach((cmd) => {
|
|
16462
|
-
cmd._checkForConflictingLocalOptions();
|
|
16463
|
-
});
|
|
16464
|
-
}
|
|
16465
|
-
parseOptions(argv) {
|
|
16466
|
-
const operands = [];
|
|
16467
|
-
const unknown = [];
|
|
16468
|
-
let dest = operands;
|
|
16469
|
-
const args = argv.slice();
|
|
16470
|
-
function maybeOption(arg) {
|
|
16471
|
-
return arg.length > 1 && arg[0] === "-";
|
|
16472
|
-
}
|
|
16473
|
-
let activeVariadicOption = null;
|
|
16474
|
-
while (args.length) {
|
|
16475
|
-
const arg = args.shift();
|
|
16476
|
-
if (arg === "--") {
|
|
16477
|
-
if (dest === unknown)
|
|
16478
|
-
dest.push(arg);
|
|
16479
|
-
dest.push(...args);
|
|
16480
|
-
break;
|
|
16481
|
-
}
|
|
16482
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
16483
|
-
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
16484
|
-
continue;
|
|
16485
|
-
}
|
|
16486
|
-
activeVariadicOption = null;
|
|
16487
|
-
if (maybeOption(arg)) {
|
|
16488
|
-
const option = this._findOption(arg);
|
|
16489
|
-
if (option) {
|
|
16490
|
-
if (option.required) {
|
|
16491
|
-
const value = args.shift();
|
|
16492
|
-
if (value === undefined)
|
|
16493
|
-
this.optionMissingArgument(option);
|
|
16494
|
-
this.emit(`option:${option.name()}`, value);
|
|
16495
|
-
} else if (option.optional) {
|
|
16496
|
-
let value = null;
|
|
16497
|
-
if (args.length > 0 && !maybeOption(args[0])) {
|
|
16498
|
-
value = args.shift();
|
|
16499
|
-
}
|
|
16500
|
-
this.emit(`option:${option.name()}`, value);
|
|
16501
|
-
} else {
|
|
16502
|
-
this.emit(`option:${option.name()}`);
|
|
16503
|
-
}
|
|
16504
|
-
activeVariadicOption = option.variadic ? option : null;
|
|
16505
|
-
continue;
|
|
16506
|
-
}
|
|
16507
|
-
}
|
|
16508
|
-
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
16509
|
-
const option = this._findOption(`-${arg[1]}`);
|
|
16510
|
-
if (option) {
|
|
16511
|
-
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
16512
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
16513
|
-
} else {
|
|
16514
|
-
this.emit(`option:${option.name()}`);
|
|
16515
|
-
args.unshift(`-${arg.slice(2)}`);
|
|
16516
|
-
}
|
|
16517
|
-
continue;
|
|
16518
|
-
}
|
|
16519
|
-
}
|
|
16520
|
-
if (/^--[^=]+=/.test(arg)) {
|
|
16521
|
-
const index = arg.indexOf("=");
|
|
16522
|
-
const option = this._findOption(arg.slice(0, index));
|
|
16523
|
-
if (option && (option.required || option.optional)) {
|
|
16524
|
-
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
16525
|
-
continue;
|
|
16526
|
-
}
|
|
16527
|
-
}
|
|
16528
|
-
if (maybeOption(arg)) {
|
|
16529
|
-
dest = unknown;
|
|
16530
|
-
}
|
|
16531
|
-
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
16532
|
-
if (this._findCommand(arg)) {
|
|
16533
|
-
operands.push(arg);
|
|
16534
|
-
if (args.length > 0)
|
|
16535
|
-
unknown.push(...args);
|
|
16536
|
-
break;
|
|
16537
|
-
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
16538
|
-
operands.push(arg);
|
|
16539
|
-
if (args.length > 0)
|
|
16540
|
-
operands.push(...args);
|
|
16541
|
-
break;
|
|
16542
|
-
} else if (this._defaultCommandName) {
|
|
16543
|
-
unknown.push(arg);
|
|
16544
|
-
if (args.length > 0)
|
|
16545
|
-
unknown.push(...args);
|
|
16546
|
-
break;
|
|
16547
|
-
}
|
|
16548
|
-
}
|
|
16549
|
-
if (this._passThroughOptions) {
|
|
16550
|
-
dest.push(arg);
|
|
16551
|
-
if (args.length > 0)
|
|
16552
|
-
dest.push(...args);
|
|
16553
|
-
break;
|
|
16554
|
-
}
|
|
16555
|
-
dest.push(arg);
|
|
16556
|
-
}
|
|
16557
|
-
return { operands, unknown };
|
|
16558
|
-
}
|
|
16559
|
-
opts() {
|
|
16560
|
-
if (this._storeOptionsAsProperties) {
|
|
16561
|
-
const result = {};
|
|
16562
|
-
const len = this.options.length;
|
|
16563
|
-
for (let i2 = 0;i2 < len; i2++) {
|
|
16564
|
-
const key = this.options[i2].attributeName();
|
|
16565
|
-
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
16566
|
-
}
|
|
16567
|
-
return result;
|
|
16568
|
-
}
|
|
16569
|
-
return this._optionValues;
|
|
16570
|
-
}
|
|
16571
|
-
optsWithGlobals() {
|
|
16572
|
-
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
16573
|
-
}
|
|
16574
|
-
error(message, errorOptions) {
|
|
16575
|
-
this._outputConfiguration.outputError(`${message}
|
|
16576
|
-
`, this._outputConfiguration.writeErr);
|
|
16577
|
-
if (typeof this._showHelpAfterError === "string") {
|
|
16578
|
-
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
16579
|
-
`);
|
|
16580
|
-
} else if (this._showHelpAfterError) {
|
|
16581
|
-
this._outputConfiguration.writeErr(`
|
|
16582
|
-
`);
|
|
16583
|
-
this.outputHelp({ error: true });
|
|
16584
|
-
}
|
|
16585
|
-
const config = errorOptions || {};
|
|
16586
|
-
const exitCode = config.exitCode || 1;
|
|
16587
|
-
const code = config.code || "commander.error";
|
|
16588
|
-
this._exit(exitCode, code, message);
|
|
16589
|
-
}
|
|
16590
|
-
_parseOptionsEnv() {
|
|
16591
|
-
this.options.forEach((option) => {
|
|
16592
|
-
if (option.envVar && option.envVar in process2.env) {
|
|
16593
|
-
const optionKey = option.attributeName();
|
|
16594
|
-
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
16595
|
-
if (option.required || option.optional) {
|
|
16596
|
-
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
16597
|
-
} else {
|
|
16598
|
-
this.emit(`optionEnv:${option.name()}`);
|
|
16599
|
-
}
|
|
16600
|
-
}
|
|
16601
|
-
}
|
|
16602
|
-
});
|
|
16603
|
-
}
|
|
16604
|
-
_parseOptionsImplied() {
|
|
16605
|
-
const dualHelper = new DualOptions(this.options);
|
|
16606
|
-
const hasCustomOptionValue = (optionKey) => {
|
|
16607
|
-
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
16608
|
-
};
|
|
16609
|
-
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
16610
|
-
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
16611
|
-
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
16612
|
-
});
|
|
16613
|
-
});
|
|
16614
|
-
}
|
|
16615
|
-
missingArgument(name) {
|
|
16616
|
-
const message = `error: missing required argument '${name}'`;
|
|
16617
|
-
this.error(message, { code: "commander.missingArgument" });
|
|
16618
|
-
}
|
|
16619
|
-
optionMissingArgument(option) {
|
|
16620
|
-
const message = `error: option '${option.flags}' argument missing`;
|
|
16621
|
-
this.error(message, { code: "commander.optionMissingArgument" });
|
|
16622
|
-
}
|
|
16623
|
-
missingMandatoryOptionValue(option) {
|
|
16624
|
-
const message = `error: required option '${option.flags}' not specified`;
|
|
16625
|
-
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
16626
|
-
}
|
|
16627
|
-
_conflictingOption(option, conflictingOption) {
|
|
16628
|
-
const findBestOptionFromValue = (option2) => {
|
|
16629
|
-
const optionKey = option2.attributeName();
|
|
16630
|
-
const optionValue = this.getOptionValue(optionKey);
|
|
16631
|
-
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
16632
|
-
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
16633
|
-
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
16634
|
-
return negativeOption;
|
|
16635
|
-
}
|
|
16636
|
-
return positiveOption || option2;
|
|
16637
|
-
};
|
|
16638
|
-
const getErrorMessage = (option2) => {
|
|
16639
|
-
const bestOption = findBestOptionFromValue(option2);
|
|
16640
|
-
const optionKey = bestOption.attributeName();
|
|
16641
|
-
const source = this.getOptionValueSource(optionKey);
|
|
16642
|
-
if (source === "env") {
|
|
16643
|
-
return `environment variable '${bestOption.envVar}'`;
|
|
16644
|
-
}
|
|
16645
|
-
return `option '${bestOption.flags}'`;
|
|
16646
|
-
};
|
|
16647
|
-
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
16648
|
-
this.error(message, { code: "commander.conflictingOption" });
|
|
16649
|
-
}
|
|
16650
|
-
unknownOption(flag) {
|
|
16651
|
-
if (this._allowUnknownOption)
|
|
16652
|
-
return;
|
|
16653
|
-
let suggestion = "";
|
|
16654
|
-
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
16655
|
-
let candidateFlags = [];
|
|
16656
|
-
let command = this;
|
|
16657
|
-
do {
|
|
16658
|
-
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
16659
|
-
candidateFlags = candidateFlags.concat(moreFlags);
|
|
16660
|
-
command = command.parent;
|
|
16661
|
-
} while (command && !command._enablePositionalOptions);
|
|
16662
|
-
suggestion = suggestSimilar(flag, candidateFlags);
|
|
16663
|
-
}
|
|
16664
|
-
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
16665
|
-
this.error(message, { code: "commander.unknownOption" });
|
|
16666
|
-
}
|
|
16667
|
-
_excessArguments(receivedArgs) {
|
|
16668
|
-
if (this._allowExcessArguments)
|
|
16669
|
-
return;
|
|
16670
|
-
const expected = this.registeredArguments.length;
|
|
16671
|
-
const s2 = expected === 1 ? "" : "s";
|
|
16672
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
16673
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s2} but got ${receivedArgs.length}.`;
|
|
16674
|
-
this.error(message, { code: "commander.excessArguments" });
|
|
16675
|
-
}
|
|
16676
|
-
unknownCommand() {
|
|
16677
|
-
const unknownName = this.args[0];
|
|
16678
|
-
let suggestion = "";
|
|
16679
|
-
if (this._showSuggestionAfterError) {
|
|
16680
|
-
const candidateNames = [];
|
|
16681
|
-
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
16682
|
-
candidateNames.push(command.name());
|
|
16683
|
-
if (command.alias())
|
|
16684
|
-
candidateNames.push(command.alias());
|
|
16685
|
-
});
|
|
16686
|
-
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
16687
|
-
}
|
|
16688
|
-
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
16689
|
-
this.error(message, { code: "commander.unknownCommand" });
|
|
16690
|
-
}
|
|
16691
|
-
version(str, flags, description) {
|
|
16692
|
-
if (str === undefined)
|
|
16693
|
-
return this._version;
|
|
16694
|
-
this._version = str;
|
|
16695
|
-
flags = flags || "-V, --version";
|
|
16696
|
-
description = description || "output the version number";
|
|
16697
|
-
const versionOption = this.createOption(flags, description);
|
|
16698
|
-
this._versionOptionName = versionOption.attributeName();
|
|
16699
|
-
this._registerOption(versionOption);
|
|
16700
|
-
this.on("option:" + versionOption.name(), () => {
|
|
16701
|
-
this._outputConfiguration.writeOut(`${str}
|
|
16702
|
-
`);
|
|
16703
|
-
this._exit(0, "commander.version", str);
|
|
16704
|
-
});
|
|
16705
|
-
return this;
|
|
16706
|
-
}
|
|
16707
|
-
description(str, argsDescription) {
|
|
16708
|
-
if (str === undefined && argsDescription === undefined)
|
|
16709
|
-
return this._description;
|
|
16710
|
-
this._description = str;
|
|
16711
|
-
if (argsDescription) {
|
|
16712
|
-
this._argsDescription = argsDescription;
|
|
16713
|
-
}
|
|
16714
|
-
return this;
|
|
16715
|
-
}
|
|
16716
|
-
summary(str) {
|
|
16717
|
-
if (str === undefined)
|
|
16718
|
-
return this._summary;
|
|
16719
|
-
this._summary = str;
|
|
16720
|
-
return this;
|
|
16721
|
-
}
|
|
16722
|
-
alias(alias) {
|
|
16723
|
-
if (alias === undefined)
|
|
16724
|
-
return this._aliases[0];
|
|
16725
|
-
let command = this;
|
|
16726
|
-
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
16727
|
-
command = this.commands[this.commands.length - 1];
|
|
16728
|
-
}
|
|
16729
|
-
if (alias === command._name)
|
|
16730
|
-
throw new Error("Command alias can't be the same as its name");
|
|
16731
|
-
const matchingCommand = this.parent?._findCommand(alias);
|
|
16732
|
-
if (matchingCommand) {
|
|
16733
|
-
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
16734
|
-
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
16735
|
-
}
|
|
16736
|
-
command._aliases.push(alias);
|
|
16737
|
-
return this;
|
|
16738
|
-
}
|
|
16739
|
-
aliases(aliases) {
|
|
16740
|
-
if (aliases === undefined)
|
|
16741
|
-
return this._aliases;
|
|
16742
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
16743
|
-
return this;
|
|
16744
|
-
}
|
|
16745
|
-
usage(str) {
|
|
16746
|
-
if (str === undefined) {
|
|
16747
|
-
if (this._usage)
|
|
16748
|
-
return this._usage;
|
|
16749
|
-
const args = this.registeredArguments.map((arg) => {
|
|
16750
|
-
return humanReadableArgName(arg);
|
|
16751
|
-
});
|
|
16752
|
-
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
16753
|
-
}
|
|
16754
|
-
this._usage = str;
|
|
16755
|
-
return this;
|
|
16756
|
-
}
|
|
16757
|
-
name(str) {
|
|
16758
|
-
if (str === undefined)
|
|
16759
|
-
return this._name;
|
|
16760
|
-
this._name = str;
|
|
16761
|
-
return this;
|
|
16762
|
-
}
|
|
16763
|
-
nameFromFilename(filename) {
|
|
16764
|
-
this._name = path11.basename(filename, path11.extname(filename));
|
|
16765
|
-
return this;
|
|
16766
|
-
}
|
|
16767
|
-
executableDir(path12) {
|
|
16768
|
-
if (path12 === undefined)
|
|
16769
|
-
return this._executableDir;
|
|
16770
|
-
this._executableDir = path12;
|
|
16771
|
-
return this;
|
|
16772
|
-
}
|
|
16773
|
-
helpInformation(contextOptions) {
|
|
16774
|
-
const helper = this.createHelp();
|
|
16775
|
-
if (helper.helpWidth === undefined) {
|
|
16776
|
-
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
16777
|
-
}
|
|
16778
|
-
return helper.formatHelp(this, helper);
|
|
16779
|
-
}
|
|
16780
|
-
_getHelpContext(contextOptions) {
|
|
16781
|
-
contextOptions = contextOptions || {};
|
|
16782
|
-
const context = { error: !!contextOptions.error };
|
|
16783
|
-
let write;
|
|
16784
|
-
if (context.error) {
|
|
16785
|
-
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
16786
|
-
} else {
|
|
16787
|
-
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
16788
|
-
}
|
|
16789
|
-
context.write = contextOptions.write || write;
|
|
16790
|
-
context.command = this;
|
|
16791
|
-
return context;
|
|
16792
|
-
}
|
|
16793
|
-
outputHelp(contextOptions) {
|
|
16794
|
-
let deprecatedCallback;
|
|
16795
|
-
if (typeof contextOptions === "function") {
|
|
16796
|
-
deprecatedCallback = contextOptions;
|
|
16797
|
-
contextOptions = undefined;
|
|
16798
|
-
}
|
|
16799
|
-
const context = this._getHelpContext(contextOptions);
|
|
16800
|
-
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
16801
|
-
this.emit("beforeHelp", context);
|
|
16802
|
-
let helpInformation = this.helpInformation(context);
|
|
16803
|
-
if (deprecatedCallback) {
|
|
16804
|
-
helpInformation = deprecatedCallback(helpInformation);
|
|
16805
|
-
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
16806
|
-
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
16807
|
-
}
|
|
16808
|
-
}
|
|
16809
|
-
context.write(helpInformation);
|
|
16810
|
-
if (this._getHelpOption()?.long) {
|
|
16811
|
-
this.emit(this._getHelpOption().long);
|
|
16812
|
-
}
|
|
16813
|
-
this.emit("afterHelp", context);
|
|
16814
|
-
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
16815
|
-
}
|
|
16816
|
-
helpOption(flags, description) {
|
|
16817
|
-
if (typeof flags === "boolean") {
|
|
16818
|
-
if (flags) {
|
|
16819
|
-
this._helpOption = this._helpOption ?? undefined;
|
|
16820
|
-
} else {
|
|
16821
|
-
this._helpOption = null;
|
|
16822
|
-
}
|
|
16823
|
-
return this;
|
|
16824
|
-
}
|
|
16825
|
-
flags = flags ?? "-h, --help";
|
|
16826
|
-
description = description ?? "display help for command";
|
|
16827
|
-
this._helpOption = this.createOption(flags, description);
|
|
16828
|
-
return this;
|
|
16829
|
-
}
|
|
16830
|
-
_getHelpOption() {
|
|
16831
|
-
if (this._helpOption === undefined) {
|
|
16832
|
-
this.helpOption(undefined, undefined);
|
|
16833
|
-
}
|
|
16834
|
-
return this._helpOption;
|
|
16835
|
-
}
|
|
16836
|
-
addHelpOption(option) {
|
|
16837
|
-
this._helpOption = option;
|
|
16838
|
-
return this;
|
|
16839
|
-
}
|
|
16840
|
-
help(contextOptions) {
|
|
16841
|
-
this.outputHelp(contextOptions);
|
|
16842
|
-
let exitCode = process2.exitCode || 0;
|
|
16843
|
-
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
16844
|
-
exitCode = 1;
|
|
16845
|
-
}
|
|
16846
|
-
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
16847
|
-
}
|
|
16848
|
-
addHelpText(position, text2) {
|
|
16849
|
-
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
16850
|
-
if (!allowedValues.includes(position)) {
|
|
16851
|
-
throw new Error(`Unexpected value for position to addHelpText.
|
|
16852
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
16853
|
-
}
|
|
16854
|
-
const helpEvent = `${position}Help`;
|
|
16855
|
-
this.on(helpEvent, (context) => {
|
|
16856
|
-
let helpStr;
|
|
16857
|
-
if (typeof text2 === "function") {
|
|
16858
|
-
helpStr = text2({ error: context.error, command: context.command });
|
|
16859
|
-
} else {
|
|
16860
|
-
helpStr = text2;
|
|
16861
|
-
}
|
|
16862
|
-
if (helpStr) {
|
|
16863
|
-
context.write(`${helpStr}
|
|
16864
|
-
`);
|
|
16865
|
-
}
|
|
16866
|
-
});
|
|
16867
|
-
return this;
|
|
16868
|
-
}
|
|
16869
|
-
_outputHelpIfRequested(args) {
|
|
16870
|
-
const helpOption = this._getHelpOption();
|
|
16871
|
-
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
16872
|
-
if (helpRequested) {
|
|
16873
|
-
this.outputHelp();
|
|
16874
|
-
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
16875
|
-
}
|
|
16876
|
-
}
|
|
16877
|
-
}
|
|
16878
|
-
function incrementNodeInspectorPort(args) {
|
|
16879
|
-
return args.map((arg) => {
|
|
16880
|
-
if (!arg.startsWith("--inspect")) {
|
|
16881
|
-
return arg;
|
|
16882
|
-
}
|
|
16883
|
-
let debugOption;
|
|
16884
|
-
let debugHost = "127.0.0.1";
|
|
16885
|
-
let debugPort = "9229";
|
|
16886
|
-
let match;
|
|
16887
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
16888
|
-
debugOption = match[1];
|
|
16889
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
16890
|
-
debugOption = match[1];
|
|
16891
|
-
if (/^\d+$/.test(match[3])) {
|
|
16892
|
-
debugPort = match[3];
|
|
16893
|
-
} else {
|
|
16894
|
-
debugHost = match[3];
|
|
16895
|
-
}
|
|
16896
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
16897
|
-
debugOption = match[1];
|
|
16898
|
-
debugHost = match[3];
|
|
16899
|
-
debugPort = match[4];
|
|
16900
|
-
}
|
|
16901
|
-
if (debugOption && debugPort !== "0") {
|
|
16902
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
16903
|
-
}
|
|
16904
|
-
return arg;
|
|
16905
|
-
});
|
|
16906
|
-
}
|
|
16907
|
-
exports.Command = Command2;
|
|
16908
|
-
});
|
|
16909
|
-
|
|
16910
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/index.js
|
|
16911
|
-
var require_commander2 = __commonJS((exports) => {
|
|
16912
|
-
var { Argument: Argument2 } = require_argument2();
|
|
16913
|
-
var { Command: Command2 } = require_command2();
|
|
16914
|
-
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error2();
|
|
16915
|
-
var { Help: Help2 } = require_help2();
|
|
16916
|
-
var { Option: Option2 } = require_option2();
|
|
16917
|
-
exports.program = new Command2;
|
|
16918
|
-
exports.createCommand = (name) => new Command2(name);
|
|
16919
|
-
exports.createOption = (flags, description) => new Option2(flags, description);
|
|
16920
|
-
exports.createArgument = (name, description) => new Argument2(name, description);
|
|
16921
|
-
exports.Command = Command2;
|
|
16922
|
-
exports.Option = Option2;
|
|
16923
|
-
exports.Argument = Argument2;
|
|
16924
|
-
exports.Help = Help2;
|
|
16925
|
-
exports.CommanderError = CommanderError2;
|
|
16926
|
-
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
16927
|
-
exports.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
16928
|
-
});
|
|
16929
|
-
|
|
16930
15091
|
// ../../../node_modules/jpeg-js/lib/encoder.js
|
|
16931
15092
|
var require_encoder = __commonJS((exports, module) => {
|
|
16932
15093
|
var btoa2 = btoa2 || function(buf) {
|
|
@@ -101751,21 +99912,6 @@ function createProgram3() {
|
|
|
101751
99912
|
});
|
|
101752
99913
|
return program2;
|
|
101753
99914
|
}
|
|
101754
|
-
// ../../@aurochs-cli/pdf-cli/node_modules/commander/esm.mjs
|
|
101755
|
-
var import__3 = __toESM(require_commander2(), 1);
|
|
101756
|
-
var {
|
|
101757
|
-
program: program2,
|
|
101758
|
-
createCommand: createCommand2,
|
|
101759
|
-
createArgument: createArgument2,
|
|
101760
|
-
createOption: createOption2,
|
|
101761
|
-
CommanderError: CommanderError2,
|
|
101762
|
-
InvalidArgumentError: InvalidArgumentError2,
|
|
101763
|
-
InvalidOptionArgumentError: InvalidOptionArgumentError2,
|
|
101764
|
-
Command: Command2,
|
|
101765
|
-
Argument: Argument2,
|
|
101766
|
-
Option: Option2,
|
|
101767
|
-
Help: Help2
|
|
101768
|
-
} = import__3.default;
|
|
101769
99915
|
// ../../@aurochs/pdf/src/domain/font/defaults.ts
|
|
101770
99916
|
var DEFAULT_FONT_METRICS = {
|
|
101771
99917
|
widths: new Map,
|
|
@@ -129951,43 +128097,43 @@ function parseStrictPositiveInteger(value, label) {
|
|
|
129951
128097
|
return parsed;
|
|
129952
128098
|
}
|
|
129953
128099
|
function createProgram4() {
|
|
129954
|
-
const
|
|
129955
|
-
|
|
129956
|
-
|
|
129957
|
-
const mode =
|
|
128100
|
+
const program2 = new Command;
|
|
128101
|
+
program2.name("pdf").description("CLI tool for inspecting PDF files").version("0.1.0").option("-o, --output <mode>", "Output mode (json|pretty|mermaid)", "pretty");
|
|
128102
|
+
program2.command("info").description("Display PDF metadata").argument("<file>", "PDF file path").action(async (file) => {
|
|
128103
|
+
const mode = program2.opts().output;
|
|
129958
128104
|
const result = await runInfo4(file);
|
|
129959
128105
|
output({ result, mode, prettyFormatter: formatInfoPretty4 });
|
|
129960
128106
|
});
|
|
129961
|
-
|
|
129962
|
-
const mode =
|
|
128107
|
+
program2.command("list").description("List pages with summary").argument("<file>", "PDF file path").action(async (file) => {
|
|
128108
|
+
const mode = program2.opts().output;
|
|
129963
128109
|
const result = await runList4(file);
|
|
129964
128110
|
output({ result, mode, prettyFormatter: formatListPretty4 });
|
|
129965
128111
|
});
|
|
129966
|
-
|
|
128112
|
+
program2.command("show").description("Display detailed page content").argument("<file>", "PDF file path").argument("<page>", "Page number (1-based)").action(async (file, page) => {
|
|
129967
128113
|
const pageNumber = parseStrictPositiveInteger(page, "Page number");
|
|
129968
128114
|
if (pageNumber === null) {
|
|
129969
128115
|
return;
|
|
129970
128116
|
}
|
|
129971
|
-
const mode =
|
|
128117
|
+
const mode = program2.opts().output;
|
|
129972
128118
|
const result = await runShow4(file, pageNumber);
|
|
129973
128119
|
output({ result, mode, prettyFormatter: formatShowPretty4 });
|
|
129974
128120
|
});
|
|
129975
|
-
|
|
129976
|
-
const mode =
|
|
128121
|
+
program2.command("extract").description("Extract page text").argument("<file>", "PDF file path").option("--pages <range>", 'Page range (e.g., "1,3-5")').action(async (file, options) => {
|
|
128122
|
+
const mode = program2.opts().output;
|
|
129977
128123
|
const result = await runExtract4(file, options);
|
|
129978
128124
|
output({ result, mode, prettyFormatter: formatExtractPretty4 });
|
|
129979
128125
|
});
|
|
129980
|
-
|
|
129981
|
-
const mode =
|
|
128126
|
+
program2.command("build").description("Build PdfDocument JSON from a build spec").argument("<spec>", "JSON spec file path").action(async (spec) => {
|
|
128127
|
+
const mode = program2.opts().output;
|
|
129982
128128
|
const result = await runBuild4(spec);
|
|
129983
128129
|
output({ result, mode, prettyFormatter: formatBuildPretty4 });
|
|
129984
128130
|
});
|
|
129985
|
-
|
|
129986
|
-
const mode =
|
|
128131
|
+
program2.command("write").description("Write PdfDocument JSON to PDF binary").argument("<spec>", "JSON spec file path").action(async (spec) => {
|
|
128132
|
+
const mode = program2.opts().output;
|
|
129987
128133
|
const result = await runWrite(spec);
|
|
129988
128134
|
output({ result, mode, prettyFormatter: formatWritePretty });
|
|
129989
128135
|
});
|
|
129990
|
-
|
|
128136
|
+
program2.command("preview").description("Render one page or all pages as SVG").argument("<file>", "PDF file path").argument("[page]", "Page number (1-based, omit for all pages)").option("--width <value>", "Output SVG width").option("--height <value>", "Output SVG height").option("--background <color>", "SVG background color").action(async (file, page, options) => {
|
|
129991
128137
|
const parsedPageNumber = page === undefined ? undefined : parseStrictPositiveInteger(page, "Page number");
|
|
129992
128138
|
if (parsedPageNumber === null) {
|
|
129993
128139
|
return;
|
|
@@ -129995,7 +128141,7 @@ function createProgram4() {
|
|
|
129995
128141
|
const pageNumber = parsedPageNumber;
|
|
129996
128142
|
const width = options.width === undefined ? undefined : Number.parseFloat(options.width);
|
|
129997
128143
|
const height = options.height === undefined ? undefined : Number.parseFloat(options.height);
|
|
129998
|
-
const mode =
|
|
128144
|
+
const mode = program2.opts().output;
|
|
129999
128145
|
const result = await runPreview4(file, pageNumber, {
|
|
130000
128146
|
width,
|
|
130001
128147
|
height,
|
|
@@ -130003,12 +128149,267 @@ function createProgram4() {
|
|
|
130003
128149
|
});
|
|
130004
128150
|
output({ result, mode, prettyFormatter: formatPreviewPretty4 });
|
|
130005
128151
|
});
|
|
130006
|
-
return
|
|
128152
|
+
return program2;
|
|
128153
|
+
}
|
|
128154
|
+
// ../../@aurochs-cli/cli/src/convert.ts
|
|
128155
|
+
import { extname as extname3 } from "node:path";
|
|
128156
|
+
import * as fs15 from "node:fs/promises";
|
|
128157
|
+
|
|
128158
|
+
// ../../@aurochs-renderer/pdf/src/mermaid/page-renderer.ts
|
|
128159
|
+
function groupIntoLines(items, pageHeight) {
|
|
128160
|
+
if (items.length === 0)
|
|
128161
|
+
return [];
|
|
128162
|
+
const sorted = [...items].sort((a, b) => {
|
|
128163
|
+
const topA = a.y + a.height;
|
|
128164
|
+
const topB = b.y + b.height;
|
|
128165
|
+
if (Math.abs(topA - topB) > Math.min(a.height, b.height) * 0.5) {
|
|
128166
|
+
return topB - topA;
|
|
128167
|
+
}
|
|
128168
|
+
return a.x - b.x;
|
|
128169
|
+
});
|
|
128170
|
+
const lines = [];
|
|
128171
|
+
let currentLine = [sorted[0]];
|
|
128172
|
+
let currentTop = sorted[0].y + sorted[0].height;
|
|
128173
|
+
for (let i3 = 1;i3 < sorted.length; i3++) {
|
|
128174
|
+
const item = sorted[i3];
|
|
128175
|
+
const itemTop = item.y + item.height;
|
|
128176
|
+
const threshold = Math.min(item.height, currentLine[0].height) * 0.5;
|
|
128177
|
+
if (Math.abs(currentTop - itemTop) <= threshold) {
|
|
128178
|
+
currentLine.push(item);
|
|
128179
|
+
} else {
|
|
128180
|
+
currentLine.sort((a, b) => a.x - b.x);
|
|
128181
|
+
const avgY2 = currentLine.reduce((sum, it) => sum + it.y, 0) / currentLine.length;
|
|
128182
|
+
lines.push({ y: avgY2, items: currentLine });
|
|
128183
|
+
currentLine = [item];
|
|
128184
|
+
currentTop = itemTop;
|
|
128185
|
+
}
|
|
128186
|
+
}
|
|
128187
|
+
currentLine.sort((a, b) => a.x - b.x);
|
|
128188
|
+
const avgY = currentLine.reduce((sum, it) => sum + it.y, 0) / currentLine.length;
|
|
128189
|
+
lines.push({ y: avgY, items: currentLine });
|
|
128190
|
+
return lines;
|
|
128191
|
+
}
|
|
128192
|
+
function detectBodyFontSize(items) {
|
|
128193
|
+
if (items.length === 0)
|
|
128194
|
+
return;
|
|
128195
|
+
const sizeWeights = new Map;
|
|
128196
|
+
for (const item of items) {
|
|
128197
|
+
const rounded = Math.round(item.fontSize * 2) / 2;
|
|
128198
|
+
sizeWeights.set(rounded, (sizeWeights.get(rounded) ?? 0) + item.text.length);
|
|
128199
|
+
}
|
|
128200
|
+
let maxWeight = 0;
|
|
128201
|
+
let bodySize = items[0].fontSize;
|
|
128202
|
+
for (const [size, weight] of sizeWeights) {
|
|
128203
|
+
if (weight > maxWeight) {
|
|
128204
|
+
maxWeight = weight;
|
|
128205
|
+
bodySize = size;
|
|
128206
|
+
}
|
|
128207
|
+
}
|
|
128208
|
+
return bodySize;
|
|
128209
|
+
}
|
|
128210
|
+
function fontSizeToHeadingLevel(fontSize, bodyFontSize) {
|
|
128211
|
+
const ratio = fontSize / bodyFontSize;
|
|
128212
|
+
if (ratio >= 1.8)
|
|
128213
|
+
return 1;
|
|
128214
|
+
if (ratio >= 1.4)
|
|
128215
|
+
return 2;
|
|
128216
|
+
if (ratio >= 1.15)
|
|
128217
|
+
return 3;
|
|
128218
|
+
return;
|
|
128219
|
+
}
|
|
128220
|
+
function joinLineItems(items) {
|
|
128221
|
+
if (items.length === 0)
|
|
128222
|
+
return "";
|
|
128223
|
+
const parts = [];
|
|
128224
|
+
for (let i3 = 0;i3 < items.length; i3++) {
|
|
128225
|
+
const item = items[i3];
|
|
128226
|
+
const text2 = item.text.trim();
|
|
128227
|
+
if (!text2)
|
|
128228
|
+
continue;
|
|
128229
|
+
if (i3 > 0) {
|
|
128230
|
+
const prev = items[i3 - 1];
|
|
128231
|
+
const gap = item.x - (prev.x + prev.width);
|
|
128232
|
+
if (gap > item.fontSize * 0.25) {
|
|
128233
|
+
parts.push(" ");
|
|
128234
|
+
}
|
|
128235
|
+
}
|
|
128236
|
+
let formatted = text2;
|
|
128237
|
+
if (item.isBold && item.isItalic) {
|
|
128238
|
+
formatted = `***${text2}***`;
|
|
128239
|
+
} else if (item.isBold) {
|
|
128240
|
+
formatted = `**${text2}**`;
|
|
128241
|
+
} else if (item.isItalic) {
|
|
128242
|
+
formatted = `*${text2}*`;
|
|
128243
|
+
}
|
|
128244
|
+
parts.push(formatted);
|
|
128245
|
+
}
|
|
128246
|
+
return parts.join("");
|
|
128247
|
+
}
|
|
128248
|
+
function renderPdfPageMermaid(page) {
|
|
128249
|
+
if (page.textItems.length === 0)
|
|
128250
|
+
return "";
|
|
128251
|
+
const lines = groupIntoLines(page.textItems, page.height);
|
|
128252
|
+
const bodyFontSize = detectBodyFontSize(page.textItems);
|
|
128253
|
+
const sections = [];
|
|
128254
|
+
for (const line2 of lines) {
|
|
128255
|
+
const text2 = joinLineItems(line2.items);
|
|
128256
|
+
if (!text2.trim())
|
|
128257
|
+
continue;
|
|
128258
|
+
if (bodyFontSize !== undefined) {
|
|
128259
|
+
const maxFontSize = Math.max(...line2.items.map((it) => it.fontSize));
|
|
128260
|
+
const headingLevel = fontSizeToHeadingLevel(maxFontSize, bodyFontSize);
|
|
128261
|
+
if (headingLevel !== undefined) {
|
|
128262
|
+
const hashes = "#".repeat(headingLevel);
|
|
128263
|
+
const cleaned = text2.replace(/\*{2,3}([^*]+)\*{2,3}/g, "$1");
|
|
128264
|
+
sections.push(`${hashes} ${cleaned}`);
|
|
128265
|
+
continue;
|
|
128266
|
+
}
|
|
128267
|
+
}
|
|
128268
|
+
sections.push(text2);
|
|
128269
|
+
}
|
|
128270
|
+
return sections.join(`
|
|
128271
|
+
|
|
128272
|
+
`);
|
|
128273
|
+
}
|
|
128274
|
+
// ../../@aurochs-cli/cli/src/convert.ts
|
|
128275
|
+
var EXTENSION_MAP = {
|
|
128276
|
+
".pptx": { format: "pptx", legacy: false },
|
|
128277
|
+
".ppt": { format: "pptx", legacy: true },
|
|
128278
|
+
".xlsx": { format: "xlsx", legacy: false },
|
|
128279
|
+
".xls": { format: "xlsx", legacy: true },
|
|
128280
|
+
".docx": { format: "docx", legacy: false },
|
|
128281
|
+
".doc": { format: "docx", legacy: true },
|
|
128282
|
+
".pdf": { format: "pdf", legacy: false }
|
|
128283
|
+
};
|
|
128284
|
+
function detectFormat(filePath) {
|
|
128285
|
+
const ext = extname3(filePath).toLowerCase();
|
|
128286
|
+
return EXTENSION_MAP[ext];
|
|
128287
|
+
}
|
|
128288
|
+
async function convertPptxToMarkdown(filePath) {
|
|
128289
|
+
const result = await runPreview(filePath, undefined, { width: 80 });
|
|
128290
|
+
if (!result.success) {
|
|
128291
|
+
throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
128292
|
+
}
|
|
128293
|
+
const sections = [];
|
|
128294
|
+
for (const slide of result.data.slides) {
|
|
128295
|
+
const header = `## Slide ${slide.number}`;
|
|
128296
|
+
const markdown = renderSlideMermaid({ shapes: slide.shapes, slideNumber: slide.number });
|
|
128297
|
+
sections.push(markdown ? `${header}
|
|
128298
|
+
|
|
128299
|
+
${markdown}` : header);
|
|
128300
|
+
}
|
|
128301
|
+
return sections.join(`
|
|
128302
|
+
|
|
128303
|
+
`);
|
|
128304
|
+
}
|
|
128305
|
+
async function convertXlsxToMarkdown(filePath) {
|
|
128306
|
+
const result = await runPreview3(filePath, undefined, { width: 80 });
|
|
128307
|
+
if (!result.success) {
|
|
128308
|
+
throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
128309
|
+
}
|
|
128310
|
+
const sections = [];
|
|
128311
|
+
for (const sheet of result.data.sheets) {
|
|
128312
|
+
const header = `## ${sheet.name}`;
|
|
128313
|
+
const markdown = renderSheetMermaid({
|
|
128314
|
+
name: sheet.name,
|
|
128315
|
+
rows: sheet.rows,
|
|
128316
|
+
columnCount: sheet.colCount
|
|
128317
|
+
});
|
|
128318
|
+
sections.push(markdown ? `${header}
|
|
128319
|
+
|
|
128320
|
+
${markdown}` : header);
|
|
128321
|
+
}
|
|
128322
|
+
return sections.join(`
|
|
128323
|
+
|
|
128324
|
+
`);
|
|
128325
|
+
}
|
|
128326
|
+
async function convertDocxToMarkdown(filePath) {
|
|
128327
|
+
const result = await runPreview2(filePath, undefined, { width: 80 });
|
|
128328
|
+
if (!result.success) {
|
|
128329
|
+
throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
128330
|
+
}
|
|
128331
|
+
const sections = [];
|
|
128332
|
+
for (const section of result.data.sections) {
|
|
128333
|
+
const header = `## Section ${section.number}`;
|
|
128334
|
+
const markdown = renderDocxMermaid({ blocks: section.blocks });
|
|
128335
|
+
sections.push(markdown ? `${header}
|
|
128336
|
+
|
|
128337
|
+
${markdown}` : header);
|
|
128338
|
+
}
|
|
128339
|
+
return sections.join(`
|
|
128340
|
+
|
|
128341
|
+
`);
|
|
128342
|
+
}
|
|
128343
|
+
function isTextElement2(element) {
|
|
128344
|
+
return element.type === "text";
|
|
128345
|
+
}
|
|
128346
|
+
async function convertPdfToMarkdown(filePath) {
|
|
128347
|
+
const data = new Uint8Array(await fs15.readFile(filePath));
|
|
128348
|
+
const document2 = await buildPdf({
|
|
128349
|
+
data,
|
|
128350
|
+
buildOptions: {
|
|
128351
|
+
includeText: true,
|
|
128352
|
+
includePaths: false
|
|
128353
|
+
}
|
|
128354
|
+
});
|
|
128355
|
+
const sections = [];
|
|
128356
|
+
for (const page of document2.pages) {
|
|
128357
|
+
const header = `## Page ${page.pageNumber}`;
|
|
128358
|
+
const textItems = page.elements.filter(isTextElement2).map((el2) => ({
|
|
128359
|
+
text: el2.text,
|
|
128360
|
+
x: el2.x,
|
|
128361
|
+
y: el2.y,
|
|
128362
|
+
width: el2.width,
|
|
128363
|
+
height: el2.height,
|
|
128364
|
+
fontSize: el2.fontSize,
|
|
128365
|
+
isBold: el2.isBold,
|
|
128366
|
+
isItalic: el2.isItalic
|
|
128367
|
+
}));
|
|
128368
|
+
const markdown = renderPdfPageMermaid({
|
|
128369
|
+
pageNumber: page.pageNumber,
|
|
128370
|
+
width: page.width,
|
|
128371
|
+
height: page.height,
|
|
128372
|
+
textItems
|
|
128373
|
+
});
|
|
128374
|
+
sections.push(markdown ? `${header}
|
|
128375
|
+
|
|
128376
|
+
${markdown}` : header);
|
|
128377
|
+
}
|
|
128378
|
+
return sections.join(`
|
|
128379
|
+
|
|
128380
|
+
`);
|
|
128381
|
+
}
|
|
128382
|
+
var FORMAT_CONVERTERS = {
|
|
128383
|
+
pptx: convertPptxToMarkdown,
|
|
128384
|
+
xlsx: convertXlsxToMarkdown,
|
|
128385
|
+
docx: convertDocxToMarkdown,
|
|
128386
|
+
pdf: convertPdfToMarkdown
|
|
128387
|
+
};
|
|
128388
|
+
async function convertToMarkdown(inputPath, options = {}) {
|
|
128389
|
+
const detected = detectFormat(inputPath);
|
|
128390
|
+
if (!detected) {
|
|
128391
|
+
const ext = extname3(inputPath).toLowerCase();
|
|
128392
|
+
const supported = Object.keys(EXTENSION_MAP).join(", ");
|
|
128393
|
+
throw new Error(`Unsupported file format: "${ext}". Supported formats: ${supported}`);
|
|
128394
|
+
}
|
|
128395
|
+
const converter = FORMAT_CONVERTERS[detected.format];
|
|
128396
|
+
const markdown = await converter(inputPath);
|
|
128397
|
+
if (options.outputPath) {
|
|
128398
|
+
await fs15.writeFile(options.outputPath, markdown, "utf-8");
|
|
128399
|
+
}
|
|
128400
|
+
return {
|
|
128401
|
+
markdown,
|
|
128402
|
+
format: detected.format,
|
|
128403
|
+
isLegacy: detected.legacy
|
|
128404
|
+
};
|
|
128405
|
+
}
|
|
128406
|
+
function getSupportedExtensions() {
|
|
128407
|
+
return Object.keys(EXTENSION_MAP);
|
|
130007
128408
|
}
|
|
130008
128409
|
// ../../@aurochs-cli/cli/package.json
|
|
130009
128410
|
var package_default = {
|
|
130010
128411
|
name: "@aurochs-cli/cli",
|
|
130011
|
-
version: "0.
|
|
128412
|
+
version: "0.11.0",
|
|
130012
128413
|
type: "module",
|
|
130013
128414
|
bin: {
|
|
130014
128415
|
aurochs: "./dist/cli.js"
|
|
@@ -130021,19 +128422,69 @@ var package_default = {
|
|
|
130021
128422
|
typecheck: "tsc -p tsconfig.json --noEmit"
|
|
130022
128423
|
},
|
|
130023
128424
|
dependencies: {
|
|
128425
|
+
"@aurochs-builder/pdf": "workspace:*",
|
|
130024
128426
|
"@aurochs-cli/docx-cli": "workspace:*",
|
|
130025
128427
|
"@aurochs-cli/pdf-cli": "workspace:*",
|
|
130026
128428
|
"@aurochs-cli/pptx-cli": "workspace:*",
|
|
130027
128429
|
"@aurochs-cli/xlsx-cli": "workspace:*",
|
|
128430
|
+
"@aurochs-renderer/docx": "workspace:*",
|
|
128431
|
+
"@aurochs-renderer/pdf": "workspace:*",
|
|
128432
|
+
"@aurochs-renderer/pptx": "workspace:*",
|
|
128433
|
+
"@aurochs-renderer/xlsx": "workspace:*",
|
|
128434
|
+
"@aurochs/pdf": "workspace:*",
|
|
130028
128435
|
commander: "^14.0.3"
|
|
130029
128436
|
}
|
|
130030
128437
|
};
|
|
130031
128438
|
|
|
130032
128439
|
// ../../@aurochs-cli/cli/src/cli.ts
|
|
130033
|
-
var
|
|
130034
|
-
|
|
130035
|
-
|
|
130036
|
-
|
|
130037
|
-
|
|
130038
|
-
|
|
130039
|
-
|
|
128440
|
+
var program2 = new Command;
|
|
128441
|
+
program2.name("aurochs").description("Unified CLI for Office document inspection").version(package_default.version);
|
|
128442
|
+
program2.option("-i, --input <file>", "Input file path for conversion").option("-o, --output <file>", "Output file path (default: stdout)").option("-f, --format <type>", "Output format (markdown)", "markdown");
|
|
128443
|
+
program2.addCommand(createProgram());
|
|
128444
|
+
program2.addCommand(createProgram2());
|
|
128445
|
+
program2.addCommand(createProgram3());
|
|
128446
|
+
program2.addCommand(createProgram4());
|
|
128447
|
+
program2.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
128448
|
+
if (actionCommand !== program2) {
|
|
128449
|
+
return;
|
|
128450
|
+
}
|
|
128451
|
+
});
|
|
128452
|
+
program2.action(async () => {
|
|
128453
|
+
const opts = program2.opts();
|
|
128454
|
+
if (!opts.input) {
|
|
128455
|
+
program2.help();
|
|
128456
|
+
return;
|
|
128457
|
+
}
|
|
128458
|
+
if (opts.format && opts.format !== "markdown") {
|
|
128459
|
+
console.error(`Error: Unsupported output format "${opts.format}". Currently supported: markdown`);
|
|
128460
|
+
process.exitCode = 1;
|
|
128461
|
+
return;
|
|
128462
|
+
}
|
|
128463
|
+
try {
|
|
128464
|
+
const result = await convertToMarkdown(opts.input, {
|
|
128465
|
+
outputPath: opts.output
|
|
128466
|
+
});
|
|
128467
|
+
if (!opts.output) {
|
|
128468
|
+
console.log(result.markdown);
|
|
128469
|
+
} else {
|
|
128470
|
+
const ext = result.isLegacy ? ` (converted from legacy format)` : "";
|
|
128471
|
+
console.error(`Converted ${result.format}${ext} → ${opts.output}`);
|
|
128472
|
+
}
|
|
128473
|
+
} catch (err3) {
|
|
128474
|
+
console.error(`Error: ${err3.message}`);
|
|
128475
|
+
process.exitCode = 1;
|
|
128476
|
+
}
|
|
128477
|
+
});
|
|
128478
|
+
program2.addHelpText("after", `
|
|
128479
|
+
Conversion mode:
|
|
128480
|
+
aurochs -i <file> Convert to Markdown (stdout)
|
|
128481
|
+
aurochs -i <file> -o <file> Convert to Markdown (file)
|
|
128482
|
+
|
|
128483
|
+
Supported input formats: ${getSupportedExtensions().join(", ")}
|
|
128484
|
+
|
|
128485
|
+
Examples:
|
|
128486
|
+
aurochs -i presentation.pptx
|
|
128487
|
+
aurochs -i spreadsheet.xlsx -o output.md
|
|
128488
|
+
aurochs -i document.doc
|
|
128489
|
+
aurochs -i report.pdf -o report.md`);
|
|
128490
|
+
program2.parse();
|