@weaver-wow/cli 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wvr.mjs ADDED
@@ -0,0 +1,3920 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ var __create = Object.create;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __toESM = (mod, isNodeMode, target) => {
9
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
10
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
+ for (let key of __getOwnPropNames(mod))
12
+ if (!__hasOwnProp.call(to, key))
13
+ __defProp(to, key, {
14
+ get: () => mod[key],
15
+ enumerable: true
16
+ });
17
+ return to;
18
+ };
19
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
20
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
21
+
22
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/error.js
23
+ var require_error = __commonJS((exports) => {
24
+ class CommanderError extends Error {
25
+ constructor(exitCode, code, message) {
26
+ super(message);
27
+ Error.captureStackTrace(this, this.constructor);
28
+ this.name = this.constructor.name;
29
+ this.code = code;
30
+ this.exitCode = exitCode;
31
+ this.nestedError = undefined;
32
+ }
33
+ }
34
+
35
+ class InvalidArgumentError extends CommanderError {
36
+ constructor(message) {
37
+ super(1, "commander.invalidArgument", message);
38
+ Error.captureStackTrace(this, this.constructor);
39
+ this.name = this.constructor.name;
40
+ }
41
+ }
42
+ exports.CommanderError = CommanderError;
43
+ exports.InvalidArgumentError = InvalidArgumentError;
44
+ });
45
+
46
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/argument.js
47
+ var require_argument = __commonJS((exports) => {
48
+ var { InvalidArgumentError } = require_error();
49
+
50
+ class Argument {
51
+ constructor(name, description) {
52
+ this.description = description || "";
53
+ this.variadic = false;
54
+ this.parseArg = undefined;
55
+ this.defaultValue = undefined;
56
+ this.defaultValueDescription = undefined;
57
+ this.argChoices = undefined;
58
+ switch (name[0]) {
59
+ case "<":
60
+ this.required = true;
61
+ this._name = name.slice(1, -1);
62
+ break;
63
+ case "[":
64
+ this.required = false;
65
+ this._name = name.slice(1, -1);
66
+ break;
67
+ default:
68
+ this.required = true;
69
+ this._name = name;
70
+ break;
71
+ }
72
+ if (this._name.endsWith("...")) {
73
+ this.variadic = true;
74
+ this._name = this._name.slice(0, -3);
75
+ }
76
+ }
77
+ name() {
78
+ return this._name;
79
+ }
80
+ _collectValue(value, previous) {
81
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
82
+ return [value];
83
+ }
84
+ previous.push(value);
85
+ return previous;
86
+ }
87
+ default(value, description) {
88
+ this.defaultValue = value;
89
+ this.defaultValueDescription = description;
90
+ return this;
91
+ }
92
+ argParser(fn) {
93
+ this.parseArg = fn;
94
+ return this;
95
+ }
96
+ choices(values) {
97
+ this.argChoices = values.slice();
98
+ this.parseArg = (arg, previous) => {
99
+ if (!this.argChoices.includes(arg)) {
100
+ throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
101
+ }
102
+ if (this.variadic) {
103
+ return this._collectValue(arg, previous);
104
+ }
105
+ return arg;
106
+ };
107
+ return this;
108
+ }
109
+ argRequired() {
110
+ this.required = true;
111
+ return this;
112
+ }
113
+ argOptional() {
114
+ this.required = false;
115
+ return this;
116
+ }
117
+ }
118
+ function humanReadableArgName(arg) {
119
+ const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
120
+ return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
121
+ }
122
+ exports.Argument = Argument;
123
+ exports.humanReadableArgName = humanReadableArgName;
124
+ });
125
+
126
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/help.js
127
+ var require_help = __commonJS((exports) => {
128
+ var { humanReadableArgName } = require_argument();
129
+
130
+ class Help {
131
+ constructor() {
132
+ this.helpWidth = undefined;
133
+ this.minWidthToWrap = 40;
134
+ this.sortSubcommands = false;
135
+ this.sortOptions = false;
136
+ this.showGlobalOptions = false;
137
+ }
138
+ prepareContext(contextOptions) {
139
+ this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
140
+ }
141
+ visibleCommands(cmd) {
142
+ const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
143
+ const helpCommand = cmd._getHelpCommand();
144
+ if (helpCommand && !helpCommand._hidden) {
145
+ visibleCommands.push(helpCommand);
146
+ }
147
+ if (this.sortSubcommands) {
148
+ visibleCommands.sort((a, b) => {
149
+ return a.name().localeCompare(b.name());
150
+ });
151
+ }
152
+ return visibleCommands;
153
+ }
154
+ compareOptions(a, b) {
155
+ const getSortKey = (option) => {
156
+ return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
157
+ };
158
+ return getSortKey(a).localeCompare(getSortKey(b));
159
+ }
160
+ visibleOptions(cmd) {
161
+ const visibleOptions = cmd.options.filter((option) => !option.hidden);
162
+ const helpOption = cmd._getHelpOption();
163
+ if (helpOption && !helpOption.hidden) {
164
+ const removeShort = helpOption.short && cmd._findOption(helpOption.short);
165
+ const removeLong = helpOption.long && cmd._findOption(helpOption.long);
166
+ if (!removeShort && !removeLong) {
167
+ visibleOptions.push(helpOption);
168
+ } else if (helpOption.long && !removeLong) {
169
+ visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
170
+ } else if (helpOption.short && !removeShort) {
171
+ visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
172
+ }
173
+ }
174
+ if (this.sortOptions) {
175
+ visibleOptions.sort(this.compareOptions);
176
+ }
177
+ return visibleOptions;
178
+ }
179
+ visibleGlobalOptions(cmd) {
180
+ if (!this.showGlobalOptions)
181
+ return [];
182
+ const globalOptions = [];
183
+ for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
184
+ const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
185
+ globalOptions.push(...visibleOptions);
186
+ }
187
+ if (this.sortOptions) {
188
+ globalOptions.sort(this.compareOptions);
189
+ }
190
+ return globalOptions;
191
+ }
192
+ visibleArguments(cmd) {
193
+ if (cmd._argsDescription) {
194
+ cmd.registeredArguments.forEach((argument) => {
195
+ argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
196
+ });
197
+ }
198
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
199
+ return cmd.registeredArguments;
200
+ }
201
+ return [];
202
+ }
203
+ subcommandTerm(cmd) {
204
+ const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
205
+ return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
206
+ }
207
+ optionTerm(option) {
208
+ return option.flags;
209
+ }
210
+ argumentTerm(argument) {
211
+ return argument.name();
212
+ }
213
+ longestSubcommandTermLength(cmd, helper) {
214
+ return helper.visibleCommands(cmd).reduce((max, command) => {
215
+ return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
216
+ }, 0);
217
+ }
218
+ longestOptionTermLength(cmd, helper) {
219
+ return helper.visibleOptions(cmd).reduce((max, option) => {
220
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
221
+ }, 0);
222
+ }
223
+ longestGlobalOptionTermLength(cmd, helper) {
224
+ return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
225
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
226
+ }, 0);
227
+ }
228
+ longestArgumentTermLength(cmd, helper) {
229
+ return helper.visibleArguments(cmd).reduce((max, argument) => {
230
+ return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
231
+ }, 0);
232
+ }
233
+ commandUsage(cmd) {
234
+ let cmdName = cmd._name;
235
+ if (cmd._aliases[0]) {
236
+ cmdName = cmdName + "|" + cmd._aliases[0];
237
+ }
238
+ let ancestorCmdNames = "";
239
+ for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
240
+ ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
241
+ }
242
+ return ancestorCmdNames + cmdName + " " + cmd.usage();
243
+ }
244
+ commandDescription(cmd) {
245
+ return cmd.description();
246
+ }
247
+ subcommandDescription(cmd) {
248
+ return cmd.summary() || cmd.description();
249
+ }
250
+ optionDescription(option) {
251
+ const extraInfo = [];
252
+ if (option.argChoices) {
253
+ extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
254
+ }
255
+ if (option.defaultValue !== undefined) {
256
+ const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
257
+ if (showDefault) {
258
+ extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
259
+ }
260
+ }
261
+ if (option.presetArg !== undefined && option.optional) {
262
+ extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
263
+ }
264
+ if (option.envVar !== undefined) {
265
+ extraInfo.push(`env: ${option.envVar}`);
266
+ }
267
+ if (extraInfo.length > 0) {
268
+ const extraDescription = `(${extraInfo.join(", ")})`;
269
+ if (option.description) {
270
+ return `${option.description} ${extraDescription}`;
271
+ }
272
+ return extraDescription;
273
+ }
274
+ return option.description;
275
+ }
276
+ argumentDescription(argument) {
277
+ const extraInfo = [];
278
+ if (argument.argChoices) {
279
+ extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
280
+ }
281
+ if (argument.defaultValue !== undefined) {
282
+ extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
283
+ }
284
+ if (extraInfo.length > 0) {
285
+ const extraDescription = `(${extraInfo.join(", ")})`;
286
+ if (argument.description) {
287
+ return `${argument.description} ${extraDescription}`;
288
+ }
289
+ return extraDescription;
290
+ }
291
+ return argument.description;
292
+ }
293
+ formatItemList(heading, items, helper) {
294
+ if (items.length === 0)
295
+ return [];
296
+ return [helper.styleTitle(heading), ...items, ""];
297
+ }
298
+ groupItems(unsortedItems, visibleItems, getGroup) {
299
+ const result = new Map;
300
+ unsortedItems.forEach((item) => {
301
+ const group = getGroup(item);
302
+ if (!result.has(group))
303
+ result.set(group, []);
304
+ });
305
+ visibleItems.forEach((item) => {
306
+ const group = getGroup(item);
307
+ if (!result.has(group)) {
308
+ result.set(group, []);
309
+ }
310
+ result.get(group).push(item);
311
+ });
312
+ return result;
313
+ }
314
+ formatHelp(cmd, helper) {
315
+ const termWidth = helper.padWidth(cmd, helper);
316
+ const helpWidth = helper.helpWidth ?? 80;
317
+ function callFormatItem(term, description) {
318
+ return helper.formatItem(term, termWidth, description, helper);
319
+ }
320
+ let output = [
321
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
322
+ ""
323
+ ];
324
+ const commandDescription = helper.commandDescription(cmd);
325
+ if (commandDescription.length > 0) {
326
+ output = output.concat([
327
+ helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
328
+ ""
329
+ ]);
330
+ }
331
+ const argumentList = helper.visibleArguments(cmd).map((argument) => {
332
+ return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
333
+ });
334
+ output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
335
+ const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
336
+ optionGroups.forEach((options, group) => {
337
+ const optionList = options.map((option) => {
338
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
339
+ });
340
+ output = output.concat(this.formatItemList(group, optionList, helper));
341
+ });
342
+ if (helper.showGlobalOptions) {
343
+ const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
344
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
345
+ });
346
+ output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
347
+ }
348
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
349
+ commandGroups.forEach((commands, group) => {
350
+ const commandList = commands.map((sub) => {
351
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
352
+ });
353
+ output = output.concat(this.formatItemList(group, commandList, helper));
354
+ });
355
+ return output.join(`
356
+ `);
357
+ }
358
+ displayWidth(str) {
359
+ return stripColor(str).length;
360
+ }
361
+ styleTitle(str) {
362
+ return str;
363
+ }
364
+ styleUsage(str) {
365
+ return str.split(" ").map((word) => {
366
+ if (word === "[options]")
367
+ return this.styleOptionText(word);
368
+ if (word === "[command]")
369
+ return this.styleSubcommandText(word);
370
+ if (word[0] === "[" || word[0] === "<")
371
+ return this.styleArgumentText(word);
372
+ return this.styleCommandText(word);
373
+ }).join(" ");
374
+ }
375
+ styleCommandDescription(str) {
376
+ return this.styleDescriptionText(str);
377
+ }
378
+ styleOptionDescription(str) {
379
+ return this.styleDescriptionText(str);
380
+ }
381
+ styleSubcommandDescription(str) {
382
+ return this.styleDescriptionText(str);
383
+ }
384
+ styleArgumentDescription(str) {
385
+ return this.styleDescriptionText(str);
386
+ }
387
+ styleDescriptionText(str) {
388
+ return str;
389
+ }
390
+ styleOptionTerm(str) {
391
+ return this.styleOptionText(str);
392
+ }
393
+ styleSubcommandTerm(str) {
394
+ return str.split(" ").map((word) => {
395
+ if (word === "[options]")
396
+ return this.styleOptionText(word);
397
+ if (word[0] === "[" || word[0] === "<")
398
+ return this.styleArgumentText(word);
399
+ return this.styleSubcommandText(word);
400
+ }).join(" ");
401
+ }
402
+ styleArgumentTerm(str) {
403
+ return this.styleArgumentText(str);
404
+ }
405
+ styleOptionText(str) {
406
+ return str;
407
+ }
408
+ styleArgumentText(str) {
409
+ return str;
410
+ }
411
+ styleSubcommandText(str) {
412
+ return str;
413
+ }
414
+ styleCommandText(str) {
415
+ return str;
416
+ }
417
+ padWidth(cmd, helper) {
418
+ return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
419
+ }
420
+ preformatted(str) {
421
+ return /\n[^\S\r\n]/.test(str);
422
+ }
423
+ formatItem(term, termWidth, description, helper) {
424
+ const itemIndent = 2;
425
+ const itemIndentStr = " ".repeat(itemIndent);
426
+ if (!description)
427
+ return itemIndentStr + term;
428
+ const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
429
+ const spacerWidth = 2;
430
+ const helpWidth = this.helpWidth ?? 80;
431
+ const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
432
+ let formattedDescription;
433
+ if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
434
+ formattedDescription = description;
435
+ } else {
436
+ const wrappedDescription = helper.boxWrap(description, remainingWidth);
437
+ formattedDescription = wrappedDescription.replace(/\n/g, `
438
+ ` + " ".repeat(termWidth + spacerWidth));
439
+ }
440
+ return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
441
+ ${itemIndentStr}`);
442
+ }
443
+ boxWrap(str, width) {
444
+ if (width < this.minWidthToWrap)
445
+ return str;
446
+ const rawLines = str.split(/\r\n|\n/);
447
+ const chunkPattern = /[\s]*[^\s]+/g;
448
+ const wrappedLines = [];
449
+ rawLines.forEach((line) => {
450
+ const chunks = line.match(chunkPattern);
451
+ if (chunks === null) {
452
+ wrappedLines.push("");
453
+ return;
454
+ }
455
+ let sumChunks = [chunks.shift()];
456
+ let sumWidth = this.displayWidth(sumChunks[0]);
457
+ chunks.forEach((chunk) => {
458
+ const visibleWidth = this.displayWidth(chunk);
459
+ if (sumWidth + visibleWidth <= width) {
460
+ sumChunks.push(chunk);
461
+ sumWidth += visibleWidth;
462
+ return;
463
+ }
464
+ wrappedLines.push(sumChunks.join(""));
465
+ const nextChunk = chunk.trimStart();
466
+ sumChunks = [nextChunk];
467
+ sumWidth = this.displayWidth(nextChunk);
468
+ });
469
+ wrappedLines.push(sumChunks.join(""));
470
+ });
471
+ return wrappedLines.join(`
472
+ `);
473
+ }
474
+ }
475
+ function stripColor(str) {
476
+ const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
477
+ return str.replace(sgrPattern, "");
478
+ }
479
+ exports.Help = Help;
480
+ exports.stripColor = stripColor;
481
+ });
482
+
483
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/option.js
484
+ var require_option = __commonJS((exports) => {
485
+ var { InvalidArgumentError } = require_error();
486
+
487
+ class Option {
488
+ constructor(flags, description) {
489
+ this.flags = flags;
490
+ this.description = description || "";
491
+ this.required = flags.includes("<");
492
+ this.optional = flags.includes("[");
493
+ this.variadic = /\w\.\.\.[>\]]$/.test(flags);
494
+ this.mandatory = false;
495
+ const optionFlags = splitOptionFlags(flags);
496
+ this.short = optionFlags.shortFlag;
497
+ this.long = optionFlags.longFlag;
498
+ this.negate = false;
499
+ if (this.long) {
500
+ this.negate = this.long.startsWith("--no-");
501
+ }
502
+ this.defaultValue = undefined;
503
+ this.defaultValueDescription = undefined;
504
+ this.presetArg = undefined;
505
+ this.envVar = undefined;
506
+ this.parseArg = undefined;
507
+ this.hidden = false;
508
+ this.argChoices = undefined;
509
+ this.conflictsWith = [];
510
+ this.implied = undefined;
511
+ this.helpGroupHeading = undefined;
512
+ }
513
+ default(value, description) {
514
+ this.defaultValue = value;
515
+ this.defaultValueDescription = description;
516
+ return this;
517
+ }
518
+ preset(arg) {
519
+ this.presetArg = arg;
520
+ return this;
521
+ }
522
+ conflicts(names) {
523
+ this.conflictsWith = this.conflictsWith.concat(names);
524
+ return this;
525
+ }
526
+ implies(impliedOptionValues) {
527
+ let newImplied = impliedOptionValues;
528
+ if (typeof impliedOptionValues === "string") {
529
+ newImplied = { [impliedOptionValues]: true };
530
+ }
531
+ this.implied = Object.assign(this.implied || {}, newImplied);
532
+ return this;
533
+ }
534
+ env(name) {
535
+ this.envVar = name;
536
+ return this;
537
+ }
538
+ argParser(fn) {
539
+ this.parseArg = fn;
540
+ return this;
541
+ }
542
+ makeOptionMandatory(mandatory = true) {
543
+ this.mandatory = !!mandatory;
544
+ return this;
545
+ }
546
+ hideHelp(hide = true) {
547
+ this.hidden = !!hide;
548
+ return this;
549
+ }
550
+ _collectValue(value, previous) {
551
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
552
+ return [value];
553
+ }
554
+ previous.push(value);
555
+ return previous;
556
+ }
557
+ choices(values) {
558
+ this.argChoices = values.slice();
559
+ this.parseArg = (arg, previous) => {
560
+ if (!this.argChoices.includes(arg)) {
561
+ throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
562
+ }
563
+ if (this.variadic) {
564
+ return this._collectValue(arg, previous);
565
+ }
566
+ return arg;
567
+ };
568
+ return this;
569
+ }
570
+ name() {
571
+ if (this.long) {
572
+ return this.long.replace(/^--/, "");
573
+ }
574
+ return this.short.replace(/^-/, "");
575
+ }
576
+ attributeName() {
577
+ if (this.negate) {
578
+ return camelcase(this.name().replace(/^no-/, ""));
579
+ }
580
+ return camelcase(this.name());
581
+ }
582
+ helpGroup(heading) {
583
+ this.helpGroupHeading = heading;
584
+ return this;
585
+ }
586
+ is(arg) {
587
+ return this.short === arg || this.long === arg;
588
+ }
589
+ isBoolean() {
590
+ return !this.required && !this.optional && !this.negate;
591
+ }
592
+ }
593
+
594
+ class DualOptions {
595
+ constructor(options) {
596
+ this.positiveOptions = new Map;
597
+ this.negativeOptions = new Map;
598
+ this.dualOptions = new Set;
599
+ options.forEach((option) => {
600
+ if (option.negate) {
601
+ this.negativeOptions.set(option.attributeName(), option);
602
+ } else {
603
+ this.positiveOptions.set(option.attributeName(), option);
604
+ }
605
+ });
606
+ this.negativeOptions.forEach((value, key) => {
607
+ if (this.positiveOptions.has(key)) {
608
+ this.dualOptions.add(key);
609
+ }
610
+ });
611
+ }
612
+ valueFromOption(value, option) {
613
+ const optionKey = option.attributeName();
614
+ if (!this.dualOptions.has(optionKey))
615
+ return true;
616
+ const preset = this.negativeOptions.get(optionKey).presetArg;
617
+ const negativeValue = preset !== undefined ? preset : false;
618
+ return option.negate === (negativeValue === value);
619
+ }
620
+ }
621
+ function camelcase(str) {
622
+ return str.split("-").reduce((str2, word) => {
623
+ return str2 + word[0].toUpperCase() + word.slice(1);
624
+ });
625
+ }
626
+ function splitOptionFlags(flags) {
627
+ let shortFlag;
628
+ let longFlag;
629
+ const shortFlagExp = /^-[^-]$/;
630
+ const longFlagExp = /^--[^-]/;
631
+ const flagParts = flags.split(/[ |,]+/).concat("guard");
632
+ if (shortFlagExp.test(flagParts[0]))
633
+ shortFlag = flagParts.shift();
634
+ if (longFlagExp.test(flagParts[0]))
635
+ longFlag = flagParts.shift();
636
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
637
+ shortFlag = flagParts.shift();
638
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
639
+ shortFlag = longFlag;
640
+ longFlag = flagParts.shift();
641
+ }
642
+ if (flagParts[0].startsWith("-")) {
643
+ const unsupportedFlag = flagParts[0];
644
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
645
+ if (/^-[^-][^-]/.test(unsupportedFlag))
646
+ throw new Error(`${baseError}
647
+ - a short flag is a single dash and a single character
648
+ - either use a single dash and a single character (for a short flag)
649
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
650
+ if (shortFlagExp.test(unsupportedFlag))
651
+ throw new Error(`${baseError}
652
+ - too many short flags`);
653
+ if (longFlagExp.test(unsupportedFlag))
654
+ throw new Error(`${baseError}
655
+ - too many long flags`);
656
+ throw new Error(`${baseError}
657
+ - unrecognised flag format`);
658
+ }
659
+ if (shortFlag === undefined && longFlag === undefined)
660
+ throw new Error(`option creation failed due to no flags found in '${flags}'.`);
661
+ return { shortFlag, longFlag };
662
+ }
663
+ exports.Option = Option;
664
+ exports.DualOptions = DualOptions;
665
+ });
666
+
667
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
668
+ var require_suggestSimilar = __commonJS((exports) => {
669
+ var maxDistance = 3;
670
+ function editDistance(a, b) {
671
+ if (Math.abs(a.length - b.length) > maxDistance)
672
+ return Math.max(a.length, b.length);
673
+ const d = [];
674
+ for (let i = 0;i <= a.length; i++) {
675
+ d[i] = [i];
676
+ }
677
+ for (let j = 0;j <= b.length; j++) {
678
+ d[0][j] = j;
679
+ }
680
+ for (let j = 1;j <= b.length; j++) {
681
+ for (let i = 1;i <= a.length; i++) {
682
+ let cost = 1;
683
+ if (a[i - 1] === b[j - 1]) {
684
+ cost = 0;
685
+ } else {
686
+ cost = 1;
687
+ }
688
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
689
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
690
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
691
+ }
692
+ }
693
+ }
694
+ return d[a.length][b.length];
695
+ }
696
+ function suggestSimilar(word, candidates) {
697
+ if (!candidates || candidates.length === 0)
698
+ return "";
699
+ candidates = Array.from(new Set(candidates));
700
+ const searchingOptions = word.startsWith("--");
701
+ if (searchingOptions) {
702
+ word = word.slice(2);
703
+ candidates = candidates.map((candidate) => candidate.slice(2));
704
+ }
705
+ let similar = [];
706
+ let bestDistance = maxDistance;
707
+ const minSimilarity = 0.4;
708
+ candidates.forEach((candidate) => {
709
+ if (candidate.length <= 1)
710
+ return;
711
+ const distance = editDistance(word, candidate);
712
+ const length = Math.max(word.length, candidate.length);
713
+ const similarity = (length - distance) / length;
714
+ if (similarity > minSimilarity) {
715
+ if (distance < bestDistance) {
716
+ bestDistance = distance;
717
+ similar = [candidate];
718
+ } else if (distance === bestDistance) {
719
+ similar.push(candidate);
720
+ }
721
+ }
722
+ });
723
+ similar.sort((a, b) => a.localeCompare(b));
724
+ if (searchingOptions) {
725
+ similar = similar.map((candidate) => `--${candidate}`);
726
+ }
727
+ if (similar.length > 1) {
728
+ return `
729
+ (Did you mean one of ${similar.join(", ")}?)`;
730
+ }
731
+ if (similar.length === 1) {
732
+ return `
733
+ (Did you mean ${similar[0]}?)`;
734
+ }
735
+ return "";
736
+ }
737
+ exports.suggestSimilar = suggestSimilar;
738
+ });
739
+
740
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/lib/command.js
741
+ var require_command = __commonJS((exports) => {
742
+ var EventEmitter = __require("node:events").EventEmitter;
743
+ var childProcess = __require("node:child_process");
744
+ var path = __require("node:path");
745
+ var fs = __require("node:fs");
746
+ var process2 = __require("node:process");
747
+ var { Argument, humanReadableArgName } = require_argument();
748
+ var { CommanderError } = require_error();
749
+ var { Help, stripColor } = require_help();
750
+ var { Option, DualOptions } = require_option();
751
+ var { suggestSimilar } = require_suggestSimilar();
752
+
753
+ class Command extends EventEmitter {
754
+ constructor(name) {
755
+ super();
756
+ this.commands = [];
757
+ this.options = [];
758
+ this.parent = null;
759
+ this._allowUnknownOption = false;
760
+ this._allowExcessArguments = false;
761
+ this.registeredArguments = [];
762
+ this._args = this.registeredArguments;
763
+ this.args = [];
764
+ this.rawArgs = [];
765
+ this.processedArgs = [];
766
+ this._scriptPath = null;
767
+ this._name = name || "";
768
+ this._optionValues = {};
769
+ this._optionValueSources = {};
770
+ this._storeOptionsAsProperties = false;
771
+ this._actionHandler = null;
772
+ this._executableHandler = false;
773
+ this._executableFile = null;
774
+ this._executableDir = null;
775
+ this._defaultCommandName = null;
776
+ this._exitCallback = null;
777
+ this._aliases = [];
778
+ this._combineFlagAndOptionalValue = true;
779
+ this._description = "";
780
+ this._summary = "";
781
+ this._argsDescription = undefined;
782
+ this._enablePositionalOptions = false;
783
+ this._passThroughOptions = false;
784
+ this._lifeCycleHooks = {};
785
+ this._showHelpAfterError = false;
786
+ this._showSuggestionAfterError = true;
787
+ this._savedState = null;
788
+ this._outputConfiguration = {
789
+ writeOut: (str) => process2.stdout.write(str),
790
+ writeErr: (str) => process2.stderr.write(str),
791
+ outputError: (str, write) => write(str),
792
+ getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
793
+ getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
794
+ getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
795
+ getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
796
+ stripColor: (str) => stripColor(str)
797
+ };
798
+ this._hidden = false;
799
+ this._helpOption = undefined;
800
+ this._addImplicitHelpCommand = undefined;
801
+ this._helpCommand = undefined;
802
+ this._helpConfiguration = {};
803
+ this._helpGroupHeading = undefined;
804
+ this._defaultCommandGroup = undefined;
805
+ this._defaultOptionGroup = undefined;
806
+ }
807
+ copyInheritedSettings(sourceCommand) {
808
+ this._outputConfiguration = sourceCommand._outputConfiguration;
809
+ this._helpOption = sourceCommand._helpOption;
810
+ this._helpCommand = sourceCommand._helpCommand;
811
+ this._helpConfiguration = sourceCommand._helpConfiguration;
812
+ this._exitCallback = sourceCommand._exitCallback;
813
+ this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
814
+ this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
815
+ this._allowExcessArguments = sourceCommand._allowExcessArguments;
816
+ this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
817
+ this._showHelpAfterError = sourceCommand._showHelpAfterError;
818
+ this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
819
+ return this;
820
+ }
821
+ _getCommandAndAncestors() {
822
+ const result = [];
823
+ for (let command = this;command; command = command.parent) {
824
+ result.push(command);
825
+ }
826
+ return result;
827
+ }
828
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
829
+ let desc = actionOptsOrExecDesc;
830
+ let opts = execOpts;
831
+ if (typeof desc === "object" && desc !== null) {
832
+ opts = desc;
833
+ desc = null;
834
+ }
835
+ opts = opts || {};
836
+ const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
837
+ const cmd = this.createCommand(name);
838
+ if (desc) {
839
+ cmd.description(desc);
840
+ cmd._executableHandler = true;
841
+ }
842
+ if (opts.isDefault)
843
+ this._defaultCommandName = cmd._name;
844
+ cmd._hidden = !!(opts.noHelp || opts.hidden);
845
+ cmd._executableFile = opts.executableFile || null;
846
+ if (args)
847
+ cmd.arguments(args);
848
+ this._registerCommand(cmd);
849
+ cmd.parent = this;
850
+ cmd.copyInheritedSettings(this);
851
+ if (desc)
852
+ return this;
853
+ return cmd;
854
+ }
855
+ createCommand(name) {
856
+ return new Command(name);
857
+ }
858
+ createHelp() {
859
+ return Object.assign(new Help, this.configureHelp());
860
+ }
861
+ configureHelp(configuration) {
862
+ if (configuration === undefined)
863
+ return this._helpConfiguration;
864
+ this._helpConfiguration = configuration;
865
+ return this;
866
+ }
867
+ configureOutput(configuration) {
868
+ if (configuration === undefined)
869
+ return this._outputConfiguration;
870
+ this._outputConfiguration = {
871
+ ...this._outputConfiguration,
872
+ ...configuration
873
+ };
874
+ return this;
875
+ }
876
+ showHelpAfterError(displayHelp = true) {
877
+ if (typeof displayHelp !== "string")
878
+ displayHelp = !!displayHelp;
879
+ this._showHelpAfterError = displayHelp;
880
+ return this;
881
+ }
882
+ showSuggestionAfterError(displaySuggestion = true) {
883
+ this._showSuggestionAfterError = !!displaySuggestion;
884
+ return this;
885
+ }
886
+ addCommand(cmd, opts) {
887
+ if (!cmd._name) {
888
+ throw new Error(`Command passed to .addCommand() must have a name
889
+ - specify the name in Command constructor or using .name()`);
890
+ }
891
+ opts = opts || {};
892
+ if (opts.isDefault)
893
+ this._defaultCommandName = cmd._name;
894
+ if (opts.noHelp || opts.hidden)
895
+ cmd._hidden = true;
896
+ this._registerCommand(cmd);
897
+ cmd.parent = this;
898
+ cmd._checkForBrokenPassThrough();
899
+ return this;
900
+ }
901
+ createArgument(name, description) {
902
+ return new Argument(name, description);
903
+ }
904
+ argument(name, description, parseArg, defaultValue) {
905
+ const argument = this.createArgument(name, description);
906
+ if (typeof parseArg === "function") {
907
+ argument.default(defaultValue).argParser(parseArg);
908
+ } else {
909
+ argument.default(parseArg);
910
+ }
911
+ this.addArgument(argument);
912
+ return this;
913
+ }
914
+ arguments(names) {
915
+ names.trim().split(/ +/).forEach((detail) => {
916
+ this.argument(detail);
917
+ });
918
+ return this;
919
+ }
920
+ addArgument(argument) {
921
+ const previousArgument = this.registeredArguments.slice(-1)[0];
922
+ if (previousArgument?.variadic) {
923
+ throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
924
+ }
925
+ if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
926
+ throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
927
+ }
928
+ this.registeredArguments.push(argument);
929
+ return this;
930
+ }
931
+ helpCommand(enableOrNameAndArgs, description) {
932
+ if (typeof enableOrNameAndArgs === "boolean") {
933
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
934
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
935
+ this._initCommandGroup(this._getHelpCommand());
936
+ }
937
+ return this;
938
+ }
939
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
940
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
941
+ const helpDescription = description ?? "display help for command";
942
+ const helpCommand = this.createCommand(helpName);
943
+ helpCommand.helpOption(false);
944
+ if (helpArgs)
945
+ helpCommand.arguments(helpArgs);
946
+ if (helpDescription)
947
+ helpCommand.description(helpDescription);
948
+ this._addImplicitHelpCommand = true;
949
+ this._helpCommand = helpCommand;
950
+ if (enableOrNameAndArgs || description)
951
+ this._initCommandGroup(helpCommand);
952
+ return this;
953
+ }
954
+ addHelpCommand(helpCommand, deprecatedDescription) {
955
+ if (typeof helpCommand !== "object") {
956
+ this.helpCommand(helpCommand, deprecatedDescription);
957
+ return this;
958
+ }
959
+ this._addImplicitHelpCommand = true;
960
+ this._helpCommand = helpCommand;
961
+ this._initCommandGroup(helpCommand);
962
+ return this;
963
+ }
964
+ _getHelpCommand() {
965
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
966
+ if (hasImplicitHelpCommand) {
967
+ if (this._helpCommand === undefined) {
968
+ this.helpCommand(undefined, undefined);
969
+ }
970
+ return this._helpCommand;
971
+ }
972
+ return null;
973
+ }
974
+ hook(event, listener) {
975
+ const allowedValues = ["preSubcommand", "preAction", "postAction"];
976
+ if (!allowedValues.includes(event)) {
977
+ throw new Error(`Unexpected value for event passed to hook : '${event}'.
978
+ Expecting one of '${allowedValues.join("', '")}'`);
979
+ }
980
+ if (this._lifeCycleHooks[event]) {
981
+ this._lifeCycleHooks[event].push(listener);
982
+ } else {
983
+ this._lifeCycleHooks[event] = [listener];
984
+ }
985
+ return this;
986
+ }
987
+ exitOverride(fn) {
988
+ if (fn) {
989
+ this._exitCallback = fn;
990
+ } else {
991
+ this._exitCallback = (err) => {
992
+ if (err.code !== "commander.executeSubCommandAsync") {
993
+ throw err;
994
+ } else {}
995
+ };
996
+ }
997
+ return this;
998
+ }
999
+ _exit(exitCode, code, message) {
1000
+ if (this._exitCallback) {
1001
+ this._exitCallback(new CommanderError(exitCode, code, message));
1002
+ }
1003
+ process2.exit(exitCode);
1004
+ }
1005
+ action(fn) {
1006
+ const listener = (args) => {
1007
+ const expectedArgsCount = this.registeredArguments.length;
1008
+ const actionArgs = args.slice(0, expectedArgsCount);
1009
+ if (this._storeOptionsAsProperties) {
1010
+ actionArgs[expectedArgsCount] = this;
1011
+ } else {
1012
+ actionArgs[expectedArgsCount] = this.opts();
1013
+ }
1014
+ actionArgs.push(this);
1015
+ return fn.apply(this, actionArgs);
1016
+ };
1017
+ this._actionHandler = listener;
1018
+ return this;
1019
+ }
1020
+ createOption(flags, description) {
1021
+ return new Option(flags, description);
1022
+ }
1023
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
1024
+ try {
1025
+ return target.parseArg(value, previous);
1026
+ } catch (err) {
1027
+ if (err.code === "commander.invalidArgument") {
1028
+ const message = `${invalidArgumentMessage} ${err.message}`;
1029
+ this.error(message, { exitCode: err.exitCode, code: err.code });
1030
+ }
1031
+ throw err;
1032
+ }
1033
+ }
1034
+ _registerOption(option) {
1035
+ const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
1036
+ if (matchingOption) {
1037
+ const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
1038
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1039
+ - already used by option '${matchingOption.flags}'`);
1040
+ }
1041
+ this._initOptionGroup(option);
1042
+ this.options.push(option);
1043
+ }
1044
+ _registerCommand(command) {
1045
+ const knownBy = (cmd) => {
1046
+ return [cmd.name()].concat(cmd.aliases());
1047
+ };
1048
+ const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
1049
+ if (alreadyUsed) {
1050
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1051
+ const newCmd = knownBy(command).join("|");
1052
+ throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1053
+ }
1054
+ this._initCommandGroup(command);
1055
+ this.commands.push(command);
1056
+ }
1057
+ addOption(option) {
1058
+ this._registerOption(option);
1059
+ const oname = option.name();
1060
+ const name = option.attributeName();
1061
+ if (option.negate) {
1062
+ const positiveLongFlag = option.long.replace(/^--no-/, "--");
1063
+ if (!this._findOption(positiveLongFlag)) {
1064
+ this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
1065
+ }
1066
+ } else if (option.defaultValue !== undefined) {
1067
+ this.setOptionValueWithSource(name, option.defaultValue, "default");
1068
+ }
1069
+ const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1070
+ if (val == null && option.presetArg !== undefined) {
1071
+ val = option.presetArg;
1072
+ }
1073
+ const oldValue = this.getOptionValue(name);
1074
+ if (val !== null && option.parseArg) {
1075
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1076
+ } else if (val !== null && option.variadic) {
1077
+ val = option._collectValue(val, oldValue);
1078
+ }
1079
+ if (val == null) {
1080
+ if (option.negate) {
1081
+ val = false;
1082
+ } else if (option.isBoolean() || option.optional) {
1083
+ val = true;
1084
+ } else {
1085
+ val = "";
1086
+ }
1087
+ }
1088
+ this.setOptionValueWithSource(name, val, valueSource);
1089
+ };
1090
+ this.on("option:" + oname, (val) => {
1091
+ const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1092
+ handleOptionValue(val, invalidValueMessage, "cli");
1093
+ });
1094
+ if (option.envVar) {
1095
+ this.on("optionEnv:" + oname, (val) => {
1096
+ const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1097
+ handleOptionValue(val, invalidValueMessage, "env");
1098
+ });
1099
+ }
1100
+ return this;
1101
+ }
1102
+ _optionEx(config, flags, description, fn, defaultValue) {
1103
+ if (typeof flags === "object" && flags instanceof Option) {
1104
+ throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
1105
+ }
1106
+ const option = this.createOption(flags, description);
1107
+ option.makeOptionMandatory(!!config.mandatory);
1108
+ if (typeof fn === "function") {
1109
+ option.default(defaultValue).argParser(fn);
1110
+ } else if (fn instanceof RegExp) {
1111
+ const regex = fn;
1112
+ fn = (val, def) => {
1113
+ const m = regex.exec(val);
1114
+ return m ? m[0] : def;
1115
+ };
1116
+ option.default(defaultValue).argParser(fn);
1117
+ } else {
1118
+ option.default(fn);
1119
+ }
1120
+ return this.addOption(option);
1121
+ }
1122
+ option(flags, description, parseArg, defaultValue) {
1123
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
1124
+ }
1125
+ requiredOption(flags, description, parseArg, defaultValue) {
1126
+ return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1127
+ }
1128
+ combineFlagAndOptionalValue(combine = true) {
1129
+ this._combineFlagAndOptionalValue = !!combine;
1130
+ return this;
1131
+ }
1132
+ allowUnknownOption(allowUnknown = true) {
1133
+ this._allowUnknownOption = !!allowUnknown;
1134
+ return this;
1135
+ }
1136
+ allowExcessArguments(allowExcess = true) {
1137
+ this._allowExcessArguments = !!allowExcess;
1138
+ return this;
1139
+ }
1140
+ enablePositionalOptions(positional = true) {
1141
+ this._enablePositionalOptions = !!positional;
1142
+ return this;
1143
+ }
1144
+ passThroughOptions(passThrough = true) {
1145
+ this._passThroughOptions = !!passThrough;
1146
+ this._checkForBrokenPassThrough();
1147
+ return this;
1148
+ }
1149
+ _checkForBrokenPassThrough() {
1150
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1151
+ throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
1152
+ }
1153
+ }
1154
+ storeOptionsAsProperties(storeAsProperties = true) {
1155
+ if (this.options.length) {
1156
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1157
+ }
1158
+ if (Object.keys(this._optionValues).length) {
1159
+ throw new Error("call .storeOptionsAsProperties() before setting option values");
1160
+ }
1161
+ this._storeOptionsAsProperties = !!storeAsProperties;
1162
+ return this;
1163
+ }
1164
+ getOptionValue(key) {
1165
+ if (this._storeOptionsAsProperties) {
1166
+ return this[key];
1167
+ }
1168
+ return this._optionValues[key];
1169
+ }
1170
+ setOptionValue(key, value) {
1171
+ return this.setOptionValueWithSource(key, value, undefined);
1172
+ }
1173
+ setOptionValueWithSource(key, value, source) {
1174
+ if (this._storeOptionsAsProperties) {
1175
+ this[key] = value;
1176
+ } else {
1177
+ this._optionValues[key] = value;
1178
+ }
1179
+ this._optionValueSources[key] = source;
1180
+ return this;
1181
+ }
1182
+ getOptionValueSource(key) {
1183
+ return this._optionValueSources[key];
1184
+ }
1185
+ getOptionValueSourceWithGlobals(key) {
1186
+ let source;
1187
+ this._getCommandAndAncestors().forEach((cmd) => {
1188
+ if (cmd.getOptionValueSource(key) !== undefined) {
1189
+ source = cmd.getOptionValueSource(key);
1190
+ }
1191
+ });
1192
+ return source;
1193
+ }
1194
+ _prepareUserArgs(argv, parseOptions) {
1195
+ if (argv !== undefined && !Array.isArray(argv)) {
1196
+ throw new Error("first parameter to parse must be array or undefined");
1197
+ }
1198
+ parseOptions = parseOptions || {};
1199
+ if (argv === undefined && parseOptions.from === undefined) {
1200
+ if (process2.versions?.electron) {
1201
+ parseOptions.from = "electron";
1202
+ }
1203
+ const execArgv = process2.execArgv ?? [];
1204
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
1205
+ parseOptions.from = "eval";
1206
+ }
1207
+ }
1208
+ if (argv === undefined) {
1209
+ argv = process2.argv;
1210
+ }
1211
+ this.rawArgs = argv.slice();
1212
+ let userArgs;
1213
+ switch (parseOptions.from) {
1214
+ case undefined:
1215
+ case "node":
1216
+ this._scriptPath = argv[1];
1217
+ userArgs = argv.slice(2);
1218
+ break;
1219
+ case "electron":
1220
+ if (process2.defaultApp) {
1221
+ this._scriptPath = argv[1];
1222
+ userArgs = argv.slice(2);
1223
+ } else {
1224
+ userArgs = argv.slice(1);
1225
+ }
1226
+ break;
1227
+ case "user":
1228
+ userArgs = argv.slice(0);
1229
+ break;
1230
+ case "eval":
1231
+ userArgs = argv.slice(1);
1232
+ break;
1233
+ default:
1234
+ throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
1235
+ }
1236
+ if (!this._name && this._scriptPath)
1237
+ this.nameFromFilename(this._scriptPath);
1238
+ this._name = this._name || "program";
1239
+ return userArgs;
1240
+ }
1241
+ parse(argv, parseOptions) {
1242
+ this._prepareForParse();
1243
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1244
+ this._parseCommand([], userArgs);
1245
+ return this;
1246
+ }
1247
+ async parseAsync(argv, parseOptions) {
1248
+ this._prepareForParse();
1249
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1250
+ await this._parseCommand([], userArgs);
1251
+ return this;
1252
+ }
1253
+ _prepareForParse() {
1254
+ if (this._savedState === null) {
1255
+ this.saveStateBeforeParse();
1256
+ } else {
1257
+ this.restoreStateBeforeParse();
1258
+ }
1259
+ }
1260
+ saveStateBeforeParse() {
1261
+ this._savedState = {
1262
+ _name: this._name,
1263
+ _optionValues: { ...this._optionValues },
1264
+ _optionValueSources: { ...this._optionValueSources }
1265
+ };
1266
+ }
1267
+ restoreStateBeforeParse() {
1268
+ if (this._storeOptionsAsProperties)
1269
+ throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
1270
+ - either make a new Command for each call to parse, or stop storing options as properties`);
1271
+ this._name = this._savedState._name;
1272
+ this._scriptPath = null;
1273
+ this.rawArgs = [];
1274
+ this._optionValues = { ...this._savedState._optionValues };
1275
+ this._optionValueSources = { ...this._savedState._optionValueSources };
1276
+ this.args = [];
1277
+ this.processedArgs = [];
1278
+ }
1279
+ _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1280
+ if (fs.existsSync(executableFile))
1281
+ return;
1282
+ 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";
1283
+ const executableMissing = `'${executableFile}' does not exist
1284
+ - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1285
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1286
+ - ${executableDirMessage}`;
1287
+ throw new Error(executableMissing);
1288
+ }
1289
+ _executeSubCommand(subcommand, args) {
1290
+ args = args.slice();
1291
+ let launchWithNode = false;
1292
+ const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1293
+ function findFile(baseDir, baseName) {
1294
+ const localBin = path.resolve(baseDir, baseName);
1295
+ if (fs.existsSync(localBin))
1296
+ return localBin;
1297
+ if (sourceExt.includes(path.extname(baseName)))
1298
+ return;
1299
+ const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1300
+ if (foundExt)
1301
+ return `${localBin}${foundExt}`;
1302
+ return;
1303
+ }
1304
+ this._checkForMissingMandatoryOptions();
1305
+ this._checkForConflictingOptions();
1306
+ let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1307
+ let executableDir = this._executableDir || "";
1308
+ if (this._scriptPath) {
1309
+ let resolvedScriptPath;
1310
+ try {
1311
+ resolvedScriptPath = fs.realpathSync(this._scriptPath);
1312
+ } catch {
1313
+ resolvedScriptPath = this._scriptPath;
1314
+ }
1315
+ executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1316
+ }
1317
+ if (executableDir) {
1318
+ let localFile = findFile(executableDir, executableFile);
1319
+ if (!localFile && !subcommand._executableFile && this._scriptPath) {
1320
+ const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1321
+ if (legacyName !== this._name) {
1322
+ localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1323
+ }
1324
+ }
1325
+ executableFile = localFile || executableFile;
1326
+ }
1327
+ launchWithNode = sourceExt.includes(path.extname(executableFile));
1328
+ let proc;
1329
+ if (process2.platform !== "win32") {
1330
+ if (launchWithNode) {
1331
+ args.unshift(executableFile);
1332
+ args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1333
+ proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
1334
+ } else {
1335
+ proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1336
+ }
1337
+ } else {
1338
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1339
+ args.unshift(executableFile);
1340
+ args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1341
+ proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
1342
+ }
1343
+ if (!proc.killed) {
1344
+ const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1345
+ signals.forEach((signal) => {
1346
+ process2.on(signal, () => {
1347
+ if (proc.killed === false && proc.exitCode === null) {
1348
+ proc.kill(signal);
1349
+ }
1350
+ });
1351
+ });
1352
+ }
1353
+ const exitCallback = this._exitCallback;
1354
+ proc.on("close", (code) => {
1355
+ code = code ?? 1;
1356
+ if (!exitCallback) {
1357
+ process2.exit(code);
1358
+ } else {
1359
+ exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
1360
+ }
1361
+ });
1362
+ proc.on("error", (err) => {
1363
+ if (err.code === "ENOENT") {
1364
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1365
+ } else if (err.code === "EACCES") {
1366
+ throw new Error(`'${executableFile}' not executable`);
1367
+ }
1368
+ if (!exitCallback) {
1369
+ process2.exit(1);
1370
+ } else {
1371
+ const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
1372
+ wrappedError.nestedError = err;
1373
+ exitCallback(wrappedError);
1374
+ }
1375
+ });
1376
+ this.runningCommand = proc;
1377
+ }
1378
+ _dispatchSubcommand(commandName, operands, unknown) {
1379
+ const subCommand = this._findCommand(commandName);
1380
+ if (!subCommand)
1381
+ this.help({ error: true });
1382
+ subCommand._prepareForParse();
1383
+ let promiseChain;
1384
+ promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1385
+ promiseChain = this._chainOrCall(promiseChain, () => {
1386
+ if (subCommand._executableHandler) {
1387
+ this._executeSubCommand(subCommand, operands.concat(unknown));
1388
+ } else {
1389
+ return subCommand._parseCommand(operands, unknown);
1390
+ }
1391
+ });
1392
+ return promiseChain;
1393
+ }
1394
+ _dispatchHelpCommand(subcommandName) {
1395
+ if (!subcommandName) {
1396
+ this.help();
1397
+ }
1398
+ const subCommand = this._findCommand(subcommandName);
1399
+ if (subCommand && !subCommand._executableHandler) {
1400
+ subCommand.help();
1401
+ }
1402
+ return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
1403
+ }
1404
+ _checkNumberOfArguments() {
1405
+ this.registeredArguments.forEach((arg, i) => {
1406
+ if (arg.required && this.args[i] == null) {
1407
+ this.missingArgument(arg.name());
1408
+ }
1409
+ });
1410
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1411
+ return;
1412
+ }
1413
+ if (this.args.length > this.registeredArguments.length) {
1414
+ this._excessArguments(this.args);
1415
+ }
1416
+ }
1417
+ _processArguments() {
1418
+ const myParseArg = (argument, value, previous) => {
1419
+ let parsedValue = value;
1420
+ if (value !== null && argument.parseArg) {
1421
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1422
+ parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1423
+ }
1424
+ return parsedValue;
1425
+ };
1426
+ this._checkNumberOfArguments();
1427
+ const processedArgs = [];
1428
+ this.registeredArguments.forEach((declaredArg, index) => {
1429
+ let value = declaredArg.defaultValue;
1430
+ if (declaredArg.variadic) {
1431
+ if (index < this.args.length) {
1432
+ value = this.args.slice(index);
1433
+ if (declaredArg.parseArg) {
1434
+ value = value.reduce((processed, v) => {
1435
+ return myParseArg(declaredArg, v, processed);
1436
+ }, declaredArg.defaultValue);
1437
+ }
1438
+ } else if (value === undefined) {
1439
+ value = [];
1440
+ }
1441
+ } else if (index < this.args.length) {
1442
+ value = this.args[index];
1443
+ if (declaredArg.parseArg) {
1444
+ value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1445
+ }
1446
+ }
1447
+ processedArgs[index] = value;
1448
+ });
1449
+ this.processedArgs = processedArgs;
1450
+ }
1451
+ _chainOrCall(promise, fn) {
1452
+ if (promise?.then && typeof promise.then === "function") {
1453
+ return promise.then(() => fn());
1454
+ }
1455
+ return fn();
1456
+ }
1457
+ _chainOrCallHooks(promise, event) {
1458
+ let result = promise;
1459
+ const hooks = [];
1460
+ this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
1461
+ hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1462
+ hooks.push({ hookedCommand, callback });
1463
+ });
1464
+ });
1465
+ if (event === "postAction") {
1466
+ hooks.reverse();
1467
+ }
1468
+ hooks.forEach((hookDetail) => {
1469
+ result = this._chainOrCall(result, () => {
1470
+ return hookDetail.callback(hookDetail.hookedCommand, this);
1471
+ });
1472
+ });
1473
+ return result;
1474
+ }
1475
+ _chainOrCallSubCommandHook(promise, subCommand, event) {
1476
+ let result = promise;
1477
+ if (this._lifeCycleHooks[event] !== undefined) {
1478
+ this._lifeCycleHooks[event].forEach((hook) => {
1479
+ result = this._chainOrCall(result, () => {
1480
+ return hook(this, subCommand);
1481
+ });
1482
+ });
1483
+ }
1484
+ return result;
1485
+ }
1486
+ _parseCommand(operands, unknown) {
1487
+ const parsed = this.parseOptions(unknown);
1488
+ this._parseOptionsEnv();
1489
+ this._parseOptionsImplied();
1490
+ operands = operands.concat(parsed.operands);
1491
+ unknown = parsed.unknown;
1492
+ this.args = operands.concat(unknown);
1493
+ if (operands && this._findCommand(operands[0])) {
1494
+ return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1495
+ }
1496
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1497
+ return this._dispatchHelpCommand(operands[1]);
1498
+ }
1499
+ if (this._defaultCommandName) {
1500
+ this._outputHelpIfRequested(unknown);
1501
+ return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1502
+ }
1503
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1504
+ this.help({ error: true });
1505
+ }
1506
+ this._outputHelpIfRequested(parsed.unknown);
1507
+ this._checkForMissingMandatoryOptions();
1508
+ this._checkForConflictingOptions();
1509
+ const checkForUnknownOptions = () => {
1510
+ if (parsed.unknown.length > 0) {
1511
+ this.unknownOption(parsed.unknown[0]);
1512
+ }
1513
+ };
1514
+ const commandEvent = `command:${this.name()}`;
1515
+ if (this._actionHandler) {
1516
+ checkForUnknownOptions();
1517
+ this._processArguments();
1518
+ let promiseChain;
1519
+ promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
1520
+ promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1521
+ if (this.parent) {
1522
+ promiseChain = this._chainOrCall(promiseChain, () => {
1523
+ this.parent.emit(commandEvent, operands, unknown);
1524
+ });
1525
+ }
1526
+ promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1527
+ return promiseChain;
1528
+ }
1529
+ if (this.parent?.listenerCount(commandEvent)) {
1530
+ checkForUnknownOptions();
1531
+ this._processArguments();
1532
+ this.parent.emit(commandEvent, operands, unknown);
1533
+ } else if (operands.length) {
1534
+ if (this._findCommand("*")) {
1535
+ return this._dispatchSubcommand("*", operands, unknown);
1536
+ }
1537
+ if (this.listenerCount("command:*")) {
1538
+ this.emit("command:*", operands, unknown);
1539
+ } else if (this.commands.length) {
1540
+ this.unknownCommand();
1541
+ } else {
1542
+ checkForUnknownOptions();
1543
+ this._processArguments();
1544
+ }
1545
+ } else if (this.commands.length) {
1546
+ checkForUnknownOptions();
1547
+ this.help({ error: true });
1548
+ } else {
1549
+ checkForUnknownOptions();
1550
+ this._processArguments();
1551
+ }
1552
+ }
1553
+ _findCommand(name) {
1554
+ if (!name)
1555
+ return;
1556
+ return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
1557
+ }
1558
+ _findOption(arg) {
1559
+ return this.options.find((option) => option.is(arg));
1560
+ }
1561
+ _checkForMissingMandatoryOptions() {
1562
+ this._getCommandAndAncestors().forEach((cmd) => {
1563
+ cmd.options.forEach((anOption) => {
1564
+ if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
1565
+ cmd.missingMandatoryOptionValue(anOption);
1566
+ }
1567
+ });
1568
+ });
1569
+ }
1570
+ _checkForConflictingLocalOptions() {
1571
+ const definedNonDefaultOptions = this.options.filter((option) => {
1572
+ const optionKey = option.attributeName();
1573
+ if (this.getOptionValue(optionKey) === undefined) {
1574
+ return false;
1575
+ }
1576
+ return this.getOptionValueSource(optionKey) !== "default";
1577
+ });
1578
+ const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
1579
+ optionsWithConflicting.forEach((option) => {
1580
+ const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
1581
+ if (conflictingAndDefined) {
1582
+ this._conflictingOption(option, conflictingAndDefined);
1583
+ }
1584
+ });
1585
+ }
1586
+ _checkForConflictingOptions() {
1587
+ this._getCommandAndAncestors().forEach((cmd) => {
1588
+ cmd._checkForConflictingLocalOptions();
1589
+ });
1590
+ }
1591
+ parseOptions(args) {
1592
+ const operands = [];
1593
+ const unknown = [];
1594
+ let dest = operands;
1595
+ function maybeOption(arg) {
1596
+ return arg.length > 1 && arg[0] === "-";
1597
+ }
1598
+ const negativeNumberArg = (arg) => {
1599
+ if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
1600
+ return false;
1601
+ return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
1602
+ };
1603
+ let activeVariadicOption = null;
1604
+ let activeGroup = null;
1605
+ let i = 0;
1606
+ while (i < args.length || activeGroup) {
1607
+ const arg = activeGroup ?? args[i++];
1608
+ activeGroup = null;
1609
+ if (arg === "--") {
1610
+ if (dest === unknown)
1611
+ dest.push(arg);
1612
+ dest.push(...args.slice(i));
1613
+ break;
1614
+ }
1615
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1616
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
1617
+ continue;
1618
+ }
1619
+ activeVariadicOption = null;
1620
+ if (maybeOption(arg)) {
1621
+ const option = this._findOption(arg);
1622
+ if (option) {
1623
+ if (option.required) {
1624
+ const value = args[i++];
1625
+ if (value === undefined)
1626
+ this.optionMissingArgument(option);
1627
+ this.emit(`option:${option.name()}`, value);
1628
+ } else if (option.optional) {
1629
+ let value = null;
1630
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
1631
+ value = args[i++];
1632
+ }
1633
+ this.emit(`option:${option.name()}`, value);
1634
+ } else {
1635
+ this.emit(`option:${option.name()}`);
1636
+ }
1637
+ activeVariadicOption = option.variadic ? option : null;
1638
+ continue;
1639
+ }
1640
+ }
1641
+ if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
1642
+ const option = this._findOption(`-${arg[1]}`);
1643
+ if (option) {
1644
+ if (option.required || option.optional && this._combineFlagAndOptionalValue) {
1645
+ this.emit(`option:${option.name()}`, arg.slice(2));
1646
+ } else {
1647
+ this.emit(`option:${option.name()}`);
1648
+ activeGroup = `-${arg.slice(2)}`;
1649
+ }
1650
+ continue;
1651
+ }
1652
+ }
1653
+ if (/^--[^=]+=/.test(arg)) {
1654
+ const index = arg.indexOf("=");
1655
+ const option = this._findOption(arg.slice(0, index));
1656
+ if (option && (option.required || option.optional)) {
1657
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
1658
+ continue;
1659
+ }
1660
+ }
1661
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
1662
+ dest = unknown;
1663
+ }
1664
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1665
+ if (this._findCommand(arg)) {
1666
+ operands.push(arg);
1667
+ unknown.push(...args.slice(i));
1668
+ break;
1669
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1670
+ operands.push(arg, ...args.slice(i));
1671
+ break;
1672
+ } else if (this._defaultCommandName) {
1673
+ unknown.push(arg, ...args.slice(i));
1674
+ break;
1675
+ }
1676
+ }
1677
+ if (this._passThroughOptions) {
1678
+ dest.push(arg, ...args.slice(i));
1679
+ break;
1680
+ }
1681
+ dest.push(arg);
1682
+ }
1683
+ return { operands, unknown };
1684
+ }
1685
+ opts() {
1686
+ if (this._storeOptionsAsProperties) {
1687
+ const result = {};
1688
+ const len = this.options.length;
1689
+ for (let i = 0;i < len; i++) {
1690
+ const key = this.options[i].attributeName();
1691
+ result[key] = key === this._versionOptionName ? this._version : this[key];
1692
+ }
1693
+ return result;
1694
+ }
1695
+ return this._optionValues;
1696
+ }
1697
+ optsWithGlobals() {
1698
+ return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
1699
+ }
1700
+ error(message, errorOptions) {
1701
+ this._outputConfiguration.outputError(`${message}
1702
+ `, this._outputConfiguration.writeErr);
1703
+ if (typeof this._showHelpAfterError === "string") {
1704
+ this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1705
+ `);
1706
+ } else if (this._showHelpAfterError) {
1707
+ this._outputConfiguration.writeErr(`
1708
+ `);
1709
+ this.outputHelp({ error: true });
1710
+ }
1711
+ const config = errorOptions || {};
1712
+ const exitCode = config.exitCode || 1;
1713
+ const code = config.code || "commander.error";
1714
+ this._exit(exitCode, code, message);
1715
+ }
1716
+ _parseOptionsEnv() {
1717
+ this.options.forEach((option) => {
1718
+ if (option.envVar && option.envVar in process2.env) {
1719
+ const optionKey = option.attributeName();
1720
+ if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
1721
+ if (option.required || option.optional) {
1722
+ this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
1723
+ } else {
1724
+ this.emit(`optionEnv:${option.name()}`);
1725
+ }
1726
+ }
1727
+ }
1728
+ });
1729
+ }
1730
+ _parseOptionsImplied() {
1731
+ const dualHelper = new DualOptions(this.options);
1732
+ const hasCustomOptionValue = (optionKey) => {
1733
+ return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
1734
+ };
1735
+ this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
1736
+ Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
1737
+ this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
1738
+ });
1739
+ });
1740
+ }
1741
+ missingArgument(name) {
1742
+ const message = `error: missing required argument '${name}'`;
1743
+ this.error(message, { code: "commander.missingArgument" });
1744
+ }
1745
+ optionMissingArgument(option) {
1746
+ const message = `error: option '${option.flags}' argument missing`;
1747
+ this.error(message, { code: "commander.optionMissingArgument" });
1748
+ }
1749
+ missingMandatoryOptionValue(option) {
1750
+ const message = `error: required option '${option.flags}' not specified`;
1751
+ this.error(message, { code: "commander.missingMandatoryOptionValue" });
1752
+ }
1753
+ _conflictingOption(option, conflictingOption) {
1754
+ const findBestOptionFromValue = (option2) => {
1755
+ const optionKey = option2.attributeName();
1756
+ const optionValue = this.getOptionValue(optionKey);
1757
+ const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
1758
+ const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
1759
+ if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
1760
+ return negativeOption;
1761
+ }
1762
+ return positiveOption || option2;
1763
+ };
1764
+ const getErrorMessage = (option2) => {
1765
+ const bestOption = findBestOptionFromValue(option2);
1766
+ const optionKey = bestOption.attributeName();
1767
+ const source = this.getOptionValueSource(optionKey);
1768
+ if (source === "env") {
1769
+ return `environment variable '${bestOption.envVar}'`;
1770
+ }
1771
+ return `option '${bestOption.flags}'`;
1772
+ };
1773
+ const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1774
+ this.error(message, { code: "commander.conflictingOption" });
1775
+ }
1776
+ unknownOption(flag) {
1777
+ if (this._allowUnknownOption)
1778
+ return;
1779
+ let suggestion = "";
1780
+ if (flag.startsWith("--") && this._showSuggestionAfterError) {
1781
+ let candidateFlags = [];
1782
+ let command = this;
1783
+ do {
1784
+ const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
1785
+ candidateFlags = candidateFlags.concat(moreFlags);
1786
+ command = command.parent;
1787
+ } while (command && !command._enablePositionalOptions);
1788
+ suggestion = suggestSimilar(flag, candidateFlags);
1789
+ }
1790
+ const message = `error: unknown option '${flag}'${suggestion}`;
1791
+ this.error(message, { code: "commander.unknownOption" });
1792
+ }
1793
+ _excessArguments(receivedArgs) {
1794
+ if (this._allowExcessArguments)
1795
+ return;
1796
+ const expected = this.registeredArguments.length;
1797
+ const s = expected === 1 ? "" : "s";
1798
+ const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
1799
+ const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
1800
+ this.error(message, { code: "commander.excessArguments" });
1801
+ }
1802
+ unknownCommand() {
1803
+ const unknownName = this.args[0];
1804
+ let suggestion = "";
1805
+ if (this._showSuggestionAfterError) {
1806
+ const candidateNames = [];
1807
+ this.createHelp().visibleCommands(this).forEach((command) => {
1808
+ candidateNames.push(command.name());
1809
+ if (command.alias())
1810
+ candidateNames.push(command.alias());
1811
+ });
1812
+ suggestion = suggestSimilar(unknownName, candidateNames);
1813
+ }
1814
+ const message = `error: unknown command '${unknownName}'${suggestion}`;
1815
+ this.error(message, { code: "commander.unknownCommand" });
1816
+ }
1817
+ version(str, flags, description) {
1818
+ if (str === undefined)
1819
+ return this._version;
1820
+ this._version = str;
1821
+ flags = flags || "-V, --version";
1822
+ description = description || "output the version number";
1823
+ const versionOption = this.createOption(flags, description);
1824
+ this._versionOptionName = versionOption.attributeName();
1825
+ this._registerOption(versionOption);
1826
+ this.on("option:" + versionOption.name(), () => {
1827
+ this._outputConfiguration.writeOut(`${str}
1828
+ `);
1829
+ this._exit(0, "commander.version", str);
1830
+ });
1831
+ return this;
1832
+ }
1833
+ description(str, argsDescription) {
1834
+ if (str === undefined && argsDescription === undefined)
1835
+ return this._description;
1836
+ this._description = str;
1837
+ if (argsDescription) {
1838
+ this._argsDescription = argsDescription;
1839
+ }
1840
+ return this;
1841
+ }
1842
+ summary(str) {
1843
+ if (str === undefined)
1844
+ return this._summary;
1845
+ this._summary = str;
1846
+ return this;
1847
+ }
1848
+ alias(alias) {
1849
+ if (alias === undefined)
1850
+ return this._aliases[0];
1851
+ let command = this;
1852
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1853
+ command = this.commands[this.commands.length - 1];
1854
+ }
1855
+ if (alias === command._name)
1856
+ throw new Error("Command alias can't be the same as its name");
1857
+ const matchingCommand = this.parent?._findCommand(alias);
1858
+ if (matchingCommand) {
1859
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
1860
+ throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1861
+ }
1862
+ command._aliases.push(alias);
1863
+ return this;
1864
+ }
1865
+ aliases(aliases) {
1866
+ if (aliases === undefined)
1867
+ return this._aliases;
1868
+ aliases.forEach((alias) => this.alias(alias));
1869
+ return this;
1870
+ }
1871
+ usage(str) {
1872
+ if (str === undefined) {
1873
+ if (this._usage)
1874
+ return this._usage;
1875
+ const args = this.registeredArguments.map((arg) => {
1876
+ return humanReadableArgName(arg);
1877
+ });
1878
+ return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
1879
+ }
1880
+ this._usage = str;
1881
+ return this;
1882
+ }
1883
+ name(str) {
1884
+ if (str === undefined)
1885
+ return this._name;
1886
+ this._name = str;
1887
+ return this;
1888
+ }
1889
+ helpGroup(heading) {
1890
+ if (heading === undefined)
1891
+ return this._helpGroupHeading ?? "";
1892
+ this._helpGroupHeading = heading;
1893
+ return this;
1894
+ }
1895
+ commandsGroup(heading) {
1896
+ if (heading === undefined)
1897
+ return this._defaultCommandGroup ?? "";
1898
+ this._defaultCommandGroup = heading;
1899
+ return this;
1900
+ }
1901
+ optionsGroup(heading) {
1902
+ if (heading === undefined)
1903
+ return this._defaultOptionGroup ?? "";
1904
+ this._defaultOptionGroup = heading;
1905
+ return this;
1906
+ }
1907
+ _initOptionGroup(option) {
1908
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
1909
+ option.helpGroup(this._defaultOptionGroup);
1910
+ }
1911
+ _initCommandGroup(cmd) {
1912
+ if (this._defaultCommandGroup && !cmd.helpGroup())
1913
+ cmd.helpGroup(this._defaultCommandGroup);
1914
+ }
1915
+ nameFromFilename(filename) {
1916
+ this._name = path.basename(filename, path.extname(filename));
1917
+ return this;
1918
+ }
1919
+ executableDir(path2) {
1920
+ if (path2 === undefined)
1921
+ return this._executableDir;
1922
+ this._executableDir = path2;
1923
+ return this;
1924
+ }
1925
+ helpInformation(contextOptions) {
1926
+ const helper = this.createHelp();
1927
+ const context = this._getOutputContext(contextOptions);
1928
+ helper.prepareContext({
1929
+ error: context.error,
1930
+ helpWidth: context.helpWidth,
1931
+ outputHasColors: context.hasColors
1932
+ });
1933
+ const text = helper.formatHelp(this, helper);
1934
+ if (context.hasColors)
1935
+ return text;
1936
+ return this._outputConfiguration.stripColor(text);
1937
+ }
1938
+ _getOutputContext(contextOptions) {
1939
+ contextOptions = contextOptions || {};
1940
+ const error = !!contextOptions.error;
1941
+ let baseWrite;
1942
+ let hasColors;
1943
+ let helpWidth;
1944
+ if (error) {
1945
+ baseWrite = (str) => this._outputConfiguration.writeErr(str);
1946
+ hasColors = this._outputConfiguration.getErrHasColors();
1947
+ helpWidth = this._outputConfiguration.getErrHelpWidth();
1948
+ } else {
1949
+ baseWrite = (str) => this._outputConfiguration.writeOut(str);
1950
+ hasColors = this._outputConfiguration.getOutHasColors();
1951
+ helpWidth = this._outputConfiguration.getOutHelpWidth();
1952
+ }
1953
+ const write = (str) => {
1954
+ if (!hasColors)
1955
+ str = this._outputConfiguration.stripColor(str);
1956
+ return baseWrite(str);
1957
+ };
1958
+ return { error, write, hasColors, helpWidth };
1959
+ }
1960
+ outputHelp(contextOptions) {
1961
+ let deprecatedCallback;
1962
+ if (typeof contextOptions === "function") {
1963
+ deprecatedCallback = contextOptions;
1964
+ contextOptions = undefined;
1965
+ }
1966
+ const outputContext = this._getOutputContext(contextOptions);
1967
+ const eventContext = {
1968
+ error: outputContext.error,
1969
+ write: outputContext.write,
1970
+ command: this
1971
+ };
1972
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
1973
+ this.emit("beforeHelp", eventContext);
1974
+ let helpInformation = this.helpInformation({ error: outputContext.error });
1975
+ if (deprecatedCallback) {
1976
+ helpInformation = deprecatedCallback(helpInformation);
1977
+ if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1978
+ throw new Error("outputHelp callback must return a string or a Buffer");
1979
+ }
1980
+ }
1981
+ outputContext.write(helpInformation);
1982
+ if (this._getHelpOption()?.long) {
1983
+ this.emit(this._getHelpOption().long);
1984
+ }
1985
+ this.emit("afterHelp", eventContext);
1986
+ this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
1987
+ }
1988
+ helpOption(flags, description) {
1989
+ if (typeof flags === "boolean") {
1990
+ if (flags) {
1991
+ if (this._helpOption === null)
1992
+ this._helpOption = undefined;
1993
+ if (this._defaultOptionGroup) {
1994
+ this._initOptionGroup(this._getHelpOption());
1995
+ }
1996
+ } else {
1997
+ this._helpOption = null;
1998
+ }
1999
+ return this;
2000
+ }
2001
+ this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
2002
+ if (flags || description)
2003
+ this._initOptionGroup(this._helpOption);
2004
+ return this;
2005
+ }
2006
+ _getHelpOption() {
2007
+ if (this._helpOption === undefined) {
2008
+ this.helpOption(undefined, undefined);
2009
+ }
2010
+ return this._helpOption;
2011
+ }
2012
+ addHelpOption(option) {
2013
+ this._helpOption = option;
2014
+ this._initOptionGroup(option);
2015
+ return this;
2016
+ }
2017
+ help(contextOptions) {
2018
+ this.outputHelp(contextOptions);
2019
+ let exitCode = Number(process2.exitCode ?? 0);
2020
+ if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
2021
+ exitCode = 1;
2022
+ }
2023
+ this._exit(exitCode, "commander.help", "(outputHelp)");
2024
+ }
2025
+ addHelpText(position, text) {
2026
+ const allowedValues = ["beforeAll", "before", "after", "afterAll"];
2027
+ if (!allowedValues.includes(position)) {
2028
+ throw new Error(`Unexpected value for position to addHelpText.
2029
+ Expecting one of '${allowedValues.join("', '")}'`);
2030
+ }
2031
+ const helpEvent = `${position}Help`;
2032
+ this.on(helpEvent, (context) => {
2033
+ let helpStr;
2034
+ if (typeof text === "function") {
2035
+ helpStr = text({ error: context.error, command: context.command });
2036
+ } else {
2037
+ helpStr = text;
2038
+ }
2039
+ if (helpStr) {
2040
+ context.write(`${helpStr}
2041
+ `);
2042
+ }
2043
+ });
2044
+ return this;
2045
+ }
2046
+ _outputHelpIfRequested(args) {
2047
+ const helpOption = this._getHelpOption();
2048
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
2049
+ if (helpRequested) {
2050
+ this.outputHelp();
2051
+ this._exit(0, "commander.helpDisplayed", "(outputHelp)");
2052
+ }
2053
+ }
2054
+ }
2055
+ function incrementNodeInspectorPort(args) {
2056
+ return args.map((arg) => {
2057
+ if (!arg.startsWith("--inspect")) {
2058
+ return arg;
2059
+ }
2060
+ let debugOption;
2061
+ let debugHost = "127.0.0.1";
2062
+ let debugPort = "9229";
2063
+ let match;
2064
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2065
+ debugOption = match[1];
2066
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2067
+ debugOption = match[1];
2068
+ if (/^\d+$/.test(match[3])) {
2069
+ debugPort = match[3];
2070
+ } else {
2071
+ debugHost = match[3];
2072
+ }
2073
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2074
+ debugOption = match[1];
2075
+ debugHost = match[3];
2076
+ debugPort = match[4];
2077
+ }
2078
+ if (debugOption && debugPort !== "0") {
2079
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2080
+ }
2081
+ return arg;
2082
+ });
2083
+ }
2084
+ function useColor() {
2085
+ if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
2086
+ return false;
2087
+ if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
2088
+ return true;
2089
+ return;
2090
+ }
2091
+ exports.Command = Command;
2092
+ exports.useColor = useColor;
2093
+ });
2094
+
2095
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/index.js
2096
+ var require_commander = __commonJS((exports) => {
2097
+ var { Argument } = require_argument();
2098
+ var { Command } = require_command();
2099
+ var { CommanderError, InvalidArgumentError } = require_error();
2100
+ var { Help } = require_help();
2101
+ var { Option } = require_option();
2102
+ exports.program = new Command;
2103
+ exports.createCommand = (name) => new Command(name);
2104
+ exports.createOption = (flags, description) => new Option(flags, description);
2105
+ exports.createArgument = (name, description) => new Argument(name, description);
2106
+ exports.Command = Command;
2107
+ exports.Option = Option;
2108
+ exports.Argument = Argument;
2109
+ exports.Help = Help;
2110
+ exports.CommanderError = CommanderError;
2111
+ exports.InvalidArgumentError = InvalidArgumentError;
2112
+ exports.InvalidOptionArgumentError = InvalidArgumentError;
2113
+ });
2114
+
2115
+ // ../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
2116
+ var require_picocolors = __commonJS((exports, module) => {
2117
+ var p = process || {};
2118
+ var argv = p.argv || [];
2119
+ var env = p.env || {};
2120
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
2121
+ var formatter = (open, close, replace = open) => (input) => {
2122
+ let string = "" + input, index = string.indexOf(close, open.length);
2123
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
2124
+ };
2125
+ var replaceClose = (string, close, replace, index) => {
2126
+ let result = "", cursor = 0;
2127
+ do {
2128
+ result += string.substring(cursor, index) + replace;
2129
+ cursor = index + close.length;
2130
+ index = string.indexOf(close, cursor);
2131
+ } while (~index);
2132
+ return result + string.substring(cursor);
2133
+ };
2134
+ var createColors = (enabled = isColorSupported) => {
2135
+ let f = enabled ? formatter : () => String;
2136
+ return {
2137
+ isColorSupported: enabled,
2138
+ reset: f("\x1B[0m", "\x1B[0m"),
2139
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
2140
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
2141
+ italic: f("\x1B[3m", "\x1B[23m"),
2142
+ underline: f("\x1B[4m", "\x1B[24m"),
2143
+ inverse: f("\x1B[7m", "\x1B[27m"),
2144
+ hidden: f("\x1B[8m", "\x1B[28m"),
2145
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
2146
+ black: f("\x1B[30m", "\x1B[39m"),
2147
+ red: f("\x1B[31m", "\x1B[39m"),
2148
+ green: f("\x1B[32m", "\x1B[39m"),
2149
+ yellow: f("\x1B[33m", "\x1B[39m"),
2150
+ blue: f("\x1B[34m", "\x1B[39m"),
2151
+ magenta: f("\x1B[35m", "\x1B[39m"),
2152
+ cyan: f("\x1B[36m", "\x1B[39m"),
2153
+ white: f("\x1B[37m", "\x1B[39m"),
2154
+ gray: f("\x1B[90m", "\x1B[39m"),
2155
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
2156
+ bgRed: f("\x1B[41m", "\x1B[49m"),
2157
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
2158
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
2159
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
2160
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
2161
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
2162
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
2163
+ blackBright: f("\x1B[90m", "\x1B[39m"),
2164
+ redBright: f("\x1B[91m", "\x1B[39m"),
2165
+ greenBright: f("\x1B[92m", "\x1B[39m"),
2166
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
2167
+ blueBright: f("\x1B[94m", "\x1B[39m"),
2168
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
2169
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
2170
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
2171
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
2172
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
2173
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
2174
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
2175
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
2176
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
2177
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
2178
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
2179
+ };
2180
+ };
2181
+ module.exports = createColors();
2182
+ module.exports.createColors = createColors;
2183
+ });
2184
+
2185
+ // ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
2186
+ var require_src = __commonJS((exports, module) => {
2187
+ var ESC = "\x1B";
2188
+ var CSI = `${ESC}[`;
2189
+ var beep = "\x07";
2190
+ var cursor = {
2191
+ to(x, y) {
2192
+ if (!y)
2193
+ return `${CSI}${x + 1}G`;
2194
+ return `${CSI}${y + 1};${x + 1}H`;
2195
+ },
2196
+ move(x, y) {
2197
+ let ret = "";
2198
+ if (x < 0)
2199
+ ret += `${CSI}${-x}D`;
2200
+ else if (x > 0)
2201
+ ret += `${CSI}${x}C`;
2202
+ if (y < 0)
2203
+ ret += `${CSI}${-y}A`;
2204
+ else if (y > 0)
2205
+ ret += `${CSI}${y}B`;
2206
+ return ret;
2207
+ },
2208
+ up: (count = 1) => `${CSI}${count}A`,
2209
+ down: (count = 1) => `${CSI}${count}B`,
2210
+ forward: (count = 1) => `${CSI}${count}C`,
2211
+ backward: (count = 1) => `${CSI}${count}D`,
2212
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
2213
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
2214
+ left: `${CSI}G`,
2215
+ hide: `${CSI}?25l`,
2216
+ show: `${CSI}?25h`,
2217
+ save: `${ESC}7`,
2218
+ restore: `${ESC}8`
2219
+ };
2220
+ var scroll = {
2221
+ up: (count = 1) => `${CSI}S`.repeat(count),
2222
+ down: (count = 1) => `${CSI}T`.repeat(count)
2223
+ };
2224
+ var erase = {
2225
+ screen: `${CSI}2J`,
2226
+ up: (count = 1) => `${CSI}1J`.repeat(count),
2227
+ down: (count = 1) => `${CSI}J`.repeat(count),
2228
+ line: `${CSI}2K`,
2229
+ lineEnd: `${CSI}K`,
2230
+ lineStart: `${CSI}1K`,
2231
+ lines(count) {
2232
+ let clear = "";
2233
+ for (let i = 0;i < count; i++)
2234
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
2235
+ if (count)
2236
+ clear += cursor.left;
2237
+ return clear;
2238
+ }
2239
+ };
2240
+ module.exports = { cursor, scroll, erase, beep };
2241
+ });
2242
+
2243
+ // ../../node_modules/.bun/commander@14.0.3/node_modules/commander/esm.mjs
2244
+ var import__ = __toESM(require_commander(), 1);
2245
+ var {
2246
+ program,
2247
+ createCommand,
2248
+ createArgument,
2249
+ createOption,
2250
+ CommanderError,
2251
+ InvalidArgumentError,
2252
+ InvalidOptionArgumentError,
2253
+ Command,
2254
+ Argument,
2255
+ Option,
2256
+ Help
2257
+ } = import__.default;
2258
+
2259
+ // ../../node_modules/.bun/@clack+core@1.0.0/node_modules/@clack/core/dist/index.mjs
2260
+ var import_picocolors = __toESM(require_picocolors(), 1);
2261
+ var import_sisteransi = __toESM(require_src(), 1);
2262
+ import { stdout as R, stdin as q } from "node:process";
2263
+ import * as k from "node:readline";
2264
+ import ot from "node:readline";
2265
+ import { ReadStream as J } from "node:tty";
2266
+ var at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
2267
+ var lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
2268
+ var ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
2269
+ var O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
2270
+ var y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
2271
+ var M = /\t{1,1000}/y;
2272
+ var P = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
2273
+ var L = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
2274
+ var ct = /\p{M}+/gu;
2275
+ var pt = { limit: 1 / 0, ellipsis: "" };
2276
+ var X = (t, e = {}, s = {}) => {
2277
+ const i = e.limit ?? 1 / 0, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X(r, pt, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
2278
+ let h = 0, o = 0, f = t.length, v = 0, F = false, d = f, b = Math.max(0, i - n), C = 0, B = 0, c = 0, p = 0;
2279
+ t:
2280
+ for (;; ) {
2281
+ if (B > C || o >= f && o > h) {
2282
+ const ut = t.slice(C, B) || t.slice(h, o);
2283
+ v = 0;
2284
+ for (const Y of ut.replaceAll(ct, "")) {
2285
+ const $ = Y.codePointAt(0) || 0;
2286
+ if (lt($) ? p = m : ht($) ? p = V : E !== A && at($) ? p = E : p = A, c + p > b && (d = Math.min(d, Math.max(C, h) + v)), c + p > i) {
2287
+ F = true;
2288
+ break t;
2289
+ }
2290
+ v += Y.length, c += p;
2291
+ }
2292
+ C = B = 0;
2293
+ }
2294
+ if (o >= f)
2295
+ break;
2296
+ if (L.lastIndex = o, L.test(t)) {
2297
+ if (v = L.lastIndex - o, p = v * A, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / A))), c + p > i) {
2298
+ F = true;
2299
+ break;
2300
+ }
2301
+ c += p, C = h, B = o, o = h = L.lastIndex;
2302
+ continue;
2303
+ }
2304
+ if (O.lastIndex = o, O.test(t)) {
2305
+ if (c + u > b && (d = Math.min(d, o)), c + u > i) {
2306
+ F = true;
2307
+ break;
2308
+ }
2309
+ c += u, C = h, B = o, o = h = O.lastIndex;
2310
+ continue;
2311
+ }
2312
+ if (y.lastIndex = o, y.test(t)) {
2313
+ if (v = y.lastIndex - o, p = v * a, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / a))), c + p > i) {
2314
+ F = true;
2315
+ break;
2316
+ }
2317
+ c += p, C = h, B = o, o = h = y.lastIndex;
2318
+ continue;
2319
+ }
2320
+ if (M.lastIndex = o, M.test(t)) {
2321
+ if (v = M.lastIndex - o, p = v * l, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / l))), c + p > i) {
2322
+ F = true;
2323
+ break;
2324
+ }
2325
+ c += p, C = h, B = o, o = h = M.lastIndex;
2326
+ continue;
2327
+ }
2328
+ if (P.lastIndex = o, P.test(t)) {
2329
+ if (c + g > b && (d = Math.min(d, o)), c + g > i) {
2330
+ F = true;
2331
+ break;
2332
+ }
2333
+ c += g, C = h, B = o, o = h = P.lastIndex;
2334
+ continue;
2335
+ }
2336
+ o += 1;
2337
+ }
2338
+ return { width: F ? b : c, index: F ? d : f, truncated: F, ellipsed: F && i >= n };
2339
+ };
2340
+ var ft = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
2341
+ var S = (t, e = {}) => X(t, ft, e).width;
2342
+ var W = "\x1B";
2343
+ var Z = "›";
2344
+ var Ft = 39;
2345
+ var j = "\x07";
2346
+ var Q = "[";
2347
+ var dt = "]";
2348
+ var tt = "m";
2349
+ var U = `${dt}8;;`;
2350
+ var et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
2351
+ var mt = (t) => {
2352
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97)
2353
+ return 39;
2354
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107)
2355
+ return 49;
2356
+ if (t === 1 || t === 2)
2357
+ return 22;
2358
+ if (t === 3)
2359
+ return 23;
2360
+ if (t === 4)
2361
+ return 24;
2362
+ if (t === 7)
2363
+ return 27;
2364
+ if (t === 8)
2365
+ return 28;
2366
+ if (t === 9)
2367
+ return 29;
2368
+ if (t === 0)
2369
+ return 0;
2370
+ };
2371
+ var st = (t) => `${W}${Q}${t}${tt}`;
2372
+ var it = (t) => `${W}${U}${t}${j}`;
2373
+ var gt = (t) => t.map((e) => S(e));
2374
+ var G = (t, e, s) => {
2375
+ const i = e[Symbol.iterator]();
2376
+ let r = false, n = false, u = t.at(-1), a = u === undefined ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
2377
+ for (;!l.done; ) {
2378
+ const m = l.value, A = S(m);
2379
+ a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = true, n = e.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
2380
+ }
2381
+ u = t.at(-1), !a && u !== undefined && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
2382
+ };
2383
+ var vt = (t) => {
2384
+ const e = t.split(" ");
2385
+ let s = e.length;
2386
+ for (;s > 0 && !(S(e[s - 1]) > 0); )
2387
+ s--;
2388
+ return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
2389
+ };
2390
+ var Et = (t, e, s = {}) => {
2391
+ if (s.trim !== false && t.trim() === "")
2392
+ return "";
2393
+ let i = "", r, n;
2394
+ const u = t.split(" "), a = gt(u);
2395
+ let l = [""];
2396
+ for (const [h, o] of u.entries()) {
2397
+ s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
2398
+ let f = S(l.at(-1) ?? "");
2399
+ if (h !== 0 && (f >= e && (s.wordWrap === false || s.trim === false) && (l.push(""), f = 0), (f > 0 || s.trim === false) && (l[l.length - 1] += " ", f++)), s.hard && a[h] > e) {
2400
+ const v = e - f, F = 1 + Math.floor((a[h] - v - 1) / e);
2401
+ Math.floor((a[h] - 1) / e) < F && l.push(""), G(l, o, e);
2402
+ continue;
2403
+ }
2404
+ if (f + a[h] > e && f > 0 && a[h] > 0) {
2405
+ if (s.wordWrap === false && f < e) {
2406
+ G(l, o, e);
2407
+ continue;
2408
+ }
2409
+ l.push("");
2410
+ }
2411
+ if (f + a[h] > e && s.wordWrap === false) {
2412
+ G(l, o, e);
2413
+ continue;
2414
+ }
2415
+ l[l.length - 1] += o;
2416
+ }
2417
+ s.trim !== false && (l = l.map((h) => vt(h)));
2418
+ const E = l.join(`
2419
+ `), g = E[Symbol.iterator]();
2420
+ let m = g.next(), A = g.next(), V = 0;
2421
+ for (;!m.done; ) {
2422
+ const h = m.value, o = A.value;
2423
+ if (i += h, h === W || h === Z) {
2424
+ et.lastIndex = V + 1;
2425
+ const F = et.exec(E)?.groups;
2426
+ if (F?.code !== undefined) {
2427
+ const d = Number.parseFloat(F.code);
2428
+ r = d === Ft ? undefined : d;
2429
+ } else
2430
+ F?.uri !== undefined && (n = F.uri.length === 0 ? undefined : F.uri);
2431
+ }
2432
+ const f = r ? mt(r) : undefined;
2433
+ o === `
2434
+ ` ? (n && (i += it("")), r && f && (i += st(f))) : h === `
2435
+ ` && (r && f && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
2436
+ }
2437
+ return i;
2438
+ };
2439
+ function K(t, e, s) {
2440
+ return String(t).normalize().replaceAll(`\r
2441
+ `, `
2442
+ `).split(`
2443
+ `).map((i) => Et(i, e, s)).join(`
2444
+ `);
2445
+ }
2446
+ var At = ["up", "down", "left", "right", "space", "enter", "cancel"];
2447
+ var _ = { actions: new Set(At), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
2448
+ function H(t, e) {
2449
+ if (typeof t == "string")
2450
+ return _.aliases.get(t) === e;
2451
+ for (const s of t)
2452
+ if (s !== undefined && H(s, e))
2453
+ return true;
2454
+ return false;
2455
+ }
2456
+ function _t(t, e) {
2457
+ if (t === e)
2458
+ return;
2459
+ const s = t.split(`
2460
+ `), i = e.split(`
2461
+ `), r = Math.max(s.length, i.length), n = [];
2462
+ for (let u = 0;u < r; u++)
2463
+ s[u] !== i[u] && n.push(u);
2464
+ return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
2465
+ }
2466
+ var bt = globalThis.process.platform.startsWith("win");
2467
+ var z = Symbol("clack:cancel");
2468
+ function T(t, e) {
2469
+ const s = t;
2470
+ s.isTTY && s.setRawMode(e);
2471
+ }
2472
+ function xt({ input: t = q, output: e = R, overwrite: s = true, hideCursor: i = true } = {}) {
2473
+ const r = k.createInterface({ input: t, output: e, prompt: "", tabSize: 1 });
2474
+ k.emitKeypressEvents(t, r), t instanceof J && t.isTTY && t.setRawMode(true);
2475
+ const n = (u, { name: a, sequence: l }) => {
2476
+ const E = String(u);
2477
+ if (H([E, a, l], "cancel")) {
2478
+ i && e.write(import_sisteransi.cursor.show), process.exit(0);
2479
+ return;
2480
+ }
2481
+ if (!s)
2482
+ return;
2483
+ const g = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
2484
+ k.moveCursor(e, g, m, () => {
2485
+ k.clearLine(e, 1, () => {
2486
+ t.once("keypress", n);
2487
+ });
2488
+ });
2489
+ };
2490
+ return i && e.write(import_sisteransi.cursor.hide), t.once("keypress", n), () => {
2491
+ t.off("keypress", n), i && e.write(import_sisteransi.cursor.show), t instanceof J && t.isTTY && !bt && t.setRawMode(false), r.terminal = false, r.close();
2492
+ };
2493
+ }
2494
+ var rt = (t) => ("columns" in t) && typeof t.columns == "number" ? t.columns : 80;
2495
+ var nt = (t) => ("rows" in t) && typeof t.rows == "number" ? t.rows : 20;
2496
+ function Bt(t, e, s, i = s) {
2497
+ const r = rt(t ?? R);
2498
+ return K(e, r - s.length, { hard: true, trim: false }).split(`
2499
+ `).map((n, u) => `${u === 0 ? i : s}${n}`).join(`
2500
+ `);
2501
+ }
2502
+
2503
+ class x {
2504
+ input;
2505
+ output;
2506
+ _abortSignal;
2507
+ rl;
2508
+ opts;
2509
+ _render;
2510
+ _track = false;
2511
+ _prevFrame = "";
2512
+ _subscribers = new Map;
2513
+ _cursor = 0;
2514
+ state = "initial";
2515
+ error = "";
2516
+ value;
2517
+ userInput = "";
2518
+ constructor(e, s = true) {
2519
+ const { input: i = q, output: r = R, render: n, signal: u, ...a } = e;
2520
+ this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
2521
+ }
2522
+ unsubscribe() {
2523
+ this._subscribers.clear();
2524
+ }
2525
+ setSubscriber(e, s) {
2526
+ const i = this._subscribers.get(e) ?? [];
2527
+ i.push(s), this._subscribers.set(e, i);
2528
+ }
2529
+ on(e, s) {
2530
+ this.setSubscriber(e, { cb: s });
2531
+ }
2532
+ once(e, s) {
2533
+ this.setSubscriber(e, { cb: s, once: true });
2534
+ }
2535
+ emit(e, ...s) {
2536
+ const i = this._subscribers.get(e) ?? [], r = [];
2537
+ for (const n of i)
2538
+ n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
2539
+ for (const n of r)
2540
+ n();
2541
+ }
2542
+ prompt() {
2543
+ return new Promise((e) => {
2544
+ if (this._abortSignal) {
2545
+ if (this._abortSignal.aborted)
2546
+ return this.state = "cancel", this.close(), e(z);
2547
+ this._abortSignal.addEventListener("abort", () => {
2548
+ this.state = "cancel", this.close();
2549
+ }, { once: true });
2550
+ }
2551
+ this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), T(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
2552
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(this.value);
2553
+ }), this.once("cancel", () => {
2554
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e(z);
2555
+ });
2556
+ });
2557
+ }
2558
+ _isActionKey(e, s) {
2559
+ return e === "\t";
2560
+ }
2561
+ _setValue(e) {
2562
+ this.value = e, this.emit("value", this.value);
2563
+ }
2564
+ _setUserInput(e, s) {
2565
+ this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
2566
+ }
2567
+ _clearUserInput() {
2568
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
2569
+ }
2570
+ onKeypress(e, s) {
2571
+ if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
2572
+ if (this.opts.validate) {
2573
+ const i = this.opts.validate(this.value);
2574
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
2575
+ }
2576
+ this.state !== "error" && (this.state = "submit");
2577
+ }
2578
+ H([e, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
2579
+ }
2580
+ close() {
2581
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
2582
+ `), T(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
2583
+ }
2584
+ restoreCursor() {
2585
+ const e = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
2586
+ `).length - 1;
2587
+ this.output.write(import_sisteransi.cursor.move(-999, e * -1));
2588
+ }
2589
+ render() {
2590
+ const e = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
2591
+ if (e !== this._prevFrame) {
2592
+ if (this.state === "initial")
2593
+ this.output.write(import_sisteransi.cursor.hide);
2594
+ else {
2595
+ const s = _t(this._prevFrame, e), i = nt(this.output);
2596
+ if (this.restoreCursor(), s) {
2597
+ const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
2598
+ let u = s.lines.find((a) => a >= r);
2599
+ if (u === undefined) {
2600
+ this._prevFrame = e;
2601
+ return;
2602
+ }
2603
+ if (s.lines.length === 1) {
2604
+ this.output.write(import_sisteransi.cursor.move(0, u - n)), this.output.write(import_sisteransi.erase.lines(1));
2605
+ const a = e.split(`
2606
+ `);
2607
+ this.output.write(a[u]), this._prevFrame = e, this.output.write(import_sisteransi.cursor.move(0, a.length - u - 1));
2608
+ return;
2609
+ } else if (s.lines.length > 1) {
2610
+ if (r < n)
2611
+ u = r;
2612
+ else {
2613
+ const l = u - n;
2614
+ l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
2615
+ }
2616
+ this.output.write(import_sisteransi.erase.down());
2617
+ const a = e.split(`
2618
+ `).slice(u);
2619
+ this.output.write(a.join(`
2620
+ `)), this._prevFrame = e;
2621
+ return;
2622
+ }
2623
+ }
2624
+ this.output.write(import_sisteransi.erase.down());
2625
+ }
2626
+ this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
2627
+ }
2628
+ }
2629
+ }
2630
+ function wt(t, e) {
2631
+ if (t === undefined || e.length === 0)
2632
+ return 0;
2633
+ const s = e.findIndex((i) => i.value === t);
2634
+ return s !== -1 ? s : 0;
2635
+ }
2636
+ function Dt(t, e) {
2637
+ return (e.label ?? String(e.value)).toLowerCase().includes(t.toLowerCase());
2638
+ }
2639
+ function St(t, e) {
2640
+ if (e)
2641
+ return t ? e : e[0];
2642
+ }
2643
+
2644
+ class Vt extends x {
2645
+ filteredOptions;
2646
+ multiple;
2647
+ isNavigating = false;
2648
+ selectedValues = [];
2649
+ focusedValue;
2650
+ #t = 0;
2651
+ #s = "";
2652
+ #i;
2653
+ #e;
2654
+ get cursor() {
2655
+ return this.#t;
2656
+ }
2657
+ get userInputWithCursor() {
2658
+ if (!this.userInput)
2659
+ return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
2660
+ if (this._cursor >= this.userInput.length)
2661
+ return `${this.userInput}█`;
2662
+ const e = this.userInput.slice(0, this._cursor), [s, ...i] = this.userInput.slice(this._cursor);
2663
+ return `${e}${import_picocolors.default.inverse(s)}${i.join("")}`;
2664
+ }
2665
+ get options() {
2666
+ return typeof this.#e == "function" ? this.#e() : this.#e;
2667
+ }
2668
+ constructor(e) {
2669
+ super(e), this.#e = e.options;
2670
+ const s = this.options;
2671
+ this.filteredOptions = [...s], this.multiple = e.multiple === true, this.#i = e.filter ?? Dt;
2672
+ let i;
2673
+ if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
2674
+ for (const r of i) {
2675
+ const n = s.findIndex((u) => u.value === r);
2676
+ n !== -1 && (this.toggleSelected(r), this.#t = n);
2677
+ }
2678
+ this.focusedValue = this.options[this.#t]?.value, this.on("key", (r, n) => this.#r(r, n)), this.on("userInput", (r) => this.#n(r));
2679
+ }
2680
+ _isActionKey(e, s) {
2681
+ return e === "\t" || this.multiple && this.isNavigating && s.name === "space" && e !== undefined && e !== "";
2682
+ }
2683
+ #r(e, s) {
2684
+ const i = s.name === "up", r = s.name === "down", n = s.name === "return";
2685
+ i || r ? (this.#t = Math.max(0, Math.min(this.#t + (i ? -1 : 1), this.filteredOptions.length - 1)), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = St(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
2686
+ }
2687
+ deselectAll() {
2688
+ this.selectedValues = [];
2689
+ }
2690
+ toggleSelected(e) {
2691
+ this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((s) => s !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
2692
+ }
2693
+ #n(e) {
2694
+ if (e !== this.#s) {
2695
+ this.#s = e;
2696
+ const s = this.options;
2697
+ e ? this.filteredOptions = s.filter((i) => this.#i(e, i)) : this.filteredOptions = [...s], this.#t = wt(this.focusedValue, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
2698
+ }
2699
+ }
2700
+ }
2701
+
2702
+ class kt extends x {
2703
+ get cursor() {
2704
+ return this.value ? 0 : 1;
2705
+ }
2706
+ get _value() {
2707
+ return this.cursor === 0;
2708
+ }
2709
+ constructor(e) {
2710
+ super(e, false), this.value = !!e.initialValue, this.on("userInput", () => {
2711
+ this.value = this._value;
2712
+ }), this.on("confirm", (s) => {
2713
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
2714
+ }), this.on("cursor", () => {
2715
+ this.value = !this.value;
2716
+ });
2717
+ }
2718
+ }
2719
+
2720
+ class yt extends x {
2721
+ options;
2722
+ cursor = 0;
2723
+ #t;
2724
+ getGroupItems(e) {
2725
+ return this.options.filter((s) => s.group === e);
2726
+ }
2727
+ isGroupSelected(e) {
2728
+ const s = this.getGroupItems(e), i = this.value;
2729
+ return i === undefined ? false : s.every((r) => i.includes(r.value));
2730
+ }
2731
+ toggleValue() {
2732
+ const e = this.options[this.cursor];
2733
+ if (this.value === undefined && (this.value = []), e.group === true) {
2734
+ const s = e.value, i = this.getGroupItems(s);
2735
+ this.isGroupSelected(s) ? this.value = this.value.filter((r) => i.findIndex((n) => n.value === r) === -1) : this.value = [...this.value, ...i.map((r) => r.value)], this.value = Array.from(new Set(this.value));
2736
+ } else {
2737
+ const s = this.value.includes(e.value);
2738
+ this.value = s ? this.value.filter((i) => i !== e.value) : [...this.value, e.value];
2739
+ }
2740
+ }
2741
+ constructor(e) {
2742
+ super(e, false);
2743
+ const { options: s } = e;
2744
+ this.#t = e.selectableGroups !== false, this.options = Object.entries(s).flatMap(([i, r]) => [{ value: i, group: true, label: i }, ...r.map((n) => ({ ...n, group: i }))]), this.value = [...e.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), this.#t ? 0 : 1), this.on("cursor", (i) => {
2745
+ switch (i) {
2746
+ case "left":
2747
+ case "up": {
2748
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
2749
+ const r = this.options[this.cursor]?.group === true;
2750
+ !this.#t && r && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
2751
+ break;
2752
+ }
2753
+ case "down":
2754
+ case "right": {
2755
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
2756
+ const r = this.options[this.cursor]?.group === true;
2757
+ !this.#t && r && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
2758
+ break;
2759
+ }
2760
+ case "space":
2761
+ this.toggleValue();
2762
+ break;
2763
+ }
2764
+ });
2765
+ }
2766
+ }
2767
+ function D(t, e, s) {
2768
+ const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
2769
+ return s[n].disabled ? D(n, e < 0 ? -1 : 1, s) : n;
2770
+ }
2771
+ class Wt extends x {
2772
+ options;
2773
+ cursor = 0;
2774
+ get _selectedValue() {
2775
+ return this.options[this.cursor];
2776
+ }
2777
+ changeValue() {
2778
+ this.value = this._selectedValue.value;
2779
+ }
2780
+ constructor(e) {
2781
+ super(e, false), this.options = e.options;
2782
+ const s = this.options.findIndex(({ value: r }) => r === e.initialValue), i = s === -1 ? 0 : s;
2783
+ this.cursor = this.options[i].disabled ? D(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
2784
+ switch (r) {
2785
+ case "left":
2786
+ case "up":
2787
+ this.cursor = D(this.cursor, -1, this.options);
2788
+ break;
2789
+ case "down":
2790
+ case "right":
2791
+ this.cursor = D(this.cursor, 1, this.options);
2792
+ break;
2793
+ }
2794
+ this.changeValue();
2795
+ });
2796
+ }
2797
+ }
2798
+ class $t extends x {
2799
+ get userInputWithCursor() {
2800
+ if (this.state === "submit")
2801
+ return this.userInput;
2802
+ const e = this.userInput;
2803
+ if (this.cursor >= e.length)
2804
+ return `${this.userInput}█`;
2805
+ const s = e.slice(0, this.cursor), [i, ...r] = e.slice(this.cursor);
2806
+ return `${s}${import_picocolors.default.inverse(i)}${r.join("")}`;
2807
+ }
2808
+ get cursor() {
2809
+ return this._cursor;
2810
+ }
2811
+ constructor(e) {
2812
+ super({ ...e, initialUserInput: e.initialUserInput ?? e.initialValue }), this.on("userInput", (s) => {
2813
+ this._setValue(s);
2814
+ }), this.on("finalize", () => {
2815
+ this.value || (this.value = e.defaultValue), this.value === undefined && (this.value = "");
2816
+ });
2817
+ }
2818
+ }
2819
+
2820
+ // ../../node_modules/.bun/@clack+prompts@1.0.0/node_modules/@clack/prompts/dist/index.mjs
2821
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
2822
+ import P2 from "node:process";
2823
+ var import_sisteransi2 = __toESM(require_src(), 1);
2824
+ function ht2() {
2825
+ return P2.platform !== "win32" ? P2.env.TERM !== "linux" : !!P2.env.CI || !!P2.env.WT_SESSION || !!P2.env.TERMINUS_SUBLIME || P2.env.ConEmuTask === "{cmd::Cmder}" || P2.env.TERM_PROGRAM === "Terminus-Sublime" || P2.env.TERM_PROGRAM === "vscode" || P2.env.TERM === "xterm-256color" || P2.env.TERM === "alacritty" || P2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
2826
+ }
2827
+ var ee = ht2();
2828
+ var ue = () => process.env.CI === "true";
2829
+ var w2 = (e, r) => ee ? e : r;
2830
+ var Me = w2("◆", "*");
2831
+ var ce = w2("■", "x");
2832
+ var de = w2("▲", "x");
2833
+ var k2 = w2("◇", "o");
2834
+ var $e = w2("┌", "T");
2835
+ var h = w2("│", "|");
2836
+ var x2 = w2("└", "—");
2837
+ var Re = w2("┐", "T");
2838
+ var Oe = w2("┘", "—");
2839
+ var Y = w2("●", ">");
2840
+ var K2 = w2("○", " ");
2841
+ var te = w2("◻", "[•]");
2842
+ var G2 = w2("◼", "[+]");
2843
+ var z2 = w2("◻", "[ ]");
2844
+ var Pe = w2("▪", "•");
2845
+ var se = w2("─", "-");
2846
+ var he = w2("╮", "+");
2847
+ var Ne = w2("├", "+");
2848
+ var me = w2("╯", "+");
2849
+ var pe = w2("╰", "+");
2850
+ var We = w2("╭", "+");
2851
+ var ge = w2("●", "•");
2852
+ var fe = w2("◆", "*");
2853
+ var Fe = w2("▲", "!");
2854
+ var ye = w2("■", "x");
2855
+ var N2 = (e) => {
2856
+ switch (e) {
2857
+ case "initial":
2858
+ case "active":
2859
+ return import_picocolors2.default.cyan(Me);
2860
+ case "cancel":
2861
+ return import_picocolors2.default.red(ce);
2862
+ case "error":
2863
+ return import_picocolors2.default.yellow(de);
2864
+ case "submit":
2865
+ return import_picocolors2.default.green(k2);
2866
+ }
2867
+ };
2868
+ var Ee = (e) => {
2869
+ switch (e) {
2870
+ case "initial":
2871
+ case "active":
2872
+ return import_picocolors2.default.cyan(h);
2873
+ case "cancel":
2874
+ return import_picocolors2.default.red(h);
2875
+ case "error":
2876
+ return import_picocolors2.default.yellow(h);
2877
+ case "submit":
2878
+ return import_picocolors2.default.green(h);
2879
+ }
2880
+ };
2881
+ var mt2 = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109;
2882
+ var pt2 = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510;
2883
+ var gt2 = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141;
2884
+ var ve = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
2885
+ var re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
2886
+ var ie = /\t{1,1000}/y;
2887
+ var Ae = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
2888
+ var ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
2889
+ var ft2 = /\p{M}+/gu;
2890
+ var Ft2 = { limit: 1 / 0, ellipsis: "" };
2891
+ var Le = (e, r = {}, s = {}) => {
2892
+ const i = r.limit ?? 1 / 0, n = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (n ? Le(n, Ft2, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, a = s.tabWidth ?? 8, d = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, E = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, y2 = s.wideWidth ?? 2;
2893
+ let $ = 0, c = 0, m = e.length, f = 0, F = false, v = m, S2 = Math.max(0, i - o), B = 0, b = 0, A = 0, C = 0;
2894
+ e:
2895
+ for (;; ) {
2896
+ if (b > B || c >= m && c > $) {
2897
+ const _2 = e.slice(B, b) || e.slice($, c);
2898
+ f = 0;
2899
+ for (const D2 of _2.replaceAll(ft2, "")) {
2900
+ const T2 = D2.codePointAt(0) || 0;
2901
+ if (pt2(T2) ? C = E : gt2(T2) ? C = y2 : d !== p && mt2(T2) ? C = d : C = p, A + C > S2 && (v = Math.min(v, Math.max(B, $) + f)), A + C > i) {
2902
+ F = true;
2903
+ break e;
2904
+ }
2905
+ f += D2.length, A += C;
2906
+ }
2907
+ B = b = 0;
2908
+ }
2909
+ if (c >= m)
2910
+ break;
2911
+ if (ne.lastIndex = c, ne.test(e)) {
2912
+ if (f = ne.lastIndex - c, C = f * p, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / p))), A + C > i) {
2913
+ F = true;
2914
+ break;
2915
+ }
2916
+ A += C, B = $, b = c, c = $ = ne.lastIndex;
2917
+ continue;
2918
+ }
2919
+ if (ve.lastIndex = c, ve.test(e)) {
2920
+ if (A + u > S2 && (v = Math.min(v, c)), A + u > i) {
2921
+ F = true;
2922
+ break;
2923
+ }
2924
+ A += u, B = $, b = c, c = $ = ve.lastIndex;
2925
+ continue;
2926
+ }
2927
+ if (re.lastIndex = c, re.test(e)) {
2928
+ if (f = re.lastIndex - c, C = f * l, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / l))), A + C > i) {
2929
+ F = true;
2930
+ break;
2931
+ }
2932
+ A += C, B = $, b = c, c = $ = re.lastIndex;
2933
+ continue;
2934
+ }
2935
+ if (ie.lastIndex = c, ie.test(e)) {
2936
+ if (f = ie.lastIndex - c, C = f * a, A + C > S2 && (v = Math.min(v, c + Math.floor((S2 - A) / a))), A + C > i) {
2937
+ F = true;
2938
+ break;
2939
+ }
2940
+ A += C, B = $, b = c, c = $ = ie.lastIndex;
2941
+ continue;
2942
+ }
2943
+ if (Ae.lastIndex = c, Ae.test(e)) {
2944
+ if (A + g > S2 && (v = Math.min(v, c)), A + g > i) {
2945
+ F = true;
2946
+ break;
2947
+ }
2948
+ A += g, B = $, b = c, c = $ = Ae.lastIndex;
2949
+ continue;
2950
+ }
2951
+ c += 1;
2952
+ }
2953
+ return { width: F ? S2 : A, index: F ? v : m, truncated: F, ellipsed: F && i >= o };
2954
+ };
2955
+ var yt2 = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
2956
+ var M2 = (e, r = {}) => Le(e, yt2, r).width;
2957
+ var ae = "\x1B";
2958
+ var je = "›";
2959
+ var Et2 = 39;
2960
+ var Ce = "\x07";
2961
+ var Ve = "[";
2962
+ var vt2 = "]";
2963
+ var ke = "m";
2964
+ var we = `${vt2}8;;`;
2965
+ var Ge = new RegExp(`(?:\\${Ve}(?<code>\\d+)m|\\${we}(?<uri>.*)${Ce})`, "y");
2966
+ var At2 = (e) => {
2967
+ if (e >= 30 && e <= 37 || e >= 90 && e <= 97)
2968
+ return 39;
2969
+ if (e >= 40 && e <= 47 || e >= 100 && e <= 107)
2970
+ return 49;
2971
+ if (e === 1 || e === 2)
2972
+ return 22;
2973
+ if (e === 3)
2974
+ return 23;
2975
+ if (e === 4)
2976
+ return 24;
2977
+ if (e === 7)
2978
+ return 27;
2979
+ if (e === 8)
2980
+ return 28;
2981
+ if (e === 9)
2982
+ return 29;
2983
+ if (e === 0)
2984
+ return 0;
2985
+ };
2986
+ var He = (e) => `${ae}${Ve}${e}${ke}`;
2987
+ var Ue = (e) => `${ae}${we}${e}${Ce}`;
2988
+ var Ct2 = (e) => e.map((r) => M2(r));
2989
+ var Se = (e, r, s) => {
2990
+ const i = r[Symbol.iterator]();
2991
+ let n = false, o = false, u = e.at(-1), l = u === undefined ? 0 : M2(u), a = i.next(), d = i.next(), g = 0;
2992
+ for (;!a.done; ) {
2993
+ const E = a.value, p = M2(E);
2994
+ l + p <= s ? e[e.length - 1] += E : (e.push(E), l = 0), (E === ae || E === je) && (n = true, o = r.startsWith(we, g + 1)), n ? o ? E === Ce && (n = false, o = false) : E === ke && (n = false) : (l += p, l === s && !d.done && (e.push(""), l = 0)), a = d, d = i.next(), g += E.length;
2995
+ }
2996
+ u = e.at(-1), !l && u !== undefined && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
2997
+ };
2998
+ var wt2 = (e) => {
2999
+ const r = e.split(" ");
3000
+ let s = r.length;
3001
+ for (;s > 0 && !(M2(r[s - 1]) > 0); )
3002
+ s--;
3003
+ return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
3004
+ };
3005
+ var St2 = (e, r, s = {}) => {
3006
+ if (s.trim !== false && e.trim() === "")
3007
+ return "";
3008
+ let i = "", n, o;
3009
+ const u = e.split(" "), l = Ct2(u);
3010
+ let a = [""];
3011
+ for (const [$, c] of u.entries()) {
3012
+ s.trim !== false && (a[a.length - 1] = (a.at(-1) ?? "").trimStart());
3013
+ let m = M2(a.at(-1) ?? "");
3014
+ if ($ !== 0 && (m >= r && (s.wordWrap === false || s.trim === false) && (a.push(""), m = 0), (m > 0 || s.trim === false) && (a[a.length - 1] += " ", m++)), s.hard && l[$] > r) {
3015
+ const f = r - m, F = 1 + Math.floor((l[$] - f - 1) / r);
3016
+ Math.floor((l[$] - 1) / r) < F && a.push(""), Se(a, c, r);
3017
+ continue;
3018
+ }
3019
+ if (m + l[$] > r && m > 0 && l[$] > 0) {
3020
+ if (s.wordWrap === false && m < r) {
3021
+ Se(a, c, r);
3022
+ continue;
3023
+ }
3024
+ a.push("");
3025
+ }
3026
+ if (m + l[$] > r && s.wordWrap === false) {
3027
+ Se(a, c, r);
3028
+ continue;
3029
+ }
3030
+ a[a.length - 1] += c;
3031
+ }
3032
+ s.trim !== false && (a = a.map(($) => wt2($)));
3033
+ const d = a.join(`
3034
+ `), g = d[Symbol.iterator]();
3035
+ let E = g.next(), p = g.next(), y2 = 0;
3036
+ for (;!E.done; ) {
3037
+ const $ = E.value, c = p.value;
3038
+ if (i += $, $ === ae || $ === je) {
3039
+ Ge.lastIndex = y2 + 1;
3040
+ const F = Ge.exec(d)?.groups;
3041
+ if (F?.code !== undefined) {
3042
+ const v = Number.parseFloat(F.code);
3043
+ n = v === Et2 ? undefined : v;
3044
+ } else
3045
+ F?.uri !== undefined && (o = F.uri.length === 0 ? undefined : F.uri);
3046
+ }
3047
+ const m = n ? At2(n) : undefined;
3048
+ c === `
3049
+ ` ? (o && (i += Ue("")), n && m && (i += He(m))) : $ === `
3050
+ ` && (n && m && (i += He(n)), o && (i += Ue(o))), y2 += $.length, E = p, p = g.next();
3051
+ }
3052
+ return i;
3053
+ };
3054
+ function q2(e, r, s) {
3055
+ return String(e).normalize().replaceAll(`\r
3056
+ `, `
3057
+ `).split(`
3058
+ `).map((i) => St2(i, r, s)).join(`
3059
+ `);
3060
+ }
3061
+ var It2 = (e, r, s, i, n) => {
3062
+ let o = r, u = 0;
3063
+ for (let l = s;l < i; l++) {
3064
+ const a = e[l];
3065
+ if (o = o - a.length, u++, o <= n)
3066
+ break;
3067
+ }
3068
+ return { lineCount: o, removals: u };
3069
+ };
3070
+ var J2 = (e) => {
3071
+ const { cursor: r, options: s, style: i } = e, n = e.output ?? process.stdout, o = rt(n), u = e.columnPadding ?? 0, l = e.rowPadding ?? 4, a = o - u, d = nt(n), g = import_picocolors2.default.dim("..."), E = e.maxItems ?? Number.POSITIVE_INFINITY, p = Math.max(d - l, 0), y2 = Math.max(Math.min(E, p), 5);
3072
+ let $ = 0;
3073
+ r >= y2 - 3 && ($ = Math.max(Math.min(r - y2 + 3, s.length - y2), 0));
3074
+ let c = y2 < s.length && $ > 0, m = y2 < s.length && $ + y2 < s.length;
3075
+ const f = Math.min($ + y2, s.length), F = [];
3076
+ let v = 0;
3077
+ c && v++, m && v++;
3078
+ const S2 = $ + (c ? 1 : 0), B = f - (m ? 1 : 0);
3079
+ for (let A = S2;A < B; A++) {
3080
+ const C = q2(i(s[A], A === r), a, { hard: true, trim: false }).split(`
3081
+ `);
3082
+ F.push(C), v += C.length;
3083
+ }
3084
+ if (v > p) {
3085
+ let A = 0, C = 0, _2 = v;
3086
+ const D2 = r - S2, T2 = (W2, I2) => It2(F, _2, W2, I2, p);
3087
+ c ? ({ lineCount: _2, removals: A } = T2(0, D2), _2 > p && ({ lineCount: _2, removals: C } = T2(D2 + 1, F.length))) : ({ lineCount: _2, removals: C } = T2(D2 + 1, F.length), _2 > p && ({ lineCount: _2, removals: A } = T2(0, D2))), A > 0 && (c = true, F.splice(0, A)), C > 0 && (m = true, F.splice(F.length - C, C));
3088
+ }
3089
+ const b = [];
3090
+ c && b.push(g);
3091
+ for (const A of F)
3092
+ for (const C of A)
3093
+ b.push(C);
3094
+ return m && b.push(g), b;
3095
+ };
3096
+ var Mt2 = (e) => {
3097
+ const r = e.active ?? "Yes", s = e.inactive ?? "No";
3098
+ return new kt({ active: r, inactive: s, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue ?? true, render() {
3099
+ const i = `${import_picocolors2.default.gray(h)}
3100
+ ${N2(this.state)} ${e.message}
3101
+ `, n = this.value ? r : s;
3102
+ switch (this.state) {
3103
+ case "submit":
3104
+ return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.dim(n)}`;
3105
+ case "cancel":
3106
+ return `${i}${import_picocolors2.default.gray(h)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(n))}
3107
+ ${import_picocolors2.default.gray(h)}`;
3108
+ default:
3109
+ return `${i}${import_picocolors2.default.cyan(h)} ${this.value ? `${import_picocolors2.default.green(Y)} ${r}` : `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(r)}`} ${import_picocolors2.default.dim("/")} ${this.value ? `${import_picocolors2.default.dim(K2)} ${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.green(Y)} ${s}`}
3110
+ ${import_picocolors2.default.cyan(x2)}
3111
+ `;
3112
+ }
3113
+ } }).prompt();
3114
+ };
3115
+ var Nt = (e = "", r) => {
3116
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray($e)} ${e}
3117
+ `);
3118
+ };
3119
+ var Wt2 = (e = "", r) => {
3120
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(h)}
3121
+ ${import_picocolors2.default.gray(x2)} ${e}
3122
+
3123
+ `);
3124
+ };
3125
+ var Ut = import_picocolors2.default.magenta;
3126
+ var Ie = ({ indicator: e = "dots", onCancel: r, output: s = process.stdout, cancelMessage: i, errorMessage: n, frames: o = ee ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"], delay: u = ee ? 80 : 120, signal: l, ...a } = {}) => {
3127
+ const d = ue();
3128
+ let g, E, p = false, y2 = false, $ = "", c, m = performance.now();
3129
+ const f = rt(s), F = a?.styleFrame ?? Ut, v = (I2) => {
3130
+ const O2 = I2 > 1 ? n ?? _.messages.error : i ?? _.messages.cancel;
3131
+ y2 = I2 === 1, p && (W2(O2, I2), y2 && typeof r == "function" && r());
3132
+ }, S2 = () => v(2), B = () => v(1), b = () => {
3133
+ process.on("uncaughtExceptionMonitor", S2), process.on("unhandledRejection", S2), process.on("SIGINT", B), process.on("SIGTERM", B), process.on("exit", v), l && l.addEventListener("abort", B);
3134
+ }, A = () => {
3135
+ process.removeListener("uncaughtExceptionMonitor", S2), process.removeListener("unhandledRejection", S2), process.removeListener("SIGINT", B), process.removeListener("SIGTERM", B), process.removeListener("exit", v), l && l.removeEventListener("abort", B);
3136
+ }, C = () => {
3137
+ if (c === undefined)
3138
+ return;
3139
+ d && s.write(`
3140
+ `);
3141
+ const I2 = q2(c, f, { hard: true, trim: false }).split(`
3142
+ `);
3143
+ I2.length > 1 && s.write(import_sisteransi2.cursor.up(I2.length - 1)), s.write(import_sisteransi2.cursor.to(0)), s.write(import_sisteransi2.erase.down());
3144
+ }, _2 = (I2) => I2.replace(/\.+$/, ""), D2 = (I2) => {
3145
+ const O2 = (performance.now() - I2) / 1000, L2 = Math.floor(O2 / 60), j2 = Math.floor(O2 % 60);
3146
+ return L2 > 0 ? `[${L2}m ${j2}s]` : `[${j2}s]`;
3147
+ }, T2 = (I2 = "") => {
3148
+ p = true, g = xt({ output: s }), $ = _2(I2), m = performance.now(), s.write(`${import_picocolors2.default.gray(h)}
3149
+ `);
3150
+ let O2 = 0, L2 = 0;
3151
+ b(), E = setInterval(() => {
3152
+ if (d && $ === c)
3153
+ return;
3154
+ C(), c = $;
3155
+ const j2 = F(o[O2]);
3156
+ let Z2;
3157
+ if (d)
3158
+ Z2 = `${j2} ${$}...`;
3159
+ else if (e === "timer")
3160
+ Z2 = `${j2} ${$} ${D2(m)}`;
3161
+ else {
3162
+ const Ze = ".".repeat(Math.floor(L2)).slice(0, 3);
3163
+ Z2 = `${j2} ${$}${Ze}`;
3164
+ }
3165
+ const Qe = q2(Z2, f, { hard: true, trim: false });
3166
+ s.write(Qe), O2 = O2 + 1 < o.length ? O2 + 1 : 0, L2 = L2 < 4 ? L2 + 0.125 : 0;
3167
+ }, u);
3168
+ }, W2 = (I2 = "", O2 = 0, L2 = false) => {
3169
+ if (!p)
3170
+ return;
3171
+ p = false, clearInterval(E), C();
3172
+ const j2 = O2 === 0 ? import_picocolors2.default.green(k2) : O2 === 1 ? import_picocolors2.default.red(ce) : import_picocolors2.default.red(de);
3173
+ $ = I2 ?? $, L2 || (e === "timer" ? s.write(`${j2} ${$} ${D2(m)}
3174
+ `) : s.write(`${j2} ${$}
3175
+ `)), A(), g();
3176
+ };
3177
+ return { start: T2, stop: (I2 = "") => W2(I2, 0), message: (I2 = "") => {
3178
+ $ = _2(I2 ?? $);
3179
+ }, cancel: (I2 = "") => W2(I2, 1), error: (I2 = "") => W2(I2, 2), clear: () => W2("", 0, true), get isCancelled() {
3180
+ return y2;
3181
+ } };
3182
+ };
3183
+ var Ye = { light: w2("─", "-"), heavy: w2("━", "="), block: w2("█", "#") };
3184
+ var oe = (e, r) => e.includes(`
3185
+ `) ? e.split(`
3186
+ `).map((s) => r(s)).join(`
3187
+ `) : r(e);
3188
+ var qt = (e) => {
3189
+ const r = (s, i) => {
3190
+ const n = s.label ?? String(s.value);
3191
+ switch (i) {
3192
+ case "disabled":
3193
+ return `${import_picocolors2.default.gray(K2)} ${oe(n, import_picocolors2.default.gray)}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint ?? "disabled"})`)}` : ""}`;
3194
+ case "selected":
3195
+ return `${oe(n, import_picocolors2.default.dim)}`;
3196
+ case "active":
3197
+ return `${import_picocolors2.default.green(Y)} ${n}${s.hint ? ` ${import_picocolors2.default.dim(`(${s.hint})`)}` : ""}`;
3198
+ case "cancelled":
3199
+ return `${oe(n, (o) => import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o)))}`;
3200
+ default:
3201
+ return `${import_picocolors2.default.dim(K2)} ${oe(n, import_picocolors2.default.dim)}`;
3202
+ }
3203
+ };
3204
+ return new Wt({ options: e.options, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue, render() {
3205
+ const s = `${N2(this.state)} `, i = `${Ee(this.state)} `, n = Bt(e.output, e.message, i, s), o = `${import_picocolors2.default.gray(h)}
3206
+ ${n}
3207
+ `;
3208
+ switch (this.state) {
3209
+ case "submit": {
3210
+ const u = `${import_picocolors2.default.gray(h)} `, l = Bt(e.output, r(this.options[this.cursor], "selected"), u);
3211
+ return `${o}${l}`;
3212
+ }
3213
+ case "cancel": {
3214
+ const u = `${import_picocolors2.default.gray(h)} `, l = Bt(e.output, r(this.options[this.cursor], "cancelled"), u);
3215
+ return `${o}${l}
3216
+ ${import_picocolors2.default.gray(h)}`;
3217
+ }
3218
+ default: {
3219
+ const u = `${import_picocolors2.default.cyan(h)} `, l = o.split(`
3220
+ `).length;
3221
+ return `${o}${u}${J2({ output: e.output, cursor: this.cursor, options: this.options, maxItems: e.maxItems, columnPadding: u.length, rowPadding: l + 2, style: (a, d) => r(a, a.disabled ? "disabled" : d ? "active" : "inactive") }).join(`
3222
+ ${u}`)}
3223
+ ${import_picocolors2.default.cyan(x2)}
3224
+ `;
3225
+ }
3226
+ }
3227
+ } }).prompt();
3228
+ };
3229
+ var ze = `${import_picocolors2.default.gray(h)} `;
3230
+ var Qt = (e) => new $t({ validate: e.validate, placeholder: e.placeholder, defaultValue: e.defaultValue, initialValue: e.initialValue, output: e.output, signal: e.signal, input: e.input, render() {
3231
+ const r = (e?.withGuide ?? _.withGuide) !== false, s = `${`${r ? `${import_picocolors2.default.gray(h)}
3232
+ ` : ""}${N2(this.state)} `}${e.message}
3233
+ `, i = e.placeholder ? import_picocolors2.default.inverse(e.placeholder[0]) + import_picocolors2.default.dim(e.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), n = this.userInput ? this.userInputWithCursor : i, o = this.value ?? "";
3234
+ switch (this.state) {
3235
+ case "error": {
3236
+ const u = this.error ? ` ${import_picocolors2.default.yellow(this.error)}` : "", l = r ? `${import_picocolors2.default.yellow(h)} ` : "", a = r ? import_picocolors2.default.yellow(x2) : "";
3237
+ return `${s.trim()}
3238
+ ${l}${n}
3239
+ ${a}${u}
3240
+ `;
3241
+ }
3242
+ case "submit": {
3243
+ const u = o ? ` ${import_picocolors2.default.dim(o)}` : "", l = r ? import_picocolors2.default.gray(h) : "";
3244
+ return `${s}${l}${u}`;
3245
+ }
3246
+ case "cancel": {
3247
+ const u = o ? ` ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o))}` : "", l = r ? import_picocolors2.default.gray(h) : "";
3248
+ return `${s}${l}${u}${o.trim() ? `
3249
+ ${l}` : ""}`;
3250
+ }
3251
+ default: {
3252
+ const u = r ? `${import_picocolors2.default.cyan(h)} ` : "", l = r ? import_picocolors2.default.cyan(x2) : "";
3253
+ return `${s}${u}${n}
3254
+ ${l}
3255
+ `;
3256
+ }
3257
+ }
3258
+ } }).prompt();
3259
+
3260
+ // src/cli/utils/wow-path.ts
3261
+ import { execSync } from "node:child_process";
3262
+ import { existsSync } from "node:fs";
3263
+ async function findWoWPath() {
3264
+ if (process.platform === "win32") {
3265
+ try {
3266
+ const result = execSync('reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Blizzard Entertainment\\World of Warcraft" /v InstallPath', { encoding: "utf-8" });
3267
+ const match = result.match(/REG_SZ\s+(.*)/);
3268
+ if (match && match[1]) {
3269
+ const path = match[1].trim();
3270
+ if (existsSync(path))
3271
+ return path;
3272
+ }
3273
+ } catch (e) {}
3274
+ }
3275
+ const commonPaths = [
3276
+ "C:\\Games\\World of Warcraft",
3277
+ "D:\\Games\\World of Warcraft",
3278
+ "E:\\Games\\World of Warcraft",
3279
+ "C:\\Program Files (x86)\\World of Warcraft",
3280
+ "C:\\Program Files\\World of Warcraft"
3281
+ ];
3282
+ for (const path of commonPaths) {
3283
+ if (existsSync(path))
3284
+ return path;
3285
+ }
3286
+ return null;
3287
+ }
3288
+
3289
+ // src/cli/commands/init.ts
3290
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
3291
+ import { writeFileSync, readFileSync, existsSync as existsSync2, mkdirSync } from "node:fs";
3292
+ async function initCommand(options) {
3293
+ Nt(import_picocolors3.default.bgBlue(" \uD83E\uDDF5 Weaver Init "));
3294
+ let defaultName = "MyAddon";
3295
+ let defaultAuthor = "Me";
3296
+ if (existsSync2("package.json")) {
3297
+ try {
3298
+ const pkg = JSON.parse(readFileSync("package.json", "utf-8"));
3299
+ if (pkg.name)
3300
+ defaultName = pkg.name;
3301
+ if (pkg.author)
3302
+ defaultAuthor = pkg.author;
3303
+ } catch {}
3304
+ }
3305
+ let wowPath = "";
3306
+ let addonName = defaultName;
3307
+ let flavor = "_retail_";
3308
+ if (options.yes) {
3309
+ wowPath = await findWoWPath() || "C:\\Program Files (x86)\\World of Warcraft";
3310
+ } else {
3311
+ const path = await findWoWPath();
3312
+ wowPath = path || "";
3313
+ if (path) {
3314
+ const confirmPath = await Mt2({
3315
+ message: `Found WoW at ${import_picocolors3.default.cyan(path)}. Use this?`,
3316
+ initialValue: true
3317
+ });
3318
+ if (!confirmPath) {
3319
+ const manualPath = await Qt({
3320
+ message: "Enter the path to your World of Warcraft installation:",
3321
+ placeholder: "C:\\Program Files (x86)\\World of Warcraft",
3322
+ validate(value) {
3323
+ if (value.length === 0)
3324
+ return "Path is required";
3325
+ }
3326
+ });
3327
+ if (typeof manualPath === "symbol") {
3328
+ process.exit(0);
3329
+ }
3330
+ wowPath = manualPath;
3331
+ }
3332
+ } else {
3333
+ const manualPath = await Qt({
3334
+ message: "Could not auto-detect WoW. Enter the path manually:",
3335
+ placeholder: "C:\\Program Files (x86)\\World of Warcraft",
3336
+ validate(value) {
3337
+ if (value.length === 0)
3338
+ return "Path is required";
3339
+ }
3340
+ });
3341
+ if (typeof manualPath === "symbol") {
3342
+ process.exit(0);
3343
+ }
3344
+ wowPath = manualPath;
3345
+ }
3346
+ const addonNameInput = await Qt({
3347
+ message: "Addon Name (used for folder name and TOC):",
3348
+ placeholder: defaultName,
3349
+ validate(value) {
3350
+ if (value && !/^[a-zA-Z0-9]+$/.test(value))
3351
+ return "Only alphanumeric characters allowed";
3352
+ }
3353
+ });
3354
+ if (typeof addonNameInput === "symbol") {
3355
+ process.exit(0);
3356
+ }
3357
+ addonName = addonNameInput || defaultName;
3358
+ const flavorInput = await qt({
3359
+ message: "Target Game Version:",
3360
+ options: [
3361
+ { value: "_retail_", label: "Retail (The War Within)" },
3362
+ { value: "_classic_", label: "Cataclysm Classic" },
3363
+ { value: "_classic_era_", label: "Classic Era / Hardcore" }
3364
+ ]
3365
+ });
3366
+ if (typeof flavorInput === "symbol") {
3367
+ process.exit(0);
3368
+ }
3369
+ flavor = flavorInput;
3370
+ }
3371
+ const interfaceMap = {
3372
+ _retail_: "110007",
3373
+ _classic_: "40400",
3374
+ _classic_era_: "11503"
3375
+ };
3376
+ const interfaceVersion = interfaceMap[flavor] || "110000";
3377
+ const s = Ie();
3378
+ s.start("Scaffolding your Weaver project...");
3379
+ const configContent = `
3380
+ import type { WeaverConfig } from "@weaver-wow/core";
3381
+
3382
+ const config: WeaverConfig = {
3383
+ addonName: "${addonName}",
3384
+ flavor: "${flavor}",
3385
+ interface: "${interfaceVersion}",
3386
+ wowPath: String.raw\`${wowPath}\`,
3387
+ };
3388
+
3389
+ export default config;
3390
+ `.trim();
3391
+ writeFileSync("weaver.config.ts", configContent);
3392
+ const tsconfigContent = `
3393
+ {
3394
+ "compilerOptions": {
3395
+ "target": "ESNext",
3396
+ "lib": ["ESNext"],
3397
+ "moduleResolution": "Node",
3398
+ "types": [],
3399
+ "jsx": "react",
3400
+ "jsxFactory": "createElement",
3401
+ "strict": false,
3402
+ "skipLibCheck": true,
3403
+ "sourceMap": false,
3404
+ "baseUrl": ".",
3405
+ "paths": {
3406
+ "react/jsx-runtime": ["node_modules/@weaver-wow/core/src/types/react-jsx-runtime.d.ts"]
3407
+ }
3408
+ },
3409
+ "tstl": {
3410
+ "luaTarget": "5.1",
3411
+ "luaBundle": "dist/App.lua",
3412
+ "noHeader": true
3413
+ },
3414
+ "include": ["src/**/*.tsx", "src/**/*.ts", "src/**/*.d.ts"]
3415
+ }
3416
+ `.trim();
3417
+ if (!existsSync2("tsconfig.json")) {
3418
+ writeFileSync("tsconfig.json", tsconfigContent);
3419
+ }
3420
+ if (!existsSync2("src")) {
3421
+ mkdirSync("src");
3422
+ }
3423
+ if (!existsSync2("src/App.tsx") && !existsSync2("src/index.tsx")) {
3424
+ const appContent = `
3425
+ import {
3426
+ useState,
3427
+ useEffect,
3428
+ Frame,
3429
+ Texture,
3430
+ Button,
3431
+ mount,
3432
+ createElement
3433
+ } from '@weaver-wow/core';
3434
+
3435
+ const ${addonName} = () => {
3436
+ const [clicks, setClicks] = useState("clickCount", 0);
3437
+
3438
+ useEffect(() => {
3439
+ print("${addonName} initialized!");
3440
+ }, []);
3441
+
3442
+ return (
3443
+ <Frame name="${addonName}Frame" size={[220, 100]} setPoint={["CENTER", 0, 0]}>
3444
+ <Texture setAllPoints={true} color={[0, 0, 0, 0.6]} />
3445
+ <Button
3446
+ text={\`Clicks: \${clicks}\`}
3447
+ onClick={() => setClicks(clicks + 1)}
3448
+ />
3449
+ </Frame>
3450
+ );
3451
+ };
3452
+
3453
+ mount("${addonName}", () => ${addonName}());
3454
+ `.trim();
3455
+ writeFileSync("src/App.tsx", appContent);
3456
+ }
3457
+ if (!existsSync2("package.json")) {
3458
+ const packageContent = {
3459
+ name: addonName.toLowerCase(),
3460
+ version: "0.1.0",
3461
+ private: true,
3462
+ type: "module",
3463
+ scripts: {
3464
+ build: "bun x wvr build",
3465
+ dev: "bun x wvr dev",
3466
+ link: "bun x wvr link"
3467
+ },
3468
+ dependencies: {
3469
+ "@weaver-wow/core": "^1.0.0"
3470
+ },
3471
+ devDependencies: {
3472
+ "typescript-to-lua": "latest"
3473
+ }
3474
+ };
3475
+ writeFileSync("package.json", JSON.stringify(packageContent, null, 2));
3476
+ }
3477
+ const gitignoreContent = `
3478
+ node_modules/
3479
+ dist/
3480
+ .tstl.build.json
3481
+ *.log
3482
+ `.trim();
3483
+ if (!existsSync2(".gitignore")) {
3484
+ writeFileSync(".gitignore", gitignoreContent);
3485
+ }
3486
+ s.stop("Project initialized successfully!");
3487
+ Wt2(`
3488
+ ${import_picocolors3.default.green("Project layout created:")}
3489
+ - ${import_picocolors3.default.cyan("src/App.tsx")} (Addon source)
3490
+ - ${import_picocolors3.default.cyan("weaver.config.ts")} (Addon metadata)
3491
+ - ${import_picocolors3.default.cyan("tsconfig.json")} (Compiler settings)
3492
+
3493
+ Run ${import_picocolors3.default.bold("bun install")} and then ${import_picocolors3.default.bold("bun run dev")} to start coding!
3494
+ `);
3495
+ }
3496
+
3497
+ // src/cli/commands/build.ts
3498
+ var import_picocolors5 = __toESM(require_picocolors(), 1);
3499
+
3500
+ // src/cli/utils/config.ts
3501
+ import { existsSync as existsSync3 } from "node:fs";
3502
+ import { pathToFileURL } from "node:url";
3503
+ async function loadConfig() {
3504
+ if (existsSync3("weaver.config.ts")) {
3505
+ try {
3506
+ const configPath = pathToFileURL("weaver.config.ts").href;
3507
+ const configModule = await import(configPath);
3508
+ return configModule.default;
3509
+ } catch (e) {
3510
+ console.warn("Failed to load weaver.config.ts:", e);
3511
+ }
3512
+ }
3513
+ return null;
3514
+ }
3515
+
3516
+ // src/cli/builder.ts
3517
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
3518
+ import { execSync as execSync2 } from "node:child_process";
3519
+ import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync4, readdirSync, mkdirSync as mkdirSync2, unlinkSync } from "node:fs";
3520
+ import { dirname, join, relative } from "node:path";
3521
+ import { createRequire as createRequire2 } from "node:module";
3522
+ var require2 = createRequire2(import.meta.url);
3523
+ var GENERATED_TSTL_CONFIG = ".tstl.build.json";
3524
+ async function buildProject(config, silent = false) {
3525
+ if (!silent)
3526
+ console.log("Building...");
3527
+ let pkg = {};
3528
+ if (existsSync4("package.json")) {
3529
+ try {
3530
+ pkg = JSON.parse(readFileSync2("package.json", "utf-8"));
3531
+ } catch {}
3532
+ }
3533
+ const addonName = config?.addonName || (pkg.name ? pkg.name.charAt(0).toUpperCase() + pkg.name.slice(1) : "MyAddon");
3534
+ const interfaceVersion = config?.interface || "110000";
3535
+ const author = pkg.author || "Unknown";
3536
+ const version = pkg.version || "1.0.0";
3537
+ const description = pkg.description || "Generated by Weaver";
3538
+ if (!existsSync4("tsconfig.json") && !existsSync4("tsconfig.tstl.json")) {
3539
+ throw new Error(`Missing ${import_picocolors4.default.bold("tsconfig.json")}.
3540
+ Run ${import_picocolors4.default.cyan("wvr init")} to set up your project structure.`);
3541
+ }
3542
+ let entryPoint = config?.entry;
3543
+ if (!entryPoint) {
3544
+ const potentialEntries = ["src/App.tsx", "src/index.tsx", "src/App.ts", "src/index.ts"];
3545
+ for (const pe2 of potentialEntries) {
3546
+ if (existsSync4(pe2)) {
3547
+ entryPoint = pe2;
3548
+ break;
3549
+ }
3550
+ }
3551
+ }
3552
+ const finalEntryPoint = entryPoint || "src/App.tsx";
3553
+ if (!existsSync4(finalEntryPoint)) {
3554
+ const others = ["src/App.tsx", "src/index.tsx", "src/App.ts", "src/index.ts"].filter((pe2) => pe2 !== finalEntryPoint && existsSync4(pe2));
3555
+ let suggestion = "";
3556
+ if (others.length > 0) {
3557
+ suggestion = `
3558
+ ${import_picocolors4.default.yellow("Suggestion:")} Found ${import_picocolors4.default.cyan(others[0])}. Did you mean to use that?`;
3559
+ }
3560
+ throw new Error(`Entry point not found: ${import_picocolors4.default.red(finalEntryPoint)}${suggestion}
3561
+ Check your ${import_picocolors4.default.bold("weaver.config.ts")} or ensure the source file exists.`);
3562
+ }
3563
+ if (!existsSync4("dist"))
3564
+ mkdirSync2("dist");
3565
+ const buildConfig = generateBuildConfig(finalEntryPoint);
3566
+ try {
3567
+ if (silent) {
3568
+ execSync2(`npx tstl -p ${GENERATED_TSTL_CONFIG}`, { stdio: "pipe" });
3569
+ } else {
3570
+ execSync2(`npx tstl -p ${GENERATED_TSTL_CONFIG}`, { stdio: "inherit" });
3571
+ }
3572
+ } catch (e) {
3573
+ let rawError = (e.stdout?.toString() || "") + (e.stderr?.toString() || "") + (e.message || "");
3574
+ const lines = rawError.split(`
3575
+ `);
3576
+ const formattedErrors = [];
3577
+ for (const line of lines) {
3578
+ const match = line.match(/^(.+)\((\d+),(\d+)\): error (TS\d+): (.+)$/);
3579
+ if (match) {
3580
+ const [_2, file, lineNum, colNum, code, msg] = match;
3581
+ let processedMsg = msg;
3582
+ if (msg.includes("Cannot find module '@weaver-wow/core'")) {
3583
+ processedMsg += `
3584
+ ${import_picocolors4.default.yellow("Tip:")} Run ${import_picocolors4.default.bold("bun install")} to link the Weaver runtime.`;
3585
+ }
3586
+ formattedErrors.push(` ${import_picocolors4.default.dim(file)}:${import_picocolors4.default.cyan(lineNum)}:${import_picocolors4.default.cyan(colNum)}
3587
+ ` + ` ${import_picocolors4.default.red("✖")} ${import_picocolors4.default.white(processedMsg)} ${import_picocolors4.default.dim(`[${code}]`)}`);
3588
+ } else if (line.includes("error TSTL")) {
3589
+ let msg = line.trim();
3590
+ let tip = "";
3591
+ if (msg.includes("'@weaver-wow/core'")) {
3592
+ tip = `
3593
+ ${import_picocolors4.default.yellow("Tip:")} Run ${import_picocolors4.default.bold("bun install")} or ensure Weaver is in your node_modules.`;
3594
+ }
3595
+ formattedErrors.push(` ${import_picocolors4.default.red("✖")} ${import_picocolors4.default.white(msg)}${tip}`);
3596
+ }
3597
+ }
3598
+ if (formattedErrors.length > 0) {
3599
+ throw new Error(`Compilation failed:
3600
+
3601
+ ${formattedErrors.join(`
3602
+
3603
+ `)}`);
3604
+ }
3605
+ throw new Error(`Compilation failed with unknown error:
3606
+ ${rawError}`);
3607
+ } finally {}
3608
+ const bundlePath = "./dist/App.lua";
3609
+ let luaContent = "";
3610
+ if (existsSync4(bundlePath)) {
3611
+ luaContent = readFileSync2(bundlePath, "utf-8");
3612
+ } else {
3613
+ throw new Error(`Could not find generated Lua file (${bundlePath})`);
3614
+ }
3615
+ const wrappedLua = `
3616
+ local addonName, ns = ...
3617
+ -- [WEAVER RUNTIME STUB]
3618
+ ${luaContent}
3619
+ `.trim();
3620
+ writeFileSync2("./dist/Core.lua", wrappedLua);
3621
+ try {
3622
+ unlinkSync(bundlePath);
3623
+ } catch {}
3624
+ const tocContent = `## Interface: ${interfaceVersion}
3625
+ ## Title: ${addonName}
3626
+ ## Notes: ${description}
3627
+ ## Author: ${author}
3628
+ ## Version: ${version}
3629
+
3630
+ Core.lua
3631
+ `;
3632
+ writeFileSync2(`./dist/${addonName}.toc`, tocContent);
3633
+ let assetCount = 0;
3634
+ if (existsSync4("assets")) {
3635
+ const files = readdirSync("assets");
3636
+ for (const file of files) {
3637
+ if (file.endsWith(".png")) {
3638
+ assetCount++;
3639
+ }
3640
+ }
3641
+ }
3642
+ return { addonName, assetCount };
3643
+ }
3644
+ function generateBuildConfig(entryPoint) {
3645
+ console.log("BUILDER UPDATED V2");
3646
+ const baseConfigPath = existsSync4("tsconfig.tstl.json") ? "tsconfig.tstl.json" : "tsconfig.json";
3647
+ const baseConfig = JSON.parse(readFileSync2(baseConfigPath, "utf-8"));
3648
+ const entryDir = dirname(entryPoint);
3649
+ const include = [
3650
+ ...baseConfig.include || [],
3651
+ entryPoint
3652
+ ];
3653
+ let isConsumerProject = false;
3654
+ console.log("CWD:", process.cwd());
3655
+ if (existsSync4("package.json")) {
3656
+ try {
3657
+ const pkgC = readFileSync2("package.json", "utf-8");
3658
+ const pkg = JSON.parse(pkgC);
3659
+ console.log("Found package.json with deps:", Object.keys(pkg.dependencies || {}));
3660
+ if (pkg.dependencies && pkg.dependencies["@weaver-wow/core"] || pkg.devDependencies && pkg.devDependencies["@weaver-wow/core"]) {
3661
+ isConsumerProject = true;
3662
+ }
3663
+ } catch (e) {
3664
+ console.log("Error reading pkg", e);
3665
+ }
3666
+ }
3667
+ console.log("isConsumerProject:", isConsumerProject);
3668
+ let weaverPath;
3669
+ let jsxRuntimePath;
3670
+ let includePaths = [];
3671
+ const absoluteRootDir = join(dirname(import.meta.url.replace("file:///", "")), "..", "..", "..", "..");
3672
+ if (isConsumerProject) {
3673
+ weaverPath = "node_modules/@weaver-wow/core/src/index.ts";
3674
+ jsxRuntimePath = "node_modules/@weaver-wow/core/src/types/react-jsx-runtime.d.ts";
3675
+ includePaths = [
3676
+ "node_modules/@weaver-wow/core/src/**/*.ts",
3677
+ "node_modules/@weaver-wow/core/src/**/*.tsx"
3678
+ ];
3679
+ } else if (existsSync4(join(absoluteRootDir, "packages", "weaver"))) {
3680
+ const rootDir = relative(process.cwd(), absoluteRootDir) || ".";
3681
+ weaverPath = join(rootDir, "packages/weaver/src/index.ts");
3682
+ jsxRuntimePath = join(rootDir, "packages/weaver/src/types/react-jsx-runtime.d.ts");
3683
+ includePaths = [
3684
+ join(rootDir, "packages/weaver/src/**/*.ts"),
3685
+ join(rootDir, "packages/weaver/src/**/*.tsx")
3686
+ ];
3687
+ } else {
3688
+ weaverPath = "node_modules/@weaver-wow/core/src/index.ts";
3689
+ jsxRuntimePath = "node_modules/@weaver-wow/core/src/types/react-jsx-runtime.d.ts";
3690
+ includePaths = [
3691
+ "node_modules/@weaver-wow/core/src/**/*.ts",
3692
+ "node_modules/@weaver-wow/core/src/**/*.tsx"
3693
+ ];
3694
+ }
3695
+ const buildConfig = {
3696
+ ...baseConfig,
3697
+ compilerOptions: {
3698
+ ...baseConfig.compilerOptions,
3699
+ preserveSymlinks: true,
3700
+ paths: {
3701
+ ...baseConfig.compilerOptions?.paths || {},
3702
+ "@weaver-wow/core": [weaverPath],
3703
+ "react/jsx-runtime": [jsxRuntimePath]
3704
+ }
3705
+ },
3706
+ tstl: {
3707
+ ...baseConfig.tstl,
3708
+ luaBundleEntry: entryPoint
3709
+ },
3710
+ include: [
3711
+ ...include,
3712
+ ...includePaths
3713
+ ]
3714
+ };
3715
+ if (process.env.DEBUG)
3716
+ console.log("Generated config:", JSON.stringify(buildConfig, null, 2));
3717
+ writeFileSync2(GENERATED_TSTL_CONFIG, JSON.stringify(buildConfig, null, 2));
3718
+ return GENERATED_TSTL_CONFIG;
3719
+ }
3720
+
3721
+ // src/cli/commands/build.ts
3722
+ async function buildCommand() {
3723
+ Nt(import_picocolors5.default.bgBlue(" \uD83E\uDDF5 Weaver Build "));
3724
+ const s = Ie();
3725
+ s.start("Reading configuration...");
3726
+ const config = await loadConfig();
3727
+ s.message(`Building configured project...`);
3728
+ try {
3729
+ const result = await buildProject(config, true);
3730
+ s.stop(import_picocolors5.default.green("Build complete!"));
3731
+ Wt2(`Built ${import_picocolors5.default.cyan(result.addonName)} successfully to ${import_picocolors5.default.bold("dist/")}`);
3732
+ } catch (e) {
3733
+ s.stop(import_picocolors5.default.red("Build failed"));
3734
+ console.log("");
3735
+ const message = e.message || String(e);
3736
+ message.split(`
3737
+ `).forEach((line) => {
3738
+ console.log(` ${line}`);
3739
+ });
3740
+ console.log("");
3741
+ Wt2(import_picocolors5.default.red("Build failed. Fix the issues above and try again."));
3742
+ process.exit(1);
3743
+ }
3744
+ }
3745
+
3746
+ // src/cli/commands/dev.ts
3747
+ import { watch } from "node:fs";
3748
+ var import_picocolors6 = __toESM(require_picocolors(), 1);
3749
+ async function devCommand() {
3750
+ Nt(import_picocolors6.default.bgBlue(" \uD83E\uDDF5 Weaver Dev "));
3751
+ const s = Ie();
3752
+ s.start("Starting development server...");
3753
+ const config = await loadConfig();
3754
+ try {
3755
+ await buildProject(config, true);
3756
+ s.stop(import_picocolors6.default.green("Initial build complete!"));
3757
+ } catch (e) {
3758
+ s.stop(import_picocolors6.default.red("Initial build failed"));
3759
+ console.error(e);
3760
+ }
3761
+ console.log(import_picocolors6.default.cyan(`Watching for changes in ${import_picocolors6.default.bold("src/")}...`));
3762
+ let isBuilding = false;
3763
+ watch("src", { recursive: true }, async (event, filename) => {
3764
+ if (filename && (filename.endsWith(".ts") || filename.endsWith(".tsx"))) {
3765
+ if (isBuilding)
3766
+ return;
3767
+ isBuilding = true;
3768
+ console.log(import_picocolors6.default.dim(`File changed: ${filename}`));
3769
+ const rebuildSpinner = Ie();
3770
+ rebuildSpinner.start("Rebuilding...");
3771
+ try {
3772
+ const start = performance.now();
3773
+ await buildProject(config, true);
3774
+ const end = performance.now();
3775
+ rebuildSpinner.stop(import_picocolors6.default.green(`Rebuilt in ${(end - start).toFixed(0)}ms`));
3776
+ } catch (e) {
3777
+ rebuildSpinner.stop(import_picocolors6.default.red("Rebuild failed"));
3778
+ if (e instanceof Error)
3779
+ console.error(e.message);
3780
+ } finally {
3781
+ isBuilding = false;
3782
+ }
3783
+ }
3784
+ });
3785
+ try {
3786
+ watch("sandbox", { recursive: true }, async (event, filename) => {
3787
+ if (filename && (filename.endsWith(".ts") || filename.endsWith(".tsx"))) {
3788
+ if (isBuilding)
3789
+ return;
3790
+ isBuilding = true;
3791
+ console.log(import_picocolors6.default.dim(`Sandbox file changed: ${filename}`));
3792
+ const rb = Ie();
3793
+ rb.start("Rebuilding...");
3794
+ try {
3795
+ const start = performance.now();
3796
+ await buildProject(config, true);
3797
+ const end = performance.now();
3798
+ rb.stop(import_picocolors6.default.green(`Rebuilt (sandbox) in ${(end - start).toFixed(0)}ms`));
3799
+ } catch (e) {
3800
+ rb.stop(import_picocolors6.default.red("Rebuild failed"));
3801
+ if (e instanceof Error)
3802
+ console.error(e.message);
3803
+ } finally {
3804
+ isBuilding = false;
3805
+ }
3806
+ }
3807
+ });
3808
+ } catch {}
3809
+ }
3810
+
3811
+ // src/cli/commands/link.ts
3812
+ import { symlinkSync, existsSync as existsSync5, rmSync, statSync, readFileSync as readFileSync3 } from "node:fs";
3813
+ import { join as join2, resolve } from "node:path";
3814
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
3815
+ async function linkCommand() {
3816
+ Nt(import_picocolors7.default.bgBlue(" \uD83E\uDDF5 Weaver Link "));
3817
+ const s = Ie();
3818
+ s.start("Reading configuration...");
3819
+ let config = await loadConfig();
3820
+ let addonName = config?.addonName;
3821
+ if (!addonName && existsSync5("package.json")) {
3822
+ try {
3823
+ const pkg = JSON.parse(readFileSync3("package.json", "utf-8"));
3824
+ addonName = pkg.name ? pkg.name.charAt(0).toUpperCase() + pkg.name.slice(1) : "MyAddon";
3825
+ } catch {}
3826
+ }
3827
+ addonName = addonName || "MyAddon";
3828
+ let wowPath = config?.wowPath;
3829
+ if (!wowPath) {
3830
+ s.stop("Searching for WoW installation...");
3831
+ wowPath = await findWoWPath();
3832
+ if (!wowPath) {
3833
+ const manualPath = await Qt({
3834
+ message: "Could not auto-detect WoW. Enter path manually:",
3835
+ placeholder: "C:\\Program Files (x86)\\World of Warcraft"
3836
+ });
3837
+ if (typeof manualPath === "symbol")
3838
+ process.exit(0);
3839
+ wowPath = manualPath;
3840
+ } else {
3841
+ const useFound = await Mt2({
3842
+ message: `Found WoW at ${import_picocolors7.default.cyan(wowPath)}. Use this?`,
3843
+ initialValue: true
3844
+ });
3845
+ if (!useFound) {
3846
+ const manualPath = await Qt({
3847
+ message: "Enter path manually:",
3848
+ placeholder: "C:\\Program Files (x86)\\World of Warcraft"
3849
+ });
3850
+ if (typeof manualPath === "symbol")
3851
+ process.exit(0);
3852
+ wowPath = manualPath;
3853
+ }
3854
+ }
3855
+ }
3856
+ if (!wowPath) {
3857
+ console.error(import_picocolors7.default.red("WoW path is required."));
3858
+ process.exit(1);
3859
+ }
3860
+ const flavor = config?.flavor || "_retail_";
3861
+ const addonsDir = join2(wowPath, flavor, "Interface", "AddOns");
3862
+ if (!existsSync5(addonsDir)) {
3863
+ console.error(import_picocolors7.default.red(`Could not find AddOns directory at: ${addonsDir}`));
3864
+ console.log(import_picocolors7.default.yellow(`(Make sure you have run the game at least once to create folders)`));
3865
+ process.exit(1);
3866
+ }
3867
+ const targetLinkPath = join2(addonsDir, addonName);
3868
+ const sourceDistPath = resolve("dist");
3869
+ if (!existsSync5(sourceDistPath)) {
3870
+ console.error(import_picocolors7.default.red("dist/ folder does not exist. Run 'bun wvr build' first."));
3871
+ process.exit(1);
3872
+ }
3873
+ s.start(`Linking ${import_picocolors7.default.cyan(addonName)} to WoW...`);
3874
+ if (existsSync5(targetLinkPath)) {
3875
+ const stats = statSync(targetLinkPath);
3876
+ if (stats.isSymbolicLink()) {
3877
+ s.stop("Link already exists.");
3878
+ Wt2("Addon is already linked.");
3879
+ return;
3880
+ } else {
3881
+ s.stop("Target exists as a real folder.");
3882
+ const overwrite = await Mt2({
3883
+ message: `Folder ${targetLinkPath} already exists (not a link). Delete and link?`,
3884
+ initialValue: false
3885
+ });
3886
+ if (!overwrite) {
3887
+ Wt2("Aborted.");
3888
+ return;
3889
+ }
3890
+ s.start("Removing existing folder...");
3891
+ try {
3892
+ rmSync(targetLinkPath, { recursive: true, force: true });
3893
+ } catch (e) {
3894
+ s.stop(import_picocolors7.default.red("Failed to remove existing folder."));
3895
+ console.error(e);
3896
+ process.exit(1);
3897
+ }
3898
+ }
3899
+ }
3900
+ try {
3901
+ const type = process.platform === "win32" ? "junction" : "dir";
3902
+ symlinkSync(sourceDistPath, targetLinkPath, type);
3903
+ } catch (e) {
3904
+ s.stop(import_picocolors7.default.red("Failed to create symlink"));
3905
+ console.error("Error details:", e);
3906
+ console.log(import_picocolors7.default.yellow("Try running as Administrator if on Windows."));
3907
+ process.exit(1);
3908
+ }
3909
+ s.stop(import_picocolors7.default.green("Linked successfully!"));
3910
+ Wt2(`Dev changes in ${import_picocolors7.default.bold("dist/")} will now reflect in WoW immediately.`);
3911
+ }
3912
+
3913
+ // src/cli/index.ts
3914
+ var program2 = new Command;
3915
+ program2.name("wvr").description("Weaver Addon Toolchain").version("1.0.0");
3916
+ program2.command("init").description("Initialize a new Weaver project").option("-y, --yes", "Skip prompts and use defaults").action((options) => initCommand(options));
3917
+ program2.command("build").description("Build the addon for production").action(() => buildCommand());
3918
+ program2.command("dev").description("Start development server (watch mode)").action(() => devCommand());
3919
+ program2.command("link").description("Symlink dist folder to WoW AddOns").action(() => linkCommand());
3920
+ program2.parse(process.argv);