bob-core 2.0.0-beta.9 → 2.0.1

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 (56) hide show
  1. package/README.md +57 -33
  2. package/dist/cjs/package-DO_9Y5-u.cjs +1 -0
  3. package/dist/cjs/src/Cli.d.ts +10 -11
  4. package/dist/cjs/src/Command.d.ts +11 -18
  5. package/dist/cjs/src/CommandIO.d.ts +5 -2
  6. package/dist/cjs/src/CommandParser.d.ts +13 -5
  7. package/dist/cjs/src/CommandRegistry.d.ts +13 -6
  8. package/dist/cjs/src/CommandSignatureParser.d.ts +5 -4
  9. package/dist/cjs/src/CommandWithSignature.d.ts +3 -3
  10. package/dist/cjs/src/ExceptionHandler.d.ts +1 -1
  11. package/dist/cjs/src/Logger.d.ts +1 -1
  12. package/dist/cjs/src/StringSimilarity.d.ts +26 -0
  13. package/dist/cjs/src/commands/HelpCommand.d.ts +1 -1
  14. package/dist/cjs/src/contracts/CommandOption.d.ts +3 -3
  15. package/dist/cjs/src/errors/BadCommandOption.d.ts +2 -1
  16. package/dist/cjs/src/errors/BadCommandParameter.d.ts +2 -1
  17. package/dist/cjs/src/errors/CommandNotFoundError.d.ts +2 -1
  18. package/dist/cjs/src/errors/InvalidOption.d.ts +2 -1
  19. package/dist/cjs/src/errors/MissingRequiredArgumentValue.d.ts +2 -1
  20. package/dist/cjs/src/errors/MissingRequiredOptionValue.d.ts +2 -1
  21. package/dist/cjs/src/index.d.ts +1 -0
  22. package/dist/cjs/src/index.js +17 -0
  23. package/dist/cjs/src/lib/types.d.ts +4 -2
  24. package/dist/cjs/src/options/HelpOption.d.ts +1 -1
  25. package/dist/esm/package-Drh2xcXq.js +33 -0
  26. package/dist/esm/src/Cli.d.ts +10 -11
  27. package/dist/esm/src/Command.d.ts +11 -18
  28. package/dist/esm/src/CommandIO.d.ts +5 -2
  29. package/dist/esm/src/CommandParser.d.ts +13 -5
  30. package/dist/esm/src/CommandRegistry.d.ts +13 -6
  31. package/dist/esm/src/CommandSignatureParser.d.ts +5 -4
  32. package/dist/esm/src/CommandWithSignature.d.ts +3 -3
  33. package/dist/esm/src/ExceptionHandler.d.ts +1 -1
  34. package/dist/esm/src/Logger.d.ts +1 -1
  35. package/dist/esm/src/StringSimilarity.d.ts +26 -0
  36. package/dist/esm/src/commands/HelpCommand.d.ts +1 -1
  37. package/dist/esm/src/contracts/CommandOption.d.ts +3 -3
  38. package/dist/esm/src/errors/BadCommandOption.d.ts +2 -1
  39. package/dist/esm/src/errors/BadCommandParameter.d.ts +2 -1
  40. package/dist/esm/src/errors/CommandNotFoundError.d.ts +2 -1
  41. package/dist/esm/src/errors/InvalidOption.d.ts +2 -1
  42. package/dist/esm/src/errors/MissingRequiredArgumentValue.d.ts +2 -1
  43. package/dist/esm/src/errors/MissingRequiredOptionValue.d.ts +2 -1
  44. package/dist/esm/src/index.d.ts +1 -0
  45. package/dist/esm/src/index.js +1029 -0
  46. package/dist/esm/src/lib/types.d.ts +4 -2
  47. package/dist/esm/src/options/HelpOption.d.ts +1 -1
  48. package/package.json +28 -21
  49. package/dist/cjs/index.d.ts +0 -2
  50. package/dist/cjs/index.js +0 -21
  51. package/dist/cjs/package-BpbpSdBI.cjs +0 -1
  52. package/dist/cjs/src/testFixtures.d.ts +0 -11
  53. package/dist/esm/index.d.ts +0 -2
  54. package/dist/esm/index.js +0 -1247
  55. package/dist/esm/package-CjHUTRfV.js +0 -31
  56. package/dist/esm/src/testFixtures.d.ts +0 -11
