@jeffusion/bungee 2.0.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.
Files changed (2) hide show
  1. package/dist/index.js +3589 -0
  2. package/package.json +39 -0
package/dist/index.js ADDED
@@ -0,0 +1,3589 @@
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.1/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.1/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.1/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.1/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.1/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.1/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+(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.1/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/cli-progress@3.12.0/node_modules/cli-progress/lib/eta.js
2116
+ var require_eta = __commonJS((exports, module) => {
2117
+ class ETA {
2118
+ constructor(length, initTime, initValue) {
2119
+ this.etaBufferLength = length || 100;
2120
+ this.valueBuffer = [initValue];
2121
+ this.timeBuffer = [initTime];
2122
+ this.eta = "0";
2123
+ }
2124
+ update(time, value, total) {
2125
+ this.valueBuffer.push(value);
2126
+ this.timeBuffer.push(time);
2127
+ this.calculate(total - value);
2128
+ }
2129
+ getTime() {
2130
+ return this.eta;
2131
+ }
2132
+ calculate(remaining) {
2133
+ const currentBufferSize = this.valueBuffer.length;
2134
+ const buffer = Math.min(this.etaBufferLength, currentBufferSize);
2135
+ const v_diff = this.valueBuffer[currentBufferSize - 1] - this.valueBuffer[currentBufferSize - buffer];
2136
+ const t_diff = this.timeBuffer[currentBufferSize - 1] - this.timeBuffer[currentBufferSize - buffer];
2137
+ const vt_rate = v_diff / t_diff;
2138
+ this.valueBuffer = this.valueBuffer.slice(-this.etaBufferLength);
2139
+ this.timeBuffer = this.timeBuffer.slice(-this.etaBufferLength);
2140
+ const eta = Math.ceil(remaining / vt_rate / 1000);
2141
+ if (isNaN(eta)) {
2142
+ this.eta = "NULL";
2143
+ } else if (!isFinite(eta)) {
2144
+ this.eta = "INF";
2145
+ } else if (eta > 1e7) {
2146
+ this.eta = "INF";
2147
+ } else if (eta < 0) {
2148
+ this.eta = 0;
2149
+ } else {
2150
+ this.eta = eta;
2151
+ }
2152
+ }
2153
+ }
2154
+ module.exports = ETA;
2155
+ });
2156
+
2157
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/terminal.js
2158
+ var require_terminal = __commonJS((exports, module) => {
2159
+ var _readline = __require("readline");
2160
+
2161
+ class Terminal {
2162
+ constructor(outputStream) {
2163
+ this.stream = outputStream;
2164
+ this.linewrap = true;
2165
+ this.dy = 0;
2166
+ }
2167
+ cursorSave() {
2168
+ if (!this.stream.isTTY) {
2169
+ return;
2170
+ }
2171
+ this.stream.write("\x1B7");
2172
+ }
2173
+ cursorRestore() {
2174
+ if (!this.stream.isTTY) {
2175
+ return;
2176
+ }
2177
+ this.stream.write("\x1B8");
2178
+ }
2179
+ cursor(enabled) {
2180
+ if (!this.stream.isTTY) {
2181
+ return;
2182
+ }
2183
+ if (enabled) {
2184
+ this.stream.write("\x1B[?25h");
2185
+ } else {
2186
+ this.stream.write("\x1B[?25l");
2187
+ }
2188
+ }
2189
+ cursorTo(x = null, y = null) {
2190
+ if (!this.stream.isTTY) {
2191
+ return;
2192
+ }
2193
+ _readline.cursorTo(this.stream, x, y);
2194
+ }
2195
+ cursorRelative(dx = null, dy = null) {
2196
+ if (!this.stream.isTTY) {
2197
+ return;
2198
+ }
2199
+ this.dy = this.dy + dy;
2200
+ _readline.moveCursor(this.stream, dx, dy);
2201
+ }
2202
+ cursorRelativeReset() {
2203
+ if (!this.stream.isTTY) {
2204
+ return;
2205
+ }
2206
+ _readline.moveCursor(this.stream, 0, -this.dy);
2207
+ _readline.cursorTo(this.stream, 0, null);
2208
+ this.dy = 0;
2209
+ }
2210
+ clearRight() {
2211
+ if (!this.stream.isTTY) {
2212
+ return;
2213
+ }
2214
+ _readline.clearLine(this.stream, 1);
2215
+ }
2216
+ clearLine() {
2217
+ if (!this.stream.isTTY) {
2218
+ return;
2219
+ }
2220
+ _readline.clearLine(this.stream, 0);
2221
+ }
2222
+ clearBottom() {
2223
+ if (!this.stream.isTTY) {
2224
+ return;
2225
+ }
2226
+ _readline.clearScreenDown(this.stream);
2227
+ }
2228
+ newline() {
2229
+ this.stream.write(`
2230
+ `);
2231
+ this.dy++;
2232
+ }
2233
+ write(s, rawWrite = false) {
2234
+ if (this.linewrap === true && rawWrite === false) {
2235
+ this.stream.write(s.substr(0, this.getWidth()));
2236
+ } else {
2237
+ this.stream.write(s);
2238
+ }
2239
+ }
2240
+ lineWrapping(enabled) {
2241
+ if (!this.stream.isTTY) {
2242
+ return;
2243
+ }
2244
+ this.linewrap = enabled;
2245
+ if (enabled) {
2246
+ this.stream.write("\x1B[?7h");
2247
+ } else {
2248
+ this.stream.write("\x1B[?7l");
2249
+ }
2250
+ }
2251
+ isTTY() {
2252
+ return this.stream.isTTY === true;
2253
+ }
2254
+ getWidth() {
2255
+ return this.stream.columns || (this.stream.isTTY ? 80 : 200);
2256
+ }
2257
+ }
2258
+ module.exports = Terminal;
2259
+ });
2260
+
2261
+ // ../../node_modules/.bun/ansi-regex@5.0.1/node_modules/ansi-regex/index.js
2262
+ var require_ansi_regex = __commonJS((exports, module) => {
2263
+ module.exports = ({ onlyFirst = false } = {}) => {
2264
+ const pattern = [
2265
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
2266
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
2267
+ ].join("|");
2268
+ return new RegExp(pattern, onlyFirst ? undefined : "g");
2269
+ };
2270
+ });
2271
+
2272
+ // ../../node_modules/.bun/strip-ansi@6.0.1/node_modules/strip-ansi/index.js
2273
+ var require_strip_ansi = __commonJS((exports, module) => {
2274
+ var ansiRegex = require_ansi_regex();
2275
+ module.exports = (string) => typeof string === "string" ? string.replace(ansiRegex(), "") : string;
2276
+ });
2277
+
2278
+ // ../../node_modules/.bun/is-fullwidth-code-point@3.0.0/node_modules/is-fullwidth-code-point/index.js
2279
+ var require_is_fullwidth_code_point = __commonJS((exports, module) => {
2280
+ var isFullwidthCodePoint = (codePoint) => {
2281
+ if (Number.isNaN(codePoint)) {
2282
+ return false;
2283
+ }
2284
+ if (codePoint >= 4352 && (codePoint <= 4447 || codePoint === 9001 || codePoint === 9002 || 11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || 12880 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65131 || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 262141)) {
2285
+ return true;
2286
+ }
2287
+ return false;
2288
+ };
2289
+ module.exports = isFullwidthCodePoint;
2290
+ module.exports.default = isFullwidthCodePoint;
2291
+ });
2292
+
2293
+ // ../../node_modules/.bun/emoji-regex@8.0.0/node_modules/emoji-regex/index.js
2294
+ var require_emoji_regex = __commonJS((exports, module) => {
2295
+ module.exports = function() {
2296
+ return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
2297
+ };
2298
+ });
2299
+
2300
+ // ../../node_modules/.bun/string-width@4.2.3/node_modules/string-width/index.js
2301
+ var require_string_width = __commonJS((exports, module) => {
2302
+ var stripAnsi = require_strip_ansi();
2303
+ var isFullwidthCodePoint = require_is_fullwidth_code_point();
2304
+ var emojiRegex = require_emoji_regex();
2305
+ var stringWidth = (string) => {
2306
+ if (typeof string !== "string" || string.length === 0) {
2307
+ return 0;
2308
+ }
2309
+ string = stripAnsi(string);
2310
+ if (string.length === 0) {
2311
+ return 0;
2312
+ }
2313
+ string = string.replace(emojiRegex(), " ");
2314
+ let width = 0;
2315
+ for (let i = 0;i < string.length; i++) {
2316
+ const code = string.codePointAt(i);
2317
+ if (code <= 31 || code >= 127 && code <= 159) {
2318
+ continue;
2319
+ }
2320
+ if (code >= 768 && code <= 879) {
2321
+ continue;
2322
+ }
2323
+ if (code > 65535) {
2324
+ i++;
2325
+ }
2326
+ width += isFullwidthCodePoint(code) ? 2 : 1;
2327
+ }
2328
+ return width;
2329
+ };
2330
+ module.exports = stringWidth;
2331
+ module.exports.default = stringWidth;
2332
+ });
2333
+
2334
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/format-value.js
2335
+ var require_format_value = __commonJS((exports, module) => {
2336
+ module.exports = function formatValue(v, options, type) {
2337
+ if (options.autopadding !== true) {
2338
+ return v;
2339
+ }
2340
+ function autopadding(value, length) {
2341
+ return (options.autopaddingChar + value).slice(-length);
2342
+ }
2343
+ switch (type) {
2344
+ case "percentage":
2345
+ return autopadding(v, 3);
2346
+ default:
2347
+ return v;
2348
+ }
2349
+ };
2350
+ });
2351
+
2352
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/format-bar.js
2353
+ var require_format_bar = __commonJS((exports, module) => {
2354
+ module.exports = function formatBar(progress, options) {
2355
+ const completeSize = Math.round(progress * options.barsize);
2356
+ const incompleteSize = options.barsize - completeSize;
2357
+ return options.barCompleteString.substr(0, completeSize) + options.barGlue + options.barIncompleteString.substr(0, incompleteSize);
2358
+ };
2359
+ });
2360
+
2361
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/format-time.js
2362
+ var require_format_time = __commonJS((exports, module) => {
2363
+ module.exports = function formatTime(t, options, roundToMultipleOf) {
2364
+ function round(input) {
2365
+ if (roundToMultipleOf) {
2366
+ return roundToMultipleOf * Math.round(input / roundToMultipleOf);
2367
+ } else {
2368
+ return input;
2369
+ }
2370
+ }
2371
+ function autopadding(v) {
2372
+ return (options.autopaddingChar + v).slice(-2);
2373
+ }
2374
+ if (t > 3600) {
2375
+ return autopadding(Math.floor(t / 3600)) + "h" + autopadding(round(t % 3600 / 60)) + "m";
2376
+ } else if (t > 60) {
2377
+ return autopadding(Math.floor(t / 60)) + "m" + autopadding(round(t % 60)) + "s";
2378
+ } else if (t > 10) {
2379
+ return autopadding(round(t)) + "s";
2380
+ } else {
2381
+ return autopadding(t) + "s";
2382
+ }
2383
+ };
2384
+ });
2385
+
2386
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/formatter.js
2387
+ var require_formatter = __commonJS((exports, module) => {
2388
+ var _stringWidth = require_string_width();
2389
+ var _defaultFormatValue = require_format_value();
2390
+ var _defaultFormatBar = require_format_bar();
2391
+ var _defaultFormatTime = require_format_time();
2392
+ module.exports = function defaultFormatter(options, params, payload) {
2393
+ let s = options.format;
2394
+ const formatTime = options.formatTime || _defaultFormatTime;
2395
+ const formatValue = options.formatValue || _defaultFormatValue;
2396
+ const formatBar = options.formatBar || _defaultFormatBar;
2397
+ const percentage = Math.floor(params.progress * 100) + "";
2398
+ const stopTime = params.stopTime || Date.now();
2399
+ const elapsedTime = Math.round((stopTime - params.startTime) / 1000);
2400
+ const context = Object.assign({}, payload, {
2401
+ bar: formatBar(params.progress, options),
2402
+ percentage: formatValue(percentage, options, "percentage"),
2403
+ total: formatValue(params.total, options, "total"),
2404
+ value: formatValue(params.value, options, "value"),
2405
+ eta: formatValue(params.eta, options, "eta"),
2406
+ eta_formatted: formatTime(params.eta, options, 5),
2407
+ duration: formatValue(elapsedTime, options, "duration"),
2408
+ duration_formatted: formatTime(elapsedTime, options, 1)
2409
+ });
2410
+ s = s.replace(/\{(\w+)\}/g, function(match, key) {
2411
+ if (typeof context[key] !== "undefined") {
2412
+ return context[key];
2413
+ }
2414
+ return match;
2415
+ });
2416
+ const fullMargin = Math.max(0, params.maxWidth - _stringWidth(s) - 2);
2417
+ const halfMargin = Math.floor(fullMargin / 2);
2418
+ switch (options.align) {
2419
+ case "right":
2420
+ s = fullMargin > 0 ? " ".repeat(fullMargin) + s : s;
2421
+ break;
2422
+ case "center":
2423
+ s = halfMargin > 0 ? " ".repeat(halfMargin) + s : s;
2424
+ break;
2425
+ case "left":
2426
+ default:
2427
+ break;
2428
+ }
2429
+ return s;
2430
+ };
2431
+ });
2432
+
2433
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/options.js
2434
+ var require_options = __commonJS((exports, module) => {
2435
+ function mergeOption(v, defaultValue) {
2436
+ if (typeof v === "undefined" || v === null) {
2437
+ return defaultValue;
2438
+ } else {
2439
+ return v;
2440
+ }
2441
+ }
2442
+ module.exports = {
2443
+ parse: function parse(rawOptions, preset) {
2444
+ const options = {};
2445
+ const opt = Object.assign({}, preset, rawOptions);
2446
+ options.throttleTime = 1000 / mergeOption(opt.fps, 10);
2447
+ options.stream = mergeOption(opt.stream, process.stderr);
2448
+ options.terminal = mergeOption(opt.terminal, null);
2449
+ options.clearOnComplete = mergeOption(opt.clearOnComplete, false);
2450
+ options.stopOnComplete = mergeOption(opt.stopOnComplete, false);
2451
+ options.barsize = mergeOption(opt.barsize, 40);
2452
+ options.align = mergeOption(opt.align, "left");
2453
+ options.hideCursor = mergeOption(opt.hideCursor, false);
2454
+ options.linewrap = mergeOption(opt.linewrap, false);
2455
+ options.barGlue = mergeOption(opt.barGlue, "");
2456
+ options.barCompleteChar = mergeOption(opt.barCompleteChar, "=");
2457
+ options.barIncompleteChar = mergeOption(opt.barIncompleteChar, "-");
2458
+ options.format = mergeOption(opt.format, "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}");
2459
+ options.formatTime = mergeOption(opt.formatTime, null);
2460
+ options.formatValue = mergeOption(opt.formatValue, null);
2461
+ options.formatBar = mergeOption(opt.formatBar, null);
2462
+ options.etaBufferLength = mergeOption(opt.etaBuffer, 10);
2463
+ options.etaAsynchronousUpdate = mergeOption(opt.etaAsynchronousUpdate, false);
2464
+ options.progressCalculationRelative = mergeOption(opt.progressCalculationRelative, false);
2465
+ options.synchronousUpdate = mergeOption(opt.synchronousUpdate, true);
2466
+ options.noTTYOutput = mergeOption(opt.noTTYOutput, false);
2467
+ options.notTTYSchedule = mergeOption(opt.notTTYSchedule, 2000);
2468
+ options.emptyOnZero = mergeOption(opt.emptyOnZero, false);
2469
+ options.forceRedraw = mergeOption(opt.forceRedraw, false);
2470
+ options.autopadding = mergeOption(opt.autopadding, false);
2471
+ options.gracefulExit = mergeOption(opt.gracefulExit, false);
2472
+ return options;
2473
+ },
2474
+ assignDerivedOptions: function assignDerivedOptions(options) {
2475
+ options.barCompleteString = options.barCompleteChar.repeat(options.barsize + 1);
2476
+ options.barIncompleteString = options.barIncompleteChar.repeat(options.barsize + 1);
2477
+ options.autopaddingChar = options.autopadding ? mergeOption(options.autopaddingChar, " ") : "";
2478
+ return options;
2479
+ }
2480
+ };
2481
+ });
2482
+
2483
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/generic-bar.js
2484
+ var require_generic_bar = __commonJS((exports, module) => {
2485
+ var _ETA = require_eta();
2486
+ var _Terminal = require_terminal();
2487
+ var _formatter = require_formatter();
2488
+ var _options = require_options();
2489
+ var _EventEmitter = __require("events");
2490
+ module.exports = class GenericBar extends _EventEmitter {
2491
+ constructor(options) {
2492
+ super();
2493
+ this.options = _options.assignDerivedOptions(options);
2494
+ this.terminal = this.options.terminal ? this.options.terminal : new _Terminal(this.options.stream);
2495
+ this.value = 0;
2496
+ this.startValue = 0;
2497
+ this.total = 100;
2498
+ this.lastDrawnString = null;
2499
+ this.startTime = null;
2500
+ this.stopTime = null;
2501
+ this.lastRedraw = Date.now();
2502
+ this.eta = new _ETA(this.options.etaBufferLength, 0, 0);
2503
+ this.payload = {};
2504
+ this.isActive = false;
2505
+ this.formatter = typeof this.options.format === "function" ? this.options.format : _formatter;
2506
+ }
2507
+ render(forceRendering = false) {
2508
+ const params = {
2509
+ progress: this.getProgress(),
2510
+ eta: this.eta.getTime(),
2511
+ startTime: this.startTime,
2512
+ stopTime: this.stopTime,
2513
+ total: this.total,
2514
+ value: this.value,
2515
+ maxWidth: this.terminal.getWidth()
2516
+ };
2517
+ if (this.options.etaAsynchronousUpdate) {
2518
+ this.updateETA();
2519
+ }
2520
+ const s = this.formatter(this.options, params, this.payload);
2521
+ const forceRedraw = forceRendering || this.options.forceRedraw || this.options.noTTYOutput && !this.terminal.isTTY();
2522
+ if (forceRedraw || this.lastDrawnString != s) {
2523
+ this.emit("redraw-pre");
2524
+ this.terminal.cursorTo(0, null);
2525
+ this.terminal.write(s);
2526
+ this.terminal.clearRight();
2527
+ this.lastDrawnString = s;
2528
+ this.lastRedraw = Date.now();
2529
+ this.emit("redraw-post");
2530
+ }
2531
+ }
2532
+ start(total, startValue, payload) {
2533
+ this.value = startValue || 0;
2534
+ this.total = typeof total !== "undefined" && total >= 0 ? total : 100;
2535
+ this.startValue = startValue || 0;
2536
+ this.payload = payload || {};
2537
+ this.startTime = Date.now();
2538
+ this.stopTime = null;
2539
+ this.lastDrawnString = "";
2540
+ this.eta = new _ETA(this.options.etaBufferLength, this.startTime, this.value);
2541
+ this.isActive = true;
2542
+ this.emit("start", total, startValue);
2543
+ }
2544
+ stop() {
2545
+ this.isActive = false;
2546
+ this.stopTime = Date.now();
2547
+ this.emit("stop", this.total, this.value);
2548
+ }
2549
+ update(arg0, arg1 = {}) {
2550
+ if (typeof arg0 === "number") {
2551
+ this.value = arg0;
2552
+ this.eta.update(Date.now(), arg0, this.total);
2553
+ }
2554
+ const payloadData = (typeof arg0 === "object" ? arg0 : arg1) || {};
2555
+ this.emit("update", this.total, this.value);
2556
+ for (const key in payloadData) {
2557
+ this.payload[key] = payloadData[key];
2558
+ }
2559
+ if (this.value >= this.getTotal() && this.options.stopOnComplete) {
2560
+ this.stop();
2561
+ }
2562
+ }
2563
+ getProgress() {
2564
+ let progress = this.value / this.total;
2565
+ if (this.options.progressCalculationRelative) {
2566
+ progress = (this.value - this.startValue) / (this.total - this.startValue);
2567
+ }
2568
+ if (isNaN(progress)) {
2569
+ progress = this.options && this.options.emptyOnZero ? 0 : 1;
2570
+ }
2571
+ progress = Math.min(Math.max(progress, 0), 1);
2572
+ return progress;
2573
+ }
2574
+ increment(arg0 = 1, arg1 = {}) {
2575
+ if (typeof arg0 === "object") {
2576
+ this.update(this.value + 1, arg0);
2577
+ } else {
2578
+ this.update(this.value + arg0, arg1);
2579
+ }
2580
+ }
2581
+ getTotal() {
2582
+ return this.total;
2583
+ }
2584
+ setTotal(total) {
2585
+ if (typeof total !== "undefined" && total >= 0) {
2586
+ this.total = total;
2587
+ }
2588
+ }
2589
+ updateETA() {
2590
+ this.eta.update(Date.now(), this.value, this.total);
2591
+ }
2592
+ };
2593
+ });
2594
+
2595
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/single-bar.js
2596
+ var require_single_bar = __commonJS((exports, module) => {
2597
+ var _GenericBar = require_generic_bar();
2598
+ var _options = require_options();
2599
+ module.exports = class SingleBar extends _GenericBar {
2600
+ constructor(options, preset) {
2601
+ super(_options.parse(options, preset));
2602
+ this.timer = null;
2603
+ if (this.options.noTTYOutput && this.terminal.isTTY() === false) {
2604
+ this.options.synchronousUpdate = false;
2605
+ }
2606
+ this.schedulingRate = this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule;
2607
+ this.sigintCallback = null;
2608
+ }
2609
+ render() {
2610
+ if (this.timer) {
2611
+ clearTimeout(this.timer);
2612
+ this.timer = null;
2613
+ }
2614
+ super.render();
2615
+ if (this.options.noTTYOutput && this.terminal.isTTY() === false) {
2616
+ this.terminal.newline();
2617
+ }
2618
+ this.timer = setTimeout(this.render.bind(this), this.schedulingRate);
2619
+ }
2620
+ update(current, payload) {
2621
+ if (!this.timer) {
2622
+ return;
2623
+ }
2624
+ super.update(current, payload);
2625
+ if (this.options.synchronousUpdate && this.lastRedraw + this.options.throttleTime * 2 < Date.now()) {
2626
+ this.render();
2627
+ }
2628
+ }
2629
+ start(total, startValue, payload) {
2630
+ if (this.options.noTTYOutput === false && this.terminal.isTTY() === false) {
2631
+ return;
2632
+ }
2633
+ if (this.sigintCallback === null && this.options.gracefulExit) {
2634
+ this.sigintCallback = this.stop.bind(this);
2635
+ process.once("SIGINT", this.sigintCallback);
2636
+ process.once("SIGTERM", this.sigintCallback);
2637
+ }
2638
+ this.terminal.cursorSave();
2639
+ if (this.options.hideCursor === true) {
2640
+ this.terminal.cursor(false);
2641
+ }
2642
+ if (this.options.linewrap === false) {
2643
+ this.terminal.lineWrapping(false);
2644
+ }
2645
+ super.start(total, startValue, payload);
2646
+ this.render();
2647
+ }
2648
+ stop() {
2649
+ if (!this.timer) {
2650
+ return;
2651
+ }
2652
+ if (this.sigintCallback) {
2653
+ process.removeListener("SIGINT", this.sigintCallback);
2654
+ process.removeListener("SIGTERM", this.sigintCallback);
2655
+ this.sigintCallback = null;
2656
+ }
2657
+ this.render();
2658
+ super.stop();
2659
+ clearTimeout(this.timer);
2660
+ this.timer = null;
2661
+ if (this.options.hideCursor === true) {
2662
+ this.terminal.cursor(true);
2663
+ }
2664
+ if (this.options.linewrap === false) {
2665
+ this.terminal.lineWrapping(true);
2666
+ }
2667
+ this.terminal.cursorRestore();
2668
+ if (this.options.clearOnComplete) {
2669
+ this.terminal.cursorTo(0, null);
2670
+ this.terminal.clearLine();
2671
+ } else {
2672
+ this.terminal.newline();
2673
+ }
2674
+ }
2675
+ };
2676
+ });
2677
+
2678
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/lib/multi-bar.js
2679
+ var require_multi_bar = __commonJS((exports, module) => {
2680
+ var _Terminal = require_terminal();
2681
+ var _BarElement = require_generic_bar();
2682
+ var _options = require_options();
2683
+ var _EventEmitter = __require("events");
2684
+ module.exports = class MultiBar extends _EventEmitter {
2685
+ constructor(options, preset) {
2686
+ super();
2687
+ this.bars = [];
2688
+ this.options = _options.parse(options, preset);
2689
+ this.options.synchronousUpdate = false;
2690
+ this.terminal = this.options.terminal ? this.options.terminal : new _Terminal(this.options.stream);
2691
+ this.timer = null;
2692
+ this.isActive = false;
2693
+ this.schedulingRate = this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule;
2694
+ this.loggingBuffer = [];
2695
+ this.sigintCallback = null;
2696
+ }
2697
+ create(total, startValue, payload, barOptions = {}) {
2698
+ const bar = new _BarElement(Object.assign({}, this.options, {
2699
+ terminal: this.terminal
2700
+ }, barOptions));
2701
+ this.bars.push(bar);
2702
+ if (this.options.noTTYOutput === false && this.terminal.isTTY() === false) {
2703
+ return bar;
2704
+ }
2705
+ if (this.sigintCallback === null && this.options.gracefulExit) {
2706
+ this.sigintCallback = this.stop.bind(this);
2707
+ process.once("SIGINT", this.sigintCallback);
2708
+ process.once("SIGTERM", this.sigintCallback);
2709
+ }
2710
+ if (!this.isActive) {
2711
+ if (this.options.hideCursor === true) {
2712
+ this.terminal.cursor(false);
2713
+ }
2714
+ if (this.options.linewrap === false) {
2715
+ this.terminal.lineWrapping(false);
2716
+ }
2717
+ this.timer = setTimeout(this.update.bind(this), this.schedulingRate);
2718
+ }
2719
+ this.isActive = true;
2720
+ bar.start(total, startValue, payload);
2721
+ this.emit("start");
2722
+ return bar;
2723
+ }
2724
+ remove(bar) {
2725
+ const index = this.bars.indexOf(bar);
2726
+ if (index < 0) {
2727
+ return false;
2728
+ }
2729
+ this.bars.splice(index, 1);
2730
+ this.update();
2731
+ this.terminal.newline();
2732
+ this.terminal.clearBottom();
2733
+ return true;
2734
+ }
2735
+ update() {
2736
+ if (this.timer) {
2737
+ clearTimeout(this.timer);
2738
+ this.timer = null;
2739
+ }
2740
+ this.emit("update-pre");
2741
+ this.terminal.cursorRelativeReset();
2742
+ this.emit("redraw-pre");
2743
+ if (this.loggingBuffer.length > 0) {
2744
+ this.terminal.clearLine();
2745
+ while (this.loggingBuffer.length > 0) {
2746
+ this.terminal.write(this.loggingBuffer.shift(), true);
2747
+ }
2748
+ }
2749
+ for (let i = 0;i < this.bars.length; i++) {
2750
+ if (i > 0) {
2751
+ this.terminal.newline();
2752
+ }
2753
+ this.bars[i].render();
2754
+ }
2755
+ this.emit("redraw-post");
2756
+ if (this.options.noTTYOutput && this.terminal.isTTY() === false) {
2757
+ this.terminal.newline();
2758
+ this.terminal.newline();
2759
+ }
2760
+ this.timer = setTimeout(this.update.bind(this), this.schedulingRate);
2761
+ this.emit("update-post");
2762
+ if (this.options.stopOnComplete && !this.bars.find((bar) => bar.isActive)) {
2763
+ this.stop();
2764
+ }
2765
+ }
2766
+ stop() {
2767
+ clearTimeout(this.timer);
2768
+ this.timer = null;
2769
+ if (this.sigintCallback) {
2770
+ process.removeListener("SIGINT", this.sigintCallback);
2771
+ process.removeListener("SIGTERM", this.sigintCallback);
2772
+ this.sigintCallback = null;
2773
+ }
2774
+ this.isActive = false;
2775
+ if (this.options.hideCursor === true) {
2776
+ this.terminal.cursor(true);
2777
+ }
2778
+ if (this.options.linewrap === false) {
2779
+ this.terminal.lineWrapping(true);
2780
+ }
2781
+ this.terminal.cursorRelativeReset();
2782
+ this.emit("stop-pre-clear");
2783
+ if (this.options.clearOnComplete) {
2784
+ this.terminal.clearBottom();
2785
+ } else {
2786
+ for (let i = 0;i < this.bars.length; i++) {
2787
+ if (i > 0) {
2788
+ this.terminal.newline();
2789
+ }
2790
+ this.bars[i].render();
2791
+ this.bars[i].stop();
2792
+ }
2793
+ this.terminal.newline();
2794
+ }
2795
+ this.emit("stop");
2796
+ }
2797
+ log(s) {
2798
+ this.loggingBuffer.push(s);
2799
+ }
2800
+ };
2801
+ });
2802
+
2803
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/presets/legacy.js
2804
+ var require_legacy = __commonJS((exports, module) => {
2805
+ module.exports = {
2806
+ format: "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",
2807
+ barCompleteChar: "=",
2808
+ barIncompleteChar: "-"
2809
+ };
2810
+ });
2811
+
2812
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/presets/shades-classic.js
2813
+ var require_shades_classic = __commonJS((exports, module) => {
2814
+ module.exports = {
2815
+ format: " {bar} {percentage}% | ETA: {eta}s | {value}/{total}",
2816
+ barCompleteChar: "█",
2817
+ barIncompleteChar: "░"
2818
+ };
2819
+ });
2820
+
2821
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/presets/shades-grey.js
2822
+ var require_shades_grey = __commonJS((exports, module) => {
2823
+ module.exports = {
2824
+ format: " \x1B[90m{bar}\x1B[0m {percentage}% | ETA: {eta}s | {value}/{total}",
2825
+ barCompleteChar: "█",
2826
+ barIncompleteChar: "░"
2827
+ };
2828
+ });
2829
+
2830
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/presets/rect.js
2831
+ var require_rect = __commonJS((exports, module) => {
2832
+ module.exports = {
2833
+ format: " {bar}■ {percentage}% | ETA: {eta}s | {value}/{total}",
2834
+ barCompleteChar: "■",
2835
+ barIncompleteChar: " "
2836
+ };
2837
+ });
2838
+
2839
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/presets/index.js
2840
+ var require_presets = __commonJS((exports, module) => {
2841
+ var _legacy = require_legacy();
2842
+ var _shades_classic = require_shades_classic();
2843
+ var _shades_grey = require_shades_grey();
2844
+ var _rect = require_rect();
2845
+ module.exports = {
2846
+ legacy: _legacy,
2847
+ shades_classic: _shades_classic,
2848
+ shades_grey: _shades_grey,
2849
+ rect: _rect
2850
+ };
2851
+ });
2852
+
2853
+ // ../../node_modules/.bun/cli-progress@3.12.0/node_modules/cli-progress/cli-progress.js
2854
+ var require_cli_progress = __commonJS((exports, module) => {
2855
+ var _SingleBar = require_single_bar();
2856
+ var _MultiBar = require_multi_bar();
2857
+ var _Presets = require_presets();
2858
+ var _Formatter = require_formatter();
2859
+ var _defaultFormatValue = require_format_value();
2860
+ var _defaultFormatBar = require_format_bar();
2861
+ var _defaultFormatTime = require_format_time();
2862
+ module.exports = {
2863
+ Bar: _SingleBar,
2864
+ SingleBar: _SingleBar,
2865
+ MultiBar: _MultiBar,
2866
+ Presets: _Presets,
2867
+ Format: {
2868
+ Formatter: _Formatter,
2869
+ BarFormat: _defaultFormatBar,
2870
+ ValueFormat: _defaultFormatValue,
2871
+ TimeFormat: _defaultFormatTime
2872
+ }
2873
+ };
2874
+ });
2875
+
2876
+ // ../../node_modules/.bun/commander@14.0.1/node_modules/commander/esm.mjs
2877
+ var import__ = __toESM(require_commander(), 1);
2878
+ var {
2879
+ program,
2880
+ createCommand,
2881
+ createArgument,
2882
+ createOption,
2883
+ CommanderError,
2884
+ InvalidArgumentError,
2885
+ InvalidOptionArgumentError,
2886
+ Command,
2887
+ Argument,
2888
+ Option,
2889
+ Help
2890
+ } = import__.default;
2891
+
2892
+ // src/commands/init.ts
2893
+ import path2 from "path";
2894
+ import fs from "fs";
2895
+ import { fileURLToPath } from "url";
2896
+ import { dirname } from "path";
2897
+
2898
+ // src/config/paths.ts
2899
+ import path from "path";
2900
+ import os from "os";
2901
+
2902
+ class ConfigPaths {
2903
+ static CONFIG_DIR = path.join(os.homedir(), ".bungee");
2904
+ static DEFAULT_CONFIG_FILE = path.join(ConfigPaths.CONFIG_DIR, "config.json");
2905
+ static PID_FILE = path.join(ConfigPaths.CONFIG_DIR, "bungee.pid");
2906
+ static LOG_FILE = path.join(ConfigPaths.CONFIG_DIR, "bungee.log");
2907
+ static ERROR_LOG_FILE = path.join(ConfigPaths.CONFIG_DIR, "bungee.error.log");
2908
+ static DATA_DIR = path.join(ConfigPaths.CONFIG_DIR, "data");
2909
+ static STATS_DIR = path.join(ConfigPaths.DATA_DIR, "stats");
2910
+ static resolveConfigPath(userProvidedPath) {
2911
+ if (userProvidedPath) {
2912
+ return path.resolve(userProvidedPath);
2913
+ }
2914
+ return ConfigPaths.DEFAULT_CONFIG_FILE;
2915
+ }
2916
+ static ensureConfigDir() {
2917
+ const fs = __require("fs");
2918
+ if (!fs.existsSync(ConfigPaths.CONFIG_DIR)) {
2919
+ fs.mkdirSync(ConfigPaths.CONFIG_DIR, { recursive: true });
2920
+ }
2921
+ }
2922
+ }
2923
+
2924
+ // src/commands/init.ts
2925
+ var __filename2 = fileURLToPath(import.meta.url);
2926
+ var __dirname2 = dirname(__filename2);
2927
+ async function initCommand(configPath, options = {}) {
2928
+ try {
2929
+ const targetPath = configPath ? path2.resolve(configPath) : ConfigPaths.DEFAULT_CONFIG_FILE;
2930
+ ConfigPaths.ensureConfigDir();
2931
+ if (fs.existsSync(targetPath) && !options.force) {
2932
+ console.log(`❌ Configuration file already exists at: ${targetPath}`);
2933
+ console.log("\uD83D\uDCA1 Use --force to overwrite the existing file.");
2934
+ process.exit(1);
2935
+ }
2936
+ const possibleTemplatePaths = [
2937
+ path2.resolve(__dirname2, "../../../config.example.json"),
2938
+ path2.resolve(__dirname2, "../../config.example.json"),
2939
+ path2.resolve(__dirname2, "../config.example.json"),
2940
+ path2.resolve(process.execPath, "../config.example.json"),
2941
+ path2.resolve(path2.dirname(process.execPath), "../config.example.json"),
2942
+ path2.resolve(process.cwd(), "config.example.json")
2943
+ ];
2944
+ let templatePath = null;
2945
+ for (const possiblePath of possibleTemplatePaths) {
2946
+ if (fs.existsSync(possiblePath)) {
2947
+ templatePath = possiblePath;
2948
+ break;
2949
+ }
2950
+ }
2951
+ if (!templatePath) {
2952
+ console.log("❌ Configuration template not found.");
2953
+ console.log("\uD83D\uDCA1 Searched locations:");
2954
+ possibleTemplatePaths.forEach((path3) => console.log(` - ${path3}`));
2955
+ console.log("\uD83D\uDCA1 Please ensure config.example.json is available.");
2956
+ process.exit(1);
2957
+ }
2958
+ const targetDir = path2.dirname(targetPath);
2959
+ if (!fs.existsSync(targetDir)) {
2960
+ fs.mkdirSync(targetDir, { recursive: true });
2961
+ }
2962
+ await fs.promises.copyFile(templatePath, targetPath);
2963
+ console.log(`✅ Configuration file created at: ${targetPath}`);
2964
+ console.log();
2965
+ if (targetPath === ConfigPaths.DEFAULT_CONFIG_FILE) {
2966
+ console.log("\uD83D\uDCDD This is the default configuration location.");
2967
+ console.log("\uD83D\uDE80 You can now start Bungee with: bungee start");
2968
+ } else {
2969
+ console.log("\uD83D\uDCDD You created a custom configuration file.");
2970
+ console.log(`\uD83D\uDE80 Start Bungee with: bungee start ${targetPath}`);
2971
+ }
2972
+ console.log();
2973
+ console.log("⚙️ Please edit the configuration file before starting the server.");
2974
+ console.log('\uD83D\uDCA1 Use "bungee status" to check if the server is running.');
2975
+ } catch (error) {
2976
+ console.error("❌ Failed to initialize configuration:", error);
2977
+ process.exit(1);
2978
+ }
2979
+ }
2980
+
2981
+ // src/daemon/manager.ts
2982
+ import path3 from "path";
2983
+ import fs2 from "fs";
2984
+ import { spawn } from "child_process";
2985
+
2986
+ // src/binary/manager.ts
2987
+ import { existsSync, mkdirSync, chmodSync, writeFileSync, readFileSync, unlinkSync } from "fs";
2988
+ import { join } from "path";
2989
+ import { homedir, platform, arch } from "os";
2990
+ // package.json
2991
+ var package_default = {
2992
+ name: "@jeffusion/bungee",
2993
+ version: "2.0.0",
2994
+ description: "High-performance reverse proxy server CLI",
2995
+ type: "module",
2996
+ bin: {
2997
+ bungee: "./dist/index.js"
2998
+ },
2999
+ main: "dist/index.js",
3000
+ scripts: {
3001
+ dev: "bun --watch src/index.ts",
3002
+ build: "bun build src/index.ts --outdir dist --target node",
3003
+ test: "echo 'No tests for CLI package yet'"
3004
+ },
3005
+ dependencies: {
3006
+ "@jeffusion/bungee-core": "workspace:*",
3007
+ "@jeffusion/bungee-types": "workspace:*",
3008
+ "cli-progress": "^3.12.0",
3009
+ commander: "^14.0.1"
3010
+ },
3011
+ devDependencies: {
3012
+ "@types/cli-progress": "^3.11.6"
3013
+ },
3014
+ keywords: [
3015
+ "reverse-proxy",
3016
+ "bun",
3017
+ "cli",
3018
+ "daemon"
3019
+ ],
3020
+ files: [
3021
+ "dist/",
3022
+ "README.md"
3023
+ ],
3024
+ preferGlobal: true,
3025
+ engines: {
3026
+ node: ">=18.0.0"
3027
+ },
3028
+ license: "MIT"
3029
+ };
3030
+
3031
+ // src/binary/manager.ts
3032
+ var import_cli_progress = __toESM(require_cli_progress(), 1);
3033
+ import { createInterface } from "readline";
3034
+
3035
+ class BinaryManager {
3036
+ static BINARY_DIR = join(homedir(), ".bungee", "bin");
3037
+ static VERSION_FILE = join(homedir(), ".bungee", "version.txt");
3038
+ static GITHUB_REPO = "jeffusion/bungee";
3039
+ static getBinaryName() {
3040
+ const platformName = platform();
3041
+ const archName = arch();
3042
+ if (platformName === "darwin") {
3043
+ return archName === "arm64" ? "bungee-macos-arm64" : "bungee-macos";
3044
+ } else if (platformName === "linux") {
3045
+ return "bungee-linux";
3046
+ } else if (platformName === "win32") {
3047
+ return "bungee-windows.exe";
3048
+ }
3049
+ throw new Error(`Unsupported platform: ${platformName}-${archName}`);
3050
+ }
3051
+ static getLocalBinaryPath() {
3052
+ return join(this.BINARY_DIR, this.getBinaryName());
3053
+ }
3054
+ static isBinaryInstalled() {
3055
+ return existsSync(this.getLocalBinaryPath());
3056
+ }
3057
+ static getInstalledVersion() {
3058
+ try {
3059
+ if (!existsSync(this.VERSION_FILE)) {
3060
+ return null;
3061
+ }
3062
+ return readFileSync(this.VERSION_FILE, "utf-8").trim();
3063
+ } catch {
3064
+ return null;
3065
+ }
3066
+ }
3067
+ static saveVersion(version) {
3068
+ const dir = join(homedir(), ".bungee");
3069
+ if (!existsSync(dir)) {
3070
+ mkdirSync(dir, { recursive: true });
3071
+ }
3072
+ writeFileSync(this.VERSION_FILE, version);
3073
+ }
3074
+ static checkVersion() {
3075
+ const installedVersion = this.getInstalledVersion();
3076
+ const currentVersion = package_default.version;
3077
+ if (!installedVersion) {
3078
+ return false;
3079
+ }
3080
+ return installedVersion === currentVersion;
3081
+ }
3082
+ static getDownloadUrl() {
3083
+ const version = package_default.version;
3084
+ const binaryName = this.getBinaryName();
3085
+ return `https://github.com/${this.GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
3086
+ }
3087
+ static async promptConfirm(message) {
3088
+ const rl = createInterface({
3089
+ input: process.stdin,
3090
+ output: process.stdout
3091
+ });
3092
+ return new Promise((resolve) => {
3093
+ rl.question(`${message} (y/N): `, (answer) => {
3094
+ rl.close();
3095
+ resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
3096
+ });
3097
+ });
3098
+ }
3099
+ static async downloadBinary(options = {}) {
3100
+ const url = this.getDownloadUrl();
3101
+ const localPath = this.getLocalBinaryPath();
3102
+ const version = package_default.version;
3103
+ if (!options.silent) {
3104
+ console.log("\uD83D\uDCE6 Downloading Bungee binary...");
3105
+ console.log(` Platform: ${platform()}-${arch()}`);
3106
+ console.log(` Version: v${version}`);
3107
+ console.log(` URL: ${url}
3108
+ `);
3109
+ }
3110
+ if (!existsSync(this.BINARY_DIR)) {
3111
+ mkdirSync(this.BINARY_DIR, { recursive: true });
3112
+ }
3113
+ try {
3114
+ const response = await fetch(url);
3115
+ if (!response.ok) {
3116
+ if (response.status === 404) {
3117
+ throw new Error(`Binary not found for ${platform()}-${arch()}.
3118
+ ` + `Please check if version v${version} has been released with binaries.
3119
+ ` + `URL: ${url}`);
3120
+ }
3121
+ throw new Error(`Failed to download: ${response.statusText}`);
3122
+ }
3123
+ const contentLength = parseInt(response.headers.get("content-length") || "0");
3124
+ if (!options.silent && contentLength > 0) {
3125
+ const progressBar = new import_cli_progress.default.SingleBar({
3126
+ format: " Downloading |{bar}| {percentage}% | {value}/{total} MB | Speed: {speed} MB/s | ETA: {eta}s",
3127
+ barCompleteChar: "█",
3128
+ barIncompleteChar: "░",
3129
+ hideCursor: true
3130
+ });
3131
+ progressBar.start(Math.ceil(contentLength / 1024 / 1024), 0, {
3132
+ speed: "0.00"
3133
+ });
3134
+ const reader = response.body.getReader();
3135
+ const chunks = [];
3136
+ let receivedLength = 0;
3137
+ const startTime = Date.now();
3138
+ while (true) {
3139
+ const { done, value } = await reader.read();
3140
+ if (done)
3141
+ break;
3142
+ chunks.push(value);
3143
+ receivedLength += value.length;
3144
+ const receivedMB = receivedLength / 1024 / 1024;
3145
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
3146
+ const speed = (receivedMB / elapsedSeconds).toFixed(2);
3147
+ progressBar.update(Math.ceil(receivedMB), {
3148
+ speed
3149
+ });
3150
+ }
3151
+ progressBar.stop();
3152
+ const buffer = Buffer.concat(chunks);
3153
+ writeFileSync(localPath, buffer);
3154
+ } else {
3155
+ const arrayBuffer = await response.arrayBuffer();
3156
+ const buffer = Buffer.from(arrayBuffer);
3157
+ writeFileSync(localPath, buffer);
3158
+ }
3159
+ chmodSync(localPath, 493);
3160
+ this.saveVersion(version);
3161
+ if (!options.silent) {
3162
+ console.log(`
3163
+ ✅ Binary downloaded successfully`);
3164
+ console.log(` Location: ${localPath}`);
3165
+ console.log(` Version: v${version}
3166
+ `);
3167
+ }
3168
+ } catch (error) {
3169
+ throw new Error(`Failed to download binary: ${error.message}`);
3170
+ }
3171
+ }
3172
+ static async ensureBinary(options = {}) {
3173
+ const localPath = this.getLocalBinaryPath();
3174
+ const isInstalled = this.isBinaryInstalled();
3175
+ const versionMatches = this.checkVersion();
3176
+ if (!isInstalled) {
3177
+ console.log(`⚠️ Bungee binary not found locally
3178
+ `);
3179
+ if (!options.force) {
3180
+ const confirmed = await this.promptConfirm("\uD83D\uDCE5 Download binary now?");
3181
+ if (!confirmed) {
3182
+ throw new Error("Binary download cancelled by user");
3183
+ }
3184
+ }
3185
+ await this.downloadBinary({ force: options.force });
3186
+ return localPath;
3187
+ }
3188
+ if (!versionMatches) {
3189
+ const installedVersion = this.getInstalledVersion();
3190
+ const currentVersion = package_default.version;
3191
+ console.log("⚠️ Binary version mismatch detected");
3192
+ console.log(` Installed: v${installedVersion || "unknown"}`);
3193
+ console.log(` Required: v${currentVersion}
3194
+ `);
3195
+ if (options.autoUpgrade) {
3196
+ console.log(`\uD83D\uDD04 Auto-upgrading binary...
3197
+ `);
3198
+ await this.downloadBinary({ force: true });
3199
+ return localPath;
3200
+ }
3201
+ if (!options.force) {
3202
+ const confirmed = await this.promptConfirm("\uD83D\uDCE5 Upgrade binary now?");
3203
+ if (!confirmed) {
3204
+ console.log(`
3205
+ ⚠️ Using outdated binary. Run "bungee upgrade" to update.
3206
+ `);
3207
+ return localPath;
3208
+ }
3209
+ }
3210
+ await this.downloadBinary({ force: options.force });
3211
+ return localPath;
3212
+ }
3213
+ return localPath;
3214
+ }
3215
+ static async upgrade(options = {}) {
3216
+ const isInstalled = this.isBinaryInstalled();
3217
+ const versionMatches = this.checkVersion();
3218
+ if (!isInstalled) {
3219
+ console.log(`⚠️ Binary not installed. Installing...
3220
+ `);
3221
+ await this.downloadBinary({ force: options.force });
3222
+ return;
3223
+ }
3224
+ if (versionMatches) {
3225
+ console.log("✅ Binary is already up to date");
3226
+ console.log(` Version: v${package_default.version}
3227
+ `);
3228
+ if (!options.force) {
3229
+ return;
3230
+ }
3231
+ console.log(`\uD83D\uDD04 Force re-downloading...
3232
+ `);
3233
+ } else {
3234
+ const installedVersion = this.getInstalledVersion();
3235
+ console.log("\uD83D\uDD04 Upgrading binary...");
3236
+ console.log(` From: v${installedVersion || "unknown"}`);
3237
+ console.log(` To: v${package_default.version}
3238
+ `);
3239
+ }
3240
+ const localPath = this.getLocalBinaryPath();
3241
+ if (existsSync(localPath)) {
3242
+ unlinkSync(localPath);
3243
+ }
3244
+ await this.downloadBinary({ force: true });
3245
+ }
3246
+ static getBinaryInfo() {
3247
+ return {
3248
+ platform: platform(),
3249
+ arch: arch(),
3250
+ binaryName: this.getBinaryName(),
3251
+ localPath: this.getLocalBinaryPath(),
3252
+ installed: this.isBinaryInstalled(),
3253
+ installedVersion: this.getInstalledVersion(),
3254
+ requiredVersion: package_default.version,
3255
+ versionMatches: this.checkVersion()
3256
+ };
3257
+ }
3258
+ }
3259
+
3260
+ // src/daemon/manager.ts
3261
+ class DaemonManager {
3262
+ configDir;
3263
+ pidFile;
3264
+ logFile;
3265
+ errorLogFile;
3266
+ constructor() {
3267
+ this.configDir = ConfigPaths.CONFIG_DIR;
3268
+ this.pidFile = ConfigPaths.PID_FILE;
3269
+ this.logFile = ConfigPaths.LOG_FILE;
3270
+ this.errorLogFile = ConfigPaths.ERROR_LOG_FILE;
3271
+ ConfigPaths.ensureConfigDir();
3272
+ }
3273
+ async isRunning() {
3274
+ try {
3275
+ const pid = await this.getPid();
3276
+ if (!pid)
3277
+ return false;
3278
+ process.kill(pid, 0);
3279
+ return true;
3280
+ } catch {
3281
+ if (fs2.existsSync(this.pidFile)) {
3282
+ fs2.unlinkSync(this.pidFile);
3283
+ }
3284
+ return false;
3285
+ }
3286
+ }
3287
+ async getPid() {
3288
+ try {
3289
+ if (!fs2.existsSync(this.pidFile)) {
3290
+ return null;
3291
+ }
3292
+ const pidContent = await fs2.promises.readFile(this.pidFile, "utf-8");
3293
+ const pid = parseInt(pidContent.trim());
3294
+ return isNaN(pid) ? null : pid;
3295
+ } catch {
3296
+ return null;
3297
+ }
3298
+ }
3299
+ async start(configPath, options = {}) {
3300
+ if (await this.isRunning()) {
3301
+ throw new Error('Bungee is already running. Use "bungee status" to check status.');
3302
+ }
3303
+ const resolvedConfigPath = path3.resolve(configPath);
3304
+ if (!fs2.existsSync(resolvedConfigPath)) {
3305
+ throw new Error(`Configuration file not found: ${resolvedConfigPath}`);
3306
+ }
3307
+ const binaryPath = await BinaryManager.ensureBinary({
3308
+ autoUpgrade: options.autoUpgrade
3309
+ });
3310
+ const logFd = fs2.openSync(this.logFile, "a");
3311
+ const errorLogFd = fs2.openSync(this.errorLogFile, "a");
3312
+ const env = {
3313
+ ...process.env,
3314
+ CONFIG_PATH: resolvedConfigPath,
3315
+ WORKER_COUNT: options.workers || "2",
3316
+ DAEMON_MODE: "true",
3317
+ ...options.port && { PORT: options.port }
3318
+ };
3319
+ const child = spawn(binaryPath, [], {
3320
+ detached: true,
3321
+ stdio: ["ignore", logFd, errorLogFd],
3322
+ env,
3323
+ cwd: process.cwd()
3324
+ });
3325
+ fs2.closeSync(logFd);
3326
+ fs2.closeSync(errorLogFd);
3327
+ child.unref();
3328
+ await fs2.promises.writeFile(this.pidFile, child.pid.toString());
3329
+ await new Promise((resolve) => setTimeout(resolve, 1000));
3330
+ if (!await this.isRunning()) {
3331
+ let errorMsg = "Failed to start daemon";
3332
+ try {
3333
+ const errorLog = await fs2.promises.readFile(this.errorLogFile, "utf-8");
3334
+ const lastError = errorLog.split(`
3335
+ `).filter((line) => line.trim()).slice(-5).join(`
3336
+ `);
3337
+ if (lastError) {
3338
+ errorMsg += `:
3339
+ ${lastError}`;
3340
+ }
3341
+ } catch {}
3342
+ throw new Error(errorMsg);
3343
+ }
3344
+ console.log("✅ Bungee daemon started successfully");
3345
+ console.log(`\uD83D\uDCCB PID: ${child.pid}`);
3346
+ console.log(`\uD83D\uDCC4 Config: ${resolvedConfigPath}`);
3347
+ console.log(`\uD83D\uDCDD Logs: ${this.logFile}`);
3348
+ }
3349
+ async stop() {
3350
+ const pid = await this.getPid();
3351
+ if (!pid) {
3352
+ throw new Error("Bungee is not running");
3353
+ }
3354
+ try {
3355
+ process.kill(pid, "SIGTERM");
3356
+ let attempts = 0;
3357
+ const maxAttempts = 30;
3358
+ while (attempts < maxAttempts) {
3359
+ if (!await this.isRunning()) {
3360
+ console.log("✅ Bungee daemon stopped successfully");
3361
+ return;
3362
+ }
3363
+ await new Promise((resolve) => setTimeout(resolve, 1000));
3364
+ attempts++;
3365
+ if (attempts === 15) {
3366
+ process.kill(pid, "SIGKILL");
3367
+ }
3368
+ }
3369
+ throw new Error("Failed to stop daemon within timeout period");
3370
+ } catch (error) {
3371
+ if (error.code === "ESRCH") {
3372
+ if (fs2.existsSync(this.pidFile)) {
3373
+ fs2.unlinkSync(this.pidFile);
3374
+ }
3375
+ console.log("✅ Bungee daemon was not running");
3376
+ } else {
3377
+ throw error;
3378
+ }
3379
+ }
3380
+ }
3381
+ async restart(configPath, options = {}) {
3382
+ console.log("\uD83D\uDD04 Restarting Bungee daemon...");
3383
+ try {
3384
+ await this.stop();
3385
+ } catch (error) {
3386
+ console.log("ℹ️ Daemon was not running");
3387
+ }
3388
+ await new Promise((resolve) => setTimeout(resolve, 1000));
3389
+ await this.start(configPath, options);
3390
+ }
3391
+ async getStatus() {
3392
+ const running = await this.isRunning();
3393
+ const pid = await this.getPid();
3394
+ return {
3395
+ running,
3396
+ ...pid && { pid },
3397
+ configDir: this.configDir,
3398
+ logFile: this.logFile,
3399
+ errorLogFile: this.errorLogFile
3400
+ };
3401
+ }
3402
+ async getLogs(lines = 50, follow = false) {
3403
+ if (!fs2.existsSync(this.logFile)) {
3404
+ console.log("No logs found. Make sure Bungee is running or has been started.");
3405
+ return;
3406
+ }
3407
+ if (follow) {
3408
+ const { spawn: spawn2 } = await import("child_process");
3409
+ const tail = spawn2("tail", ["-f", "-n", lines.toString(), this.logFile], {
3410
+ stdio: "inherit"
3411
+ });
3412
+ process.on("SIGINT", () => {
3413
+ tail.kill();
3414
+ process.exit(0);
3415
+ });
3416
+ } else {
3417
+ const content = await fs2.promises.readFile(this.logFile, "utf-8");
3418
+ const allLines = content.split(`
3419
+ `);
3420
+ const lastLines = allLines.slice(-lines).join(`
3421
+ `);
3422
+ console.log(lastLines);
3423
+ }
3424
+ }
3425
+ }
3426
+
3427
+ // src/commands/start.ts
3428
+ async function startCommand(configPath, options = {}) {
3429
+ const daemonManager = new DaemonManager;
3430
+ try {
3431
+ const resolvedConfigPath = ConfigPaths.resolveConfigPath(configPath);
3432
+ console.log("\uD83D\uDE80 Starting Bungee daemon...");
3433
+ console.log(`\uD83D\uDCC4 Config: ${resolvedConfigPath}`);
3434
+ console.log(`\uD83D\uDC65 Workers: ${options.workers || "2"}`);
3435
+ if (options.port) {
3436
+ console.log(`\uD83D\uDD0C Port override: ${options.port}`);
3437
+ }
3438
+ await daemonManager.start(resolvedConfigPath, {
3439
+ workers: options.workers,
3440
+ port: options.port,
3441
+ autoUpgrade: options.autoUpgrade
3442
+ });
3443
+ } catch (error) {
3444
+ console.error("❌ Failed to start Bungee:", error.message);
3445
+ console.log();
3446
+ if (error.message.includes("Configuration file not found")) {
3447
+ console.log("\uD83D\uDCA1 Create a configuration file first with: bungee init");
3448
+ }
3449
+ process.exit(1);
3450
+ }
3451
+ }
3452
+
3453
+ // src/commands/stop.ts
3454
+ async function stopCommand() {
3455
+ const daemonManager = new DaemonManager;
3456
+ try {
3457
+ console.log("⏹️ Stopping Bungee daemon...");
3458
+ await daemonManager.stop();
3459
+ } catch (error) {
3460
+ console.error("❌ Failed to stop Bungee:", error.message);
3461
+ process.exit(1);
3462
+ }
3463
+ }
3464
+
3465
+ // src/commands/status.ts
3466
+ async function statusCommand() {
3467
+ const daemonManager = new DaemonManager;
3468
+ try {
3469
+ const status = await daemonManager.getStatus();
3470
+ console.log("\uD83D\uDCCA Bungee Status");
3471
+ console.log("================");
3472
+ if (status.running) {
3473
+ console.log("✅ Status: Running");
3474
+ console.log(`\uD83D\uDCCB PID: ${status.pid}`);
3475
+ } else {
3476
+ console.log("❌ Status: Not running");
3477
+ }
3478
+ console.log(`\uD83D\uDCC1 Config Dir: ${status.configDir}`);
3479
+ console.log(`\uD83D\uDCDD Log File: ${status.logFile}`);
3480
+ console.log(`\uD83D\uDEA8 Error Log: ${status.errorLogFile}`);
3481
+ if (status.running) {
3482
+ console.log(`
3483
+ \uD83D\uDCA1 Use "bungee logs" to view logs`);
3484
+ console.log('\uD83D\uDCA1 Use "bungee stop" to stop the daemon');
3485
+ } else {
3486
+ console.log(`
3487
+ \uD83D\uDCA1 Use "bungee start" to start the daemon`);
3488
+ }
3489
+ } catch (error) {
3490
+ console.error("❌ Failed to get status:", error.message);
3491
+ process.exit(1);
3492
+ }
3493
+ }
3494
+
3495
+ // src/commands/restart.ts
3496
+ async function restartCommand(configPath, options = {}) {
3497
+ const daemonManager = new DaemonManager;
3498
+ try {
3499
+ const resolvedConfigPath = ConfigPaths.resolveConfigPath(configPath);
3500
+ await daemonManager.restart(resolvedConfigPath, {
3501
+ workers: options.workers,
3502
+ port: options.port,
3503
+ autoUpgrade: options.autoUpgrade
3504
+ });
3505
+ } catch (error) {
3506
+ console.error("❌ Failed to restart Bungee:", error.message);
3507
+ if (error.message.includes("Configuration file not found")) {
3508
+ console.log("\uD83D\uDCA1 Create a configuration file first with: bungee init");
3509
+ }
3510
+ process.exit(1);
3511
+ }
3512
+ }
3513
+
3514
+ // src/commands/logs.ts
3515
+ async function logsCommand(options = {}) {
3516
+ const daemonManager = new DaemonManager;
3517
+ try {
3518
+ const lines = parseInt(options.lines || "50");
3519
+ const follow = options.follow || false;
3520
+ if (follow) {
3521
+ console.log(`\uD83D\uDCDD Following Bungee logs (Press Ctrl+C to exit)...
3522
+ `);
3523
+ } else {
3524
+ console.log(`\uD83D\uDCDD Showing last ${lines} lines of Bungee logs:
3525
+ `);
3526
+ }
3527
+ await daemonManager.getLogs(lines, follow);
3528
+ } catch (error) {
3529
+ console.error("❌ Failed to get logs:", error.message);
3530
+ process.exit(1);
3531
+ }
3532
+ }
3533
+
3534
+ // src/commands/ui.ts
3535
+ async function uiCommand(options) {
3536
+ const port = parseInt(options.port || "8088");
3537
+ const host = options.host || "localhost";
3538
+ const url = `http://${host}:${port}/__ui/`;
3539
+ console.log(`
3540
+ \uD83D\uDE80 Opening Bungee Dashboard at ${url}
3541
+ `);
3542
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
3543
+ try {
3544
+ await Bun.spawn([command, url]);
3545
+ } catch (error) {
3546
+ console.error(`Failed to open browser automatically.`);
3547
+ console.log(`Please open ${url} manually in your browser.
3548
+ `);
3549
+ }
3550
+ }
3551
+
3552
+ // src/commands/upgrade.ts
3553
+ async function upgradeCommand(options) {
3554
+ console.log(`\uD83D\uDE80 Checking for binary updates...
3555
+ `);
3556
+ try {
3557
+ const info = BinaryManager.getBinaryInfo();
3558
+ if (!info.installed) {
3559
+ console.log(`⚠️ Binary not installed. Installing for the first time...
3560
+ `);
3561
+ } else if (info.versionMatches && !options.force) {
3562
+ console.log("✅ Binary is already up to date");
3563
+ console.log(` Version: v${info.requiredVersion}`);
3564
+ console.log(` Location: ${info.localPath}
3565
+ `);
3566
+ console.log(`\uD83D\uDCA1 Use --force to re-download
3567
+ `);
3568
+ return;
3569
+ }
3570
+ await BinaryManager.upgrade({ force: options.force });
3571
+ console.log(`✅ Upgrade completed successfully!
3572
+ `);
3573
+ } catch (error) {
3574
+ console.error("❌ Upgrade failed:", error.message);
3575
+ process.exit(1);
3576
+ }
3577
+ }
3578
+
3579
+ // src/index.ts
3580
+ program.name("bungee").description("High-performance reverse proxy server built with Bun and TypeScript").version(package_default.version);
3581
+ program.command("init [path]").description("Initialize configuration file (default: ~/.bungee/config.json)").option("-f, --force", "Overwrite existing config file").action(initCommand);
3582
+ program.command("start [config]").description("Start proxy server as daemon (default config: ~/.bungee/config.json)").option("-p, --port <port>", "Override default port").option("-w, --workers <count>", "Number of worker processes", "2").option("-d, --detach", "Run as daemon (default)", true).option("--auto-upgrade", "Automatically upgrade binary if version mismatch").action(startCommand);
3583
+ program.command("stop").description("Stop proxy server daemon").action(stopCommand);
3584
+ program.command("restart [config]").description("Restart proxy server daemon (default config: ~/.bungee/config.json)").option("-p, --port <port>", "Override default port").option("-w, --workers <count>", "Number of worker processes", "2").option("--auto-upgrade", "Automatically upgrade binary if version mismatch").action(restartCommand);
3585
+ program.command("status").description("Show daemon status and health").action(statusCommand);
3586
+ program.command("logs").description("Show daemon logs").option("-f, --follow", "Follow log output").option("-n, --lines <number>", "Number of lines to show", "50").action(logsCommand);
3587
+ program.command("ui").description("Open web dashboard (proxy server must be running)").option("-p, --port <port>", "Proxy server port", "8088").option("-H, --host <host>", "Proxy server host", "localhost").action(uiCommand);
3588
+ program.command("upgrade").description("Upgrade Bungee binary to the latest version").option("-f, --force", "Force re-download even if already up to date").action(upgradeCommand);
3589
+ program.parse();