@agiflowai/agent-cli 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,3 +1,2300 @@
1
1
  #!/usr/bin/env node
2
- "use strict";require("./cli-Cr-ovvgN.js");
2
+ import { bq as z, bh as H, br as P, bi as M } from "./index-CVYu2Dkh.mjs";
3
+ import Q from "node:events";
4
+ import X from "node:child_process";
5
+ import Z from "node:path";
6
+ import ee from "node:fs";
7
+ import te from "node:process";
8
+ import ie from "dotenv";
9
+ var E = {}, S = {}, V = {}, W;
10
+ function D() {
11
+ if (W) return V;
12
+ W = 1;
13
+ class g extends Error {
14
+ /**
15
+ * Constructs the CommanderError class
16
+ * @param {number} exitCode suggested exit code which could be used with process.exit
17
+ * @param {string} code an id string representing the error
18
+ * @param {string} message human-readable description of the error
19
+ */
20
+ constructor(o, n, u) {
21
+ super(u), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name, this.code = n, this.exitCode = o, this.nestedError = void 0;
22
+ }
23
+ }
24
+ class C extends g {
25
+ /**
26
+ * Constructs the InvalidArgumentError class
27
+ * @param {string} [message] explanation of why argument is invalid
28
+ */
29
+ constructor(o) {
30
+ super(1, "commander.invalidArgument", o), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name;
31
+ }
32
+ }
33
+ return V.CommanderError = g, V.InvalidArgumentError = C, V;
34
+ }
35
+ var j;
36
+ function N() {
37
+ if (j) return S;
38
+ j = 1;
39
+ const { InvalidArgumentError: g } = D();
40
+ class C {
41
+ /**
42
+ * Initialize a new command argument with the given name and description.
43
+ * The default is that the argument is required, and you can explicitly
44
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
45
+ *
46
+ * @param {string} name
47
+ * @param {string} [description]
48
+ */
49
+ constructor(n, u) {
50
+ switch (this.description = u || "", this.variadic = !1, this.parseArg = void 0, this.defaultValue = void 0, this.defaultValueDescription = void 0, this.argChoices = void 0, n[0]) {
51
+ case "<":
52
+ this.required = !0, this._name = n.slice(1, -1);
53
+ break;
54
+ case "[":
55
+ this.required = !1, this._name = n.slice(1, -1);
56
+ break;
57
+ default:
58
+ this.required = !0, this._name = n;
59
+ break;
60
+ }
61
+ this._name.length > 3 && this._name.slice(-3) === "..." && (this.variadic = !0, this._name = this._name.slice(0, -3));
62
+ }
63
+ /**
64
+ * Return argument name.
65
+ *
66
+ * @return {string}
67
+ */
68
+ name() {
69
+ return this._name;
70
+ }
71
+ /**
72
+ * @package
73
+ */
74
+ _concatValue(n, u) {
75
+ return u === this.defaultValue || !Array.isArray(u) ? [n] : u.concat(n);
76
+ }
77
+ /**
78
+ * Set the default value, and optionally supply the description to be displayed in the help.
79
+ *
80
+ * @param {*} value
81
+ * @param {string} [description]
82
+ * @return {Argument}
83
+ */
84
+ default(n, u) {
85
+ return this.defaultValue = n, this.defaultValueDescription = u, this;
86
+ }
87
+ /**
88
+ * Set the custom handler for processing CLI command arguments into argument values.
89
+ *
90
+ * @param {Function} [fn]
91
+ * @return {Argument}
92
+ */
93
+ argParser(n) {
94
+ return this.parseArg = n, this;
95
+ }
96
+ /**
97
+ * Only allow argument value to be one of choices.
98
+ *
99
+ * @param {string[]} values
100
+ * @return {Argument}
101
+ */
102
+ choices(n) {
103
+ return this.argChoices = n.slice(), this.parseArg = (u, a) => {
104
+ if (!this.argChoices.includes(u))
105
+ throw new g(
106
+ `Allowed choices are ${this.argChoices.join(", ")}.`
107
+ );
108
+ return this.variadic ? this._concatValue(u, a) : u;
109
+ }, this;
110
+ }
111
+ /**
112
+ * Make argument required.
113
+ *
114
+ * @returns {Argument}
115
+ */
116
+ argRequired() {
117
+ return this.required = !0, this;
118
+ }
119
+ /**
120
+ * Make argument optional.
121
+ *
122
+ * @returns {Argument}
123
+ */
124
+ argOptional() {
125
+ return this.required = !1, this;
126
+ }
127
+ }
128
+ function _(o) {
129
+ const n = o.name() + (o.variadic === !0 ? "..." : "");
130
+ return o.required ? "<" + n + ">" : "[" + n + "]";
131
+ }
132
+ return S.Argument = C, S.humanReadableArgName = _, S;
133
+ }
134
+ var T = {}, F = {}, R;
135
+ function J() {
136
+ if (R) return F;
137
+ R = 1;
138
+ const { humanReadableArgName: g } = N();
139
+ class C {
140
+ constructor() {
141
+ this.helpWidth = void 0, this.sortSubcommands = !1, this.sortOptions = !1, this.showGlobalOptions = !1;
142
+ }
143
+ /**
144
+ * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
145
+ *
146
+ * @param {Command} cmd
147
+ * @returns {Command[]}
148
+ */
149
+ visibleCommands(o) {
150
+ const n = o.commands.filter((a) => !a._hidden), u = o._getHelpCommand();
151
+ return u && !u._hidden && n.push(u), this.sortSubcommands && n.sort((a, h) => a.name().localeCompare(h.name())), n;
152
+ }
153
+ /**
154
+ * Compare options for sort.
155
+ *
156
+ * @param {Option} a
157
+ * @param {Option} b
158
+ * @returns {number}
159
+ */
160
+ compareOptions(o, n) {
161
+ const u = (a) => a.short ? a.short.replace(/^-/, "") : a.long.replace(/^--/, "");
162
+ return u(o).localeCompare(u(n));
163
+ }
164
+ /**
165
+ * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
166
+ *
167
+ * @param {Command} cmd
168
+ * @returns {Option[]}
169
+ */
170
+ visibleOptions(o) {
171
+ const n = o.options.filter((a) => !a.hidden), u = o._getHelpOption();
172
+ if (u && !u.hidden) {
173
+ const a = u.short && o._findOption(u.short), h = u.long && o._findOption(u.long);
174
+ !a && !h ? n.push(u) : u.long && !h ? n.push(
175
+ o.createOption(u.long, u.description)
176
+ ) : u.short && !a && n.push(
177
+ o.createOption(u.short, u.description)
178
+ );
179
+ }
180
+ return this.sortOptions && n.sort(this.compareOptions), n;
181
+ }
182
+ /**
183
+ * Get an array of the visible global options. (Not including help.)
184
+ *
185
+ * @param {Command} cmd
186
+ * @returns {Option[]}
187
+ */
188
+ visibleGlobalOptions(o) {
189
+ if (!this.showGlobalOptions) return [];
190
+ const n = [];
191
+ for (let u = o.parent; u; u = u.parent) {
192
+ const a = u.options.filter(
193
+ (h) => !h.hidden
194
+ );
195
+ n.push(...a);
196
+ }
197
+ return this.sortOptions && n.sort(this.compareOptions), n;
198
+ }
199
+ /**
200
+ * Get an array of the arguments if any have a description.
201
+ *
202
+ * @param {Command} cmd
203
+ * @returns {Argument[]}
204
+ */
205
+ visibleArguments(o) {
206
+ return o._argsDescription && o.registeredArguments.forEach((n) => {
207
+ n.description = n.description || o._argsDescription[n.name()] || "";
208
+ }), o.registeredArguments.find((n) => n.description) ? o.registeredArguments : [];
209
+ }
210
+ /**
211
+ * Get the command term to show in the list of subcommands.
212
+ *
213
+ * @param {Command} cmd
214
+ * @returns {string}
215
+ */
216
+ subcommandTerm(o) {
217
+ const n = o.registeredArguments.map((u) => g(u)).join(" ");
218
+ return o._name + (o._aliases[0] ? "|" + o._aliases[0] : "") + (o.options.length ? " [options]" : "") + // simplistic check for non-help option
219
+ (n ? " " + n : "");
220
+ }
221
+ /**
222
+ * Get the option term to show in the list of options.
223
+ *
224
+ * @param {Option} option
225
+ * @returns {string}
226
+ */
227
+ optionTerm(o) {
228
+ return o.flags;
229
+ }
230
+ /**
231
+ * Get the argument term to show in the list of arguments.
232
+ *
233
+ * @param {Argument} argument
234
+ * @returns {string}
235
+ */
236
+ argumentTerm(o) {
237
+ return o.name();
238
+ }
239
+ /**
240
+ * Get the longest command term length.
241
+ *
242
+ * @param {Command} cmd
243
+ * @param {Help} helper
244
+ * @returns {number}
245
+ */
246
+ longestSubcommandTermLength(o, n) {
247
+ return n.visibleCommands(o).reduce((u, a) => Math.max(u, n.subcommandTerm(a).length), 0);
248
+ }
249
+ /**
250
+ * Get the longest option term length.
251
+ *
252
+ * @param {Command} cmd
253
+ * @param {Help} helper
254
+ * @returns {number}
255
+ */
256
+ longestOptionTermLength(o, n) {
257
+ return n.visibleOptions(o).reduce((u, a) => Math.max(u, n.optionTerm(a).length), 0);
258
+ }
259
+ /**
260
+ * Get the longest global option term length.
261
+ *
262
+ * @param {Command} cmd
263
+ * @param {Help} helper
264
+ * @returns {number}
265
+ */
266
+ longestGlobalOptionTermLength(o, n) {
267
+ return n.visibleGlobalOptions(o).reduce((u, a) => Math.max(u, n.optionTerm(a).length), 0);
268
+ }
269
+ /**
270
+ * Get the longest argument term length.
271
+ *
272
+ * @param {Command} cmd
273
+ * @param {Help} helper
274
+ * @returns {number}
275
+ */
276
+ longestArgumentTermLength(o, n) {
277
+ return n.visibleArguments(o).reduce((u, a) => Math.max(u, n.argumentTerm(a).length), 0);
278
+ }
279
+ /**
280
+ * Get the command usage to be displayed at the top of the built-in help.
281
+ *
282
+ * @param {Command} cmd
283
+ * @returns {string}
284
+ */
285
+ commandUsage(o) {
286
+ let n = o._name;
287
+ o._aliases[0] && (n = n + "|" + o._aliases[0]);
288
+ let u = "";
289
+ for (let a = o.parent; a; a = a.parent)
290
+ u = a.name() + " " + u;
291
+ return u + n + " " + o.usage();
292
+ }
293
+ /**
294
+ * Get the description for the command.
295
+ *
296
+ * @param {Command} cmd
297
+ * @returns {string}
298
+ */
299
+ commandDescription(o) {
300
+ return o.description();
301
+ }
302
+ /**
303
+ * Get the subcommand summary to show in the list of subcommands.
304
+ * (Fallback to description for backwards compatibility.)
305
+ *
306
+ * @param {Command} cmd
307
+ * @returns {string}
308
+ */
309
+ subcommandDescription(o) {
310
+ return o.summary() || o.description();
311
+ }
312
+ /**
313
+ * Get the option description to show in the list of options.
314
+ *
315
+ * @param {Option} option
316
+ * @return {string}
317
+ */
318
+ optionDescription(o) {
319
+ const n = [];
320
+ return o.argChoices && n.push(
321
+ // use stringify to match the display of the default value
322
+ `choices: ${o.argChoices.map((u) => JSON.stringify(u)).join(", ")}`
323
+ ), o.defaultValue !== void 0 && (o.required || o.optional || o.isBoolean() && typeof o.defaultValue == "boolean") && n.push(
324
+ `default: ${o.defaultValueDescription || JSON.stringify(o.defaultValue)}`
325
+ ), o.presetArg !== void 0 && o.optional && n.push(`preset: ${JSON.stringify(o.presetArg)}`), o.envVar !== void 0 && n.push(`env: ${o.envVar}`), n.length > 0 ? `${o.description} (${n.join(", ")})` : o.description;
326
+ }
327
+ /**
328
+ * Get the argument description to show in the list of arguments.
329
+ *
330
+ * @param {Argument} argument
331
+ * @return {string}
332
+ */
333
+ argumentDescription(o) {
334
+ const n = [];
335
+ if (o.argChoices && n.push(
336
+ // use stringify to match the display of the default value
337
+ `choices: ${o.argChoices.map((u) => JSON.stringify(u)).join(", ")}`
338
+ ), o.defaultValue !== void 0 && n.push(
339
+ `default: ${o.defaultValueDescription || JSON.stringify(o.defaultValue)}`
340
+ ), n.length > 0) {
341
+ const u = `(${n.join(", ")})`;
342
+ return o.description ? `${o.description} ${u}` : u;
343
+ }
344
+ return o.description;
345
+ }
346
+ /**
347
+ * Generate the built-in help text.
348
+ *
349
+ * @param {Command} cmd
350
+ * @param {Help} helper
351
+ * @returns {string}
352
+ */
353
+ formatHelp(o, n) {
354
+ const u = n.padWidth(o, n), a = n.helpWidth || 80, h = 2, f = 2;
355
+ function O(t, i) {
356
+ if (i) {
357
+ const s = `${t.padEnd(u + f)}${i}`;
358
+ return n.wrap(
359
+ s,
360
+ a - h,
361
+ u + f
362
+ );
363
+ }
364
+ return t;
365
+ }
366
+ function w(t) {
367
+ return t.join(`
368
+ `).replace(/^/gm, " ".repeat(h));
369
+ }
370
+ let A = [`Usage: ${n.commandUsage(o)}`, ""];
371
+ const v = n.commandDescription(o);
372
+ v.length > 0 && (A = A.concat([
373
+ n.wrap(v, a, 0),
374
+ ""
375
+ ]));
376
+ const x = n.visibleArguments(o).map((t) => O(
377
+ n.argumentTerm(t),
378
+ n.argumentDescription(t)
379
+ ));
380
+ x.length > 0 && (A = A.concat(["Arguments:", w(x), ""]));
381
+ const $ = n.visibleOptions(o).map((t) => O(
382
+ n.optionTerm(t),
383
+ n.optionDescription(t)
384
+ ));
385
+ if ($.length > 0 && (A = A.concat(["Options:", w($), ""])), this.showGlobalOptions) {
386
+ const t = n.visibleGlobalOptions(o).map((i) => O(
387
+ n.optionTerm(i),
388
+ n.optionDescription(i)
389
+ ));
390
+ t.length > 0 && (A = A.concat([
391
+ "Global Options:",
392
+ w(t),
393
+ ""
394
+ ]));
395
+ }
396
+ const e = n.visibleCommands(o).map((t) => O(
397
+ n.subcommandTerm(t),
398
+ n.subcommandDescription(t)
399
+ ));
400
+ return e.length > 0 && (A = A.concat(["Commands:", w(e), ""])), A.join(`
401
+ `);
402
+ }
403
+ /**
404
+ * Calculate the pad width from the maximum term length.
405
+ *
406
+ * @param {Command} cmd
407
+ * @param {Help} helper
408
+ * @returns {number}
409
+ */
410
+ padWidth(o, n) {
411
+ return Math.max(
412
+ n.longestOptionTermLength(o, n),
413
+ n.longestGlobalOptionTermLength(o, n),
414
+ n.longestSubcommandTermLength(o, n),
415
+ n.longestArgumentTermLength(o, n)
416
+ );
417
+ }
418
+ /**
419
+ * Wrap the given string to width characters per line, with lines after the first indented.
420
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
421
+ *
422
+ * @param {string} str
423
+ * @param {number} width
424
+ * @param {number} indent
425
+ * @param {number} [minColumnWidth=40]
426
+ * @return {string}
427
+ *
428
+ */
429
+ wrap(o, n, u, a = 40) {
430
+ const h = " \\f\\t\\v   -    \uFEFF", f = new RegExp(`[\\n][${h}]+`);
431
+ if (o.match(f)) return o;
432
+ const O = n - u;
433
+ if (O < a) return o;
434
+ const w = o.slice(0, u), A = o.slice(u).replace(`\r
435
+ `, `
436
+ `), v = " ".repeat(u), $ = "\\s​", e = new RegExp(
437
+ `
438
+ |.{1,${O - 1}}([${$}]|$)|[^${$}]+?([${$}]|$)`,
439
+ "g"
440
+ ), t = A.match(e) || [];
441
+ return w + t.map((i, s) => i === `
442
+ ` ? "" : (s > 0 ? v : "") + i.trimEnd()).join(`
443
+ `);
444
+ }
445
+ }
446
+ return F.Help = C, F;
447
+ }
448
+ var k = {}, L;
449
+ function K() {
450
+ if (L) return k;
451
+ L = 1;
452
+ const { InvalidArgumentError: g } = D();
453
+ class C {
454
+ /**
455
+ * Initialize a new `Option` with the given `flags` and `description`.
456
+ *
457
+ * @param {string} flags
458
+ * @param {string} [description]
459
+ */
460
+ constructor(a, h) {
461
+ this.flags = a, this.description = h || "", this.required = a.includes("<"), this.optional = a.includes("["), this.variadic = /\w\.\.\.[>\]]$/.test(a), this.mandatory = !1;
462
+ const f = n(a);
463
+ this.short = f.shortFlag, this.long = f.longFlag, this.negate = !1, this.long && (this.negate = this.long.startsWith("--no-")), this.defaultValue = void 0, this.defaultValueDescription = void 0, this.presetArg = void 0, this.envVar = void 0, this.parseArg = void 0, this.hidden = !1, this.argChoices = void 0, this.conflictsWith = [], this.implied = void 0;
464
+ }
465
+ /**
466
+ * Set the default value, and optionally supply the description to be displayed in the help.
467
+ *
468
+ * @param {*} value
469
+ * @param {string} [description]
470
+ * @return {Option}
471
+ */
472
+ default(a, h) {
473
+ return this.defaultValue = a, this.defaultValueDescription = h, this;
474
+ }
475
+ /**
476
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
477
+ * The custom processing (parseArg) is called.
478
+ *
479
+ * @example
480
+ * new Option('--color').default('GREYSCALE').preset('RGB');
481
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
482
+ *
483
+ * @param {*} arg
484
+ * @return {Option}
485
+ */
486
+ preset(a) {
487
+ return this.presetArg = a, this;
488
+ }
489
+ /**
490
+ * Add option name(s) that conflict with this option.
491
+ * An error will be displayed if conflicting options are found during parsing.
492
+ *
493
+ * @example
494
+ * new Option('--rgb').conflicts('cmyk');
495
+ * new Option('--js').conflicts(['ts', 'jsx']);
496
+ *
497
+ * @param {(string | string[])} names
498
+ * @return {Option}
499
+ */
500
+ conflicts(a) {
501
+ return this.conflictsWith = this.conflictsWith.concat(a), this;
502
+ }
503
+ /**
504
+ * Specify implied option values for when this option is set and the implied options are not.
505
+ *
506
+ * The custom processing (parseArg) is not called on the implied values.
507
+ *
508
+ * @example
509
+ * program
510
+ * .addOption(new Option('--log', 'write logging information to file'))
511
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
512
+ *
513
+ * @param {object} impliedOptionValues
514
+ * @return {Option}
515
+ */
516
+ implies(a) {
517
+ let h = a;
518
+ return typeof a == "string" && (h = { [a]: !0 }), this.implied = Object.assign(this.implied || {}, h), this;
519
+ }
520
+ /**
521
+ * Set environment variable to check for option value.
522
+ *
523
+ * An environment variable is only used if when processed the current option value is
524
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
525
+ *
526
+ * @param {string} name
527
+ * @return {Option}
528
+ */
529
+ env(a) {
530
+ return this.envVar = a, this;
531
+ }
532
+ /**
533
+ * Set the custom handler for processing CLI option arguments into option values.
534
+ *
535
+ * @param {Function} [fn]
536
+ * @return {Option}
537
+ */
538
+ argParser(a) {
539
+ return this.parseArg = a, this;
540
+ }
541
+ /**
542
+ * Whether the option is mandatory and must have a value after parsing.
543
+ *
544
+ * @param {boolean} [mandatory=true]
545
+ * @return {Option}
546
+ */
547
+ makeOptionMandatory(a = !0) {
548
+ return this.mandatory = !!a, this;
549
+ }
550
+ /**
551
+ * Hide option in help.
552
+ *
553
+ * @param {boolean} [hide=true]
554
+ * @return {Option}
555
+ */
556
+ hideHelp(a = !0) {
557
+ return this.hidden = !!a, this;
558
+ }
559
+ /**
560
+ * @package
561
+ */
562
+ _concatValue(a, h) {
563
+ return h === this.defaultValue || !Array.isArray(h) ? [a] : h.concat(a);
564
+ }
565
+ /**
566
+ * Only allow option value to be one of choices.
567
+ *
568
+ * @param {string[]} values
569
+ * @return {Option}
570
+ */
571
+ choices(a) {
572
+ return this.argChoices = a.slice(), this.parseArg = (h, f) => {
573
+ if (!this.argChoices.includes(h))
574
+ throw new g(
575
+ `Allowed choices are ${this.argChoices.join(", ")}.`
576
+ );
577
+ return this.variadic ? this._concatValue(h, f) : h;
578
+ }, this;
579
+ }
580
+ /**
581
+ * Return option name.
582
+ *
583
+ * @return {string}
584
+ */
585
+ name() {
586
+ return this.long ? this.long.replace(/^--/, "") : this.short.replace(/^-/, "");
587
+ }
588
+ /**
589
+ * Return option name, in a camelcase format that can be used
590
+ * as a object attribute key.
591
+ *
592
+ * @return {string}
593
+ */
594
+ attributeName() {
595
+ return o(this.name().replace(/^no-/, ""));
596
+ }
597
+ /**
598
+ * Check if `arg` matches the short or long flag.
599
+ *
600
+ * @param {string} arg
601
+ * @return {boolean}
602
+ * @package
603
+ */
604
+ is(a) {
605
+ return this.short === a || this.long === a;
606
+ }
607
+ /**
608
+ * Return whether a boolean option.
609
+ *
610
+ * Options are one of boolean, negated, required argument, or optional argument.
611
+ *
612
+ * @return {boolean}
613
+ * @package
614
+ */
615
+ isBoolean() {
616
+ return !this.required && !this.optional && !this.negate;
617
+ }
618
+ }
619
+ class _ {
620
+ /**
621
+ * @param {Option[]} options
622
+ */
623
+ constructor(a) {
624
+ this.positiveOptions = /* @__PURE__ */ new Map(), this.negativeOptions = /* @__PURE__ */ new Map(), this.dualOptions = /* @__PURE__ */ new Set(), a.forEach((h) => {
625
+ h.negate ? this.negativeOptions.set(h.attributeName(), h) : this.positiveOptions.set(h.attributeName(), h);
626
+ }), this.negativeOptions.forEach((h, f) => {
627
+ this.positiveOptions.has(f) && this.dualOptions.add(f);
628
+ });
629
+ }
630
+ /**
631
+ * Did the value come from the option, and not from possible matching dual option?
632
+ *
633
+ * @param {*} value
634
+ * @param {Option} option
635
+ * @returns {boolean}
636
+ */
637
+ valueFromOption(a, h) {
638
+ const f = h.attributeName();
639
+ if (!this.dualOptions.has(f)) return !0;
640
+ const O = this.negativeOptions.get(f).presetArg, w = O !== void 0 ? O : !1;
641
+ return h.negate === (w === a);
642
+ }
643
+ }
644
+ function o(u) {
645
+ return u.split("-").reduce((a, h) => a + h[0].toUpperCase() + h.slice(1));
646
+ }
647
+ function n(u) {
648
+ let a, h;
649
+ const f = u.split(/[ |,]+/);
650
+ return f.length > 1 && !/^[[<]/.test(f[1]) && (a = f.shift()), h = f.shift(), !a && /^-[^-]$/.test(h) && (a = h, h = void 0), { shortFlag: a, longFlag: h };
651
+ }
652
+ return k.Option = C, k.DualOptions = _, k;
653
+ }
654
+ var I = {}, G;
655
+ function ne() {
656
+ if (G) return I;
657
+ G = 1;
658
+ const g = 3;
659
+ function C(o, n) {
660
+ if (Math.abs(o.length - n.length) > g)
661
+ return Math.max(o.length, n.length);
662
+ const u = [];
663
+ for (let a = 0; a <= o.length; a++)
664
+ u[a] = [a];
665
+ for (let a = 0; a <= n.length; a++)
666
+ u[0][a] = a;
667
+ for (let a = 1; a <= n.length; a++)
668
+ for (let h = 1; h <= o.length; h++) {
669
+ let f = 1;
670
+ o[h - 1] === n[a - 1] ? f = 0 : f = 1, u[h][a] = Math.min(
671
+ u[h - 1][a] + 1,
672
+ // deletion
673
+ u[h][a - 1] + 1,
674
+ // insertion
675
+ u[h - 1][a - 1] + f
676
+ // substitution
677
+ ), h > 1 && a > 1 && o[h - 1] === n[a - 2] && o[h - 2] === n[a - 1] && (u[h][a] = Math.min(u[h][a], u[h - 2][a - 2] + 1));
678
+ }
679
+ return u[o.length][n.length];
680
+ }
681
+ function _(o, n) {
682
+ if (!n || n.length === 0) return "";
683
+ n = Array.from(new Set(n));
684
+ const u = o.startsWith("--");
685
+ u && (o = o.slice(2), n = n.map((O) => O.slice(2)));
686
+ let a = [], h = g;
687
+ const f = 0.4;
688
+ return n.forEach((O) => {
689
+ if (O.length <= 1) return;
690
+ const w = C(o, O), A = Math.max(o.length, O.length);
691
+ (A - w) / A > f && (w < h ? (h = w, a = [O]) : w === h && a.push(O));
692
+ }), a.sort((O, w) => O.localeCompare(w)), u && (a = a.map((O) => `--${O}`)), a.length > 1 ? `
693
+ (Did you mean one of ${a.join(", ")}?)` : a.length === 1 ? `
694
+ (Did you mean ${a[0]}?)` : "";
695
+ }
696
+ return I.suggestSimilar = _, I;
697
+ }
698
+ var U;
699
+ function se() {
700
+ if (U) return T;
701
+ U = 1;
702
+ const g = Q.EventEmitter, C = X, _ = Z, o = ee, n = te, { Argument: u, humanReadableArgName: a } = N(), { CommanderError: h } = D(), { Help: f } = J(), { Option: O, DualOptions: w } = K(), { suggestSimilar: A } = ne();
703
+ class v extends g {
704
+ /**
705
+ * Initialize a new `Command`.
706
+ *
707
+ * @param {string} [name]
708
+ */
709
+ constructor(e) {
710
+ super(), this.commands = [], this.options = [], this.parent = null, this._allowUnknownOption = !1, this._allowExcessArguments = !0, this.registeredArguments = [], this._args = this.registeredArguments, this.args = [], this.rawArgs = [], this.processedArgs = [], this._scriptPath = null, this._name = e || "", this._optionValues = {}, this._optionValueSources = {}, this._storeOptionsAsProperties = !1, this._actionHandler = null, this._executableHandler = !1, this._executableFile = null, this._executableDir = null, this._defaultCommandName = null, this._exitCallback = null, this._aliases = [], this._combineFlagAndOptionalValue = !0, this._description = "", this._summary = "", this._argsDescription = void 0, this._enablePositionalOptions = !1, this._passThroughOptions = !1, this._lifeCycleHooks = {}, this._showHelpAfterError = !1, this._showSuggestionAfterError = !0, this._outputConfiguration = {
711
+ writeOut: (t) => n.stdout.write(t),
712
+ writeErr: (t) => n.stderr.write(t),
713
+ getOutHelpWidth: () => n.stdout.isTTY ? n.stdout.columns : void 0,
714
+ getErrHelpWidth: () => n.stderr.isTTY ? n.stderr.columns : void 0,
715
+ outputError: (t, i) => i(t)
716
+ }, this._hidden = !1, this._helpOption = void 0, this._addImplicitHelpCommand = void 0, this._helpCommand = void 0, this._helpConfiguration = {};
717
+ }
718
+ /**
719
+ * Copy settings that are useful to have in common across root command and subcommands.
720
+ *
721
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
722
+ *
723
+ * @param {Command} sourceCommand
724
+ * @return {Command} `this` command for chaining
725
+ */
726
+ copyInheritedSettings(e) {
727
+ return this._outputConfiguration = e._outputConfiguration, this._helpOption = e._helpOption, this._helpCommand = e._helpCommand, this._helpConfiguration = e._helpConfiguration, this._exitCallback = e._exitCallback, this._storeOptionsAsProperties = e._storeOptionsAsProperties, this._combineFlagAndOptionalValue = e._combineFlagAndOptionalValue, this._allowExcessArguments = e._allowExcessArguments, this._enablePositionalOptions = e._enablePositionalOptions, this._showHelpAfterError = e._showHelpAfterError, this._showSuggestionAfterError = e._showSuggestionAfterError, this;
728
+ }
729
+ /**
730
+ * @returns {Command[]}
731
+ * @private
732
+ */
733
+ _getCommandAndAncestors() {
734
+ const e = [];
735
+ for (let t = this; t; t = t.parent)
736
+ e.push(t);
737
+ return e;
738
+ }
739
+ /**
740
+ * Define a command.
741
+ *
742
+ * There are two styles of command: pay attention to where to put the description.
743
+ *
744
+ * @example
745
+ * // Command implemented using action handler (description is supplied separately to `.command`)
746
+ * program
747
+ * .command('clone <source> [destination]')
748
+ * .description('clone a repository into a newly created directory')
749
+ * .action((source, destination) => {
750
+ * console.log('clone command called');
751
+ * });
752
+ *
753
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
754
+ * program
755
+ * .command('start <service>', 'start named service')
756
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
757
+ *
758
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
759
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
760
+ * @param {object} [execOpts] - configuration options (for executable)
761
+ * @return {Command} returns new command for action handler, or `this` for executable command
762
+ */
763
+ command(e, t, i) {
764
+ let s = t, r = i;
765
+ typeof s == "object" && s !== null && (r = s, s = null), r = r || {};
766
+ const [, l, m] = e.match(/([^ ]+) *(.*)/), c = this.createCommand(l);
767
+ return s && (c.description(s), c._executableHandler = !0), r.isDefault && (this._defaultCommandName = c._name), c._hidden = !!(r.noHelp || r.hidden), c._executableFile = r.executableFile || null, m && c.arguments(m), this._registerCommand(c), c.parent = this, c.copyInheritedSettings(this), s ? this : c;
768
+ }
769
+ /**
770
+ * Factory routine to create a new unattached command.
771
+ *
772
+ * See .command() for creating an attached subcommand, which uses this routine to
773
+ * create the command. You can override createCommand to customise subcommands.
774
+ *
775
+ * @param {string} [name]
776
+ * @return {Command} new command
777
+ */
778
+ createCommand(e) {
779
+ return new v(e);
780
+ }
781
+ /**
782
+ * You can customise the help with a subclass of Help by overriding createHelp,
783
+ * or by overriding Help properties using configureHelp().
784
+ *
785
+ * @return {Help}
786
+ */
787
+ createHelp() {
788
+ return Object.assign(new f(), this.configureHelp());
789
+ }
790
+ /**
791
+ * You can customise the help by overriding Help properties using configureHelp(),
792
+ * or with a subclass of Help by overriding createHelp().
793
+ *
794
+ * @param {object} [configuration] - configuration options
795
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
796
+ */
797
+ configureHelp(e) {
798
+ return e === void 0 ? this._helpConfiguration : (this._helpConfiguration = e, this);
799
+ }
800
+ /**
801
+ * The default output goes to stdout and stderr. You can customise this for special
802
+ * applications. You can also customise the display of errors by overriding outputError.
803
+ *
804
+ * The configuration properties are all functions:
805
+ *
806
+ * // functions to change where being written, stdout and stderr
807
+ * writeOut(str)
808
+ * writeErr(str)
809
+ * // matching functions to specify width for wrapping help
810
+ * getOutHelpWidth()
811
+ * getErrHelpWidth()
812
+ * // functions based on what is being written out
813
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
814
+ *
815
+ * @param {object} [configuration] - configuration options
816
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
817
+ */
818
+ configureOutput(e) {
819
+ return e === void 0 ? this._outputConfiguration : (Object.assign(this._outputConfiguration, e), this);
820
+ }
821
+ /**
822
+ * Display the help or a custom message after an error occurs.
823
+ *
824
+ * @param {(boolean|string)} [displayHelp]
825
+ * @return {Command} `this` command for chaining
826
+ */
827
+ showHelpAfterError(e = !0) {
828
+ return typeof e != "string" && (e = !!e), this._showHelpAfterError = e, this;
829
+ }
830
+ /**
831
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
832
+ *
833
+ * @param {boolean} [displaySuggestion]
834
+ * @return {Command} `this` command for chaining
835
+ */
836
+ showSuggestionAfterError(e = !0) {
837
+ return this._showSuggestionAfterError = !!e, this;
838
+ }
839
+ /**
840
+ * Add a prepared subcommand.
841
+ *
842
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
843
+ *
844
+ * @param {Command} cmd - new subcommand
845
+ * @param {object} [opts] - configuration options
846
+ * @return {Command} `this` command for chaining
847
+ */
848
+ addCommand(e, t) {
849
+ if (!e._name)
850
+ throw new Error(`Command passed to .addCommand() must have a name
851
+ - specify the name in Command constructor or using .name()`);
852
+ return t = t || {}, t.isDefault && (this._defaultCommandName = e._name), (t.noHelp || t.hidden) && (e._hidden = !0), this._registerCommand(e), e.parent = this, e._checkForBrokenPassThrough(), this;
853
+ }
854
+ /**
855
+ * Factory routine to create a new unattached argument.
856
+ *
857
+ * See .argument() for creating an attached argument, which uses this routine to
858
+ * create the argument. You can override createArgument to return a custom argument.
859
+ *
860
+ * @param {string} name
861
+ * @param {string} [description]
862
+ * @return {Argument} new argument
863
+ */
864
+ createArgument(e, t) {
865
+ return new u(e, t);
866
+ }
867
+ /**
868
+ * Define argument syntax for command.
869
+ *
870
+ * The default is that the argument is required, and you can explicitly
871
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
872
+ *
873
+ * @example
874
+ * program.argument('<input-file>');
875
+ * program.argument('[output-file]');
876
+ *
877
+ * @param {string} name
878
+ * @param {string} [description]
879
+ * @param {(Function|*)} [fn] - custom argument processing function
880
+ * @param {*} [defaultValue]
881
+ * @return {Command} `this` command for chaining
882
+ */
883
+ argument(e, t, i, s) {
884
+ const r = this.createArgument(e, t);
885
+ return typeof i == "function" ? r.default(s).argParser(i) : r.default(i), this.addArgument(r), this;
886
+ }
887
+ /**
888
+ * Define argument syntax for command, adding multiple at once (without descriptions).
889
+ *
890
+ * See also .argument().
891
+ *
892
+ * @example
893
+ * program.arguments('<cmd> [env]');
894
+ *
895
+ * @param {string} names
896
+ * @return {Command} `this` command for chaining
897
+ */
898
+ arguments(e) {
899
+ return e.trim().split(/ +/).forEach((t) => {
900
+ this.argument(t);
901
+ }), this;
902
+ }
903
+ /**
904
+ * Define argument syntax for command, adding a prepared argument.
905
+ *
906
+ * @param {Argument} argument
907
+ * @return {Command} `this` command for chaining
908
+ */
909
+ addArgument(e) {
910
+ const t = this.registeredArguments.slice(-1)[0];
911
+ if (t && t.variadic)
912
+ throw new Error(
913
+ `only the last argument can be variadic '${t.name()}'`
914
+ );
915
+ if (e.required && e.defaultValue !== void 0 && e.parseArg === void 0)
916
+ throw new Error(
917
+ `a default value for a required argument is never used: '${e.name()}'`
918
+ );
919
+ return this.registeredArguments.push(e), this;
920
+ }
921
+ /**
922
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
923
+ *
924
+ * @example
925
+ * program.helpCommand('help [cmd]');
926
+ * program.helpCommand('help [cmd]', 'show help');
927
+ * program.helpCommand(false); // suppress default help command
928
+ * program.helpCommand(true); // add help command even if no subcommands
929
+ *
930
+ * @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
931
+ * @param {string} [description] - custom description
932
+ * @return {Command} `this` command for chaining
933
+ */
934
+ helpCommand(e, t) {
935
+ if (typeof e == "boolean")
936
+ return this._addImplicitHelpCommand = e, this;
937
+ e = e ?? "help [command]";
938
+ const [, i, s] = e.match(/([^ ]+) *(.*)/), r = t ?? "display help for command", l = this.createCommand(i);
939
+ return l.helpOption(!1), s && l.arguments(s), r && l.description(r), this._addImplicitHelpCommand = !0, this._helpCommand = l, this;
940
+ }
941
+ /**
942
+ * Add prepared custom help command.
943
+ *
944
+ * @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
945
+ * @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
946
+ * @return {Command} `this` command for chaining
947
+ */
948
+ addHelpCommand(e, t) {
949
+ return typeof e != "object" ? (this.helpCommand(e, t), this) : (this._addImplicitHelpCommand = !0, this._helpCommand = e, this);
950
+ }
951
+ /**
952
+ * Lazy create help command.
953
+ *
954
+ * @return {(Command|null)}
955
+ * @package
956
+ */
957
+ _getHelpCommand() {
958
+ return this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help")) ? (this._helpCommand === void 0 && this.helpCommand(void 0, void 0), this._helpCommand) : null;
959
+ }
960
+ /**
961
+ * Add hook for life cycle event.
962
+ *
963
+ * @param {string} event
964
+ * @param {Function} listener
965
+ * @return {Command} `this` command for chaining
966
+ */
967
+ hook(e, t) {
968
+ const i = ["preSubcommand", "preAction", "postAction"];
969
+ if (!i.includes(e))
970
+ throw new Error(`Unexpected value for event passed to hook : '${e}'.
971
+ Expecting one of '${i.join("', '")}'`);
972
+ return this._lifeCycleHooks[e] ? this._lifeCycleHooks[e].push(t) : this._lifeCycleHooks[e] = [t], this;
973
+ }
974
+ /**
975
+ * Register callback to use as replacement for calling process.exit.
976
+ *
977
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
978
+ * @return {Command} `this` command for chaining
979
+ */
980
+ exitOverride(e) {
981
+ return e ? this._exitCallback = e : this._exitCallback = (t) => {
982
+ if (t.code !== "commander.executeSubCommandAsync")
983
+ throw t;
984
+ }, this;
985
+ }
986
+ /**
987
+ * Call process.exit, and _exitCallback if defined.
988
+ *
989
+ * @param {number} exitCode exit code for using with process.exit
990
+ * @param {string} code an id string representing the error
991
+ * @param {string} message human-readable description of the error
992
+ * @return never
993
+ * @private
994
+ */
995
+ _exit(e, t, i) {
996
+ this._exitCallback && this._exitCallback(new h(e, t, i)), n.exit(e);
997
+ }
998
+ /**
999
+ * Register callback `fn` for the command.
1000
+ *
1001
+ * @example
1002
+ * program
1003
+ * .command('serve')
1004
+ * .description('start service')
1005
+ * .action(function() {
1006
+ * // do work here
1007
+ * });
1008
+ *
1009
+ * @param {Function} fn
1010
+ * @return {Command} `this` command for chaining
1011
+ */
1012
+ action(e) {
1013
+ const t = (i) => {
1014
+ const s = this.registeredArguments.length, r = i.slice(0, s);
1015
+ return this._storeOptionsAsProperties ? r[s] = this : r[s] = this.opts(), r.push(this), e.apply(this, r);
1016
+ };
1017
+ return this._actionHandler = t, this;
1018
+ }
1019
+ /**
1020
+ * Factory routine to create a new unattached option.
1021
+ *
1022
+ * See .option() for creating an attached option, which uses this routine to
1023
+ * create the option. You can override createOption to return a custom option.
1024
+ *
1025
+ * @param {string} flags
1026
+ * @param {string} [description]
1027
+ * @return {Option} new option
1028
+ */
1029
+ createOption(e, t) {
1030
+ return new O(e, t);
1031
+ }
1032
+ /**
1033
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
1034
+ *
1035
+ * @param {(Option | Argument)} target
1036
+ * @param {string} value
1037
+ * @param {*} previous
1038
+ * @param {string} invalidArgumentMessage
1039
+ * @private
1040
+ */
1041
+ _callParseArg(e, t, i, s) {
1042
+ try {
1043
+ return e.parseArg(t, i);
1044
+ } catch (r) {
1045
+ if (r.code === "commander.invalidArgument") {
1046
+ const l = `${s} ${r.message}`;
1047
+ this.error(l, { exitCode: r.exitCode, code: r.code });
1048
+ }
1049
+ throw r;
1050
+ }
1051
+ }
1052
+ /**
1053
+ * Check for option flag conflicts.
1054
+ * Register option if no conflicts found, or throw on conflict.
1055
+ *
1056
+ * @param {Option} option
1057
+ * @private
1058
+ */
1059
+ _registerOption(e) {
1060
+ const t = e.short && this._findOption(e.short) || e.long && this._findOption(e.long);
1061
+ if (t) {
1062
+ const i = e.long && this._findOption(e.long) ? e.long : e.short;
1063
+ throw new Error(`Cannot add option '${e.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${i}'
1064
+ - already used by option '${t.flags}'`);
1065
+ }
1066
+ this.options.push(e);
1067
+ }
1068
+ /**
1069
+ * Check for command name and alias conflicts with existing commands.
1070
+ * Register command if no conflicts found, or throw on conflict.
1071
+ *
1072
+ * @param {Command} command
1073
+ * @private
1074
+ */
1075
+ _registerCommand(e) {
1076
+ const t = (s) => [s.name()].concat(s.aliases()), i = t(e).find(
1077
+ (s) => this._findCommand(s)
1078
+ );
1079
+ if (i) {
1080
+ const s = t(this._findCommand(i)).join("|"), r = t(e).join("|");
1081
+ throw new Error(
1082
+ `cannot add command '${r}' as already have command '${s}'`
1083
+ );
1084
+ }
1085
+ this.commands.push(e);
1086
+ }
1087
+ /**
1088
+ * Add an option.
1089
+ *
1090
+ * @param {Option} option
1091
+ * @return {Command} `this` command for chaining
1092
+ */
1093
+ addOption(e) {
1094
+ this._registerOption(e);
1095
+ const t = e.name(), i = e.attributeName();
1096
+ if (e.negate) {
1097
+ const r = e.long.replace(/^--no-/, "--");
1098
+ this._findOption(r) || this.setOptionValueWithSource(
1099
+ i,
1100
+ e.defaultValue === void 0 ? !0 : e.defaultValue,
1101
+ "default"
1102
+ );
1103
+ } else e.defaultValue !== void 0 && this.setOptionValueWithSource(i, e.defaultValue, "default");
1104
+ const s = (r, l, m) => {
1105
+ r == null && e.presetArg !== void 0 && (r = e.presetArg);
1106
+ const c = this.getOptionValue(i);
1107
+ r !== null && e.parseArg ? r = this._callParseArg(e, r, c, l) : r !== null && e.variadic && (r = e._concatValue(r, c)), r == null && (e.negate ? r = !1 : e.isBoolean() || e.optional ? r = !0 : r = ""), this.setOptionValueWithSource(i, r, m);
1108
+ };
1109
+ return this.on("option:" + t, (r) => {
1110
+ const l = `error: option '${e.flags}' argument '${r}' is invalid.`;
1111
+ s(r, l, "cli");
1112
+ }), e.envVar && this.on("optionEnv:" + t, (r) => {
1113
+ const l = `error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;
1114
+ s(r, l, "env");
1115
+ }), this;
1116
+ }
1117
+ /**
1118
+ * Internal implementation shared by .option() and .requiredOption()
1119
+ *
1120
+ * @return {Command} `this` command for chaining
1121
+ * @private
1122
+ */
1123
+ _optionEx(e, t, i, s, r) {
1124
+ if (typeof t == "object" && t instanceof O)
1125
+ throw new Error(
1126
+ "To add an Option object use addOption() instead of option() or requiredOption()"
1127
+ );
1128
+ const l = this.createOption(t, i);
1129
+ if (l.makeOptionMandatory(!!e.mandatory), typeof s == "function")
1130
+ l.default(r).argParser(s);
1131
+ else if (s instanceof RegExp) {
1132
+ const m = s;
1133
+ s = (c, p) => {
1134
+ const d = m.exec(c);
1135
+ return d ? d[0] : p;
1136
+ }, l.default(r).argParser(s);
1137
+ } else
1138
+ l.default(s);
1139
+ return this.addOption(l);
1140
+ }
1141
+ /**
1142
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
1143
+ *
1144
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
1145
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
1146
+ *
1147
+ * See the README for more details, and see also addOption() and requiredOption().
1148
+ *
1149
+ * @example
1150
+ * program
1151
+ * .option('-p, --pepper', 'add pepper')
1152
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
1153
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
1154
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1155
+ *
1156
+ * @param {string} flags
1157
+ * @param {string} [description]
1158
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1159
+ * @param {*} [defaultValue]
1160
+ * @return {Command} `this` command for chaining
1161
+ */
1162
+ option(e, t, i, s) {
1163
+ return this._optionEx({}, e, t, i, s);
1164
+ }
1165
+ /**
1166
+ * Add a required option which must have a value after parsing. This usually means
1167
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1168
+ *
1169
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1170
+ *
1171
+ * @param {string} flags
1172
+ * @param {string} [description]
1173
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1174
+ * @param {*} [defaultValue]
1175
+ * @return {Command} `this` command for chaining
1176
+ */
1177
+ requiredOption(e, t, i, s) {
1178
+ return this._optionEx(
1179
+ { mandatory: !0 },
1180
+ e,
1181
+ t,
1182
+ i,
1183
+ s
1184
+ );
1185
+ }
1186
+ /**
1187
+ * Alter parsing of short flags with optional values.
1188
+ *
1189
+ * @example
1190
+ * // for `.option('-f,--flag [value]'):
1191
+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
1192
+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1193
+ *
1194
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
1195
+ * @return {Command} `this` command for chaining
1196
+ */
1197
+ combineFlagAndOptionalValue(e = !0) {
1198
+ return this._combineFlagAndOptionalValue = !!e, this;
1199
+ }
1200
+ /**
1201
+ * Allow unknown options on the command line.
1202
+ *
1203
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
1204
+ * @return {Command} `this` command for chaining
1205
+ */
1206
+ allowUnknownOption(e = !0) {
1207
+ return this._allowUnknownOption = !!e, this;
1208
+ }
1209
+ /**
1210
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1211
+ *
1212
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
1213
+ * @return {Command} `this` command for chaining
1214
+ */
1215
+ allowExcessArguments(e = !0) {
1216
+ return this._allowExcessArguments = !!e, this;
1217
+ }
1218
+ /**
1219
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1220
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1221
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1222
+ *
1223
+ * @param {boolean} [positional]
1224
+ * @return {Command} `this` command for chaining
1225
+ */
1226
+ enablePositionalOptions(e = !0) {
1227
+ return this._enablePositionalOptions = !!e, this;
1228
+ }
1229
+ /**
1230
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1231
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1232
+ * positional options to have been enabled on the program (parent commands).
1233
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1234
+ *
1235
+ * @param {boolean} [passThrough] for unknown options.
1236
+ * @return {Command} `this` command for chaining
1237
+ */
1238
+ passThroughOptions(e = !0) {
1239
+ return this._passThroughOptions = !!e, this._checkForBrokenPassThrough(), this;
1240
+ }
1241
+ /**
1242
+ * @private
1243
+ */
1244
+ _checkForBrokenPassThrough() {
1245
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions)
1246
+ throw new Error(
1247
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
1248
+ );
1249
+ }
1250
+ /**
1251
+ * Whether to store option values as properties on command object,
1252
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
1253
+ *
1254
+ * @param {boolean} [storeAsProperties=true]
1255
+ * @return {Command} `this` command for chaining
1256
+ */
1257
+ storeOptionsAsProperties(e = !0) {
1258
+ if (this.options.length)
1259
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1260
+ if (Object.keys(this._optionValues).length)
1261
+ throw new Error(
1262
+ "call .storeOptionsAsProperties() before setting option values"
1263
+ );
1264
+ return this._storeOptionsAsProperties = !!e, this;
1265
+ }
1266
+ /**
1267
+ * Retrieve option value.
1268
+ *
1269
+ * @param {string} key
1270
+ * @return {object} value
1271
+ */
1272
+ getOptionValue(e) {
1273
+ return this._storeOptionsAsProperties ? this[e] : this._optionValues[e];
1274
+ }
1275
+ /**
1276
+ * Store option value.
1277
+ *
1278
+ * @param {string} key
1279
+ * @param {object} value
1280
+ * @return {Command} `this` command for chaining
1281
+ */
1282
+ setOptionValue(e, t) {
1283
+ return this.setOptionValueWithSource(e, t, void 0);
1284
+ }
1285
+ /**
1286
+ * Store option value and where the value came from.
1287
+ *
1288
+ * @param {string} key
1289
+ * @param {object} value
1290
+ * @param {string} source - expected values are default/config/env/cli/implied
1291
+ * @return {Command} `this` command for chaining
1292
+ */
1293
+ setOptionValueWithSource(e, t, i) {
1294
+ return this._storeOptionsAsProperties ? this[e] = t : this._optionValues[e] = t, this._optionValueSources[e] = i, this;
1295
+ }
1296
+ /**
1297
+ * Get source of option value.
1298
+ * Expected values are default | config | env | cli | implied
1299
+ *
1300
+ * @param {string} key
1301
+ * @return {string}
1302
+ */
1303
+ getOptionValueSource(e) {
1304
+ return this._optionValueSources[e];
1305
+ }
1306
+ /**
1307
+ * Get source of option value. See also .optsWithGlobals().
1308
+ * Expected values are default | config | env | cli | implied
1309
+ *
1310
+ * @param {string} key
1311
+ * @return {string}
1312
+ */
1313
+ getOptionValueSourceWithGlobals(e) {
1314
+ let t;
1315
+ return this._getCommandAndAncestors().forEach((i) => {
1316
+ i.getOptionValueSource(e) !== void 0 && (t = i.getOptionValueSource(e));
1317
+ }), t;
1318
+ }
1319
+ /**
1320
+ * Get user arguments from implied or explicit arguments.
1321
+ * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
1322
+ *
1323
+ * @private
1324
+ */
1325
+ _prepareUserArgs(e, t) {
1326
+ if (e !== void 0 && !Array.isArray(e))
1327
+ throw new Error("first parameter to parse must be array or undefined");
1328
+ if (t = t || {}, e === void 0 && t.from === void 0) {
1329
+ n.versions?.electron && (t.from = "electron");
1330
+ const s = n.execArgv ?? [];
1331
+ (s.includes("-e") || s.includes("--eval") || s.includes("-p") || s.includes("--print")) && (t.from = "eval");
1332
+ }
1333
+ e === void 0 && (e = n.argv), this.rawArgs = e.slice();
1334
+ let i;
1335
+ switch (t.from) {
1336
+ case void 0:
1337
+ case "node":
1338
+ this._scriptPath = e[1], i = e.slice(2);
1339
+ break;
1340
+ case "electron":
1341
+ n.defaultApp ? (this._scriptPath = e[1], i = e.slice(2)) : i = e.slice(1);
1342
+ break;
1343
+ case "user":
1344
+ i = e.slice(0);
1345
+ break;
1346
+ case "eval":
1347
+ i = e.slice(1);
1348
+ break;
1349
+ default:
1350
+ throw new Error(
1351
+ `unexpected parse option { from: '${t.from}' }`
1352
+ );
1353
+ }
1354
+ return !this._name && this._scriptPath && this.nameFromFilename(this._scriptPath), this._name = this._name || "program", i;
1355
+ }
1356
+ /**
1357
+ * Parse `argv`, setting options and invoking commands when defined.
1358
+ *
1359
+ * Use parseAsync instead of parse if any of your action handlers are async.
1360
+ *
1361
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1362
+ *
1363
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1364
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1365
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1366
+ * - `'user'`: just user arguments
1367
+ *
1368
+ * @example
1369
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
1370
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
1371
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1372
+ *
1373
+ * @param {string[]} [argv] - optional, defaults to process.argv
1374
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
1375
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
1376
+ * @return {Command} `this` command for chaining
1377
+ */
1378
+ parse(e, t) {
1379
+ const i = this._prepareUserArgs(e, t);
1380
+ return this._parseCommand([], i), this;
1381
+ }
1382
+ /**
1383
+ * Parse `argv`, setting options and invoking commands when defined.
1384
+ *
1385
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1386
+ *
1387
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1388
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1389
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1390
+ * - `'user'`: just user arguments
1391
+ *
1392
+ * @example
1393
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
1394
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
1395
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1396
+ *
1397
+ * @param {string[]} [argv]
1398
+ * @param {object} [parseOptions]
1399
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
1400
+ * @return {Promise}
1401
+ */
1402
+ async parseAsync(e, t) {
1403
+ const i = this._prepareUserArgs(e, t);
1404
+ return await this._parseCommand([], i), this;
1405
+ }
1406
+ /**
1407
+ * Execute a sub-command executable.
1408
+ *
1409
+ * @private
1410
+ */
1411
+ _executeSubCommand(e, t) {
1412
+ t = t.slice();
1413
+ let i = !1;
1414
+ const s = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1415
+ function r(d, b) {
1416
+ const y = _.resolve(d, b);
1417
+ if (o.existsSync(y)) return y;
1418
+ if (s.includes(_.extname(b))) return;
1419
+ const q = s.find(
1420
+ (Y) => o.existsSync(`${y}${Y}`)
1421
+ );
1422
+ if (q) return `${y}${q}`;
1423
+ }
1424
+ this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
1425
+ let l = e._executableFile || `${this._name}-${e._name}`, m = this._executableDir || "";
1426
+ if (this._scriptPath) {
1427
+ let d;
1428
+ try {
1429
+ d = o.realpathSync(this._scriptPath);
1430
+ } catch {
1431
+ d = this._scriptPath;
1432
+ }
1433
+ m = _.resolve(
1434
+ _.dirname(d),
1435
+ m
1436
+ );
1437
+ }
1438
+ if (m) {
1439
+ let d = r(m, l);
1440
+ if (!d && !e._executableFile && this._scriptPath) {
1441
+ const b = _.basename(
1442
+ this._scriptPath,
1443
+ _.extname(this._scriptPath)
1444
+ );
1445
+ b !== this._name && (d = r(
1446
+ m,
1447
+ `${b}-${e._name}`
1448
+ ));
1449
+ }
1450
+ l = d || l;
1451
+ }
1452
+ i = s.includes(_.extname(l));
1453
+ let c;
1454
+ n.platform !== "win32" ? i ? (t.unshift(l), t = x(n.execArgv).concat(t), c = C.spawn(n.argv[0], t, { stdio: "inherit" })) : c = C.spawn(l, t, { stdio: "inherit" }) : (t.unshift(l), t = x(n.execArgv).concat(t), c = C.spawn(n.execPath, t, { stdio: "inherit" })), c.killed || ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"].forEach((b) => {
1455
+ n.on(b, () => {
1456
+ c.killed === !1 && c.exitCode === null && c.kill(b);
1457
+ });
1458
+ });
1459
+ const p = this._exitCallback;
1460
+ c.on("close", (d) => {
1461
+ d = d ?? 1, p ? p(
1462
+ new h(
1463
+ d,
1464
+ "commander.executeSubCommandAsync",
1465
+ "(close)"
1466
+ )
1467
+ ) : n.exit(d);
1468
+ }), c.on("error", (d) => {
1469
+ if (d.code === "ENOENT") {
1470
+ const b = m ? `searched for local subcommand relative to directory '${m}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory", y = `'${l}' does not exist
1471
+ - if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1472
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1473
+ - ${b}`;
1474
+ throw new Error(y);
1475
+ } else if (d.code === "EACCES")
1476
+ throw new Error(`'${l}' not executable`);
1477
+ if (!p)
1478
+ n.exit(1);
1479
+ else {
1480
+ const b = new h(
1481
+ 1,
1482
+ "commander.executeSubCommandAsync",
1483
+ "(error)"
1484
+ );
1485
+ b.nestedError = d, p(b);
1486
+ }
1487
+ }), this.runningCommand = c;
1488
+ }
1489
+ /**
1490
+ * @private
1491
+ */
1492
+ _dispatchSubcommand(e, t, i) {
1493
+ const s = this._findCommand(e);
1494
+ s || this.help({ error: !0 });
1495
+ let r;
1496
+ return r = this._chainOrCallSubCommandHook(
1497
+ r,
1498
+ s,
1499
+ "preSubcommand"
1500
+ ), r = this._chainOrCall(r, () => {
1501
+ if (s._executableHandler)
1502
+ this._executeSubCommand(s, t.concat(i));
1503
+ else
1504
+ return s._parseCommand(t, i);
1505
+ }), r;
1506
+ }
1507
+ /**
1508
+ * Invoke help directly if possible, or dispatch if necessary.
1509
+ * e.g. help foo
1510
+ *
1511
+ * @private
1512
+ */
1513
+ _dispatchHelpCommand(e) {
1514
+ e || this.help();
1515
+ const t = this._findCommand(e);
1516
+ return t && !t._executableHandler && t.help(), this._dispatchSubcommand(
1517
+ e,
1518
+ [],
1519
+ [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
1520
+ );
1521
+ }
1522
+ /**
1523
+ * Check this.args against expected this.registeredArguments.
1524
+ *
1525
+ * @private
1526
+ */
1527
+ _checkNumberOfArguments() {
1528
+ this.registeredArguments.forEach((e, t) => {
1529
+ e.required && this.args[t] == null && this.missingArgument(e.name());
1530
+ }), !(this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) && this.args.length > this.registeredArguments.length && this._excessArguments(this.args);
1531
+ }
1532
+ /**
1533
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
1534
+ *
1535
+ * @private
1536
+ */
1537
+ _processArguments() {
1538
+ const e = (i, s, r) => {
1539
+ let l = s;
1540
+ if (s !== null && i.parseArg) {
1541
+ const m = `error: command-argument value '${s}' is invalid for argument '${i.name()}'.`;
1542
+ l = this._callParseArg(
1543
+ i,
1544
+ s,
1545
+ r,
1546
+ m
1547
+ );
1548
+ }
1549
+ return l;
1550
+ };
1551
+ this._checkNumberOfArguments();
1552
+ const t = [];
1553
+ this.registeredArguments.forEach((i, s) => {
1554
+ let r = i.defaultValue;
1555
+ i.variadic ? s < this.args.length ? (r = this.args.slice(s), i.parseArg && (r = r.reduce((l, m) => e(i, m, l), i.defaultValue))) : r === void 0 && (r = []) : s < this.args.length && (r = this.args[s], i.parseArg && (r = e(i, r, i.defaultValue))), t[s] = r;
1556
+ }), this.processedArgs = t;
1557
+ }
1558
+ /**
1559
+ * Once we have a promise we chain, but call synchronously until then.
1560
+ *
1561
+ * @param {(Promise|undefined)} promise
1562
+ * @param {Function} fn
1563
+ * @return {(Promise|undefined)}
1564
+ * @private
1565
+ */
1566
+ _chainOrCall(e, t) {
1567
+ return e && e.then && typeof e.then == "function" ? e.then(() => t()) : t();
1568
+ }
1569
+ /**
1570
+ *
1571
+ * @param {(Promise|undefined)} promise
1572
+ * @param {string} event
1573
+ * @return {(Promise|undefined)}
1574
+ * @private
1575
+ */
1576
+ _chainOrCallHooks(e, t) {
1577
+ let i = e;
1578
+ const s = [];
1579
+ return this._getCommandAndAncestors().reverse().filter((r) => r._lifeCycleHooks[t] !== void 0).forEach((r) => {
1580
+ r._lifeCycleHooks[t].forEach((l) => {
1581
+ s.push({ hookedCommand: r, callback: l });
1582
+ });
1583
+ }), t === "postAction" && s.reverse(), s.forEach((r) => {
1584
+ i = this._chainOrCall(i, () => r.callback(r.hookedCommand, this));
1585
+ }), i;
1586
+ }
1587
+ /**
1588
+ *
1589
+ * @param {(Promise|undefined)} promise
1590
+ * @param {Command} subCommand
1591
+ * @param {string} event
1592
+ * @return {(Promise|undefined)}
1593
+ * @private
1594
+ */
1595
+ _chainOrCallSubCommandHook(e, t, i) {
1596
+ let s = e;
1597
+ return this._lifeCycleHooks[i] !== void 0 && this._lifeCycleHooks[i].forEach((r) => {
1598
+ s = this._chainOrCall(s, () => r(this, t));
1599
+ }), s;
1600
+ }
1601
+ /**
1602
+ * Process arguments in context of this command.
1603
+ * Returns action result, in case it is a promise.
1604
+ *
1605
+ * @private
1606
+ */
1607
+ _parseCommand(e, t) {
1608
+ const i = this.parseOptions(t);
1609
+ if (this._parseOptionsEnv(), this._parseOptionsImplied(), e = e.concat(i.operands), t = i.unknown, this.args = e.concat(t), e && this._findCommand(e[0]))
1610
+ return this._dispatchSubcommand(e[0], e.slice(1), t);
1611
+ if (this._getHelpCommand() && e[0] === this._getHelpCommand().name())
1612
+ return this._dispatchHelpCommand(e[1]);
1613
+ if (this._defaultCommandName)
1614
+ return this._outputHelpIfRequested(t), this._dispatchSubcommand(
1615
+ this._defaultCommandName,
1616
+ e,
1617
+ t
1618
+ );
1619
+ this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName && this.help({ error: !0 }), this._outputHelpIfRequested(i.unknown), this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
1620
+ const s = () => {
1621
+ i.unknown.length > 0 && this.unknownOption(i.unknown[0]);
1622
+ }, r = `command:${this.name()}`;
1623
+ if (this._actionHandler) {
1624
+ s(), this._processArguments();
1625
+ let l;
1626
+ return l = this._chainOrCallHooks(l, "preAction"), l = this._chainOrCall(
1627
+ l,
1628
+ () => this._actionHandler(this.processedArgs)
1629
+ ), this.parent && (l = this._chainOrCall(l, () => {
1630
+ this.parent.emit(r, e, t);
1631
+ })), l = this._chainOrCallHooks(l, "postAction"), l;
1632
+ }
1633
+ if (this.parent && this.parent.listenerCount(r))
1634
+ s(), this._processArguments(), this.parent.emit(r, e, t);
1635
+ else if (e.length) {
1636
+ if (this._findCommand("*"))
1637
+ return this._dispatchSubcommand("*", e, t);
1638
+ this.listenerCount("command:*") ? this.emit("command:*", e, t) : this.commands.length ? this.unknownCommand() : (s(), this._processArguments());
1639
+ } else this.commands.length ? (s(), this.help({ error: !0 })) : (s(), this._processArguments());
1640
+ }
1641
+ /**
1642
+ * Find matching command.
1643
+ *
1644
+ * @private
1645
+ * @return {Command | undefined}
1646
+ */
1647
+ _findCommand(e) {
1648
+ if (e)
1649
+ return this.commands.find(
1650
+ (t) => t._name === e || t._aliases.includes(e)
1651
+ );
1652
+ }
1653
+ /**
1654
+ * Return an option matching `arg` if any.
1655
+ *
1656
+ * @param {string} arg
1657
+ * @return {Option}
1658
+ * @package
1659
+ */
1660
+ _findOption(e) {
1661
+ return this.options.find((t) => t.is(e));
1662
+ }
1663
+ /**
1664
+ * Display an error message if a mandatory option does not have a value.
1665
+ * Called after checking for help flags in leaf subcommand.
1666
+ *
1667
+ * @private
1668
+ */
1669
+ _checkForMissingMandatoryOptions() {
1670
+ this._getCommandAndAncestors().forEach((e) => {
1671
+ e.options.forEach((t) => {
1672
+ t.mandatory && e.getOptionValue(t.attributeName()) === void 0 && e.missingMandatoryOptionValue(t);
1673
+ });
1674
+ });
1675
+ }
1676
+ /**
1677
+ * Display an error message if conflicting options are used together in this.
1678
+ *
1679
+ * @private
1680
+ */
1681
+ _checkForConflictingLocalOptions() {
1682
+ const e = this.options.filter((i) => {
1683
+ const s = i.attributeName();
1684
+ return this.getOptionValue(s) === void 0 ? !1 : this.getOptionValueSource(s) !== "default";
1685
+ });
1686
+ e.filter(
1687
+ (i) => i.conflictsWith.length > 0
1688
+ ).forEach((i) => {
1689
+ const s = e.find(
1690
+ (r) => i.conflictsWith.includes(r.attributeName())
1691
+ );
1692
+ s && this._conflictingOption(i, s);
1693
+ });
1694
+ }
1695
+ /**
1696
+ * Display an error message if conflicting options are used together.
1697
+ * Called after checking for help flags in leaf subcommand.
1698
+ *
1699
+ * @private
1700
+ */
1701
+ _checkForConflictingOptions() {
1702
+ this._getCommandAndAncestors().forEach((e) => {
1703
+ e._checkForConflictingLocalOptions();
1704
+ });
1705
+ }
1706
+ /**
1707
+ * Parse options from `argv` removing known options,
1708
+ * and return argv split into operands and unknown arguments.
1709
+ *
1710
+ * Examples:
1711
+ *
1712
+ * argv => operands, unknown
1713
+ * --known kkk op => [op], []
1714
+ * op --known kkk => [op], []
1715
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
1716
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
1717
+ *
1718
+ * @param {string[]} argv
1719
+ * @return {{operands: string[], unknown: string[]}}
1720
+ */
1721
+ parseOptions(e) {
1722
+ const t = [], i = [];
1723
+ let s = t;
1724
+ const r = e.slice();
1725
+ function l(c) {
1726
+ return c.length > 1 && c[0] === "-";
1727
+ }
1728
+ let m = null;
1729
+ for (; r.length; ) {
1730
+ const c = r.shift();
1731
+ if (c === "--") {
1732
+ s === i && s.push(c), s.push(...r);
1733
+ break;
1734
+ }
1735
+ if (m && !l(c)) {
1736
+ this.emit(`option:${m.name()}`, c);
1737
+ continue;
1738
+ }
1739
+ if (m = null, l(c)) {
1740
+ const p = this._findOption(c);
1741
+ if (p) {
1742
+ if (p.required) {
1743
+ const d = r.shift();
1744
+ d === void 0 && this.optionMissingArgument(p), this.emit(`option:${p.name()}`, d);
1745
+ } else if (p.optional) {
1746
+ let d = null;
1747
+ r.length > 0 && !l(r[0]) && (d = r.shift()), this.emit(`option:${p.name()}`, d);
1748
+ } else
1749
+ this.emit(`option:${p.name()}`);
1750
+ m = p.variadic ? p : null;
1751
+ continue;
1752
+ }
1753
+ }
1754
+ if (c.length > 2 && c[0] === "-" && c[1] !== "-") {
1755
+ const p = this._findOption(`-${c[1]}`);
1756
+ if (p) {
1757
+ p.required || p.optional && this._combineFlagAndOptionalValue ? this.emit(`option:${p.name()}`, c.slice(2)) : (this.emit(`option:${p.name()}`), r.unshift(`-${c.slice(2)}`));
1758
+ continue;
1759
+ }
1760
+ }
1761
+ if (/^--[^=]+=/.test(c)) {
1762
+ const p = c.indexOf("="), d = this._findOption(c.slice(0, p));
1763
+ if (d && (d.required || d.optional)) {
1764
+ this.emit(`option:${d.name()}`, c.slice(p + 1));
1765
+ continue;
1766
+ }
1767
+ }
1768
+ if (l(c) && (s = i), (this._enablePositionalOptions || this._passThroughOptions) && t.length === 0 && i.length === 0) {
1769
+ if (this._findCommand(c)) {
1770
+ t.push(c), r.length > 0 && i.push(...r);
1771
+ break;
1772
+ } else if (this._getHelpCommand() && c === this._getHelpCommand().name()) {
1773
+ t.push(c), r.length > 0 && t.push(...r);
1774
+ break;
1775
+ } else if (this._defaultCommandName) {
1776
+ i.push(c), r.length > 0 && i.push(...r);
1777
+ break;
1778
+ }
1779
+ }
1780
+ if (this._passThroughOptions) {
1781
+ s.push(c), r.length > 0 && s.push(...r);
1782
+ break;
1783
+ }
1784
+ s.push(c);
1785
+ }
1786
+ return { operands: t, unknown: i };
1787
+ }
1788
+ /**
1789
+ * Return an object containing local option values as key-value pairs.
1790
+ *
1791
+ * @return {object}
1792
+ */
1793
+ opts() {
1794
+ if (this._storeOptionsAsProperties) {
1795
+ const e = {}, t = this.options.length;
1796
+ for (let i = 0; i < t; i++) {
1797
+ const s = this.options[i].attributeName();
1798
+ e[s] = s === this._versionOptionName ? this._version : this[s];
1799
+ }
1800
+ return e;
1801
+ }
1802
+ return this._optionValues;
1803
+ }
1804
+ /**
1805
+ * Return an object containing merged local and global option values as key-value pairs.
1806
+ *
1807
+ * @return {object}
1808
+ */
1809
+ optsWithGlobals() {
1810
+ return this._getCommandAndAncestors().reduce(
1811
+ (e, t) => Object.assign(e, t.opts()),
1812
+ {}
1813
+ );
1814
+ }
1815
+ /**
1816
+ * Display error message and exit (or call exitOverride).
1817
+ *
1818
+ * @param {string} message
1819
+ * @param {object} [errorOptions]
1820
+ * @param {string} [errorOptions.code] - an id string representing the error
1821
+ * @param {number} [errorOptions.exitCode] - used with process.exit
1822
+ */
1823
+ error(e, t) {
1824
+ this._outputConfiguration.outputError(
1825
+ `${e}
1826
+ `,
1827
+ this._outputConfiguration.writeErr
1828
+ ), typeof this._showHelpAfterError == "string" ? this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1829
+ `) : this._showHelpAfterError && (this._outputConfiguration.writeErr(`
1830
+ `), this.outputHelp({ error: !0 }));
1831
+ const i = t || {}, s = i.exitCode || 1, r = i.code || "commander.error";
1832
+ this._exit(s, r, e);
1833
+ }
1834
+ /**
1835
+ * Apply any option related environment variables, if option does
1836
+ * not have a value from cli or client code.
1837
+ *
1838
+ * @private
1839
+ */
1840
+ _parseOptionsEnv() {
1841
+ this.options.forEach((e) => {
1842
+ if (e.envVar && e.envVar in n.env) {
1843
+ const t = e.attributeName();
1844
+ (this.getOptionValue(t) === void 0 || ["default", "config", "env"].includes(
1845
+ this.getOptionValueSource(t)
1846
+ )) && (e.required || e.optional ? this.emit(`optionEnv:${e.name()}`, n.env[e.envVar]) : this.emit(`optionEnv:${e.name()}`));
1847
+ }
1848
+ });
1849
+ }
1850
+ /**
1851
+ * Apply any implied option values, if option is undefined or default value.
1852
+ *
1853
+ * @private
1854
+ */
1855
+ _parseOptionsImplied() {
1856
+ const e = new w(this.options), t = (i) => this.getOptionValue(i) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(i));
1857
+ this.options.filter(
1858
+ (i) => i.implied !== void 0 && t(i.attributeName()) && e.valueFromOption(
1859
+ this.getOptionValue(i.attributeName()),
1860
+ i
1861
+ )
1862
+ ).forEach((i) => {
1863
+ Object.keys(i.implied).filter((s) => !t(s)).forEach((s) => {
1864
+ this.setOptionValueWithSource(
1865
+ s,
1866
+ i.implied[s],
1867
+ "implied"
1868
+ );
1869
+ });
1870
+ });
1871
+ }
1872
+ /**
1873
+ * Argument `name` is missing.
1874
+ *
1875
+ * @param {string} name
1876
+ * @private
1877
+ */
1878
+ missingArgument(e) {
1879
+ const t = `error: missing required argument '${e}'`;
1880
+ this.error(t, { code: "commander.missingArgument" });
1881
+ }
1882
+ /**
1883
+ * `Option` is missing an argument.
1884
+ *
1885
+ * @param {Option} option
1886
+ * @private
1887
+ */
1888
+ optionMissingArgument(e) {
1889
+ const t = `error: option '${e.flags}' argument missing`;
1890
+ this.error(t, { code: "commander.optionMissingArgument" });
1891
+ }
1892
+ /**
1893
+ * `Option` does not have a value, and is a mandatory option.
1894
+ *
1895
+ * @param {Option} option
1896
+ * @private
1897
+ */
1898
+ missingMandatoryOptionValue(e) {
1899
+ const t = `error: required option '${e.flags}' not specified`;
1900
+ this.error(t, { code: "commander.missingMandatoryOptionValue" });
1901
+ }
1902
+ /**
1903
+ * `Option` conflicts with another option.
1904
+ *
1905
+ * @param {Option} option
1906
+ * @param {Option} conflictingOption
1907
+ * @private
1908
+ */
1909
+ _conflictingOption(e, t) {
1910
+ const i = (l) => {
1911
+ const m = l.attributeName(), c = this.getOptionValue(m), p = this.options.find(
1912
+ (b) => b.negate && m === b.attributeName()
1913
+ ), d = this.options.find(
1914
+ (b) => !b.negate && m === b.attributeName()
1915
+ );
1916
+ return p && (p.presetArg === void 0 && c === !1 || p.presetArg !== void 0 && c === p.presetArg) ? p : d || l;
1917
+ }, s = (l) => {
1918
+ const m = i(l), c = m.attributeName();
1919
+ return this.getOptionValueSource(c) === "env" ? `environment variable '${m.envVar}'` : `option '${m.flags}'`;
1920
+ }, r = `error: ${s(e)} cannot be used with ${s(t)}`;
1921
+ this.error(r, { code: "commander.conflictingOption" });
1922
+ }
1923
+ /**
1924
+ * Unknown option `flag`.
1925
+ *
1926
+ * @param {string} flag
1927
+ * @private
1928
+ */
1929
+ unknownOption(e) {
1930
+ if (this._allowUnknownOption) return;
1931
+ let t = "";
1932
+ if (e.startsWith("--") && this._showSuggestionAfterError) {
1933
+ let s = [], r = this;
1934
+ do {
1935
+ const l = r.createHelp().visibleOptions(r).filter((m) => m.long).map((m) => m.long);
1936
+ s = s.concat(l), r = r.parent;
1937
+ } while (r && !r._enablePositionalOptions);
1938
+ t = A(e, s);
1939
+ }
1940
+ const i = `error: unknown option '${e}'${t}`;
1941
+ this.error(i, { code: "commander.unknownOption" });
1942
+ }
1943
+ /**
1944
+ * Excess arguments, more than expected.
1945
+ *
1946
+ * @param {string[]} receivedArgs
1947
+ * @private
1948
+ */
1949
+ _excessArguments(e) {
1950
+ if (this._allowExcessArguments) return;
1951
+ const t = this.registeredArguments.length, i = t === 1 ? "" : "s", r = `error: too many arguments${this.parent ? ` for '${this.name()}'` : ""}. Expected ${t} argument${i} but got ${e.length}.`;
1952
+ this.error(r, { code: "commander.excessArguments" });
1953
+ }
1954
+ /**
1955
+ * Unknown command.
1956
+ *
1957
+ * @private
1958
+ */
1959
+ unknownCommand() {
1960
+ const e = this.args[0];
1961
+ let t = "";
1962
+ if (this._showSuggestionAfterError) {
1963
+ const s = [];
1964
+ this.createHelp().visibleCommands(this).forEach((r) => {
1965
+ s.push(r.name()), r.alias() && s.push(r.alias());
1966
+ }), t = A(e, s);
1967
+ }
1968
+ const i = `error: unknown command '${e}'${t}`;
1969
+ this.error(i, { code: "commander.unknownCommand" });
1970
+ }
1971
+ /**
1972
+ * Get or set the program version.
1973
+ *
1974
+ * This method auto-registers the "-V, --version" option which will print the version number.
1975
+ *
1976
+ * You can optionally supply the flags and description to override the defaults.
1977
+ *
1978
+ * @param {string} [str]
1979
+ * @param {string} [flags]
1980
+ * @param {string} [description]
1981
+ * @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
1982
+ */
1983
+ version(e, t, i) {
1984
+ if (e === void 0) return this._version;
1985
+ this._version = e, t = t || "-V, --version", i = i || "output the version number";
1986
+ const s = this.createOption(t, i);
1987
+ return this._versionOptionName = s.attributeName(), this._registerOption(s), this.on("option:" + s.name(), () => {
1988
+ this._outputConfiguration.writeOut(`${e}
1989
+ `), this._exit(0, "commander.version", e);
1990
+ }), this;
1991
+ }
1992
+ /**
1993
+ * Set the description.
1994
+ *
1995
+ * @param {string} [str]
1996
+ * @param {object} [argsDescription]
1997
+ * @return {(string|Command)}
1998
+ */
1999
+ description(e, t) {
2000
+ return e === void 0 && t === void 0 ? this._description : (this._description = e, t && (this._argsDescription = t), this);
2001
+ }
2002
+ /**
2003
+ * Set the summary. Used when listed as subcommand of parent.
2004
+ *
2005
+ * @param {string} [str]
2006
+ * @return {(string|Command)}
2007
+ */
2008
+ summary(e) {
2009
+ return e === void 0 ? this._summary : (this._summary = e, this);
2010
+ }
2011
+ /**
2012
+ * Set an alias for the command.
2013
+ *
2014
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
2015
+ *
2016
+ * @param {string} [alias]
2017
+ * @return {(string|Command)}
2018
+ */
2019
+ alias(e) {
2020
+ if (e === void 0) return this._aliases[0];
2021
+ let t = this;
2022
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler && (t = this.commands[this.commands.length - 1]), e === t._name)
2023
+ throw new Error("Command alias can't be the same as its name");
2024
+ const i = this.parent?._findCommand(e);
2025
+ if (i) {
2026
+ const s = [i.name()].concat(i.aliases()).join("|");
2027
+ throw new Error(
2028
+ `cannot add alias '${e}' to command '${this.name()}' as already have command '${s}'`
2029
+ );
2030
+ }
2031
+ return t._aliases.push(e), this;
2032
+ }
2033
+ /**
2034
+ * Set aliases for the command.
2035
+ *
2036
+ * Only the first alias is shown in the auto-generated help.
2037
+ *
2038
+ * @param {string[]} [aliases]
2039
+ * @return {(string[]|Command)}
2040
+ */
2041
+ aliases(e) {
2042
+ return e === void 0 ? this._aliases : (e.forEach((t) => this.alias(t)), this);
2043
+ }
2044
+ /**
2045
+ * Set / get the command usage `str`.
2046
+ *
2047
+ * @param {string} [str]
2048
+ * @return {(string|Command)}
2049
+ */
2050
+ usage(e) {
2051
+ if (e === void 0) {
2052
+ if (this._usage) return this._usage;
2053
+ const t = this.registeredArguments.map((i) => a(i));
2054
+ return [].concat(
2055
+ this.options.length || this._helpOption !== null ? "[options]" : [],
2056
+ this.commands.length ? "[command]" : [],
2057
+ this.registeredArguments.length ? t : []
2058
+ ).join(" ");
2059
+ }
2060
+ return this._usage = e, this;
2061
+ }
2062
+ /**
2063
+ * Get or set the name of the command.
2064
+ *
2065
+ * @param {string} [str]
2066
+ * @return {(string|Command)}
2067
+ */
2068
+ name(e) {
2069
+ return e === void 0 ? this._name : (this._name = e, this);
2070
+ }
2071
+ /**
2072
+ * Set the name of the command from script filename, such as process.argv[1],
2073
+ * or require.main.filename, or __filename.
2074
+ *
2075
+ * (Used internally and public although not documented in README.)
2076
+ *
2077
+ * @example
2078
+ * program.nameFromFilename(require.main.filename);
2079
+ *
2080
+ * @param {string} filename
2081
+ * @return {Command}
2082
+ */
2083
+ nameFromFilename(e) {
2084
+ return this._name = _.basename(e, _.extname(e)), this;
2085
+ }
2086
+ /**
2087
+ * Get or set the directory for searching for executable subcommands of this command.
2088
+ *
2089
+ * @example
2090
+ * program.executableDir(__dirname);
2091
+ * // or
2092
+ * program.executableDir('subcommands');
2093
+ *
2094
+ * @param {string} [path]
2095
+ * @return {(string|null|Command)}
2096
+ */
2097
+ executableDir(e) {
2098
+ return e === void 0 ? this._executableDir : (this._executableDir = e, this);
2099
+ }
2100
+ /**
2101
+ * Return program help documentation.
2102
+ *
2103
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
2104
+ * @return {string}
2105
+ */
2106
+ helpInformation(e) {
2107
+ const t = this.createHelp();
2108
+ return t.helpWidth === void 0 && (t.helpWidth = e && e.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth()), t.formatHelp(this, t);
2109
+ }
2110
+ /**
2111
+ * @private
2112
+ */
2113
+ _getHelpContext(e) {
2114
+ e = e || {};
2115
+ const t = { error: !!e.error };
2116
+ let i;
2117
+ return t.error ? i = (s) => this._outputConfiguration.writeErr(s) : i = (s) => this._outputConfiguration.writeOut(s), t.write = e.write || i, t.command = this, t;
2118
+ }
2119
+ /**
2120
+ * Output help information for this command.
2121
+ *
2122
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2123
+ *
2124
+ * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2125
+ */
2126
+ outputHelp(e) {
2127
+ let t;
2128
+ typeof e == "function" && (t = e, e = void 0);
2129
+ const i = this._getHelpContext(e);
2130
+ this._getCommandAndAncestors().reverse().forEach((r) => r.emit("beforeAllHelp", i)), this.emit("beforeHelp", i);
2131
+ let s = this.helpInformation(i);
2132
+ if (t && (s = t(s), typeof s != "string" && !Buffer.isBuffer(s)))
2133
+ throw new Error("outputHelp callback must return a string or a Buffer");
2134
+ i.write(s), this._getHelpOption()?.long && this.emit(this._getHelpOption().long), this.emit("afterHelp", i), this._getCommandAndAncestors().forEach(
2135
+ (r) => r.emit("afterAllHelp", i)
2136
+ );
2137
+ }
2138
+ /**
2139
+ * You can pass in flags and a description to customise the built-in help option.
2140
+ * Pass in false to disable the built-in help option.
2141
+ *
2142
+ * @example
2143
+ * program.helpOption('-?, --help' 'show help'); // customise
2144
+ * program.helpOption(false); // disable
2145
+ *
2146
+ * @param {(string | boolean)} flags
2147
+ * @param {string} [description]
2148
+ * @return {Command} `this` command for chaining
2149
+ */
2150
+ helpOption(e, t) {
2151
+ return typeof e == "boolean" ? (e ? this._helpOption = this._helpOption ?? void 0 : this._helpOption = null, this) : (e = e ?? "-h, --help", t = t ?? "display help for command", this._helpOption = this.createOption(e, t), this);
2152
+ }
2153
+ /**
2154
+ * Lazy create help option.
2155
+ * Returns null if has been disabled with .helpOption(false).
2156
+ *
2157
+ * @returns {(Option | null)} the help option
2158
+ * @package
2159
+ */
2160
+ _getHelpOption() {
2161
+ return this._helpOption === void 0 && this.helpOption(void 0, void 0), this._helpOption;
2162
+ }
2163
+ /**
2164
+ * Supply your own option to use for the built-in help option.
2165
+ * This is an alternative to using helpOption() to customise the flags and description etc.
2166
+ *
2167
+ * @param {Option} option
2168
+ * @return {Command} `this` command for chaining
2169
+ */
2170
+ addHelpOption(e) {
2171
+ return this._helpOption = e, this;
2172
+ }
2173
+ /**
2174
+ * Output help information and exit.
2175
+ *
2176
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2177
+ *
2178
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2179
+ */
2180
+ help(e) {
2181
+ this.outputHelp(e);
2182
+ let t = n.exitCode || 0;
2183
+ t === 0 && e && typeof e != "function" && e.error && (t = 1), this._exit(t, "commander.help", "(outputHelp)");
2184
+ }
2185
+ /**
2186
+ * Add additional text to be displayed with the built-in help.
2187
+ *
2188
+ * Position is 'before' or 'after' to affect just this command,
2189
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
2190
+ *
2191
+ * @param {string} position - before or after built-in help
2192
+ * @param {(string | Function)} text - string to add, or a function returning a string
2193
+ * @return {Command} `this` command for chaining
2194
+ */
2195
+ addHelpText(e, t) {
2196
+ const i = ["beforeAll", "before", "after", "afterAll"];
2197
+ if (!i.includes(e))
2198
+ throw new Error(`Unexpected value for position to addHelpText.
2199
+ Expecting one of '${i.join("', '")}'`);
2200
+ const s = `${e}Help`;
2201
+ return this.on(s, (r) => {
2202
+ let l;
2203
+ typeof t == "function" ? l = t({ error: r.error, command: r.command }) : l = t, l && r.write(`${l}
2204
+ `);
2205
+ }), this;
2206
+ }
2207
+ /**
2208
+ * Output help information if help flags specified
2209
+ *
2210
+ * @param {Array} args - array of options to search for help flags
2211
+ * @private
2212
+ */
2213
+ _outputHelpIfRequested(e) {
2214
+ const t = this._getHelpOption();
2215
+ t && e.find((s) => t.is(s)) && (this.outputHelp(), this._exit(0, "commander.helpDisplayed", "(outputHelp)"));
2216
+ }
2217
+ }
2218
+ function x($) {
2219
+ return $.map((e) => {
2220
+ if (!e.startsWith("--inspect"))
2221
+ return e;
2222
+ let t, i = "127.0.0.1", s = "9229", r;
2223
+ return (r = e.match(/^(--inspect(-brk)?)$/)) !== null ? t = r[1] : (r = e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null ? (t = r[1], /^\d+$/.test(r[3]) ? s = r[3] : i = r[3]) : (r = e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null && (t = r[1], i = r[3], s = r[4]), t && s !== "0" ? `${t}=${i}:${parseInt(s) + 1}` : e;
2224
+ });
2225
+ }
2226
+ return T.Command = v, T;
2227
+ }
2228
+ var B;
2229
+ function re() {
2230
+ if (B) return E;
2231
+ B = 1;
2232
+ const { Argument: g } = N(), { Command: C } = se(), { CommanderError: _, InvalidArgumentError: o } = D(), { Help: n } = J(), { Option: u } = K();
2233
+ return E.program = new C(), E.createCommand = (a) => new C(a), E.createOption = (a, h) => new u(a, h), E.createArgument = (a, h) => new g(a, h), E.Command = C, E.Option = u, E.Argument = g, E.Help = n, E.CommanderError = _, E.InvalidArgumentError = o, E.InvalidOptionArgumentError = o, E;
2234
+ }
2235
+ var oe = re();
2236
+ const ae = /* @__PURE__ */ z(oe), {
2237
+ program: Ce,
2238
+ createCommand: be,
2239
+ createArgument: Ae,
2240
+ createOption: we,
2241
+ CommanderError: Ee,
2242
+ InvalidArgumentError: ve,
2243
+ InvalidOptionArgumentError: $e,
2244
+ // deprecated old name
2245
+ Command: ue,
2246
+ Argument: xe,
2247
+ Option: ye,
2248
+ Help: He
2249
+ } = ae, he = process.stdout.write;
2250
+ process.stdout.write = () => !0;
2251
+ try {
2252
+ ie.config({ debug: !1 });
2253
+ } finally {
2254
+ process.stdout.write = he;
2255
+ }
2256
+ const le = () => {
2257
+ let g = !1;
2258
+ const C = () => {
2259
+ try {
2260
+ H.get(P.StdinManager).restoreNormalMode();
2261
+ } catch {
2262
+ }
2263
+ }, _ = async () => {
2264
+ if (!g) {
2265
+ g = !0, C();
2266
+ try {
2267
+ if (H.isBound(M.DaemonManager)) {
2268
+ const o = H.get(
2269
+ M.DaemonManager
2270
+ );
2271
+ if (o.isRunning()) {
2272
+ await o.stop();
2273
+ return;
2274
+ }
2275
+ }
2276
+ } catch {
2277
+ }
2278
+ process.exit(0);
2279
+ }
2280
+ };
2281
+ process.on("exit", C), process.on("SIGINT", () => _()), process.on("SIGTERM", () => _()), process.on("uncaughtException", (o) => {
2282
+ console.error("[cli] Uncaught exception:", o), C(), process.exit(1);
2283
+ }), process.on("unhandledRejection", (o) => {
2284
+ console.error("[cli] Unhandled rejection:", o), C(), process.exit(1);
2285
+ });
2286
+ };
2287
+ le();
2288
+ async function ce() {
2289
+ const g = new ue();
2290
+ g.name("agiflow").description("@agiflowai/agent-cli").option("-v, --verbose", "enable verbose logging").option("--debug", "enable debug mode");
2291
+ const C = H.get(P.DaemonCommand), _ = H.get(P.AgentCommand), o = H.get(P.LogoutCommand);
2292
+ C.register(g), _.register(g), o.register(g);
2293
+ try {
2294
+ await g.parseAsync(process.argv);
2295
+ } catch (n) {
2296
+ console.error("[cli] error", n.message), g.opts().debug && n instanceof Error && console.error(n.stack), process.exit(1);
2297
+ }
2298
+ }
2299
+ ce();
3
2300
  //# sourceMappingURL=cli.js.map