package/dist/esm/index.js DELETED
@@ -1,1247 +0,0 @@
1
- import X from "minimist";
2
- import b from "prompts";
3
- import * as Z from "node:fs";
4
- import I from "path";
5
- import * as ee from "string-similarity";
6
- class w extends Error {
7
- }
8
- const E = 10, L = (r = 0) => (e) => `\x1B[${e + r}m`, M = (r = 0) => (e) => `\x1B[${38 + r};5;${e}m`, D = (r = 0) => (e, t, n) => `\x1B[${38 + r};2;${e};${t};${n}m`, c = {
9
- modifier: {
10
- reset: [0, 0],
11
- // 21 isn't widely supported and 22 does the same thing
12
- bold: [1, 22],
13
- dim: [2, 22],
14
- italic: [3, 23],
15
- underline: [4, 24],
16
- overline: [53, 55],
17
- inverse: [7, 27],
18
- hidden: [8, 28],
19
- strikethrough: [9, 29]
20
- },
21
- color: {
22
- black: [30, 39],
23
- red: [31, 39],
24
- green: [32, 39],
25
- yellow: [33, 39],
26
- blue: [34, 39],
27
- magenta: [35, 39],
28
- cyan: [36, 39],
29
- white: [37, 39],
30
- // Bright color
31
- blackBright: [90, 39],
32
- gray: [90, 39],
33
- // Alias of `blackBright`
34
- grey: [90, 39],
35
- // Alias of `blackBright`
36
- redBright: [91, 39],
37
- greenBright: [92, 39],
38
- yellowBright: [93, 39],
39
- blueBright: [94, 39],
40
- magentaBright: [95, 39],
41
- cyanBright: [96, 39],
42
- whiteBright: [97, 39]
43
- },
44
- bgColor: {
45
- bgBlack: [40, 49],
46
- bgRed: [41, 49],
47
- bgGreen: [42, 49],
48
- bgYellow: [43, 49],
49
- bgBlue: [44, 49],
50
- bgMagenta: [45, 49],
51
- bgCyan: [46, 49],
52
- bgWhite: [47, 49],
53
- // Bright color
54
- bgBlackBright: [100, 49],
55
- bgGray: [100, 49],
56
- // Alias of `bgBlackBright`
57
- bgGrey: [100, 49],
58
- // Alias of `bgBlackBright`
59
- bgRedBright: [101, 49],
60
- bgGreenBright: [102, 49],
61
- bgYellowBright: [103, 49],
62
- bgBlueBright: [104, 49],
63
- bgMagentaBright: [105, 49],
64
- bgCyanBright: [106, 49],
65
- bgWhiteBright: [107, 49]
66
- }
67
- };
68
- Object.keys(c.modifier);
69
- const te = Object.keys(c.color), ne = Object.keys(c.bgColor);
70
- [...te, ...ne];
71
- function re() {
72
- const r = /* @__PURE__ */ new Map();
73
- for (const [e, t] of Object.entries(c)) {
74
- for (const [n, s] of Object.entries(t))
75
- c[n] = {
76
- open: `\x1B[${s[0]}m`,
77
- close: `\x1B[${s[1]}m`
78
- }, t[n] = c[n], r.set(s[0], s[1]);
79
- Object.defineProperty(c, e, {
80
- value: t,
81
- enumerable: !1
82
- });
83
- }
84
- return Object.defineProperty(c, "codes", {
85
- value: r,
86
- enumerable: !1
87
- }), c.color.close = "\x1B[39m", c.bgColor.close = "\x1B[49m", c.color.ansi = L(), c.color.ansi256 = M(), c.color.ansi16m = D(), c.bgColor.ansi = L(E), c.bgColor.ansi256 = M(E), c.bgColor.ansi16m = D(E), Object.defineProperties(c, {
88
- rgbToAnsi256: {
89
- value(e, t, n) {
90
- return e === t && t === n ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(t / 255 * 5) + Math.round(n / 255 * 5);
91
- },
92
- enumerable: !1
93
- },
94
- hexToRgb: {
95
- value(e) {
96
- const t = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
97
- if (!t)
98
- return [0, 0, 0];
99
- let [n] = t;
100
- n.length === 3 && (n = [...n].map((i) => i + i).join(""));
101
- const s = Number.parseInt(n, 16);
102
- return [
103
- /* eslint-disable no-bitwise */
104
- s >> 16 & 255,
105
- s >> 8 & 255,
106
- s & 255
107
- /* eslint-enable no-bitwise */
108
- ];
109
- },
110
- enumerable: !1
111
- },
112
- hexToAnsi256: {
113
- value: (e) => c.rgbToAnsi256(...c.hexToRgb(e)),
114
- enumerable: !1
115
- },
116
- ansi256ToAnsi: {
117
- value(e) {
118
- if (e < 8)
119
- return 30 + e;
120
- if (e < 16)
121
- return 90 + (e - 8);
122
- let t, n, s;
123
- if (e >= 232)
124
- t = ((e - 232) * 10 + 8) / 255, n = t, s = t;
125
- else {
126
- e -= 16;
127
- const u = e % 36;
128
- t = Math.floor(e / 36) / 5, n = Math.floor(u / 6) / 5, s = u % 6 / 5;
129
- }
130
- const i = Math.max(t, n, s) * 2;
131
- if (i === 0)
132
- return 30;
133
- let o = 30 + (Math.round(s) << 2 | Math.round(n) << 1 | Math.round(t));
134
- return i === 2 && (o += 60), o;
135
- },
136
- enumerable: !1
137
- },
138
- rgbToAnsi: {
139
- value: (e, t, n) => c.ansi256ToAnsi(c.rgbToAnsi256(e, t, n)),
140
- enumerable: !1
141
- },
142
- hexToAnsi: {
143
- value: (e) => c.ansi256ToAnsi(c.hexToAnsi256(e)),
144
- enumerable: !1
145
- }
146
- }), c;
147
- }
148
- const f = re(), q = (() => {
149
- if (!("navigator" in globalThis))
150
- return 0;
151
- if (globalThis.navigator.userAgentData) {
152
- const r = navigator.userAgentData.brands.find(({ brand: e }) => e === "Chromium");
153
- if (r && r.version > 93)
154
- return 3;
155
- }
156
- return /\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent) ? 1 : 0;
157
- })(), V = q !== 0 && {
158
- level: q
159
- }, se = {
160
- stdout: V,
161
- stderr: V
162
- };
163
- function ie(r, e, t) {
164
- let n = r.indexOf(e);
165
- if (n === -1)
166
- return r;
167
- const s = e.length;
168
- let i = 0, o = "";
169
- do
170
- o += r.slice(i, n) + e + t, i = n + s, n = r.indexOf(e, i);
171
- while (n !== -1);
172
- return o += r.slice(i), o;
173
- }
174
- function oe(r, e, t, n) {
175
- let s = 0, i = "";
176
- do {
177
- const o = r[n - 1] === "\r";
178
- i += r.slice(s, o ? n - 1 : n) + e + (o ? `\r
179
- ` : `
180
- `) + t, s = n + 1, n = r.indexOf(`
181
- `, s);
182
- } while (n !== -1);
183
- return i += r.slice(s), i;
184
- }
185
- const { stdout: H, stderr: W } = se, S = Symbol("GENERATOR"), A = Symbol("STYLER"), O = Symbol("IS_EMPTY"), G = [
186
- "ansi",
187
- "ansi",
188
- "ansi256",
189
- "ansi16m"
190
- ], C = /* @__PURE__ */ Object.create(null), ae = (r, e = {}) => {
191
- if (e.level && !(Number.isInteger(e.level) && e.level >= 0 && e.level <= 3))
192
- throw new Error("The `level` option should be an integer from 0 to 3");
193
- const t = H ? H.level : 0;
194
- r.level = e.level === void 0 ? t : e.level;
195
- }, le = (r) => {
196
- const e = (...t) => t.join(" ");
197
- return ae(e, r), Object.setPrototypeOf(e, R.prototype), e;
198
- };
199
- function R(r) {
200
- return le(r);
201
- }
202
- Object.setPrototypeOf(R.prototype, Function.prototype);
203
- for (const [r, e] of Object.entries(f))
204
- C[r] = {
205
- get() {
206
- const t = x(this, B(e.open, e.close, this[A]), this[O]);
207
- return Object.defineProperty(this, r, { value: t }), t;
208
- }
209
- };
210
- C.visible = {
211
- get() {
212
- const r = x(this, this[A], !0);
213
- return Object.defineProperty(this, "visible", { value: r }), r;
214
- }
215
- };
216
- const T = (r, e, t, ...n) => r === "rgb" ? e === "ansi16m" ? f[t].ansi16m(...n) : e === "ansi256" ? f[t].ansi256(f.rgbToAnsi256(...n)) : f[t].ansi(f.rgbToAnsi(...n)) : r === "hex" ? T("rgb", e, t, ...f.hexToRgb(...n)) : f[t][r](...n), ue = ["rgb", "hex", "ansi256"];
217
- for (const r of ue) {
218
- C[r] = {
219
- get() {
220
- const { level: t } = this;
221
- return function(...n) {
222
- const s = B(T(r, G[t], "color", ...n), f.color.close, this[A]);
223
- return x(this, s, this[O]);
224
- };
225
- }
226
- };
227
- const e = "bg" + r[0].toUpperCase() + r.slice(1);
228
- C[e] = {
229
- get() {
230
- const { level: t } = this;
231
- return function(...n) {
232
- const s = B(T(r, G[t], "bgColor", ...n), f.bgColor.close, this[A]);
233
- return x(this, s, this[O]);
234
- };
235
- }
236
- };
237
- }
238
- const me = Object.defineProperties(() => {
239
- }, {
240
- ...C,
241
- level: {
242
- enumerable: !0,
243
- get() {
244
- return this[S].level;
245
- },
246
- set(r) {
247
- this[S].level = r;
248
- }
249
- }
250
- }), B = (r, e, t) => {
251
- let n, s;
252
- return t === void 0 ? (n = r, s = e) : (n = t.openAll + r, s = e + t.closeAll), {
253
- open: r,
254
- close: e,
255
- openAll: n,
256
- closeAll: s,
257
- parent: t
258
- };
259
- }, x = (r, e, t) => {
260
- const n = (...s) => de(n, s.length === 1 ? "" + s[0] : s.join(" "));
261
- return Object.setPrototypeOf(n, me), n[S] = r, n[A] = e, n[O] = t, n;
262
- }, de = (r, e) => {
263
- if (r.level <= 0 || !e)
264
- return r[O] ? "" : e;
265
- let t = r[A];
266
- if (t === void 0)
267
- return e;
268
- const { openAll: n, closeAll: s } = t;
269
- if (e.includes("\x1B"))
270
- for (; t !== void 0; )
271
- e = ie(e, t.close, t.open), t = t.parent;
272
- const i = e.indexOf(`
273
- `);
274
- return i !== -1 && (e = oe(e, s, n, i)), n + e + s;
275
- };
276
- Object.defineProperties(R.prototype, C);
277
- const a = R();
278
- R({ level: W ? W.level : 0 });
279
- class Ae extends w {
280
- constructor(e) {
281
- let t = `Argument "${e.param}" value is invalid.`;
282
- e.reason ? t += ` Reason: ${e.reason}` : t += ` Value: "${e.value}"`, super(t), this.param = e;
283
- }
284
- pretty(e) {
285
- e.log(` ${a.white.bgRed(" ERROR ")} Argument ${a.bold.yellow(this.param.param)} value is invalid. `), (this.param.value || this.param.reason) && e.log(""), this.param.value && e.log(` ${a.blue("Value")}: ${this.param.value}`), this.param.reason && e.log(` ${a.yellow("Reason")}: ${this.param.reason}`);
286
- }
287
- }
288
- class N extends w {
289
- constructor(e) {
290
- let t = `Option "${e.option}" value is invalid.`;
291
- e.reason ? t += ` Reason: ${e.reason}` : t += ` Value: "${e.value}"`, super(t), this.param = e;
292
- }
293
- pretty(e) {
294
- e.log(` ${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.param.option)} value is invalid. `), (this.param.value || this.param.reason) && e.log(""), this.param.value && e.log(` ${a.blue("Value")}: ${this.param.value}`), this.param.reason && e.log(` ${a.yellow("Reason")}: ${this.param.reason}`);
295
- }
296
- }
297
- function _(r) {
298
- if (r === "string" || r === "secret" || r === "number") return null;
299
- if (r === "boolean") return !1;
300
- if (Array.isArray(r) && r.length === 1) {
301
- if (r[0] === "string") return [];
302
- if (r[0] === "number") return [];
303
- }
304
- throw new Error("Invalid option type: " + r);
305
- }
306
- function U(r) {
307
- return !Array.isArray(r) && typeof r == "object" && r.type ? r.default !== void 0 ? r.default : _(r.type) : _(r);
308
- }
309
- function y(r) {
310
- return typeof r == "string" || Array.isArray(r) ? {
311
- type: r,
312
- default: U(r),
313
- description: "",
314
- alias: [],
315
- required: !1,
316
- variadic: !1
317
- } : {
318
- type: r.type,
319
- default: r.default ?? U(r.type),
320
- description: r.description ?? "",
321
- alias: r.alias ? Array.isArray(r.alias) ? r.alias : [r.alias] : [],
322
- required: r.required ?? !1,
323
- variadic: r.variadic ?? !1
324
- };
325
- }
326
- class k extends w {
327
- constructor(e, t = {}) {
328
- super(`Invalid option ${e} in not recognized`), this.option = e, this.optionsSchema = t;
329
- }
330
- pretty(e) {
331
- const t = Object.entries(this.optionsSchema);
332
- if (t.length > 0) {
333
- e.log(`
334
- ${a.yellow("Available options")}:`);
335
- for (const [n, s] of t) {
336
- const i = y(s), o = typeof i.alias == "string" ? [i.alias] : i.alias, u = Array.isArray(i.type) ? `[${i.type[0]}]` : i.type, m = `--${n}${o.length > 0 ? o.map((l) => `, -${l}`).join("") : ""}`, h = " ".repeat(30 - m.length);
337
- e.log(` ${a.green(m)} ${h} ${i.description || "\b"} ${a.white(`(${u})`)}`);
338
- }
339
- e.log("");
340
- }
341
- e.log(`${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.option)} is not recognized.`);
342
- }
343
- }
344
- class ce extends w {
345
- constructor(e) {
346
- super(`Command "${e}" not found.`), this.command = e;
347
- }
348
- pretty(e) {
349
- e.log(`${a.bgRed(" ERROR ")} Command ${a.yellow(this.command)} not found.`);
350
- }
351
- }
352
- class Y extends w {
353
- constructor(e) {
354
- super(`Argument "${e}" is required.`), this.argument = e;
355
- }
356
- pretty(e) {
357
- e.log(`${a.white.bgRed(" ERROR ")} Argument ${a.bold.yellow(this.argument)} is required.`);
358
- }
359
- }
360
- class he extends w {
361
- constructor(e) {
362
- super(`Argument "${e}" is required.`), this.option = e;
363
- }
364
- pretty(e) {
365
- e.log(`${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.option)} is required.`);
366
- }
367
- }
368
- function $(r, e, t, n) {
369
- if (r == null)
370
- return n ?? null;
371
- if (e === "string")
372
- return String(r);
373
- if (e === "number") {
374
- const s = Number(r);
375
- if (isNaN(s))
376
- throw new N({
377
- option: t,
378
- reason: `Expected a number, got "${r}"`
379
- });
380
- return s;
381
- }
382
- if (e === "boolean")
383
- return typeof r == "boolean" ? r : r === "true" || r === "1" ? !0 : r === "false" || r === "0" ? !1 : !!r;
384
- if (Array.isArray(e)) {
385
- const s = e[0], i = Array.isArray(r) ? r : [r];
386
- if (s === "string")
387
- return i.map((o) => String(o));
388
- if (s === "number")
389
- return i.map((o) => {
390
- const u = Number(o);
391
- if (isNaN(u))
392
- throw new N({
393
- option: t,
394
- reason: `Expected array of numbers, got "${o}" in array`
395
- });
396
- return u;
397
- });
398
- }
399
- return r;
400
- }
401
- class z {
402
- options;
403
- parsedOptions = null;
404
- arguments;
405
- parsedArguments = null;
406
- io;
407
- shouldPromptForMissingOptions = !0;
408
- constructor(e) {
409
- this.options = e.options, this.arguments = e.arguments, this.io = e.io;
410
- }
411
- // === PUBLIC METHODS ===
412
- /**
413
- * Parses raw command-line arguments into structured options and arguments
414
- * @param args - Raw command line arguments (typically from process.argv.slice(2))
415
- * @returns Object containing parsed options and arguments
416
- * @throws {InvalidOption} If an unknown option is provided
417
- * @throws {BadCommandOption} If a value cannot be converted to the expected type
418
- */
419
- init(e) {
420
- const { _: t, ...n } = X(e);
421
- return this.validateUnknownOptions(n), this.parsedOptions = this.handleOptions(n), this.parsedArguments = this.handleArguments(t), {
422
- options: this.parsedOptions,
423
- arguments: this.parsedArguments
424
- };
425
- }
426
- /**
427
- * Validates the parsed options and arguments
428
- * @throws {Error} If validation fails
429
- */
430
- async validate() {
431
- for (const e in this.options)
432
- if (y(this.options[e]).required && (this.parsedOptions?.[e] === void 0 || this.parsedOptions?.[e] === null))
433
- throw new he(e);
434
- for (const e in this.arguments) {
435
- const t = y(this.arguments[e]), n = this.parsedArguments?.[e];
436
- if (t.required && n == null) {
437
- if (this.shouldPromptForMissingOptions) {
438
- const s = await this.promptForArgument(e, t);
439
- if (s && this.parsedArguments) {
440
- this.parsedArguments[e] = $(s, t.type, e);
441
- continue;
442
- }
443
- }
444
- throw new Y(e);
445
- }
446
- if (t.required && t.variadic && Array.isArray(n) && n.length === 0) {
447
- if (this.shouldPromptForMissingOptions) {
448
- const s = await this.promptForArgument(e, t);
449
- if (s && this.parsedArguments) {
450
- this.parsedArguments[e] = $(s, t.type, e);
451
- continue;
452
- }
453
- }
454
- throw new Y(e);
455
- }
456
- }
457
- }
458
- /**
459
- * Retrieves a parsed option value by name
460
- * @param name - The option name
461
- * @returns The typed option value
462
- * @throws {Error} If init() has not been called yet
463
- */
464
- option(e) {
465
- if (!this.parsedOptions)
466
- throw new Error("Options have not been parsed yet. Call init() first.");
467
- return this.parsedOptions[e];
468
- }
469
- setOption(e, t) {
470
- if (!this.parsedOptions)
471
- throw new Error("Options have not been parsed yet. Call init() first.");
472
- if (!(e in this.options))
473
- throw new k(e, this.options);
474
- this.parsedOptions[e] = t;
475
- }
476
- /**
477
- * Retrieves a parsed argument value by name
478
- * @param name - The argument name
479
- * @returns The typed argument value
480
- * @throws {Error} If init() has not been called yet
481
- */
482
- argument(e) {
483
- if (!this.parsedArguments)
484
- throw new Error("Arguments have not been parsed yet. Call init() first.");
485
- return this.parsedArguments[e];
486
- }
487
- setArgument(e, t) {
488
- if (!this.parsedArguments)
489
- throw new Error("Arguments have not been parsed yet. Call init() first.");
490
- if (!(e in this.arguments))
491
- throw new k(e, this.arguments);
492
- this.parsedArguments[e] = t;
493
- }
494
- // === PRIVATE HELPERS ===
495
- /**
496
- * Validates that all provided options are recognized
497
- * @throws {InvalidOption} If an unknown option is found
498
- */
499
- validateUnknownOptions(e) {
500
- const t = /* @__PURE__ */ new Set();
501
- for (const n in this.options) {
502
- t.add(n);
503
- const s = y(this.options[n]);
504
- for (const i of s.alias)
505
- t.add(i);
506
- }
507
- for (const n in e)
508
- if (!t.has(n))
509
- throw new k(n, this.options);
510
- }
511
- /**
512
- * Processes named options from minimist output
513
- */
514
- handleOptions(e) {
515
- const t = {};
516
- for (const n in this.options) {
517
- const s = y(this.options[n]);
518
- t[n] = this.resolveOptionValue(
519
- n,
520
- s,
521
- e
522
- );
523
- }
524
- return t;
525
- }
526
- /**
527
- * Processes positional arguments from minimist output
528
- */
529
- handleArguments(e) {
530
- const t = {}, n = [...e];
531
- for (const s in this.arguments) {
532
- const i = y(this.arguments[s]);
533
- if (i.variadic) {
534
- t[s] = this.handleVariadicArgument(s, i, n);
535
- continue;
536
- }
537
- t[s] = this.resolveArgumentValue(s, i, n.shift());
538
- }
539
- return t;
540
- }
541
- /**
542
- * Handles variadic arguments that consume all remaining positional values
543
- */
544
- handleVariadicArgument(e, t, n) {
545
- return n.length ? $(n, t.type, e, t.default) : t.default;
546
- }
547
- /**
548
- * Resolves a single positional argument value with defaults and type conversion
549
- * Note: Does not validate required arguments - validation happens in subclass validate() methods
550
- */
551
- resolveArgumentValue(e, t, n) {
552
- return n === void 0 ? t.default : $(n, t.type, e, t.default);
553
- }
554
- /**
555
- * Resolves an option value from the parsed option values object
556
- * Handles alias resolution, defaults, and type conversion
557
- */
558
- resolveOptionValue(e, t, n) {
559
- let s;
560
- const i = [e, ...t.alias];
561
- for (const o of i)
562
- if (o in n) {
563
- s = n[o];
564
- break;
565
- }
566
- if (s === void 0) {
567
- if (t.required)
568
- throw new N({
569
- option: e,
570
- reason: "Required option is missing"
571
- });
572
- return t.default;
573
- }
574
- return $(s, t.type, e, t.default);
575
- }
576
- optionDefinitions() {
577
- const e = {};
578
- for (const t in this.options)
579
- e[t] = y(this.options[t]);
580
- return e;
581
- }
582
- argumentDefinitions() {
583
- const e = {};
584
- for (const t in this.arguments)
585
- e[t] = y(this.arguments[t]);
586
- return e;
587
- }
588
- availableOptions() {
589
- return Object.keys(this.options);
590
- }
591
- availableArguments() {
592
- return Object.keys(this.arguments);
593
- }
594
- /**
595
- * Disables prompting for missing argument values
596
- * Useful for non-interactive environments
597
- */
598
- disablePrompting() {
599
- return this.shouldPromptForMissingOptions = !1, this;
600
- }
601
- /**
602
- * Prompts the user to provide a missing argument value via CommandIO
603
- * Used by validate() when shouldPromptForMissingArgs is enabled
604
- * @param argumentName - The name of the missing argument
605
- * @param argDef - The argument's definition for type and description
606
- * @returns The user-provided value, or null if none given
607
- */
608
- async promptForArgument(e, t) {
609
- if (!Array.isArray(t.type) && !["string", "number", "secret"].includes(t.type))
610
- return null;
611
- let n = `${a.yellow.bold(e)} is required`;
612
- return t.description && (n += `: ${a.gray(`(${t.description})`)}`), n += `
613
- `, Array.isArray(t.type) ? (n += `Please provide one or more values, separated by commas:
614
- `, await this.io.askForList(
615
- n,
616
- void 0,
617
- {
618
- validate: (s) => s.length ? !0 : "Please enter at least one value"
619
- }
620
- )) : await this.io.askForInput(
621
- n,
622
- void 0,
623
- {
624
- type: t.type === "number" ? "number" : t.type === "secret" ? "password" : "text",
625
- validate: (s) => {
626
- if (t.type === "number") {
627
- const i = Number(s);
628
- if (isNaN(i))
629
- return "Please enter a valid number";
630
- } else if (t.type === "string" && (typeof s != "string" || !s.length))
631
- return "Please enter a valid text";
632
- return !0;
633
- }
634
- }
635
- );
636
- }
637
- }
638
- function j(r) {
639
- return new Array(r + 5).join(" ");
640
- }
641
- class pe {
642
- type = "boolean";
643
- option = "help";
644
- alias = ["h"];
645
- default = !1;
646
- description = `Display help for the given command. When no command is given display help for the ${a.green("list")} command`;
647
- async handler() {
648
- const e = this.parser.argumentDefinitions(), t = this.parser.optionDefinitions(), n = Object.entries(e), s = Object.entries(t), i = s.map(([l, d]) => {
649
- const p = Array.isArray(d.alias) ? d.alias : d.alias ? [d.alias] : [];
650
- return {
651
- name: l,
652
- ...d,
653
- optionWithAlias: `--${l}${p.map((g) => `, -${g}`).join("")}`
654
- };
655
- }), o = n.filter(([, l]) => l.required);
656
- this.io.log(a.yellow("Description:")), this.io.log(` ${this.description}
657
- `), this.io.log(a.yellow("Usage:")), this.io.log(` ${this.command} ${o.length > 0 ? o.map(([l]) => `<${l}>`).join(" ") : "\b"} [options]`);
658
- const u = Math.max(...i.map((l) => l.optionWithAlias.length), 0), m = Math.max(...n.map(([l]) => l.length), 0), h = m > u ? m : u;
659
- if (n.length > 0) {
660
- this.io.log(`
661
- ${a.yellow("Arguments")}:`);
662
- for (const [l, d] of n) {
663
- const p = j(h - l.length);
664
- let g = ` ${a.green(l)} ${p} ${d.description ?? "\b"}`;
665
- if (d.default !== void 0 && !d.required) {
666
- const Q = (Array.isArray(d.type) ? `[${d.type[0]}]` : d.type) === "array" || Array.isArray(d.type) ? JSON.stringify(d.default) : d.default;
667
- g += ` ${a.yellow(`[default: ${Q}]`)}`;
668
- }
669
- d.variadic && (g += ` ${a.white("(variadic)")}`), this.io.log(g);
670
- }
671
- }
672
- if (s.length > 0) {
673
- this.io.log(`
674
- ${a.yellow("Options")}:`);
675
- for (const l of i) {
676
- const d = j(h - l.optionWithAlias.length);
677
- let p = `${a.green(l.optionWithAlias)} ${d} ${l.description ?? "\b"}`;
678
- if (l.type) {
679
- const g = Array.isArray(l.type) ? `[${l.type[0]}]` : l.type;
680
- p += ` ${a.white(`(${g})`)}`;
681
- }
682
- if (l.default !== void 0 && !l.required) {
683
- const P = (Array.isArray(l.type) ? `[${l.type[0]}]` : l.type) === "array" || Array.isArray(l.type) ? JSON.stringify(l.default) : l.default;
684
- p += ` ${a.yellow(`[default: ${P}]`)}`;
685
- }
686
- this.io.log(p);
687
- }
688
- }
689
- if (this.commandsExamples.length > 0) {
690
- this.io.log(`
691
- ${a.yellow("Examples")}:`);
692
- let l = process.argv[0].split("/").pop();
693
- l === "node" && (l += " " + process.argv[1].split("/").pop());
694
- for (const [d, p] of this.commandsExamples.entries())
695
- d > 0 && this.io.log(""), this.io.log(` ${p.description}
696
- `), this.io.log(` ${a.green(`${l} ${p.command}`)}`);
697
- }
698
- return -1;
699
- }
700
- }
701
- class J {
702
- logger;
703
- constructor(e) {
704
- this.logger = e;
705
- }
706
- /**
707
- * Logger methods
708
- */
709
- log(...e) {
710
- this.logger.log(...e);
711
- }
712
- info(...e) {
713
- this.logger.info(...e);
714
- }
715
- warn(...e) {
716
- this.logger.warn(...e);
717
- }
718
- error(...e) {
719
- this.logger.error(...e);
720
- }
721
- debug(...e) {
722
- this.logger.debug(...e);
723
- }
724
- /**
725
- * Prompt utils
726
- */
727
- async askForConfirmation(e = "Do you want to continue?", t) {
728
- return (await b({
729
- type: "confirm",
730
- name: "value",
731
- message: e,
732
- initial: t ?? !1
733
- })).value;
734
- }
735
- async askForInput(e, t, n) {
736
- return (await b({
737
- type: "text",
738
- name: "value",
739
- message: e,
740
- initial: t,
741
- ...n
742
- }))?.value ?? null;
743
- }
744
- async askForDate(e, t, n) {
745
- return (await b({
746
- type: "date",
747
- name: "value",
748
- message: e,
749
- initial: t,
750
- ...n
751
- }))?.value ?? null;
752
- }
753
- async askForList(e, t, n) {
754
- return (await b({
755
- type: "list",
756
- name: "value",
757
- message: e,
758
- initial: t,
759
- ...n
760
- }))?.value ?? null;
761
- }
762
- async askForToggle(e, t, n) {
763
- return (await b({
764
- type: "toggle",
765
- name: "value",
766
- message: e,
767
- initial: t,
768
- ...n
769
- }))?.value ?? null;
770
- }
771
- async askForSelect(e, t, n) {
772
- if (t.length === 0)
773
- throw new Error("No options provided");
774
- const s = [];
775
- for (const o of t)
776
- typeof o == "string" ? s.push({ title: o, value: o }) : s.push(o);
777
- return (await b({
778
- type: "select",
779
- name: "value",
780
- message: e,
781
- choices: s,
782
- ...n
783
- }))?.value ?? null;
784
- }
785
- newLoader(e = "", t = ["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"], n = 100) {
786
- let s = e, i = null, o = 0;
787
- const u = setInterval(function() {
788
- i && (process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(i.length + 5) + "\r")), i = null), process.stdout.write(new TextEncoder().encode("\r" + t[o++] + " " + s)), o = o % t.length;
789
- }, n), m = () => {
790
- clearInterval(u), process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(s.length + 5) + "\r"));
791
- };
792
- return {
793
- [Symbol.dispose]: m,
794
- [Symbol.asyncDispose]: m,
795
- updateText: (h) => {
796
- i = s, s = h;
797
- },
798
- stop: m
799
- };
800
- }
801
- }
802
- class F {
803
- _command;
804
- description = "";
805
- group;
806
- commandsExamples = [];
807
- get command() {
808
- return this._command;
809
- }
810
- ctx;
811
- io;
812
- logger;
813
- parser;
814
- disablePromptingFlag = !1;
815
- _preHandler;
816
- _handler;
817
- tmp;
818
- defaultOptions() {
819
- return [new pe()];
820
- }
821
- newCommandParser(e) {
822
- return new z({
823
- io: e.io,
824
- options: e.options,
825
- arguments: e.arguments
826
- });
827
- }
828
- newCommandIO(e) {
829
- return new J(e.logger);
830
- }
831
- constructor(e, t) {
832
- this._command = e, this.description = t?.description ?? "", this.group = t?.group, this.tmp = {
833
- options: t?.options ?? {},
834
- arguments: t?.arguments ?? {}
835
- };
836
- const n = this.defaultOptions();
837
- if (n.length > 0)
838
- for (const s of n)
839
- this.tmp.options[s.option] = s;
840
- }
841
- disablePrompting() {
842
- return this.disablePromptingFlag = !0, this;
843
- }
844
- preHandler(e) {
845
- return this._preHandler = e, this;
846
- }
847
- handler(e) {
848
- return this._handler = e, this;
849
- }
850
- options(e) {
851
- return this.tmp = {
852
- options: {
853
- ...this.tmp?.options ?? {},
854
- ...e
855
- },
856
- arguments: this.tmp?.arguments ?? {}
857
- }, this;
858
- }
859
- arguments(e) {
860
- return this.tmp = {
861
- options: this.tmp?.options ?? {},
862
- arguments: {
863
- ...this.tmp?.arguments ?? {},
864
- ...e
865
- }
866
- }, this;
867
- }
868
- async run(e) {
869
- if (!this._handler && !this.handle)
870
- throw new Error(`No handler defined for command ${this.command || "(unknown)"}`);
871
- let t;
872
- if (this.ctx = e.ctx, this.logger = e.logger, this.io = this.newCommandIO({
873
- logger: e.logger
874
- }), e && "args" in e) {
875
- const i = this.tmp?.options ?? {};
876
- for (const o of this.defaultOptions())
877
- o.option in i || (i[o.option] = o);
878
- this.parser = this.newCommandParser({
879
- io: this.io,
880
- options: i,
881
- arguments: this.tmp?.arguments ?? {}
882
- }), t = this.parser.init(e.args);
883
- for (const o of this.defaultOptions())
884
- if (t.options[o.option] === !0) {
885
- const u = await o.handler.call(this);
886
- if (u && u !== 0)
887
- return u;
888
- }
889
- this.disablePromptingFlag && this.parser.disablePrompting(), await this.parser.validate();
890
- } else
891
- t = {
892
- options: e.options,
893
- arguments: e.arguments
894
- };
895
- const n = this.preHandle ? await this.preHandle() : null;
896
- if (n && n !== 0)
897
- return n;
898
- if (!this._handler && this.handle)
899
- this._handler = this.handle.bind(this);
900
- else if (!this._handler)
901
- throw new Error(`No handler defined for command ${this.command || "(unknown)"}`);
902
- return await this._handler(e.ctx, t) ?? 0;
903
- }
904
- }
905
- class v extends z {
906
- command;
907
- constructor(e) {
908
- const t = v.parseSignature(
909
- e.signature,
910
- e.helperDefinitions,
911
- e.defaultOptions
912
- );
913
- super({ io: e.io, options: t.options, arguments: t.arguments }), this.command = t.command;
914
- }
915
- /**
916
- * Parses command signature string into command name and parameter schemas
917
- * Example: "migrate {name} {--force}" -> { command: "migrate", arguments: {name: ...}, options: {force: ...} }
918
- */
919
- static parseSignature(e, t, n) {
920
- const [s, ...i] = e.split(/\{(.*?)\}/g).map((m) => m.trim()).filter(Boolean), o = {}, u = {};
921
- for (const m of i) {
922
- const { name: h, isOption: l, definition: d } = v.parseParamSignature(
923
- m,
924
- t
925
- );
926
- l ? o[h] = d : u[h] = d;
927
- }
928
- for (const m of n)
929
- o[m.option] = {
930
- type: m.type,
931
- required: m.required,
932
- alias: m.alias,
933
- variadic: m.variadic ?? !1,
934
- description: m.description,
935
- default: m.default ?? null
936
- };
937
- return { command: s, options: o, arguments: u };
938
- }
939
- /**
940
- * Parses a single parameter signature like "{name}" or "{--force}" or "{files*}"
941
- * Extracts name, type, default value, aliases, description, etc.
942
- *
943
- * Signature syntax:
944
- * - {arg} -> required string argument
945
- * - {arg?} -> optional argument
946
- * - {arg=default} -> argument with default value
947
- * - {arg*} -> variadic argument (array)
948
- * - {arg:desc} -> argument with description
949
- * - {--opt} -> boolean option
950
- * - {--opt=} -> string option
951
- * - {--opt|o} -> option with alias
952
- */
953
- static parseParamSignature(e, t) {
954
- let n = e, s = !1;
955
- const i = {
956
- required: !0,
957
- type: "string",
958
- description: void 0,
959
- default: null,
960
- variadic: !1
961
- };
962
- if (n.includes(":")) {
963
- const [o, u] = n.split(":");
964
- n = o.trim(), i.description = u.trim();
965
- }
966
- if (n.includes("=")) {
967
- const [o, u] = n.split("=");
968
- n = o.trim(), i.default = u.trim(), i.required = !1, i.default.length ? i.default === "true" ? (i.default = !0, i.type = "boolean") : i.default === "false" && (i.default = !1, i.type = "boolean") : i.default = null;
969
- } else n.startsWith("--") && (i.required = !1, i.default = !1, i.type = "boolean");
970
- if (n.includes("|")) {
971
- const [o, ...u] = n.split("|");
972
- n = o.trim(), i.alias = u.map((m) => m.trim());
973
- }
974
- return n.startsWith("--") && (s = !0, n = n.slice(2)), i.default === "*" && (i.default = [], i.type = ["string"]), n.endsWith("?") && (i.required = !1, n = n.slice(0, -1)), n.endsWith("*") && (i.type = ["string"], i.variadic = !0, i.default = [], n = n.slice(0, -1)), i.description = i.description ?? t[n] ?? t[`--${n}`], { name: n, isOption: s, definition: i };
975
- }
976
- }
977
- class Ce extends F {
978
- helperDefinitions = {};
979
- get command() {
980
- return this.parser ? this.parser.command : this.signature.split(" ")[0];
981
- }
982
- newCommandParser(e) {
983
- return new v({
984
- io: e.io,
985
- signature: this.signature,
986
- helperDefinitions: this.helperDefinitions,
987
- defaultOptions: this.defaultOptions()
988
- });
989
- }
990
- constructor() {
991
- super("");
992
- }
993
- option(e, t = null) {
994
- return this.parser instanceof v ? this.parser.option(e) ?? t : t;
995
- }
996
- argument(e, t = null) {
997
- return this.parser instanceof v ? this.parser.argument(e) ?? t : t;
998
- }
999
- // Prompt utils
1000
- async askForConfirmation(...e) {
1001
- return this.io.askForConfirmation(...e);
1002
- }
1003
- async askForInput(...e) {
1004
- return this.io.askForInput(...e);
1005
- }
1006
- async askForSelect(...e) {
1007
- return this.io.askForSelect(...e);
1008
- }
1009
- newLoader(...e) {
1010
- return this.io.newLoader(...e);
1011
- }
1012
- }
1013
- class K {
1014
- level;
1015
- constructor(e = {}) {
1016
- this.level = e.level ?? "info";
1017
- }
1018
- shouldLog(e) {
1019
- const t = ["debug", "info", "warn", "error"], n = t.indexOf(this.level);
1020
- return t.indexOf(e) >= n;
1021
- }
1022
- setLevel(e) {
1023
- this.level = e;
1024
- }
1025
- getLevel() {
1026
- return this.level;
1027
- }
1028
- log(...e) {
1029
- console.log(...e);
1030
- }
1031
- info(...e) {
1032
- this.shouldLog("info") && console.log(...e);
1033
- }
1034
- warn(...e) {
1035
- this.shouldLog("warn") && console.warn(...e);
1036
- }
1037
- error(...e) {
1038
- this.shouldLog("error") && console.error(...e);
1039
- }
1040
- debug(...e) {
1041
- this.shouldLog("debug") && console.log(...e);
1042
- }
1043
- }
1044
- class ge {
1045
- commands = {};
1046
- io;
1047
- logger;
1048
- get CommandIOClass() {
1049
- return J;
1050
- }
1051
- constructor(e) {
1052
- this.logger = e ?? new K(), this.io = new this.CommandIOClass(this.logger);
1053
- }
1054
- getAvailableCommands() {
1055
- return Object.keys(this.commands);
1056
- }
1057
- getCommands() {
1058
- return Object.values(this.commands);
1059
- }
1060
- importFile = async (e) => (await import(e)).default;
1061
- commandResolver = async (e) => {
1062
- let t = await this.importFile(e);
1063
- if (!t)
1064
- throw new Error(`The command at path ${e} does not have a default export.`);
1065
- return t?.default && (t = t.default), typeof t == "function" ? new t() : t instanceof F ? t : null;
1066
- };
1067
- withCommandResolver(e) {
1068
- return this.commandResolver = e, this;
1069
- }
1070
- withFileImporter(e) {
1071
- return this.importFile = e, this;
1072
- }
1073
- registerCommand(e, t = !1) {
1074
- const n = e.command;
1075
- if (!n)
1076
- throw new Error("Command signature is invalid, it must have a command name.");
1077
- if (!t && this.commands[n])
1078
- throw new Error(`Command ${n} already registered.`);
1079
- this.commands[n] = e;
1080
- }
1081
- async loadCommandsPath(e) {
1082
- for await (const t of this.listCommandsFiles(e))
1083
- try {
1084
- const n = await this.commandResolver(t);
1085
- n instanceof F && this.registerCommand(n);
1086
- } catch (n) {
1087
- throw new Error(`Command ${t} failed to load. ${n}`, {
1088
- cause: n
1089
- });
1090
- }
1091
- }
1092
- async runCommand(e, t, ...n) {
1093
- const s = typeof t == "string" ? this.commands[t] : t, i = typeof t == "string" ? t : s.command;
1094
- if (!s) {
1095
- const o = await this.suggestCommand(i);
1096
- return o ? await this.runCommand(e, o, ...n) : 1;
1097
- }
1098
- return await s.run({
1099
- ctx: e,
1100
- logger: this.logger,
1101
- args: n
1102
- }) ?? 0;
1103
- }
1104
- async suggestCommand(e) {
1105
- const t = this.getAvailableCommands(), { bestMatch: n, bestMatchIndex: s, ratings: i } = ee.findBestMatch(e, t), o = i.filter((u) => u.rating > 0.3).map((u) => u.target);
1106
- if (n.rating > 0 && o.length <= 1 || n.rating > 0.7 && o.length > 1) {
1107
- const u = t[s];
1108
- return await this.askRunSimilarCommand(e, u) ? u : null;
1109
- }
1110
- if (o.length) {
1111
- this.io.error(`${a.bgRed(" ERROR ")} Command ${a.yellow(e)} not found.
1112
- `);
1113
- const u = await this.io.askForSelect(
1114
- a.green("Did you mean to run one of these commands instead?"),
1115
- o
1116
- );
1117
- if (u)
1118
- return u;
1119
- }
1120
- throw new ce(e);
1121
- }
1122
- async askRunSimilarCommand(e, t) {
1123
- return this.io.error(`${a.bgRed(" ERROR ")} Command ${a.yellow(e)} not found.
1124
- `), this.io.askForConfirmation(`${a.green(`Do you want to run ${a.yellow(t)} instead?`)} `);
1125
- }
1126
- async *listCommandsFiles(e) {
1127
- const t = Z.readdirSync(e, { withFileTypes: !0 });
1128
- for (const n of t) {
1129
- const s = I.resolve(e, n.name);
1130
- if (n.isDirectory())
1131
- yield* this.listCommandsFiles(I.resolve(e, n.name));
1132
- else {
1133
- if (!s.endsWith(".ts") && !s.endsWith(".js") && !s.endsWith(".mjs") && !s.endsWith(".cjs"))
1134
- continue;
1135
- yield s;
1136
- }
1137
- }
1138
- }
1139
- }
1140
- class fe extends F {
1141
- constructor(e) {
1142
- super("help", {
1143
- description: a.bold("Show help information about the CLI and its commands")
1144
- }), this.opts = e;
1145
- }
1146
- async handle() {
1147
- const e = this.opts.commandRegistry.getCommands(), t = this.opts.cliName ?? "Bob CLI", n = this.opts.cliVersion ?? "0.0.0", s = (await import("./package-CjHUTRfV.js"))?.default?.version ?? "0.0.0";
1148
- this.io.log(`${t} ${a.green(n)} (core: ${a.yellow(s)})
1149
-
1150
- ${a.yellow("Usage")}:
1151
- command [options] [arguments]
1152
-
1153
- ${a.yellow("Available commands")}:
1154
- `);
1155
- const i = Math.max(...e.map((m) => m.command.length)) ?? 0, o = {};
1156
- for (const m of e) {
1157
- const h = m.group ?? m.command.split(":")[0];
1158
- o[h] || (o[h] = []), o[h].push(m);
1159
- }
1160
- const u = Object.entries(o).sort(([m], [h]) => m.toLowerCase().localeCompare(h.toLowerCase())).sort(([, m], [, h]) => m.length - h.length);
1161
- for (const [m, h] of u) {
1162
- const l = h.length > 1;
1163
- l && this.io.log(a.yellow(`${m}:`));
1164
- const d = h.sort((p, g) => p.command.toLowerCase().localeCompare(g.command.toLowerCase()));
1165
- for (const p of d) {
1166
- let g = j(i - p.command.length);
1167
- l && (g = g.slice(2)), this.io.log(`${l ? " " : ""}${a.green(p.command)} ${g} ${p.description}`);
1168
- }
1169
- }
1170
- }
1171
- }
1172
- class ye {
1173
- logger;
1174
- constructor(e) {
1175
- this.logger = e;
1176
- }
1177
- handle(e) {
1178
- if (e instanceof w)
1179
- return e.pretty(this.logger), -1;
1180
- throw e;
1181
- }
1182
- }
1183
- class $e {
1184
- ctx;
1185
- logger;
1186
- commandRegistry;
1187
- exceptionHandler;
1188
- helpCommand;
1189
- newCommandRegistry(e) {
1190
- return new ge(e.logger);
1191
- }
1192
- newHelpCommand(e) {
1193
- return new fe(e);
1194
- }
1195
- newExceptionHandler(e) {
1196
- return new ye(e.logger);
1197
- }
1198
- constructor(e = {}) {
1199
- this.ctx = e.ctx, this.logger = e.logger ?? new K(), this.commandRegistry = this.newCommandRegistry({
1200
- logger: this.logger
1201
- }), this.exceptionHandler = this.newExceptionHandler({
1202
- logger: this.logger
1203
- }), this.helpCommand = this.newHelpCommand({
1204
- cliName: e.name,
1205
- cliVersion: e.version,
1206
- commandRegistry: this.commandRegistry
1207
- });
1208
- }
1209
- withCommandResolver(e) {
1210
- return this.commandRegistry.withCommandResolver(e), this;
1211
- }
1212
- withFileImporter(e) {
1213
- return this.commandRegistry.withFileImporter(e), this;
1214
- }
1215
- async withCommands(...e) {
1216
- for (const t of e)
1217
- typeof t == "string" ? await this.commandRegistry.loadCommandsPath(t) : typeof t == "function" ? this.registerCommand(new t()) : this.registerCommand(t);
1218
- }
1219
- async runCommand(e, ...t) {
1220
- return e ? await this.commandRegistry.runCommand(this.ctx, e, ...t).catch(this.exceptionHandler.handle.bind(this.exceptionHandler)) : await this.runHelpCommand();
1221
- }
1222
- async runHelpCommand() {
1223
- return await this.runCommand(this.helpCommand);
1224
- }
1225
- registerCommand(e) {
1226
- this.commandRegistry.registerCommand(e);
1227
- }
1228
- }
1229
- export {
1230
- N as BadCommandOption,
1231
- Ae as BadCommandParameter,
1232
- w as BobError,
1233
- $e as Cli,
1234
- F as Command,
1235
- J as CommandIO,
1236
- ce as CommandNotFoundError,
1237
- z as CommandParser,
1238
- ge as CommandRegistry,
1239
- v as CommandSignatureParser,
1240
- Ce as CommandWithSignature,
1241
- ye as ExceptionHandler,
1242
- pe as HelpOption,
1243
- k as InvalidOption,
1244
- K as Logger,
1245
- Y as MissingRequiredArgumentValue,
1246
- he as MissingRequiredOptionValue
1247
- };