@c-d-cc/reap 0.15.11 → 0.15.13

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.
Files changed (3) hide show
  1. package/RELEASE_NOTICE.md +12 -0
  2. package/dist/cli.js +718 -1869
  3. package/package.json +1 -2
package/dist/cli.js CHANGED
@@ -47,1845 +47,6 @@ var __export = (target, all) => {
47
47
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
48
48
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
49
49
 
50
- // node_modules/commander/lib/error.js
51
- var require_error = __commonJS((exports) => {
52
- class CommanderError extends Error {
53
- constructor(exitCode, code, message) {
54
- super(message);
55
- Error.captureStackTrace(this, this.constructor);
56
- this.name = this.constructor.name;
57
- this.code = code;
58
- this.exitCode = exitCode;
59
- this.nestedError = undefined;
60
- }
61
- }
62
-
63
- class InvalidArgumentError extends CommanderError {
64
- constructor(message) {
65
- super(1, "commander.invalidArgument", message);
66
- Error.captureStackTrace(this, this.constructor);
67
- this.name = this.constructor.name;
68
- }
69
- }
70
- exports.CommanderError = CommanderError;
71
- exports.InvalidArgumentError = InvalidArgumentError;
72
- });
73
-
74
- // node_modules/commander/lib/argument.js
75
- var require_argument = __commonJS((exports) => {
76
- var { InvalidArgumentError } = require_error();
77
-
78
- class Argument {
79
- constructor(name, description) {
80
- this.description = description || "";
81
- this.variadic = false;
82
- this.parseArg = undefined;
83
- this.defaultValue = undefined;
84
- this.defaultValueDescription = undefined;
85
- this.argChoices = undefined;
86
- switch (name[0]) {
87
- case "<":
88
- this.required = true;
89
- this._name = name.slice(1, -1);
90
- break;
91
- case "[":
92
- this.required = false;
93
- this._name = name.slice(1, -1);
94
- break;
95
- default:
96
- this.required = true;
97
- this._name = name;
98
- break;
99
- }
100
- if (this._name.length > 3 && this._name.slice(-3) === "...") {
101
- this.variadic = true;
102
- this._name = this._name.slice(0, -3);
103
- }
104
- }
105
- name() {
106
- return this._name;
107
- }
108
- _concatValue(value, previous) {
109
- if (previous === this.defaultValue || !Array.isArray(previous)) {
110
- return [value];
111
- }
112
- return previous.concat(value);
113
- }
114
- default(value, description) {
115
- this.defaultValue = value;
116
- this.defaultValueDescription = description;
117
- return this;
118
- }
119
- argParser(fn) {
120
- this.parseArg = fn;
121
- return this;
122
- }
123
- choices(values) {
124
- this.argChoices = values.slice();
125
- this.parseArg = (arg, previous) => {
126
- if (!this.argChoices.includes(arg)) {
127
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
128
- }
129
- if (this.variadic) {
130
- return this._concatValue(arg, previous);
131
- }
132
- return arg;
133
- };
134
- return this;
135
- }
136
- argRequired() {
137
- this.required = true;
138
- return this;
139
- }
140
- argOptional() {
141
- this.required = false;
142
- return this;
143
- }
144
- }
145
- function humanReadableArgName(arg) {
146
- const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
147
- return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
148
- }
149
- exports.Argument = Argument;
150
- exports.humanReadableArgName = humanReadableArgName;
151
- });
152
-
153
- // node_modules/commander/lib/help.js
154
- var require_help = __commonJS((exports) => {
155
- var { humanReadableArgName } = require_argument();
156
-
157
- class Help {
158
- constructor() {
159
- this.helpWidth = undefined;
160
- this.sortSubcommands = false;
161
- this.sortOptions = false;
162
- this.showGlobalOptions = false;
163
- }
164
- visibleCommands(cmd) {
165
- const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
166
- const helpCommand = cmd._getHelpCommand();
167
- if (helpCommand && !helpCommand._hidden) {
168
- visibleCommands.push(helpCommand);
169
- }
170
- if (this.sortSubcommands) {
171
- visibleCommands.sort((a, b) => {
172
- return a.name().localeCompare(b.name());
173
- });
174
- }
175
- return visibleCommands;
176
- }
177
- compareOptions(a, b) {
178
- const getSortKey = (option) => {
179
- return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
180
- };
181
- return getSortKey(a).localeCompare(getSortKey(b));
182
- }
183
- visibleOptions(cmd) {
184
- const visibleOptions = cmd.options.filter((option) => !option.hidden);
185
- const helpOption = cmd._getHelpOption();
186
- if (helpOption && !helpOption.hidden) {
187
- const removeShort = helpOption.short && cmd._findOption(helpOption.short);
188
- const removeLong = helpOption.long && cmd._findOption(helpOption.long);
189
- if (!removeShort && !removeLong) {
190
- visibleOptions.push(helpOption);
191
- } else if (helpOption.long && !removeLong) {
192
- visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
193
- } else if (helpOption.short && !removeShort) {
194
- visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
195
- }
196
- }
197
- if (this.sortOptions) {
198
- visibleOptions.sort(this.compareOptions);
199
- }
200
- return visibleOptions;
201
- }
202
- visibleGlobalOptions(cmd) {
203
- if (!this.showGlobalOptions)
204
- return [];
205
- const globalOptions = [];
206
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
207
- const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
208
- globalOptions.push(...visibleOptions);
209
- }
210
- if (this.sortOptions) {
211
- globalOptions.sort(this.compareOptions);
212
- }
213
- return globalOptions;
214
- }
215
- visibleArguments(cmd) {
216
- if (cmd._argsDescription) {
217
- cmd.registeredArguments.forEach((argument) => {
218
- argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
219
- });
220
- }
221
- if (cmd.registeredArguments.find((argument) => argument.description)) {
222
- return cmd.registeredArguments;
223
- }
224
- return [];
225
- }
226
- subcommandTerm(cmd) {
227
- const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
228
- return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
229
- }
230
- optionTerm(option) {
231
- return option.flags;
232
- }
233
- argumentTerm(argument) {
234
- return argument.name();
235
- }
236
- longestSubcommandTermLength(cmd, helper) {
237
- return helper.visibleCommands(cmd).reduce((max, command) => {
238
- return Math.max(max, helper.subcommandTerm(command).length);
239
- }, 0);
240
- }
241
- longestOptionTermLength(cmd, helper) {
242
- return helper.visibleOptions(cmd).reduce((max, option) => {
243
- return Math.max(max, helper.optionTerm(option).length);
244
- }, 0);
245
- }
246
- longestGlobalOptionTermLength(cmd, helper) {
247
- return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
248
- return Math.max(max, helper.optionTerm(option).length);
249
- }, 0);
250
- }
251
- longestArgumentTermLength(cmd, helper) {
252
- return helper.visibleArguments(cmd).reduce((max, argument) => {
253
- return Math.max(max, helper.argumentTerm(argument).length);
254
- }, 0);
255
- }
256
- commandUsage(cmd) {
257
- let cmdName = cmd._name;
258
- if (cmd._aliases[0]) {
259
- cmdName = cmdName + "|" + cmd._aliases[0];
260
- }
261
- let ancestorCmdNames = "";
262
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
263
- ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
264
- }
265
- return ancestorCmdNames + cmdName + " " + cmd.usage();
266
- }
267
- commandDescription(cmd) {
268
- return cmd.description();
269
- }
270
- subcommandDescription(cmd) {
271
- return cmd.summary() || cmd.description();
272
- }
273
- optionDescription(option) {
274
- const extraInfo = [];
275
- if (option.argChoices) {
276
- extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
277
- }
278
- if (option.defaultValue !== undefined) {
279
- const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
280
- if (showDefault) {
281
- extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
282
- }
283
- }
284
- if (option.presetArg !== undefined && option.optional) {
285
- extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
286
- }
287
- if (option.envVar !== undefined) {
288
- extraInfo.push(`env: ${option.envVar}`);
289
- }
290
- if (extraInfo.length > 0) {
291
- return `${option.description} (${extraInfo.join(", ")})`;
292
- }
293
- return option.description;
294
- }
295
- argumentDescription(argument) {
296
- const extraInfo = [];
297
- if (argument.argChoices) {
298
- extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
299
- }
300
- if (argument.defaultValue !== undefined) {
301
- extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
302
- }
303
- if (extraInfo.length > 0) {
304
- const extraDescripton = `(${extraInfo.join(", ")})`;
305
- if (argument.description) {
306
- return `${argument.description} ${extraDescripton}`;
307
- }
308
- return extraDescripton;
309
- }
310
- return argument.description;
311
- }
312
- formatHelp(cmd, helper) {
313
- const termWidth = helper.padWidth(cmd, helper);
314
- const helpWidth = helper.helpWidth || 80;
315
- const itemIndentWidth = 2;
316
- const itemSeparatorWidth = 2;
317
- function formatItem(term, description) {
318
- if (description) {
319
- const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
320
- return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
321
- }
322
- return term;
323
- }
324
- function formatList(textArray) {
325
- return textArray.join(`
326
- `).replace(/^/gm, " ".repeat(itemIndentWidth));
327
- }
328
- let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
329
- const commandDescription = helper.commandDescription(cmd);
330
- if (commandDescription.length > 0) {
331
- output = output.concat([
332
- helper.wrap(commandDescription, helpWidth, 0),
333
- ""
334
- ]);
335
- }
336
- const argumentList = helper.visibleArguments(cmd).map((argument) => {
337
- return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
338
- });
339
- if (argumentList.length > 0) {
340
- output = output.concat(["Arguments:", formatList(argumentList), ""]);
341
- }
342
- const optionList = helper.visibleOptions(cmd).map((option) => {
343
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
344
- });
345
- if (optionList.length > 0) {
346
- output = output.concat(["Options:", formatList(optionList), ""]);
347
- }
348
- if (this.showGlobalOptions) {
349
- const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
350
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
351
- });
352
- if (globalOptionList.length > 0) {
353
- output = output.concat([
354
- "Global Options:",
355
- formatList(globalOptionList),
356
- ""
357
- ]);
358
- }
359
- }
360
- const commandList = helper.visibleCommands(cmd).map((cmd2) => {
361
- return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
362
- });
363
- if (commandList.length > 0) {
364
- output = output.concat(["Commands:", formatList(commandList), ""]);
365
- }
366
- return output.join(`
367
- `);
368
- }
369
- padWidth(cmd, helper) {
370
- return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
371
- }
372
- wrap(str, width, indent, minColumnWidth = 40) {
373
- const indents = " \\f\\t\\v   -    \uFEFF";
374
- const manualIndent = new RegExp(`[\\n][${indents}]+`);
375
- if (str.match(manualIndent))
376
- return str;
377
- const columnWidth = width - indent;
378
- if (columnWidth < minColumnWidth)
379
- return str;
380
- const leadingStr = str.slice(0, indent);
381
- const columnText = str.slice(indent).replace(`\r
382
- `, `
383
- `);
384
- const indentString = " ".repeat(indent);
385
- const zeroWidthSpace = "​";
386
- const breaks = `\\s${zeroWidthSpace}`;
387
- const regex = new RegExp(`
388
- |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
389
- const lines = columnText.match(regex) || [];
390
- return leadingStr + lines.map((line, i) => {
391
- if (line === `
392
- `)
393
- return "";
394
- return (i > 0 ? indentString : "") + line.trimEnd();
395
- }).join(`
396
- `);
397
- }
398
- }
399
- exports.Help = Help;
400
- });
401
-
402
- // node_modules/commander/lib/option.js
403
- var require_option = __commonJS((exports) => {
404
- var { InvalidArgumentError } = require_error();
405
-
406
- class Option {
407
- constructor(flags, description) {
408
- this.flags = flags;
409
- this.description = description || "";
410
- this.required = flags.includes("<");
411
- this.optional = flags.includes("[");
412
- this.variadic = /\w\.\.\.[>\]]$/.test(flags);
413
- this.mandatory = false;
414
- const optionFlags = splitOptionFlags(flags);
415
- this.short = optionFlags.shortFlag;
416
- this.long = optionFlags.longFlag;
417
- this.negate = false;
418
- if (this.long) {
419
- this.negate = this.long.startsWith("--no-");
420
- }
421
- this.defaultValue = undefined;
422
- this.defaultValueDescription = undefined;
423
- this.presetArg = undefined;
424
- this.envVar = undefined;
425
- this.parseArg = undefined;
426
- this.hidden = false;
427
- this.argChoices = undefined;
428
- this.conflictsWith = [];
429
- this.implied = undefined;
430
- }
431
- default(value, description) {
432
- this.defaultValue = value;
433
- this.defaultValueDescription = description;
434
- return this;
435
- }
436
- preset(arg) {
437
- this.presetArg = arg;
438
- return this;
439
- }
440
- conflicts(names) {
441
- this.conflictsWith = this.conflictsWith.concat(names);
442
- return this;
443
- }
444
- implies(impliedOptionValues) {
445
- let newImplied = impliedOptionValues;
446
- if (typeof impliedOptionValues === "string") {
447
- newImplied = { [impliedOptionValues]: true };
448
- }
449
- this.implied = Object.assign(this.implied || {}, newImplied);
450
- return this;
451
- }
452
- env(name) {
453
- this.envVar = name;
454
- return this;
455
- }
456
- argParser(fn) {
457
- this.parseArg = fn;
458
- return this;
459
- }
460
- makeOptionMandatory(mandatory = true) {
461
- this.mandatory = !!mandatory;
462
- return this;
463
- }
464
- hideHelp(hide = true) {
465
- this.hidden = !!hide;
466
- return this;
467
- }
468
- _concatValue(value, previous) {
469
- if (previous === this.defaultValue || !Array.isArray(previous)) {
470
- return [value];
471
- }
472
- return previous.concat(value);
473
- }
474
- choices(values) {
475
- this.argChoices = values.slice();
476
- this.parseArg = (arg, previous) => {
477
- if (!this.argChoices.includes(arg)) {
478
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
479
- }
480
- if (this.variadic) {
481
- return this._concatValue(arg, previous);
482
- }
483
- return arg;
484
- };
485
- return this;
486
- }
487
- name() {
488
- if (this.long) {
489
- return this.long.replace(/^--/, "");
490
- }
491
- return this.short.replace(/^-/, "");
492
- }
493
- attributeName() {
494
- return camelcase(this.name().replace(/^no-/, ""));
495
- }
496
- is(arg) {
497
- return this.short === arg || this.long === arg;
498
- }
499
- isBoolean() {
500
- return !this.required && !this.optional && !this.negate;
501
- }
502
- }
503
-
504
- class DualOptions {
505
- constructor(options) {
506
- this.positiveOptions = new Map;
507
- this.negativeOptions = new Map;
508
- this.dualOptions = new Set;
509
- options.forEach((option) => {
510
- if (option.negate) {
511
- this.negativeOptions.set(option.attributeName(), option);
512
- } else {
513
- this.positiveOptions.set(option.attributeName(), option);
514
- }
515
- });
516
- this.negativeOptions.forEach((value, key) => {
517
- if (this.positiveOptions.has(key)) {
518
- this.dualOptions.add(key);
519
- }
520
- });
521
- }
522
- valueFromOption(value, option) {
523
- const optionKey = option.attributeName();
524
- if (!this.dualOptions.has(optionKey))
525
- return true;
526
- const preset = this.negativeOptions.get(optionKey).presetArg;
527
- const negativeValue = preset !== undefined ? preset : false;
528
- return option.negate === (negativeValue === value);
529
- }
530
- }
531
- function camelcase(str) {
532
- return str.split("-").reduce((str2, word) => {
533
- return str2 + word[0].toUpperCase() + word.slice(1);
534
- });
535
- }
536
- function splitOptionFlags(flags) {
537
- let shortFlag;
538
- let longFlag;
539
- const flagParts = flags.split(/[ |,]+/);
540
- if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
541
- shortFlag = flagParts.shift();
542
- longFlag = flagParts.shift();
543
- if (!shortFlag && /^-[^-]$/.test(longFlag)) {
544
- shortFlag = longFlag;
545
- longFlag = undefined;
546
- }
547
- return { shortFlag, longFlag };
548
- }
549
- exports.Option = Option;
550
- exports.DualOptions = DualOptions;
551
- });
552
-
553
- // node_modules/commander/lib/suggestSimilar.js
554
- var require_suggestSimilar = __commonJS((exports) => {
555
- var maxDistance = 3;
556
- function editDistance(a, b) {
557
- if (Math.abs(a.length - b.length) > maxDistance)
558
- return Math.max(a.length, b.length);
559
- const d = [];
560
- for (let i = 0;i <= a.length; i++) {
561
- d[i] = [i];
562
- }
563
- for (let j = 0;j <= b.length; j++) {
564
- d[0][j] = j;
565
- }
566
- for (let j = 1;j <= b.length; j++) {
567
- for (let i = 1;i <= a.length; i++) {
568
- let cost = 1;
569
- if (a[i - 1] === b[j - 1]) {
570
- cost = 0;
571
- } else {
572
- cost = 1;
573
- }
574
- d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
575
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
576
- d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
577
- }
578
- }
579
- }
580
- return d[a.length][b.length];
581
- }
582
- function suggestSimilar(word, candidates) {
583
- if (!candidates || candidates.length === 0)
584
- return "";
585
- candidates = Array.from(new Set(candidates));
586
- const searchingOptions = word.startsWith("--");
587
- if (searchingOptions) {
588
- word = word.slice(2);
589
- candidates = candidates.map((candidate) => candidate.slice(2));
590
- }
591
- let similar = [];
592
- let bestDistance = maxDistance;
593
- const minSimilarity = 0.4;
594
- candidates.forEach((candidate) => {
595
- if (candidate.length <= 1)
596
- return;
597
- const distance = editDistance(word, candidate);
598
- const length = Math.max(word.length, candidate.length);
599
- const similarity = (length - distance) / length;
600
- if (similarity > minSimilarity) {
601
- if (distance < bestDistance) {
602
- bestDistance = distance;
603
- similar = [candidate];
604
- } else if (distance === bestDistance) {
605
- similar.push(candidate);
606
- }
607
- }
608
- });
609
- similar.sort((a, b) => a.localeCompare(b));
610
- if (searchingOptions) {
611
- similar = similar.map((candidate) => `--${candidate}`);
612
- }
613
- if (similar.length > 1) {
614
- return `
615
- (Did you mean one of ${similar.join(", ")}?)`;
616
- }
617
- if (similar.length === 1) {
618
- return `
619
- (Did you mean ${similar[0]}?)`;
620
- }
621
- return "";
622
- }
623
- exports.suggestSimilar = suggestSimilar;
624
- });
625
-
626
- // node_modules/commander/lib/command.js
627
- var require_command = __commonJS((exports) => {
628
- var EventEmitter = __require("node:events").EventEmitter;
629
- var childProcess = __require("node:child_process");
630
- var path = __require("node:path");
631
- var fs = __require("node:fs");
632
- var process2 = __require("node:process");
633
- var { Argument, humanReadableArgName } = require_argument();
634
- var { CommanderError } = require_error();
635
- var { Help } = require_help();
636
- var { Option, DualOptions } = require_option();
637
- var { suggestSimilar } = require_suggestSimilar();
638
-
639
- class Command extends EventEmitter {
640
- constructor(name) {
641
- super();
642
- this.commands = [];
643
- this.options = [];
644
- this.parent = null;
645
- this._allowUnknownOption = false;
646
- this._allowExcessArguments = true;
647
- this.registeredArguments = [];
648
- this._args = this.registeredArguments;
649
- this.args = [];
650
- this.rawArgs = [];
651
- this.processedArgs = [];
652
- this._scriptPath = null;
653
- this._name = name || "";
654
- this._optionValues = {};
655
- this._optionValueSources = {};
656
- this._storeOptionsAsProperties = false;
657
- this._actionHandler = null;
658
- this._executableHandler = false;
659
- this._executableFile = null;
660
- this._executableDir = null;
661
- this._defaultCommandName = null;
662
- this._exitCallback = null;
663
- this._aliases = [];
664
- this._combineFlagAndOptionalValue = true;
665
- this._description = "";
666
- this._summary = "";
667
- this._argsDescription = undefined;
668
- this._enablePositionalOptions = false;
669
- this._passThroughOptions = false;
670
- this._lifeCycleHooks = {};
671
- this._showHelpAfterError = false;
672
- this._showSuggestionAfterError = true;
673
- this._outputConfiguration = {
674
- writeOut: (str) => process2.stdout.write(str),
675
- writeErr: (str) => process2.stderr.write(str),
676
- getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
677
- getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
678
- outputError: (str, write) => write(str)
679
- };
680
- this._hidden = false;
681
- this._helpOption = undefined;
682
- this._addImplicitHelpCommand = undefined;
683
- this._helpCommand = undefined;
684
- this._helpConfiguration = {};
685
- }
686
- copyInheritedSettings(sourceCommand) {
687
- this._outputConfiguration = sourceCommand._outputConfiguration;
688
- this._helpOption = sourceCommand._helpOption;
689
- this._helpCommand = sourceCommand._helpCommand;
690
- this._helpConfiguration = sourceCommand._helpConfiguration;
691
- this._exitCallback = sourceCommand._exitCallback;
692
- this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
693
- this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
694
- this._allowExcessArguments = sourceCommand._allowExcessArguments;
695
- this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
696
- this._showHelpAfterError = sourceCommand._showHelpAfterError;
697
- this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
698
- return this;
699
- }
700
- _getCommandAndAncestors() {
701
- const result = [];
702
- for (let command = this;command; command = command.parent) {
703
- result.push(command);
704
- }
705
- return result;
706
- }
707
- command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
708
- let desc = actionOptsOrExecDesc;
709
- let opts = execOpts;
710
- if (typeof desc === "object" && desc !== null) {
711
- opts = desc;
712
- desc = null;
713
- }
714
- opts = opts || {};
715
- const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
716
- const cmd = this.createCommand(name);
717
- if (desc) {
718
- cmd.description(desc);
719
- cmd._executableHandler = true;
720
- }
721
- if (opts.isDefault)
722
- this._defaultCommandName = cmd._name;
723
- cmd._hidden = !!(opts.noHelp || opts.hidden);
724
- cmd._executableFile = opts.executableFile || null;
725
- if (args)
726
- cmd.arguments(args);
727
- this._registerCommand(cmd);
728
- cmd.parent = this;
729
- cmd.copyInheritedSettings(this);
730
- if (desc)
731
- return this;
732
- return cmd;
733
- }
734
- createCommand(name) {
735
- return new Command(name);
736
- }
737
- createHelp() {
738
- return Object.assign(new Help, this.configureHelp());
739
- }
740
- configureHelp(configuration) {
741
- if (configuration === undefined)
742
- return this._helpConfiguration;
743
- this._helpConfiguration = configuration;
744
- return this;
745
- }
746
- configureOutput(configuration) {
747
- if (configuration === undefined)
748
- return this._outputConfiguration;
749
- Object.assign(this._outputConfiguration, configuration);
750
- return this;
751
- }
752
- showHelpAfterError(displayHelp = true) {
753
- if (typeof displayHelp !== "string")
754
- displayHelp = !!displayHelp;
755
- this._showHelpAfterError = displayHelp;
756
- return this;
757
- }
758
- showSuggestionAfterError(displaySuggestion = true) {
759
- this._showSuggestionAfterError = !!displaySuggestion;
760
- return this;
761
- }
762
- addCommand(cmd, opts) {
763
- if (!cmd._name) {
764
- throw new Error(`Command passed to .addCommand() must have a name
765
- - specify the name in Command constructor or using .name()`);
766
- }
767
- opts = opts || {};
768
- if (opts.isDefault)
769
- this._defaultCommandName = cmd._name;
770
- if (opts.noHelp || opts.hidden)
771
- cmd._hidden = true;
772
- this._registerCommand(cmd);
773
- cmd.parent = this;
774
- cmd._checkForBrokenPassThrough();
775
- return this;
776
- }
777
- createArgument(name, description) {
778
- return new Argument(name, description);
779
- }
780
- argument(name, description, fn, defaultValue) {
781
- const argument = this.createArgument(name, description);
782
- if (typeof fn === "function") {
783
- argument.default(defaultValue).argParser(fn);
784
- } else {
785
- argument.default(fn);
786
- }
787
- this.addArgument(argument);
788
- return this;
789
- }
790
- arguments(names) {
791
- names.trim().split(/ +/).forEach((detail) => {
792
- this.argument(detail);
793
- });
794
- return this;
795
- }
796
- addArgument(argument) {
797
- const previousArgument = this.registeredArguments.slice(-1)[0];
798
- if (previousArgument && previousArgument.variadic) {
799
- throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
800
- }
801
- if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
802
- throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
803
- }
804
- this.registeredArguments.push(argument);
805
- return this;
806
- }
807
- helpCommand(enableOrNameAndArgs, description) {
808
- if (typeof enableOrNameAndArgs === "boolean") {
809
- this._addImplicitHelpCommand = enableOrNameAndArgs;
810
- return this;
811
- }
812
- enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
813
- const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
814
- const helpDescription = description ?? "display help for command";
815
- const helpCommand = this.createCommand(helpName);
816
- helpCommand.helpOption(false);
817
- if (helpArgs)
818
- helpCommand.arguments(helpArgs);
819
- if (helpDescription)
820
- helpCommand.description(helpDescription);
821
- this._addImplicitHelpCommand = true;
822
- this._helpCommand = helpCommand;
823
- return this;
824
- }
825
- addHelpCommand(helpCommand, deprecatedDescription) {
826
- if (typeof helpCommand !== "object") {
827
- this.helpCommand(helpCommand, deprecatedDescription);
828
- return this;
829
- }
830
- this._addImplicitHelpCommand = true;
831
- this._helpCommand = helpCommand;
832
- return this;
833
- }
834
- _getHelpCommand() {
835
- const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
836
- if (hasImplicitHelpCommand) {
837
- if (this._helpCommand === undefined) {
838
- this.helpCommand(undefined, undefined);
839
- }
840
- return this._helpCommand;
841
- }
842
- return null;
843
- }
844
- hook(event, listener) {
845
- const allowedValues = ["preSubcommand", "preAction", "postAction"];
846
- if (!allowedValues.includes(event)) {
847
- throw new Error(`Unexpected value for event passed to hook : '${event}'.
848
- Expecting one of '${allowedValues.join("', '")}'`);
849
- }
850
- if (this._lifeCycleHooks[event]) {
851
- this._lifeCycleHooks[event].push(listener);
852
- } else {
853
- this._lifeCycleHooks[event] = [listener];
854
- }
855
- return this;
856
- }
857
- exitOverride(fn) {
858
- if (fn) {
859
- this._exitCallback = fn;
860
- } else {
861
- this._exitCallback = (err) => {
862
- if (err.code !== "commander.executeSubCommandAsync") {
863
- throw err;
864
- } else {}
865
- };
866
- }
867
- return this;
868
- }
869
- _exit(exitCode, code, message) {
870
- if (this._exitCallback) {
871
- this._exitCallback(new CommanderError(exitCode, code, message));
872
- }
873
- process2.exit(exitCode);
874
- }
875
- action(fn) {
876
- const listener = (args) => {
877
- const expectedArgsCount = this.registeredArguments.length;
878
- const actionArgs = args.slice(0, expectedArgsCount);
879
- if (this._storeOptionsAsProperties) {
880
- actionArgs[expectedArgsCount] = this;
881
- } else {
882
- actionArgs[expectedArgsCount] = this.opts();
883
- }
884
- actionArgs.push(this);
885
- return fn.apply(this, actionArgs);
886
- };
887
- this._actionHandler = listener;
888
- return this;
889
- }
890
- createOption(flags, description) {
891
- return new Option(flags, description);
892
- }
893
- _callParseArg(target, value, previous, invalidArgumentMessage) {
894
- try {
895
- return target.parseArg(value, previous);
896
- } catch (err) {
897
- if (err.code === "commander.invalidArgument") {
898
- const message = `${invalidArgumentMessage} ${err.message}`;
899
- this.error(message, { exitCode: err.exitCode, code: err.code });
900
- }
901
- throw err;
902
- }
903
- }
904
- _registerOption(option) {
905
- const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
906
- if (matchingOption) {
907
- const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
908
- throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
909
- - already used by option '${matchingOption.flags}'`);
910
- }
911
- this.options.push(option);
912
- }
913
- _registerCommand(command) {
914
- const knownBy = (cmd) => {
915
- return [cmd.name()].concat(cmd.aliases());
916
- };
917
- const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
918
- if (alreadyUsed) {
919
- const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
920
- const newCmd = knownBy(command).join("|");
921
- throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
922
- }
923
- this.commands.push(command);
924
- }
925
- addOption(option) {
926
- this._registerOption(option);
927
- const oname = option.name();
928
- const name = option.attributeName();
929
- if (option.negate) {
930
- const positiveLongFlag = option.long.replace(/^--no-/, "--");
931
- if (!this._findOption(positiveLongFlag)) {
932
- this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
933
- }
934
- } else if (option.defaultValue !== undefined) {
935
- this.setOptionValueWithSource(name, option.defaultValue, "default");
936
- }
937
- const handleOptionValue = (val, invalidValueMessage, valueSource) => {
938
- if (val == null && option.presetArg !== undefined) {
939
- val = option.presetArg;
940
- }
941
- const oldValue = this.getOptionValue(name);
942
- if (val !== null && option.parseArg) {
943
- val = this._callParseArg(option, val, oldValue, invalidValueMessage);
944
- } else if (val !== null && option.variadic) {
945
- val = option._concatValue(val, oldValue);
946
- }
947
- if (val == null) {
948
- if (option.negate) {
949
- val = false;
950
- } else if (option.isBoolean() || option.optional) {
951
- val = true;
952
- } else {
953
- val = "";
954
- }
955
- }
956
- this.setOptionValueWithSource(name, val, valueSource);
957
- };
958
- this.on("option:" + oname, (val) => {
959
- const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
960
- handleOptionValue(val, invalidValueMessage, "cli");
961
- });
962
- if (option.envVar) {
963
- this.on("optionEnv:" + oname, (val) => {
964
- const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
965
- handleOptionValue(val, invalidValueMessage, "env");
966
- });
967
- }
968
- return this;
969
- }
970
- _optionEx(config, flags, description, fn, defaultValue) {
971
- if (typeof flags === "object" && flags instanceof Option) {
972
- throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
973
- }
974
- const option = this.createOption(flags, description);
975
- option.makeOptionMandatory(!!config.mandatory);
976
- if (typeof fn === "function") {
977
- option.default(defaultValue).argParser(fn);
978
- } else if (fn instanceof RegExp) {
979
- const regex = fn;
980
- fn = (val, def) => {
981
- const m = regex.exec(val);
982
- return m ? m[0] : def;
983
- };
984
- option.default(defaultValue).argParser(fn);
985
- } else {
986
- option.default(fn);
987
- }
988
- return this.addOption(option);
989
- }
990
- option(flags, description, parseArg, defaultValue) {
991
- return this._optionEx({}, flags, description, parseArg, defaultValue);
992
- }
993
- requiredOption(flags, description, parseArg, defaultValue) {
994
- return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
995
- }
996
- combineFlagAndOptionalValue(combine = true) {
997
- this._combineFlagAndOptionalValue = !!combine;
998
- return this;
999
- }
1000
- allowUnknownOption(allowUnknown = true) {
1001
- this._allowUnknownOption = !!allowUnknown;
1002
- return this;
1003
- }
1004
- allowExcessArguments(allowExcess = true) {
1005
- this._allowExcessArguments = !!allowExcess;
1006
- return this;
1007
- }
1008
- enablePositionalOptions(positional = true) {
1009
- this._enablePositionalOptions = !!positional;
1010
- return this;
1011
- }
1012
- passThroughOptions(passThrough = true) {
1013
- this._passThroughOptions = !!passThrough;
1014
- this._checkForBrokenPassThrough();
1015
- return this;
1016
- }
1017
- _checkForBrokenPassThrough() {
1018
- if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1019
- throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
1020
- }
1021
- }
1022
- storeOptionsAsProperties(storeAsProperties = true) {
1023
- if (this.options.length) {
1024
- throw new Error("call .storeOptionsAsProperties() before adding options");
1025
- }
1026
- if (Object.keys(this._optionValues).length) {
1027
- throw new Error("call .storeOptionsAsProperties() before setting option values");
1028
- }
1029
- this._storeOptionsAsProperties = !!storeAsProperties;
1030
- return this;
1031
- }
1032
- getOptionValue(key) {
1033
- if (this._storeOptionsAsProperties) {
1034
- return this[key];
1035
- }
1036
- return this._optionValues[key];
1037
- }
1038
- setOptionValue(key, value) {
1039
- return this.setOptionValueWithSource(key, value, undefined);
1040
- }
1041
- setOptionValueWithSource(key, value, source) {
1042
- if (this._storeOptionsAsProperties) {
1043
- this[key] = value;
1044
- } else {
1045
- this._optionValues[key] = value;
1046
- }
1047
- this._optionValueSources[key] = source;
1048
- return this;
1049
- }
1050
- getOptionValueSource(key) {
1051
- return this._optionValueSources[key];
1052
- }
1053
- getOptionValueSourceWithGlobals(key) {
1054
- let source;
1055
- this._getCommandAndAncestors().forEach((cmd) => {
1056
- if (cmd.getOptionValueSource(key) !== undefined) {
1057
- source = cmd.getOptionValueSource(key);
1058
- }
1059
- });
1060
- return source;
1061
- }
1062
- _prepareUserArgs(argv, parseOptions) {
1063
- if (argv !== undefined && !Array.isArray(argv)) {
1064
- throw new Error("first parameter to parse must be array or undefined");
1065
- }
1066
- parseOptions = parseOptions || {};
1067
- if (argv === undefined && parseOptions.from === undefined) {
1068
- if (process2.versions?.electron) {
1069
- parseOptions.from = "electron";
1070
- }
1071
- const execArgv = process2.execArgv ?? [];
1072
- if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
1073
- parseOptions.from = "eval";
1074
- }
1075
- }
1076
- if (argv === undefined) {
1077
- argv = process2.argv;
1078
- }
1079
- this.rawArgs = argv.slice();
1080
- let userArgs;
1081
- switch (parseOptions.from) {
1082
- case undefined:
1083
- case "node":
1084
- this._scriptPath = argv[1];
1085
- userArgs = argv.slice(2);
1086
- break;
1087
- case "electron":
1088
- if (process2.defaultApp) {
1089
- this._scriptPath = argv[1];
1090
- userArgs = argv.slice(2);
1091
- } else {
1092
- userArgs = argv.slice(1);
1093
- }
1094
- break;
1095
- case "user":
1096
- userArgs = argv.slice(0);
1097
- break;
1098
- case "eval":
1099
- userArgs = argv.slice(1);
1100
- break;
1101
- default:
1102
- throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
1103
- }
1104
- if (!this._name && this._scriptPath)
1105
- this.nameFromFilename(this._scriptPath);
1106
- this._name = this._name || "program";
1107
- return userArgs;
1108
- }
1109
- parse(argv, parseOptions) {
1110
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1111
- this._parseCommand([], userArgs);
1112
- return this;
1113
- }
1114
- async parseAsync(argv, parseOptions) {
1115
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1116
- await this._parseCommand([], userArgs);
1117
- return this;
1118
- }
1119
- _executeSubCommand(subcommand, args) {
1120
- args = args.slice();
1121
- let launchWithNode = false;
1122
- const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1123
- function findFile(baseDir, baseName) {
1124
- const localBin = path.resolve(baseDir, baseName);
1125
- if (fs.existsSync(localBin))
1126
- return localBin;
1127
- if (sourceExt.includes(path.extname(baseName)))
1128
- return;
1129
- const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1130
- if (foundExt)
1131
- return `${localBin}${foundExt}`;
1132
- return;
1133
- }
1134
- this._checkForMissingMandatoryOptions();
1135
- this._checkForConflictingOptions();
1136
- let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1137
- let executableDir = this._executableDir || "";
1138
- if (this._scriptPath) {
1139
- let resolvedScriptPath;
1140
- try {
1141
- resolvedScriptPath = fs.realpathSync(this._scriptPath);
1142
- } catch (err) {
1143
- resolvedScriptPath = this._scriptPath;
1144
- }
1145
- executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1146
- }
1147
- if (executableDir) {
1148
- let localFile = findFile(executableDir, executableFile);
1149
- if (!localFile && !subcommand._executableFile && this._scriptPath) {
1150
- const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1151
- if (legacyName !== this._name) {
1152
- localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1153
- }
1154
- }
1155
- executableFile = localFile || executableFile;
1156
- }
1157
- launchWithNode = sourceExt.includes(path.extname(executableFile));
1158
- let proc;
1159
- if (process2.platform !== "win32") {
1160
- if (launchWithNode) {
1161
- args.unshift(executableFile);
1162
- args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1163
- proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
1164
- } else {
1165
- proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1166
- }
1167
- } else {
1168
- args.unshift(executableFile);
1169
- args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1170
- proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
1171
- }
1172
- if (!proc.killed) {
1173
- const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1174
- signals.forEach((signal) => {
1175
- process2.on(signal, () => {
1176
- if (proc.killed === false && proc.exitCode === null) {
1177
- proc.kill(signal);
1178
- }
1179
- });
1180
- });
1181
- }
1182
- const exitCallback = this._exitCallback;
1183
- proc.on("close", (code) => {
1184
- code = code ?? 1;
1185
- if (!exitCallback) {
1186
- process2.exit(code);
1187
- } else {
1188
- exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
1189
- }
1190
- });
1191
- proc.on("error", (err) => {
1192
- if (err.code === "ENOENT") {
1193
- 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";
1194
- const executableMissing = `'${executableFile}' does not exist
1195
- - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1196
- - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1197
- - ${executableDirMessage}`;
1198
- throw new Error(executableMissing);
1199
- } else if (err.code === "EACCES") {
1200
- throw new Error(`'${executableFile}' not executable`);
1201
- }
1202
- if (!exitCallback) {
1203
- process2.exit(1);
1204
- } else {
1205
- const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
1206
- wrappedError.nestedError = err;
1207
- exitCallback(wrappedError);
1208
- }
1209
- });
1210
- this.runningCommand = proc;
1211
- }
1212
- _dispatchSubcommand(commandName, operands, unknown) {
1213
- const subCommand = this._findCommand(commandName);
1214
- if (!subCommand)
1215
- this.help({ error: true });
1216
- let promiseChain;
1217
- promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1218
- promiseChain = this._chainOrCall(promiseChain, () => {
1219
- if (subCommand._executableHandler) {
1220
- this._executeSubCommand(subCommand, operands.concat(unknown));
1221
- } else {
1222
- return subCommand._parseCommand(operands, unknown);
1223
- }
1224
- });
1225
- return promiseChain;
1226
- }
1227
- _dispatchHelpCommand(subcommandName) {
1228
- if (!subcommandName) {
1229
- this.help();
1230
- }
1231
- const subCommand = this._findCommand(subcommandName);
1232
- if (subCommand && !subCommand._executableHandler) {
1233
- subCommand.help();
1234
- }
1235
- return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
1236
- }
1237
- _checkNumberOfArguments() {
1238
- this.registeredArguments.forEach((arg, i) => {
1239
- if (arg.required && this.args[i] == null) {
1240
- this.missingArgument(arg.name());
1241
- }
1242
- });
1243
- if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1244
- return;
1245
- }
1246
- if (this.args.length > this.registeredArguments.length) {
1247
- this._excessArguments(this.args);
1248
- }
1249
- }
1250
- _processArguments() {
1251
- const myParseArg = (argument, value, previous) => {
1252
- let parsedValue = value;
1253
- if (value !== null && argument.parseArg) {
1254
- const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1255
- parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1256
- }
1257
- return parsedValue;
1258
- };
1259
- this._checkNumberOfArguments();
1260
- const processedArgs = [];
1261
- this.registeredArguments.forEach((declaredArg, index) => {
1262
- let value = declaredArg.defaultValue;
1263
- if (declaredArg.variadic) {
1264
- if (index < this.args.length) {
1265
- value = this.args.slice(index);
1266
- if (declaredArg.parseArg) {
1267
- value = value.reduce((processed, v) => {
1268
- return myParseArg(declaredArg, v, processed);
1269
- }, declaredArg.defaultValue);
1270
- }
1271
- } else if (value === undefined) {
1272
- value = [];
1273
- }
1274
- } else if (index < this.args.length) {
1275
- value = this.args[index];
1276
- if (declaredArg.parseArg) {
1277
- value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1278
- }
1279
- }
1280
- processedArgs[index] = value;
1281
- });
1282
- this.processedArgs = processedArgs;
1283
- }
1284
- _chainOrCall(promise, fn) {
1285
- if (promise && promise.then && typeof promise.then === "function") {
1286
- return promise.then(() => fn());
1287
- }
1288
- return fn();
1289
- }
1290
- _chainOrCallHooks(promise, event) {
1291
- let result = promise;
1292
- const hooks = [];
1293
- this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
1294
- hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1295
- hooks.push({ hookedCommand, callback });
1296
- });
1297
- });
1298
- if (event === "postAction") {
1299
- hooks.reverse();
1300
- }
1301
- hooks.forEach((hookDetail) => {
1302
- result = this._chainOrCall(result, () => {
1303
- return hookDetail.callback(hookDetail.hookedCommand, this);
1304
- });
1305
- });
1306
- return result;
1307
- }
1308
- _chainOrCallSubCommandHook(promise, subCommand, event) {
1309
- let result = promise;
1310
- if (this._lifeCycleHooks[event] !== undefined) {
1311
- this._lifeCycleHooks[event].forEach((hook) => {
1312
- result = this._chainOrCall(result, () => {
1313
- return hook(this, subCommand);
1314
- });
1315
- });
1316
- }
1317
- return result;
1318
- }
1319
- _parseCommand(operands, unknown) {
1320
- const parsed = this.parseOptions(unknown);
1321
- this._parseOptionsEnv();
1322
- this._parseOptionsImplied();
1323
- operands = operands.concat(parsed.operands);
1324
- unknown = parsed.unknown;
1325
- this.args = operands.concat(unknown);
1326
- if (operands && this._findCommand(operands[0])) {
1327
- return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1328
- }
1329
- if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1330
- return this._dispatchHelpCommand(operands[1]);
1331
- }
1332
- if (this._defaultCommandName) {
1333
- this._outputHelpIfRequested(unknown);
1334
- return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1335
- }
1336
- if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1337
- this.help({ error: true });
1338
- }
1339
- this._outputHelpIfRequested(parsed.unknown);
1340
- this._checkForMissingMandatoryOptions();
1341
- this._checkForConflictingOptions();
1342
- const checkForUnknownOptions = () => {
1343
- if (parsed.unknown.length > 0) {
1344
- this.unknownOption(parsed.unknown[0]);
1345
- }
1346
- };
1347
- const commandEvent = `command:${this.name()}`;
1348
- if (this._actionHandler) {
1349
- checkForUnknownOptions();
1350
- this._processArguments();
1351
- let promiseChain;
1352
- promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
1353
- promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1354
- if (this.parent) {
1355
- promiseChain = this._chainOrCall(promiseChain, () => {
1356
- this.parent.emit(commandEvent, operands, unknown);
1357
- });
1358
- }
1359
- promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1360
- return promiseChain;
1361
- }
1362
- if (this.parent && this.parent.listenerCount(commandEvent)) {
1363
- checkForUnknownOptions();
1364
- this._processArguments();
1365
- this.parent.emit(commandEvent, operands, unknown);
1366
- } else if (operands.length) {
1367
- if (this._findCommand("*")) {
1368
- return this._dispatchSubcommand("*", operands, unknown);
1369
- }
1370
- if (this.listenerCount("command:*")) {
1371
- this.emit("command:*", operands, unknown);
1372
- } else if (this.commands.length) {
1373
- this.unknownCommand();
1374
- } else {
1375
- checkForUnknownOptions();
1376
- this._processArguments();
1377
- }
1378
- } else if (this.commands.length) {
1379
- checkForUnknownOptions();
1380
- this.help({ error: true });
1381
- } else {
1382
- checkForUnknownOptions();
1383
- this._processArguments();
1384
- }
1385
- }
1386
- _findCommand(name) {
1387
- if (!name)
1388
- return;
1389
- return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
1390
- }
1391
- _findOption(arg) {
1392
- return this.options.find((option) => option.is(arg));
1393
- }
1394
- _checkForMissingMandatoryOptions() {
1395
- this._getCommandAndAncestors().forEach((cmd) => {
1396
- cmd.options.forEach((anOption) => {
1397
- if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
1398
- cmd.missingMandatoryOptionValue(anOption);
1399
- }
1400
- });
1401
- });
1402
- }
1403
- _checkForConflictingLocalOptions() {
1404
- const definedNonDefaultOptions = this.options.filter((option) => {
1405
- const optionKey = option.attributeName();
1406
- if (this.getOptionValue(optionKey) === undefined) {
1407
- return false;
1408
- }
1409
- return this.getOptionValueSource(optionKey) !== "default";
1410
- });
1411
- const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
1412
- optionsWithConflicting.forEach((option) => {
1413
- const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
1414
- if (conflictingAndDefined) {
1415
- this._conflictingOption(option, conflictingAndDefined);
1416
- }
1417
- });
1418
- }
1419
- _checkForConflictingOptions() {
1420
- this._getCommandAndAncestors().forEach((cmd) => {
1421
- cmd._checkForConflictingLocalOptions();
1422
- });
1423
- }
1424
- parseOptions(argv) {
1425
- const operands = [];
1426
- const unknown = [];
1427
- let dest = operands;
1428
- const args = argv.slice();
1429
- function maybeOption(arg) {
1430
- return arg.length > 1 && arg[0] === "-";
1431
- }
1432
- let activeVariadicOption = null;
1433
- while (args.length) {
1434
- const arg = args.shift();
1435
- if (arg === "--") {
1436
- if (dest === unknown)
1437
- dest.push(arg);
1438
- dest.push(...args);
1439
- break;
1440
- }
1441
- if (activeVariadicOption && !maybeOption(arg)) {
1442
- this.emit(`option:${activeVariadicOption.name()}`, arg);
1443
- continue;
1444
- }
1445
- activeVariadicOption = null;
1446
- if (maybeOption(arg)) {
1447
- const option = this._findOption(arg);
1448
- if (option) {
1449
- if (option.required) {
1450
- const value = args.shift();
1451
- if (value === undefined)
1452
- this.optionMissingArgument(option);
1453
- this.emit(`option:${option.name()}`, value);
1454
- } else if (option.optional) {
1455
- let value = null;
1456
- if (args.length > 0 && !maybeOption(args[0])) {
1457
- value = args.shift();
1458
- }
1459
- this.emit(`option:${option.name()}`, value);
1460
- } else {
1461
- this.emit(`option:${option.name()}`);
1462
- }
1463
- activeVariadicOption = option.variadic ? option : null;
1464
- continue;
1465
- }
1466
- }
1467
- if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
1468
- const option = this._findOption(`-${arg[1]}`);
1469
- if (option) {
1470
- if (option.required || option.optional && this._combineFlagAndOptionalValue) {
1471
- this.emit(`option:${option.name()}`, arg.slice(2));
1472
- } else {
1473
- this.emit(`option:${option.name()}`);
1474
- args.unshift(`-${arg.slice(2)}`);
1475
- }
1476
- continue;
1477
- }
1478
- }
1479
- if (/^--[^=]+=/.test(arg)) {
1480
- const index = arg.indexOf("=");
1481
- const option = this._findOption(arg.slice(0, index));
1482
- if (option && (option.required || option.optional)) {
1483
- this.emit(`option:${option.name()}`, arg.slice(index + 1));
1484
- continue;
1485
- }
1486
- }
1487
- if (maybeOption(arg)) {
1488
- dest = unknown;
1489
- }
1490
- if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1491
- if (this._findCommand(arg)) {
1492
- operands.push(arg);
1493
- if (args.length > 0)
1494
- unknown.push(...args);
1495
- break;
1496
- } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1497
- operands.push(arg);
1498
- if (args.length > 0)
1499
- operands.push(...args);
1500
- break;
1501
- } else if (this._defaultCommandName) {
1502
- unknown.push(arg);
1503
- if (args.length > 0)
1504
- unknown.push(...args);
1505
- break;
1506
- }
1507
- }
1508
- if (this._passThroughOptions) {
1509
- dest.push(arg);
1510
- if (args.length > 0)
1511
- dest.push(...args);
1512
- break;
1513
- }
1514
- dest.push(arg);
1515
- }
1516
- return { operands, unknown };
1517
- }
1518
- opts() {
1519
- if (this._storeOptionsAsProperties) {
1520
- const result = {};
1521
- const len = this.options.length;
1522
- for (let i = 0;i < len; i++) {
1523
- const key = this.options[i].attributeName();
1524
- result[key] = key === this._versionOptionName ? this._version : this[key];
1525
- }
1526
- return result;
1527
- }
1528
- return this._optionValues;
1529
- }
1530
- optsWithGlobals() {
1531
- return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
1532
- }
1533
- error(message, errorOptions) {
1534
- this._outputConfiguration.outputError(`${message}
1535
- `, this._outputConfiguration.writeErr);
1536
- if (typeof this._showHelpAfterError === "string") {
1537
- this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1538
- `);
1539
- } else if (this._showHelpAfterError) {
1540
- this._outputConfiguration.writeErr(`
1541
- `);
1542
- this.outputHelp({ error: true });
1543
- }
1544
- const config = errorOptions || {};
1545
- const exitCode = config.exitCode || 1;
1546
- const code = config.code || "commander.error";
1547
- this._exit(exitCode, code, message);
1548
- }
1549
- _parseOptionsEnv() {
1550
- this.options.forEach((option) => {
1551
- if (option.envVar && option.envVar in process2.env) {
1552
- const optionKey = option.attributeName();
1553
- if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
1554
- if (option.required || option.optional) {
1555
- this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
1556
- } else {
1557
- this.emit(`optionEnv:${option.name()}`);
1558
- }
1559
- }
1560
- }
1561
- });
1562
- }
1563
- _parseOptionsImplied() {
1564
- const dualHelper = new DualOptions(this.options);
1565
- const hasCustomOptionValue = (optionKey) => {
1566
- return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
1567
- };
1568
- this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
1569
- Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
1570
- this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
1571
- });
1572
- });
1573
- }
1574
- missingArgument(name) {
1575
- const message = `error: missing required argument '${name}'`;
1576
- this.error(message, { code: "commander.missingArgument" });
1577
- }
1578
- optionMissingArgument(option) {
1579
- const message = `error: option '${option.flags}' argument missing`;
1580
- this.error(message, { code: "commander.optionMissingArgument" });
1581
- }
1582
- missingMandatoryOptionValue(option) {
1583
- const message = `error: required option '${option.flags}' not specified`;
1584
- this.error(message, { code: "commander.missingMandatoryOptionValue" });
1585
- }
1586
- _conflictingOption(option, conflictingOption) {
1587
- const findBestOptionFromValue = (option2) => {
1588
- const optionKey = option2.attributeName();
1589
- const optionValue = this.getOptionValue(optionKey);
1590
- const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
1591
- const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
1592
- if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
1593
- return negativeOption;
1594
- }
1595
- return positiveOption || option2;
1596
- };
1597
- const getErrorMessage = (option2) => {
1598
- const bestOption = findBestOptionFromValue(option2);
1599
- const optionKey = bestOption.attributeName();
1600
- const source = this.getOptionValueSource(optionKey);
1601
- if (source === "env") {
1602
- return `environment variable '${bestOption.envVar}'`;
1603
- }
1604
- return `option '${bestOption.flags}'`;
1605
- };
1606
- const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1607
- this.error(message, { code: "commander.conflictingOption" });
1608
- }
1609
- unknownOption(flag) {
1610
- if (this._allowUnknownOption)
1611
- return;
1612
- let suggestion = "";
1613
- if (flag.startsWith("--") && this._showSuggestionAfterError) {
1614
- let candidateFlags = [];
1615
- let command = this;
1616
- do {
1617
- const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
1618
- candidateFlags = candidateFlags.concat(moreFlags);
1619
- command = command.parent;
1620
- } while (command && !command._enablePositionalOptions);
1621
- suggestion = suggestSimilar(flag, candidateFlags);
1622
- }
1623
- const message = `error: unknown option '${flag}'${suggestion}`;
1624
- this.error(message, { code: "commander.unknownOption" });
1625
- }
1626
- _excessArguments(receivedArgs) {
1627
- if (this._allowExcessArguments)
1628
- return;
1629
- const expected = this.registeredArguments.length;
1630
- const s = expected === 1 ? "" : "s";
1631
- const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
1632
- const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
1633
- this.error(message, { code: "commander.excessArguments" });
1634
- }
1635
- unknownCommand() {
1636
- const unknownName = this.args[0];
1637
- let suggestion = "";
1638
- if (this._showSuggestionAfterError) {
1639
- const candidateNames = [];
1640
- this.createHelp().visibleCommands(this).forEach((command) => {
1641
- candidateNames.push(command.name());
1642
- if (command.alias())
1643
- candidateNames.push(command.alias());
1644
- });
1645
- suggestion = suggestSimilar(unknownName, candidateNames);
1646
- }
1647
- const message = `error: unknown command '${unknownName}'${suggestion}`;
1648
- this.error(message, { code: "commander.unknownCommand" });
1649
- }
1650
- version(str, flags, description) {
1651
- if (str === undefined)
1652
- return this._version;
1653
- this._version = str;
1654
- flags = flags || "-V, --version";
1655
- description = description || "output the version number";
1656
- const versionOption = this.createOption(flags, description);
1657
- this._versionOptionName = versionOption.attributeName();
1658
- this._registerOption(versionOption);
1659
- this.on("option:" + versionOption.name(), () => {
1660
- this._outputConfiguration.writeOut(`${str}
1661
- `);
1662
- this._exit(0, "commander.version", str);
1663
- });
1664
- return this;
1665
- }
1666
- description(str, argsDescription) {
1667
- if (str === undefined && argsDescription === undefined)
1668
- return this._description;
1669
- this._description = str;
1670
- if (argsDescription) {
1671
- this._argsDescription = argsDescription;
1672
- }
1673
- return this;
1674
- }
1675
- summary(str) {
1676
- if (str === undefined)
1677
- return this._summary;
1678
- this._summary = str;
1679
- return this;
1680
- }
1681
- alias(alias) {
1682
- if (alias === undefined)
1683
- return this._aliases[0];
1684
- let command = this;
1685
- if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1686
- command = this.commands[this.commands.length - 1];
1687
- }
1688
- if (alias === command._name)
1689
- throw new Error("Command alias can't be the same as its name");
1690
- const matchingCommand = this.parent?._findCommand(alias);
1691
- if (matchingCommand) {
1692
- const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
1693
- throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1694
- }
1695
- command._aliases.push(alias);
1696
- return this;
1697
- }
1698
- aliases(aliases) {
1699
- if (aliases === undefined)
1700
- return this._aliases;
1701
- aliases.forEach((alias) => this.alias(alias));
1702
- return this;
1703
- }
1704
- usage(str) {
1705
- if (str === undefined) {
1706
- if (this._usage)
1707
- return this._usage;
1708
- const args = this.registeredArguments.map((arg) => {
1709
- return humanReadableArgName(arg);
1710
- });
1711
- return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
1712
- }
1713
- this._usage = str;
1714
- return this;
1715
- }
1716
- name(str) {
1717
- if (str === undefined)
1718
- return this._name;
1719
- this._name = str;
1720
- return this;
1721
- }
1722
- nameFromFilename(filename) {
1723
- this._name = path.basename(filename, path.extname(filename));
1724
- return this;
1725
- }
1726
- executableDir(path2) {
1727
- if (path2 === undefined)
1728
- return this._executableDir;
1729
- this._executableDir = path2;
1730
- return this;
1731
- }
1732
- helpInformation(contextOptions) {
1733
- const helper = this.createHelp();
1734
- if (helper.helpWidth === undefined) {
1735
- helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
1736
- }
1737
- return helper.formatHelp(this, helper);
1738
- }
1739
- _getHelpContext(contextOptions) {
1740
- contextOptions = contextOptions || {};
1741
- const context = { error: !!contextOptions.error };
1742
- let write;
1743
- if (context.error) {
1744
- write = (arg) => this._outputConfiguration.writeErr(arg);
1745
- } else {
1746
- write = (arg) => this._outputConfiguration.writeOut(arg);
1747
- }
1748
- context.write = contextOptions.write || write;
1749
- context.command = this;
1750
- return context;
1751
- }
1752
- outputHelp(contextOptions) {
1753
- let deprecatedCallback;
1754
- if (typeof contextOptions === "function") {
1755
- deprecatedCallback = contextOptions;
1756
- contextOptions = undefined;
1757
- }
1758
- const context = this._getHelpContext(contextOptions);
1759
- this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
1760
- this.emit("beforeHelp", context);
1761
- let helpInformation = this.helpInformation(context);
1762
- if (deprecatedCallback) {
1763
- helpInformation = deprecatedCallback(helpInformation);
1764
- if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1765
- throw new Error("outputHelp callback must return a string or a Buffer");
1766
- }
1767
- }
1768
- context.write(helpInformation);
1769
- if (this._getHelpOption()?.long) {
1770
- this.emit(this._getHelpOption().long);
1771
- }
1772
- this.emit("afterHelp", context);
1773
- this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
1774
- }
1775
- helpOption(flags, description) {
1776
- if (typeof flags === "boolean") {
1777
- if (flags) {
1778
- this._helpOption = this._helpOption ?? undefined;
1779
- } else {
1780
- this._helpOption = null;
1781
- }
1782
- return this;
1783
- }
1784
- flags = flags ?? "-h, --help";
1785
- description = description ?? "display help for command";
1786
- this._helpOption = this.createOption(flags, description);
1787
- return this;
1788
- }
1789
- _getHelpOption() {
1790
- if (this._helpOption === undefined) {
1791
- this.helpOption(undefined, undefined);
1792
- }
1793
- return this._helpOption;
1794
- }
1795
- addHelpOption(option) {
1796
- this._helpOption = option;
1797
- return this;
1798
- }
1799
- help(contextOptions) {
1800
- this.outputHelp(contextOptions);
1801
- let exitCode = process2.exitCode || 0;
1802
- if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
1803
- exitCode = 1;
1804
- }
1805
- this._exit(exitCode, "commander.help", "(outputHelp)");
1806
- }
1807
- addHelpText(position, text) {
1808
- const allowedValues = ["beforeAll", "before", "after", "afterAll"];
1809
- if (!allowedValues.includes(position)) {
1810
- throw new Error(`Unexpected value for position to addHelpText.
1811
- Expecting one of '${allowedValues.join("', '")}'`);
1812
- }
1813
- const helpEvent = `${position}Help`;
1814
- this.on(helpEvent, (context) => {
1815
- let helpStr;
1816
- if (typeof text === "function") {
1817
- helpStr = text({ error: context.error, command: context.command });
1818
- } else {
1819
- helpStr = text;
1820
- }
1821
- if (helpStr) {
1822
- context.write(`${helpStr}
1823
- `);
1824
- }
1825
- });
1826
- return this;
1827
- }
1828
- _outputHelpIfRequested(args) {
1829
- const helpOption = this._getHelpOption();
1830
- const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
1831
- if (helpRequested) {
1832
- this.outputHelp();
1833
- this._exit(0, "commander.helpDisplayed", "(outputHelp)");
1834
- }
1835
- }
1836
- }
1837
- function incrementNodeInspectorPort(args) {
1838
- return args.map((arg) => {
1839
- if (!arg.startsWith("--inspect")) {
1840
- return arg;
1841
- }
1842
- let debugOption;
1843
- let debugHost = "127.0.0.1";
1844
- let debugPort = "9229";
1845
- let match;
1846
- if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
1847
- debugOption = match[1];
1848
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
1849
- debugOption = match[1];
1850
- if (/^\d+$/.test(match[3])) {
1851
- debugPort = match[3];
1852
- } else {
1853
- debugHost = match[3];
1854
- }
1855
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
1856
- debugOption = match[1];
1857
- debugHost = match[3];
1858
- debugPort = match[4];
1859
- }
1860
- if (debugOption && debugPort !== "0") {
1861
- return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
1862
- }
1863
- return arg;
1864
- });
1865
- }
1866
- exports.Command = Command;
1867
- });
1868
-
1869
- // node_modules/commander/index.js
1870
- var require_commander = __commonJS((exports) => {
1871
- var { Argument } = require_argument();
1872
- var { Command } = require_command();
1873
- var { CommanderError, InvalidArgumentError } = require_error();
1874
- var { Help } = require_help();
1875
- var { Option } = require_option();
1876
- exports.program = new Command;
1877
- exports.createCommand = (name) => new Command(name);
1878
- exports.createOption = (flags, description) => new Option(flags, description);
1879
- exports.createArgument = (name, description) => new Argument(name, description);
1880
- exports.Command = Command;
1881
- exports.Option = Option;
1882
- exports.Argument = Argument;
1883
- exports.Help = Help;
1884
- exports.CommanderError = CommanderError;
1885
- exports.InvalidArgumentError = InvalidArgumentError;
1886
- exports.InvalidOptionArgumentError = InvalidArgumentError;
1887
- });
1888
-
1889
50
  // src/core/paths.ts
1890
51
  import { join, dirname } from "path";
1891
52
  import { homedir } from "os";
@@ -10230,7 +8391,7 @@ function checkLatestVersion() {
10230
8391
  }
10231
8392
  }
10232
8393
  function getCurrentVersion() {
10233
- return "0.15.11";
8394
+ return "0.15.13";
10234
8395
  }
10235
8396
  function formatVersionLine(current, skipCheck) {
10236
8397
  if (skipCheck) {
@@ -12443,7 +10604,7 @@ async function execute17(paths) {
12443
10604
  const gm = new GenerationManager(paths);
12444
10605
  const state = await gm.current();
12445
10606
  const configContent = await readTextFile(paths.config);
12446
- const installedVersion = "0.15.11";
10607
+ const installedVersion = "0.15.13";
12447
10608
  const autoUpdate = configContent?.match(/autoUpdate:\s*(true|false)/)?.[1] === "true";
12448
10609
  const versionDisplay = formatVersionLine(installedVersion, !autoUpdate);
12449
10610
  const rawLang = detectLanguage(configContent);
@@ -14171,7 +12332,7 @@ async function execute30(paths) {
14171
12332
  const lines = [
14172
12333
  `REAP Configuration (${paths.config})`,
14173
12334
  "",
14174
- ` version: ${"0.15.11"} (package)`,
12335
+ ` version: ${"0.15.13"} (package)`,
14175
12336
  ` project: ${config.project}`,
14176
12337
  ` entryMode: ${config.entryMode}`,
14177
12338
  ` strict: ${config.strict ?? false}`,
@@ -14477,7 +12638,7 @@ async function runCommand(command, phase, argv = []) {
14477
12638
  try {
14478
12639
  const config = await ConfigManager.read(paths);
14479
12640
  if (config.autoIssueReport) {
14480
- const version = "0.15.11";
12641
+ const version = "0.15.13";
14481
12642
  const errMsg = err instanceof Error ? err.message : String(err);
14482
12643
  const title = `[auto] reap run ${command}: ${errMsg.slice(0, 80)}`;
14483
12644
  const body = [
@@ -14531,21 +12692,692 @@ var init_run = __esm(() => {
14531
12692
  };
14532
12693
  });
14533
12694
 
14534
- // node_modules/commander/esm.mjs
14535
- var import__ = __toESM(require_commander(), 1);
14536
- var {
14537
- program,
14538
- createCommand,
14539
- createArgument,
14540
- createOption,
14541
- CommanderError,
14542
- InvalidArgumentError,
14543
- InvalidOptionArgumentError,
14544
- Command,
14545
- Argument,
14546
- Option,
14547
- Help
14548
- } = import__.default;
12695
+ // src/libs/cli.ts
12696
+ function parseOptionFlags(flags) {
12697
+ const parts = flags.split(/,\s*/);
12698
+ let short;
12699
+ let long = "";
12700
+ let boolean = true;
12701
+ let required = false;
12702
+ let variadic = false;
12703
+ let argName;
12704
+ let negate = false;
12705
+ for (const part of parts) {
12706
+ const trimmed = part.trim();
12707
+ if (trimmed.startsWith("--")) {
12708
+ const match = trimmed.match(/^(--\S+)\s*(.*)$/);
12709
+ if (match) {
12710
+ long = match[1];
12711
+ const valuePart = match[2].trim();
12712
+ if (valuePart) {
12713
+ boolean = false;
12714
+ if (valuePart.startsWith("<")) {
12715
+ required = true;
12716
+ argName = valuePart.replace(/[<>]/g, "").replace(/\.{3}$/, "");
12717
+ variadic = valuePart.includes("...");
12718
+ } else if (valuePart.startsWith("[")) {
12719
+ required = false;
12720
+ argName = valuePart.replace(/[\[\]]/g, "").replace(/\.{3}$/, "");
12721
+ variadic = valuePart.includes("...");
12722
+ }
12723
+ }
12724
+ }
12725
+ } else if (trimmed.startsWith("-")) {
12726
+ const match = trimmed.match(/^(-\S)\s*(.*)$/);
12727
+ if (match) {
12728
+ short = match[1];
12729
+ const valuePart = match[2].trim();
12730
+ if (valuePart && !long) {
12731
+ boolean = false;
12732
+ if (valuePart.startsWith("<")) {
12733
+ required = true;
12734
+ argName = valuePart.replace(/[<>]/g, "").replace(/\.{3}$/, "");
12735
+ variadic = valuePart.includes("...");
12736
+ } else if (valuePart.startsWith("[")) {
12737
+ required = false;
12738
+ argName = valuePart.replace(/[\[\]]/g, "").replace(/\.{3}$/, "");
12739
+ variadic = valuePart.includes("...");
12740
+ }
12741
+ }
12742
+ }
12743
+ }
12744
+ }
12745
+ if (long.startsWith("--no-")) {
12746
+ negate = true;
12747
+ boolean = true;
12748
+ }
12749
+ return { short, long, boolean, required, variadic, argName, negate };
12750
+ }
12751
+ function optionAttributeName(long) {
12752
+ let name = long.replace(/^--/, "").replace(/^no-/, "");
12753
+ return name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
12754
+ }
12755
+ function parseArgumentSyntax(syntax) {
12756
+ const trimmed = syntax.trim();
12757
+ let required = false;
12758
+ let variadic = false;
12759
+ let name = trimmed;
12760
+ if (trimmed.startsWith("<") && trimmed.endsWith(">")) {
12761
+ required = true;
12762
+ name = trimmed.slice(1, -1);
12763
+ } else if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
12764
+ required = false;
12765
+ name = trimmed.slice(1, -1);
12766
+ }
12767
+ if (name.endsWith("...")) {
12768
+ variadic = true;
12769
+ name = name.slice(0, -3);
12770
+ }
12771
+ return { name, required, variadic };
12772
+ }
12773
+
12774
+ class Command {
12775
+ _name = "";
12776
+ _description = "";
12777
+ _version = "";
12778
+ _versionFlags = "-V, --version";
12779
+ _aliases = [];
12780
+ _options = [];
12781
+ _arguments = [];
12782
+ _commands = [];
12783
+ _actionHandler;
12784
+ _parent;
12785
+ _allowUnknown = false;
12786
+ _passthrough = false;
12787
+ _helpOption = {
12788
+ flags: "-h, --help",
12789
+ description: "display help for command"
12790
+ };
12791
+ _preActionHooks = [];
12792
+ _postActionHooks = [];
12793
+ _showHelpAfterError = false;
12794
+ _configureOutput;
12795
+ _exitCallback;
12796
+ _exitOverride = false;
12797
+ _executableHandler = false;
12798
+ _defaultCommandName;
12799
+ _addHelpCommand;
12800
+ _hidden = false;
12801
+ _combineFlagAndOptionalValue = true;
12802
+ _rawArgs = [];
12803
+ constructor(name) {
12804
+ if (name)
12805
+ this._name = name;
12806
+ }
12807
+ name(str) {
12808
+ if (str === undefined)
12809
+ return this._name;
12810
+ this._name = str;
12811
+ return this;
12812
+ }
12813
+ description(str) {
12814
+ if (str === undefined)
12815
+ return this._description;
12816
+ this._description = str;
12817
+ return this;
12818
+ }
12819
+ version(str, flags, _description) {
12820
+ if (str === undefined)
12821
+ return this._version;
12822
+ this._version = str;
12823
+ if (flags)
12824
+ this._versionFlags = flags;
12825
+ return this;
12826
+ }
12827
+ alias(name) {
12828
+ this._aliases.push(name);
12829
+ return this;
12830
+ }
12831
+ aliases(names) {
12832
+ names.forEach((n) => this._aliases.push(n));
12833
+ return this;
12834
+ }
12835
+ command(nameAndArgs, descOrOpts, opts) {
12836
+ const parts = nameAndArgs.trim().split(/\s+/);
12837
+ const cmdName = parts[0];
12838
+ const argDefs = parts.slice(1);
12839
+ if (typeof descOrOpts === "string") {
12840
+ const sub2 = new Command(cmdName);
12841
+ sub2._description = descOrOpts;
12842
+ sub2._executableHandler = true;
12843
+ sub2._parent = this;
12844
+ if (opts?.hidden)
12845
+ sub2._hidden = true;
12846
+ if (opts?.isDefault)
12847
+ this._defaultCommandName = cmdName;
12848
+ for (const argStr of argDefs) {
12849
+ const argDef = parseArgumentSyntax(argStr);
12850
+ sub2._arguments.push({ ...argDef, description: "", defaultValue: undefined });
12851
+ }
12852
+ this._commands.push(sub2);
12853
+ return this;
12854
+ }
12855
+ const sub = new Command(cmdName);
12856
+ sub._parent = this;
12857
+ if (descOrOpts?.hidden)
12858
+ sub._hidden = true;
12859
+ if (descOrOpts?.isDefault)
12860
+ this._defaultCommandName = cmdName;
12861
+ for (const argStr of argDefs) {
12862
+ const argDef = parseArgumentSyntax(argStr);
12863
+ sub._arguments.push({ ...argDef, description: "", defaultValue: undefined });
12864
+ }
12865
+ this._commands.push(sub);
12866
+ return sub;
12867
+ }
12868
+ addCommand(cmd, opts) {
12869
+ cmd._parent = this;
12870
+ if (opts?.hidden)
12871
+ cmd._hidden = true;
12872
+ if (opts?.isDefault)
12873
+ this._defaultCommandName = cmd._name;
12874
+ this._commands.push(cmd);
12875
+ return this;
12876
+ }
12877
+ argument(syntax, description, defaultValue) {
12878
+ const argDef = parseArgumentSyntax(syntax);
12879
+ this._arguments.push({
12880
+ ...argDef,
12881
+ description: description ?? "",
12882
+ defaultValue
12883
+ });
12884
+ return this;
12885
+ }
12886
+ arguments(syntax) {
12887
+ const parts = syntax.trim().split(/\s+/);
12888
+ for (const part of parts) {
12889
+ this.argument(part);
12890
+ }
12891
+ return this;
12892
+ }
12893
+ option(flags, description, defaultValue) {
12894
+ const parsed = parseOptionFlags(flags);
12895
+ this._options.push({
12896
+ ...parsed,
12897
+ description: description ?? "",
12898
+ required: parsed.required,
12899
+ defaultValue,
12900
+ negate: parsed.negate
12901
+ });
12902
+ return this;
12903
+ }
12904
+ requiredOption(flags, description, defaultValue) {
12905
+ const parsed = parseOptionFlags(flags);
12906
+ this._options.push({
12907
+ ...parsed,
12908
+ description: description ?? "",
12909
+ required: true,
12910
+ defaultValue,
12911
+ negate: parsed.negate
12912
+ });
12913
+ return this;
12914
+ }
12915
+ addOption(opt) {
12916
+ this._options.push(opt);
12917
+ return this;
12918
+ }
12919
+ action(fn) {
12920
+ this._actionHandler = fn;
12921
+ return this;
12922
+ }
12923
+ allowUnknownOption(allow = true) {
12924
+ this._allowUnknown = allow;
12925
+ return this;
12926
+ }
12927
+ allowExcessArguments(_allow = true) {
12928
+ return this;
12929
+ }
12930
+ enablePositionalOptions(_enable = true) {
12931
+ return this;
12932
+ }
12933
+ passThroughOptions(passthrough = true) {
12934
+ this._passthrough = passthrough;
12935
+ return this;
12936
+ }
12937
+ storeOptionsAsProperties(_store = true) {
12938
+ return this;
12939
+ }
12940
+ combineFlagAndOptionalValue(combine = true) {
12941
+ this._combineFlagAndOptionalValue = combine;
12942
+ return this;
12943
+ }
12944
+ helpOption(flags, description) {
12945
+ if (flags === false) {
12946
+ this._helpOption = false;
12947
+ } else {
12948
+ this._helpOption = { flags, description: description ?? "display help for command" };
12949
+ }
12950
+ return this;
12951
+ }
12952
+ addHelpText(_position, _text) {
12953
+ return this;
12954
+ }
12955
+ addHelpCommand(enable) {
12956
+ if (typeof enable === "boolean") {
12957
+ this._addHelpCommand = enable;
12958
+ } else {
12959
+ this._addHelpCommand = true;
12960
+ }
12961
+ return this;
12962
+ }
12963
+ showHelpAfterError(show = true) {
12964
+ this._showHelpAfterError = show;
12965
+ return this;
12966
+ }
12967
+ showSuggestionAfterError(_show = true) {
12968
+ return this;
12969
+ }
12970
+ configureOutput(config) {
12971
+ this._configureOutput = config;
12972
+ return this;
12973
+ }
12974
+ exitOverride(fn) {
12975
+ this._exitOverride = true;
12976
+ if (fn)
12977
+ this._exitCallback = (_code, err) => {
12978
+ if (err)
12979
+ fn(err);
12980
+ };
12981
+ return this;
12982
+ }
12983
+ hook(event, fn) {
12984
+ if (event === "preAction")
12985
+ this._preActionHooks.push(fn);
12986
+ else
12987
+ this._postActionHooks.push(fn);
12988
+ return this;
12989
+ }
12990
+ hidden(hide = true) {
12991
+ this._hidden = hide;
12992
+ return this;
12993
+ }
12994
+ get args() {
12995
+ return this._rawArgs;
12996
+ }
12997
+ get commands() {
12998
+ return this._commands;
12999
+ }
13000
+ get parent() {
13001
+ return this._parent;
13002
+ }
13003
+ opts() {
13004
+ return this._parsedOptions;
13005
+ }
13006
+ getOptionValue(key) {
13007
+ return this._parsedOptions?.[key];
13008
+ }
13009
+ setOptionValue(key, value) {
13010
+ this._parsedOptions[key] = value;
13011
+ return this;
13012
+ }
13013
+ _parsedOptions = {};
13014
+ parse(argv, opts) {
13015
+ const args = argv ?? process.argv;
13016
+ const from = opts?.from ?? "node";
13017
+ const userArgs = from === "user" ? args : args.slice(2);
13018
+ this._parseArgs(userArgs);
13019
+ return this;
13020
+ }
13021
+ parseAsync(argv, opts) {
13022
+ const args = argv ?? process.argv;
13023
+ const from = opts?.from ?? "node";
13024
+ const userArgs = from === "user" ? args : args.slice(2);
13025
+ return this._parseArgs(userArgs, true);
13026
+ }
13027
+ _parseArgs(argv, async = false) {
13028
+ this._parsedOptions = {};
13029
+ this._rawArgs = [];
13030
+ for (const opt of this._options) {
13031
+ if (opt.defaultValue !== undefined) {
13032
+ const key = optionAttributeName(opt.long);
13033
+ this._parsedOptions[key] = opt.defaultValue;
13034
+ }
13035
+ if (opt.negate) {
13036
+ const key = optionAttributeName(opt.long);
13037
+ this._parsedOptions[key] = true;
13038
+ }
13039
+ }
13040
+ const firstNonFlag = argv.find((a) => !a.startsWith("-"));
13041
+ if (firstNonFlag) {
13042
+ const sub = this._findCommand(firstNonFlag);
13043
+ if (sub) {
13044
+ const idx = argv.indexOf(firstNonFlag);
13045
+ const subArgv = [...argv.slice(0, idx), ...argv.slice(idx + 1)];
13046
+ if (async) {
13047
+ return sub._parseArgs(subArgv, true);
13048
+ }
13049
+ sub._parseArgs(subArgv);
13050
+ return this;
13051
+ }
13052
+ }
13053
+ if (this._version) {
13054
+ const vParsed = parseOptionFlags(this._versionFlags);
13055
+ if (argv.includes(vParsed.long) || vParsed.short && argv.includes(vParsed.short)) {
13056
+ this._writeOut(`${this._version}
13057
+ `);
13058
+ this._exit(0);
13059
+ return this;
13060
+ }
13061
+ }
13062
+ if (this._helpOption && this._checkHelp(argv)) {
13063
+ this.outputHelp();
13064
+ this._exit(0);
13065
+ return this;
13066
+ }
13067
+ if (!firstNonFlag) {
13068
+ if (this._defaultCommandName) {
13069
+ const defaultCmd = this._findCommand(this._defaultCommandName);
13070
+ if (defaultCmd) {
13071
+ if (async) {
13072
+ return defaultCmd._parseArgs(argv, true);
13073
+ }
13074
+ defaultCmd._parseArgs(argv);
13075
+ return this;
13076
+ }
13077
+ }
13078
+ }
13079
+ const positionals = [];
13080
+ const unknowns = [];
13081
+ let i = 0;
13082
+ while (i < argv.length) {
13083
+ const arg = argv[i];
13084
+ if (arg === "--") {
13085
+ positionals.push(...argv.slice(i + 1));
13086
+ break;
13087
+ }
13088
+ if (arg.startsWith("--")) {
13089
+ const eqIdx = arg.indexOf("=");
13090
+ const flag = eqIdx !== -1 ? arg.slice(0, eqIdx) : arg;
13091
+ const opt = this._findOption(flag);
13092
+ if (opt) {
13093
+ const key = optionAttributeName(opt.long);
13094
+ if (opt.negate) {
13095
+ this._parsedOptions[key] = false;
13096
+ } else if (opt.boolean) {
13097
+ this._parsedOptions[key] = true;
13098
+ } else if (eqIdx !== -1) {
13099
+ const val = arg.slice(eqIdx + 1);
13100
+ this._parsedOptions[key] = opt.variadic ? [...this._parsedOptions[key] ?? [], val] : val;
13101
+ } else {
13102
+ i++;
13103
+ if (i >= argv.length) {
13104
+ this._writeErr(`error: option '${flag}' argument missing
13105
+ `);
13106
+ this._exit(1);
13107
+ return this;
13108
+ }
13109
+ const val = argv[i];
13110
+ if (opt.variadic) {
13111
+ const arr = this._parsedOptions[key] ?? [];
13112
+ arr.push(val);
13113
+ this._parsedOptions[key] = arr;
13114
+ while (i + 1 < argv.length && !argv[i + 1].startsWith("-")) {
13115
+ i++;
13116
+ arr.push(argv[i]);
13117
+ }
13118
+ } else {
13119
+ this._parsedOptions[key] = val;
13120
+ }
13121
+ }
13122
+ } else if (this._allowUnknown) {
13123
+ unknowns.push(arg);
13124
+ if (eqIdx === -1 && i + 1 < argv.length && !argv[i + 1].startsWith("-")) {
13125
+ i++;
13126
+ unknowns.push(argv[i]);
13127
+ }
13128
+ } else {
13129
+ this._writeErr(`error: unknown option '${arg}'
13130
+ `);
13131
+ if (this._showHelpAfterError)
13132
+ this.outputHelp();
13133
+ this._exit(1);
13134
+ return this;
13135
+ }
13136
+ } else if (arg.startsWith("-") && arg.length > 1 && !arg.startsWith("-")) {
13137
+ const chars = arg.slice(1);
13138
+ for (let j = 0;j < chars.length; j++) {
13139
+ const flag = `-${chars[j]}`;
13140
+ const opt = this._findOption(flag);
13141
+ if (opt) {
13142
+ const key = optionAttributeName(opt.long);
13143
+ if (opt.boolean) {
13144
+ if (opt.negate) {
13145
+ this._parsedOptions[key] = false;
13146
+ } else {
13147
+ this._parsedOptions[key] = true;
13148
+ }
13149
+ } else {
13150
+ const rest = chars.slice(j + 1);
13151
+ if (rest && this._combineFlagAndOptionalValue) {
13152
+ this._parsedOptions[key] = rest;
13153
+ } else if (rest) {
13154
+ this._parsedOptions[key] = rest;
13155
+ } else {
13156
+ i++;
13157
+ if (i >= argv.length) {
13158
+ this._writeErr(`error: option '${flag}' argument missing
13159
+ `);
13160
+ this._exit(1);
13161
+ return this;
13162
+ }
13163
+ this._parsedOptions[key] = argv[i];
13164
+ }
13165
+ break;
13166
+ }
13167
+ } else if (this._allowUnknown) {
13168
+ unknowns.push(flag);
13169
+ } else {
13170
+ this._writeErr(`error: unknown option '${flag}'
13171
+ `);
13172
+ if (this._showHelpAfterError)
13173
+ this.outputHelp();
13174
+ this._exit(1);
13175
+ return this;
13176
+ }
13177
+ }
13178
+ } else {
13179
+ positionals.push(arg);
13180
+ if (this._passthrough) {
13181
+ positionals.push(...argv.slice(i + 1));
13182
+ break;
13183
+ }
13184
+ }
13185
+ i++;
13186
+ }
13187
+ for (const opt of this._options) {
13188
+ if (opt.choices) {
13189
+ const key = optionAttributeName(opt.long);
13190
+ const val = this._parsedOptions[key];
13191
+ if (val !== undefined && !opt.choices.includes(String(val))) {
13192
+ this._writeErr(`error: option '${opt.long}' must be one of: ${opt.choices.join(", ")} (received '${val}')
13193
+ `);
13194
+ this._exit(1);
13195
+ return this;
13196
+ }
13197
+ }
13198
+ }
13199
+ for (const opt of this._options) {
13200
+ if (opt.envVar) {
13201
+ const key = optionAttributeName(opt.long);
13202
+ if (this._parsedOptions[key] === undefined && process.env[opt.envVar] !== undefined) {
13203
+ this._parsedOptions[key] = opt.boolean ? process.env[opt.envVar] !== "0" && process.env[opt.envVar] !== "false" : process.env[opt.envVar];
13204
+ }
13205
+ }
13206
+ }
13207
+ this._rawArgs = [...positionals, ...unknowns];
13208
+ const argValues = [];
13209
+ for (let ai = 0;ai < this._arguments.length; ai++) {
13210
+ const argDef = this._arguments[ai];
13211
+ if (argDef.variadic) {
13212
+ argValues.push(positionals.slice(ai));
13213
+ break;
13214
+ } else if (ai < positionals.length) {
13215
+ argValues.push(positionals[ai]);
13216
+ } else if (argDef.defaultValue !== undefined) {
13217
+ argValues.push(argDef.defaultValue);
13218
+ } else {
13219
+ argValues.push(undefined);
13220
+ }
13221
+ }
13222
+ if (this._actionHandler) {
13223
+ const actionArgs = [...argValues, this._parsedOptions, this];
13224
+ if (async) {
13225
+ return (async () => {
13226
+ for (const hook of this._preActionHooks)
13227
+ await hook(this._parent ?? this, this);
13228
+ await this._actionHandler(...actionArgs);
13229
+ for (const hook of this._postActionHooks)
13230
+ await hook(this._parent ?? this, this);
13231
+ return this;
13232
+ })();
13233
+ }
13234
+ const result = (async () => {
13235
+ for (const hook of this._preActionHooks)
13236
+ await hook(this._parent ?? this, this);
13237
+ await this._actionHandler(...actionArgs);
13238
+ for (const hook of this._postActionHooks)
13239
+ await hook(this._parent ?? this, this);
13240
+ })();
13241
+ result.catch((err) => {
13242
+ this._writeErr(`${err.message}
13243
+ `);
13244
+ this._exit(1);
13245
+ });
13246
+ }
13247
+ return this;
13248
+ }
13249
+ outputHelp() {
13250
+ this._writeOut(this.helpInformation());
13251
+ }
13252
+ helpInformation() {
13253
+ const lines = [];
13254
+ const usage = this._buildUsage();
13255
+ lines.push(`Usage: ${usage}`, "");
13256
+ if (this._description) {
13257
+ lines.push(this._description, "");
13258
+ }
13259
+ const visibleArgs = this._arguments.filter((a) => a.description);
13260
+ if (visibleArgs.length > 0) {
13261
+ lines.push("Arguments:");
13262
+ const maxLen = Math.max(...visibleArgs.map((a) => a.name.length));
13263
+ for (const arg of visibleArgs) {
13264
+ const pad = " ".repeat(maxLen - arg.name.length + 2);
13265
+ const def = arg.defaultValue !== undefined ? ` (default: ${JSON.stringify(arg.defaultValue)})` : "";
13266
+ lines.push(` ${arg.name}${pad}${arg.description}${def}`);
13267
+ }
13268
+ lines.push("");
13269
+ }
13270
+ const visibleOpts = [...this._options];
13271
+ if (this._helpOption) {
13272
+ visibleOpts.push({
13273
+ ...parseOptionFlags(this._helpOption.flags),
13274
+ description: this._helpOption.description,
13275
+ required: false,
13276
+ defaultValue: undefined,
13277
+ negate: false
13278
+ });
13279
+ }
13280
+ if (this._version) {
13281
+ const vParsed = parseOptionFlags(this._versionFlags);
13282
+ visibleOpts.push({
13283
+ ...vParsed,
13284
+ description: "output the version number",
13285
+ required: false,
13286
+ defaultValue: undefined,
13287
+ negate: false
13288
+ });
13289
+ }
13290
+ if (visibleOpts.length > 0) {
13291
+ lines.push("Options:");
13292
+ const formatted = visibleOpts.map((o) => {
13293
+ const flags = [o.short, o.long].filter(Boolean).join(", ");
13294
+ const arg = o.argName ? o.required ? ` <${o.argName}${o.variadic ? "..." : ""}>` : ` [${o.argName}${o.variadic ? "..." : ""}]` : "";
13295
+ return { label: `${flags}${arg}`, desc: o.description, def: o.defaultValue };
13296
+ });
13297
+ const maxLen = Math.max(...formatted.map((f) => f.label.length));
13298
+ for (const f of formatted) {
13299
+ const pad = " ".repeat(maxLen - f.label.length + 2);
13300
+ const def = f.def !== undefined ? ` (default: ${JSON.stringify(f.def)})` : "";
13301
+ lines.push(` ${f.label}${pad}${f.desc}${def}`);
13302
+ }
13303
+ lines.push("");
13304
+ }
13305
+ const visibleCmds = this._commands.filter((c) => !c._hidden);
13306
+ if (visibleCmds.length > 0) {
13307
+ lines.push("Commands:");
13308
+ const formatted = visibleCmds.map((c) => {
13309
+ const aliases = c._aliases.length > 0 ? `|${c._aliases.join("|")}` : "";
13310
+ return { label: `${c._name}${aliases}`, desc: c._description };
13311
+ });
13312
+ const maxLen = Math.max(...formatted.map((f) => f.label.length));
13313
+ for (const f of formatted) {
13314
+ const pad = " ".repeat(maxLen - f.label.length + 2);
13315
+ lines.push(` ${f.label}${pad}${f.desc}`);
13316
+ }
13317
+ lines.push("");
13318
+ }
13319
+ return lines.join(`
13320
+ `);
13321
+ }
13322
+ help(cb) {
13323
+ let text = this.helpInformation();
13324
+ if (cb)
13325
+ text = cb(text);
13326
+ this._writeOut(text);
13327
+ this._exit(0);
13328
+ }
13329
+ _buildUsage() {
13330
+ const parts = [];
13331
+ const chain = [];
13332
+ let cmd = this;
13333
+ while (cmd) {
13334
+ chain.unshift(cmd);
13335
+ cmd = cmd._parent;
13336
+ }
13337
+ parts.push(chain.map((c) => c._name).filter(Boolean).join(" "));
13338
+ if (this._options.length > 0)
13339
+ parts.push("[options]");
13340
+ if (this._commands.length > 0)
13341
+ parts.push("[command]");
13342
+ for (const arg of this._arguments) {
13343
+ if (arg.required) {
13344
+ parts.push(`<${arg.name}${arg.variadic ? "..." : ""}>`);
13345
+ } else {
13346
+ parts.push(`[${arg.name}${arg.variadic ? "..." : ""}]`);
13347
+ }
13348
+ }
13349
+ return parts.join(" ");
13350
+ }
13351
+ _findCommand(name) {
13352
+ return this._commands.find((c) => c._name === name || c._aliases.includes(name));
13353
+ }
13354
+ _findOption(flag) {
13355
+ return this._options.find((o) => o.long === flag || o.short === flag);
13356
+ }
13357
+ _checkHelp(argv) {
13358
+ if (!this._helpOption)
13359
+ return false;
13360
+ const parsed = parseOptionFlags(this._helpOption.flags);
13361
+ return argv.includes(parsed.long) || parsed.short !== undefined && argv.includes(parsed.short);
13362
+ }
13363
+ _writeOut(str) {
13364
+ (this._configureOutput?.writeOut ?? process.stdout.write.bind(process.stdout))(str);
13365
+ }
13366
+ _writeErr(str) {
13367
+ (this._configureOutput?.writeErr ?? process.stderr.write.bind(process.stderr))(str);
13368
+ }
13369
+ _exit(code, error) {
13370
+ if (this._exitOverride || this._exitCallback) {
13371
+ const err = error ?? new Error(`process exit with code ${code}`);
13372
+ if (this._exitCallback) {
13373
+ this._exitCallback(code, err);
13374
+ }
13375
+ throw err;
13376
+ }
13377
+ process.exit(code);
13378
+ }
13379
+ }
13380
+ var program = new Command;
14549
13381
 
14550
13382
  // src/cli/index.ts
14551
13383
  import { createInterface } from "readline";
@@ -16427,7 +15259,7 @@ async function getStatus(projectRoot) {
16427
15259
  const totalCompleted = await mgr.countAllCompleted();
16428
15260
  const integrityResult = await checkIntegrity(paths);
16429
15261
  return {
16430
- version: "0.15.11",
15262
+ version: "0.15.13",
16431
15263
  project: config.project,
16432
15264
  entryMode: config.entryMode,
16433
15265
  lastSyncedGeneration: config.lastSyncedGeneration,
@@ -16750,7 +15582,7 @@ init_fs();
16750
15582
  init_version();
16751
15583
  init_config();
16752
15584
  import { join as join34 } from "path";
16753
- program.name("reap").description("REAP — Recursive Evolutionary Autonomous Pipeline").version("0.15.11");
15585
+ program.name("reap").description("REAP — Recursive Evolutionary Autonomous Pipeline").version("0.15.13");
16754
15586
  program.command("init").description("Initialize a new REAP project (Genesis)").argument("[project-name]", "Project name (defaults to current directory name)").option("-m, --mode <mode>", "Entry mode: greenfield, migration, adoption", "greenfield").option("-p, --preset <preset>", "Bootstrap with a genome preset (e.g., bun-hono-react)").action(async (projectName, options) => {
16755
15587
  try {
16756
15588
  const cwd = process.cwd();
@@ -16807,7 +15639,7 @@ program.command("status").description("Show current project and Generation statu
16807
15639
  const paths = new ReapPaths(cwd);
16808
15640
  const config = await ConfigManager.read(paths);
16809
15641
  const skipCheck = config.autoUpdate === false;
16810
- const installedVersion = "0.15.11";
15642
+ const installedVersion = "0.15.13";
16811
15643
  const versionLine = formatVersionLine(installedVersion, skipCheck);
16812
15644
  console.log(`${versionLine} | Project: ${status.project} (${status.entryMode})`);
16813
15645
  console.log(`Completed Generations: ${status.totalGenerations}`);
@@ -16879,11 +15711,9 @@ program.command("fix").description("Diagnose and repair .reap/ directory structu
16879
15711
  });
16880
15712
  program.command("update").description("Upgrade REAP package and sync slash commands, templates, and hooks").option("--dry-run", "Show changes without applying them").action(async (options) => {
16881
15713
  try {
16882
- if (!options.dryRun) {
16883
- const upgrade = selfUpgrade();
16884
- if (upgrade.upgraded) {
16885
- console.log(`Upgraded: v${upgrade.from} → v${upgrade.to}`);
16886
- }
15714
+ const upgrade = !options.dryRun ? selfUpgrade() : { upgraded: false };
15715
+ if (upgrade.upgraded) {
15716
+ console.log(`Upgraded: v${upgrade.from} → v${upgrade.to}`);
16887
15717
  }
16888
15718
  const result = await updateProject(process.cwd(), options.dryRun ?? false);
16889
15719
  if (options.dryRun) {
@@ -16922,9 +15752,16 @@ Integrity: ✓ OK`);
16922
15752
  try {
16923
15753
  const version = getCurrentVersion();
16924
15754
  const lang = await AgentRegistry.readLanguage() ?? "en";
16925
- const notice = fetchReleaseNotice(version, lang);
16926
- if (notice)
16927
- console.log(notice);
15755
+ if (!options.dryRun && upgrade.upgraded) {
15756
+ const { execSync: execSync10 } = await import("child_process");
15757
+ const output = execSync10(`reap --show-notice ${upgrade.to} --show-notice-lang ${lang}`, { encoding: "utf-8", timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
15758
+ if (output.trim())
15759
+ console.log(output.trimEnd());
15760
+ } else {
15761
+ const notice = fetchReleaseNotice(version, lang);
15762
+ if (notice)
15763
+ console.log(notice);
15764
+ }
16928
15765
  } catch {}
16929
15766
  } catch (e) {
16930
15767
  console.error(`Error: ${e.message}`);
@@ -17084,4 +15921,16 @@ function prompt(question) {
17084
15921
  });
17085
15922
  });
17086
15923
  }
15924
+ var showNoticeIdx = process.argv.indexOf("--show-notice");
15925
+ if (showNoticeIdx !== -1) {
15926
+ const version = process.argv[showNoticeIdx + 1] ?? "";
15927
+ const langIdx = process.argv.indexOf("--show-notice-lang");
15928
+ const lang = langIdx !== -1 ? process.argv[langIdx + 1] ?? "en" : "en";
15929
+ if (version) {
15930
+ const notice = fetchReleaseNotice(version, lang);
15931
+ if (notice)
15932
+ process.stdout.write(notice);
15933
+ }
15934
+ process.exit(0);
15935
+ }
17087
15936
  program.parse();