bob-core 2.0.0-beta.7 → 2.0.0-beta.8

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/esm/index.js CHANGED
@@ -3,25 +3,25 @@ import l from "chalk";
3
3
  import y from "prompts";
4
4
  import * as D from "node:fs";
5
5
  import R from "path";
6
- import * as P from "string-similarity";
6
+ import * as I from "string-similarity";
7
7
  class f extends Error {
8
8
  }
9
9
  class U extends f {
10
- constructor(e) {
11
- let t = `Argument "${e.param}" value is invalid.`;
12
- e.reason ? t += ` Reason: ${e.reason}` : t += ` Value: "${e.value}"`, super(t), this.param = e;
10
+ constructor(t) {
11
+ let e = `Argument "${t.param}" value is invalid.`;
12
+ t.reason ? e += ` Reason: ${t.reason}` : e += ` Value: "${t.value}"`, super(e), this.param = t;
13
13
  }
14
- pretty(e) {
15
- e.log(l` {white.bgRed ERROR } Argument {bold.yellow ${this.param.param}} value is invalid. `), (this.param.value || this.param.reason) && e.log(""), this.param.value && e.log(l` {blue Value}: ${this.param.value}`), this.param.reason && e.log(l` {yellow Reason}: ${this.param.reason}`);
14
+ pretty(t) {
15
+ t.log(l` {white.bgRed ERROR } Argument {bold.yellow ${this.param.param}} value is invalid. `), (this.param.value || this.param.reason) && t.log(""), this.param.value && t.log(l` {blue Value}: ${this.param.value}`), this.param.reason && t.log(l` {yellow Reason}: ${this.param.reason}`);
16
16
  }
17
17
  }
18
18
  class A extends f {
19
- constructor(e) {
20
- let t = `Option "${e.option}" value is invalid.`;
21
- e.reason ? t += ` Reason: ${e.reason}` : t += ` Value: "${e.value}"`, super(t), this.param = e;
19
+ constructor(t) {
20
+ let e = `Option "${t.option}" value is invalid.`;
21
+ t.reason ? e += ` Reason: ${t.reason}` : e += ` Value: "${t.value}"`, super(e), this.param = t;
22
22
  }
23
- pretty(e) {
24
- e.log(l` {white.bgRed ERROR } Option {bold.yellow ${this.param.option}} value is invalid. `), (this.param.value || this.param.reason) && e.log(""), this.param.value && e.log(l` {blue Value}: ${this.param.value}`), this.param.reason && e.log(l` {yellow Reason}: ${this.param.reason}`);
23
+ pretty(t) {
24
+ t.log(l` {white.bgRed ERROR } Option {bold.yellow ${this.param.option}} value is invalid. `), (this.param.value || this.param.reason) && t.log(""), this.param.value && t.log(l` {blue Value}: ${this.param.value}`), this.param.reason && t.log(l` {yellow Reason}: ${this.param.reason}`);
25
25
  }
26
26
  }
27
27
  function x(i) {
@@ -33,20 +33,20 @@ function x(i) {
33
33
  }
34
34
  throw new Error("Invalid option type: " + i);
35
35
  }
36
- function k(i) {
36
+ function F(i) {
37
37
  return !Array.isArray(i) && typeof i == "object" && i.type ? i.default !== void 0 ? i.default : x(i.type) : x(i);
38
38
  }
39
39
  function g(i) {
40
40
  return typeof i == "string" || Array.isArray(i) ? {
41
41
  type: i,
42
- default: k(i),
42
+ default: F(i),
43
43
  description: "",
44
44
  alias: [],
45
45
  required: !1,
46
46
  variadic: !1
47
47
  } : {
48
48
  type: i.type,
49
- default: i.default ?? k(i.type),
49
+ default: i.default ?? F(i.type),
50
50
  description: i.description ?? "",
51
51
  alias: i.alias ? Array.isArray(i.alias) ? i.alias : [i.alias] : [],
52
52
  required: i.required ?? !1,
@@ -54,64 +54,64 @@ function g(i) {
54
54
  };
55
55
  }
56
56
  class b extends f {
57
- constructor(e, t = {}) {
58
- super(`Invalid option ${e} in not recognized`), this.option = e, this.optionsSchema = t;
59
- }
60
- pretty(e) {
61
- const t = Object.entries(this.optionsSchema);
62
- if (t.length > 0) {
63
- e.log(l`\n{yellow Available options}:`);
64
- for (const [n, s] of t) {
57
+ constructor(t, e = {}) {
58
+ super(`Invalid option ${t} in not recognized`), this.option = t, this.optionsSchema = e;
59
+ }
60
+ pretty(t) {
61
+ const e = Object.entries(this.optionsSchema);
62
+ if (e.length > 0) {
63
+ t.log(l`\n{yellow Available options}:`);
64
+ for (const [n, s] of e) {
65
65
  const r = g(s), o = typeof r.alias == "string" ? [r.alias] : r.alias, u = Array.isArray(r.type) ? `[${r.type[0]}]` : r.type, m = `--${n}${o.length > 0 ? o.map((a) => `, -${a}`).join("") : ""}`, p = " ".repeat(30 - m.length);
66
- e.log(l` {green ${m}} ${p} ${r.description || "\b"} {white (${u})}`);
66
+ t.log(l` {green ${m}} ${p} ${r.description || "\b"} {white (${u})}`);
67
67
  }
68
- e.log("");
68
+ t.log("");
69
69
  }
70
- e.log(l`{white.bgRed ERROR } Option {bold.yellow ${this.option}} is not recognized.`);
70
+ t.log(l`{white.bgRed ERROR } Option {bold.yellow ${this.option}} is not recognized.`);
71
71
  }
72
72
  }
73
- class I extends f {
74
- constructor(e) {
75
- super(`Command "${e}" not found.`), this.command = e;
73
+ class P extends f {
74
+ constructor(t) {
75
+ super(`Command "${t}" not found.`), this.command = t;
76
76
  }
77
- pretty(e) {
78
- e.log(l`{bgRed ERROR } Command {yellow ${this.command}} not found.`);
77
+ pretty(t) {
78
+ t.log(l`{bgRed ERROR } Command {yellow ${this.command}} not found.`);
79
79
  }
80
80
  }
81
81
  class E extends f {
82
- constructor(e) {
83
- super(`Argument "${e}" is required.`), this.argument = e;
82
+ constructor(t) {
83
+ super(`Argument "${t}" is required.`), this.argument = t;
84
84
  }
85
- pretty(e) {
86
- e.log(l`{white.bgRed ERROR } Argument {bold.yellow ${this.argument}} is required.`);
85
+ pretty(t) {
86
+ t.log(l`{white.bgRed ERROR } Argument {bold.yellow ${this.argument}} is required.`);
87
87
  }
88
88
  }
89
89
  class V extends f {
90
- constructor(e) {
91
- super(`Argument "${e}" is required.`), this.option = e;
90
+ constructor(t) {
91
+ super(`Argument "${t}" is required.`), this.option = t;
92
92
  }
93
- pretty(e) {
94
- e.log(l`{white.bgRed ERROR } Option {bold.yellow ${this.option}} is required.`);
93
+ pretty(t) {
94
+ t.log(l`{white.bgRed ERROR } Option {bold.yellow ${this.option}} is required.`);
95
95
  }
96
96
  }
97
- function v(i, e, t, n) {
97
+ function v(i, t, e, n) {
98
98
  if (i == null)
99
99
  return n ?? null;
100
- if (e === "string")
100
+ if (t === "string")
101
101
  return String(i);
102
- if (e === "number") {
102
+ if (t === "number") {
103
103
  const s = Number(i);
104
104
  if (isNaN(s))
105
105
  throw new A({
106
- option: t,
106
+ option: e,
107
107
  reason: `Expected a number, got "${i}"`
108
108
  });
109
109
  return s;
110
110
  }
111
- if (e === "boolean")
111
+ if (t === "boolean")
112
112
  return typeof i == "boolean" ? i : i === "true" || i === "1" ? !0 : i === "false" || i === "0" ? !1 : !!i;
113
- if (Array.isArray(e)) {
114
- const s = e[0], r = Array.isArray(i) ? i : [i];
113
+ if (Array.isArray(t)) {
114
+ const s = t[0], r = Array.isArray(i) ? i : [i];
115
115
  if (s === "string")
116
116
  return r.map((o) => String(o));
117
117
  if (s === "number")
@@ -119,7 +119,7 @@ function v(i, e, t, n) {
119
119
  const u = Number(o);
120
120
  if (isNaN(u))
121
121
  throw new A({
122
- option: t,
122
+ option: e,
123
123
  reason: `Expected array of numbers, got "${o}" in array`
124
124
  });
125
125
  return u;
@@ -127,15 +127,15 @@ function v(i, e, t, n) {
127
127
  }
128
128
  return i;
129
129
  }
130
- class F {
130
+ class k {
131
131
  options;
132
132
  parsedOptions = null;
133
133
  arguments;
134
134
  parsedArguments = null;
135
135
  io;
136
136
  shouldPromptForMissingOptions = !0;
137
- constructor(e) {
138
- this.options = e.options, this.arguments = e.arguments, this.io = e.io;
137
+ constructor(t) {
138
+ this.options = t.options, this.arguments = t.arguments, this.io = t.io;
139
139
  }
140
140
  // === PUBLIC METHODS ===
141
141
  /**
@@ -145,9 +145,9 @@ class F {
145
145
  * @throws {InvalidOption} If an unknown option is provided
146
146
  * @throws {BadCommandOption} If a value cannot be converted to the expected type
147
147
  */
148
- init(e) {
149
- const { _: t, ...n } = q(e);
150
- return this.validateUnknownOptions(n), this.parsedOptions = this.handleOptions(n), this.parsedArguments = this.handleArguments(t), {
148
+ init(t) {
149
+ const { _: e, ...n } = q(t);
150
+ return this.validateUnknownOptions(n), this.parsedOptions = this.handleOptions(n), this.parsedArguments = this.handleArguments(e), {
151
151
  options: this.parsedOptions,
152
152
  arguments: this.parsedArguments
153
153
  };
@@ -157,30 +157,30 @@ class F {
157
157
  * @throws {Error} If validation fails
158
158
  */
159
159
  async validate() {
160
- for (const e in this.options)
161
- if (g(this.options[e]).required && (this.parsedOptions?.[e] === void 0 || this.parsedOptions?.[e] === null))
162
- throw new V(e);
163
- for (const e in this.arguments) {
164
- const t = g(this.arguments[e]), n = this.parsedArguments?.[e];
165
- if (t.required && n == null) {
160
+ for (const t in this.options)
161
+ if (g(this.options[t]).required && (this.parsedOptions?.[t] === void 0 || this.parsedOptions?.[t] === null))
162
+ throw new V(t);
163
+ for (const t in this.arguments) {
164
+ const e = g(this.arguments[t]), n = this.parsedArguments?.[t];
165
+ if (e.required && n == null) {
166
166
  if (this.shouldPromptForMissingOptions) {
167
- const s = await this.promptForArgument(e, t);
167
+ const s = await this.promptForArgument(t, e);
168
168
  if (s && this.parsedArguments) {
169
- this.parsedArguments[e] = v(s, t.type, e);
169
+ this.parsedArguments[t] = v(s, e.type, t);
170
170
  continue;
171
171
  }
172
172
  }
173
- throw new E(e);
173
+ throw new E(t);
174
174
  }
175
- if (t.required && t.variadic && Array.isArray(n) && n.length === 0) {
175
+ if (e.required && e.variadic && Array.isArray(n) && n.length === 0) {
176
176
  if (this.shouldPromptForMissingOptions) {
177
- const s = await this.promptForArgument(e, t);
177
+ const s = await this.promptForArgument(t, e);
178
178
  if (s && this.parsedArguments) {
179
- this.parsedArguments[e] = v(s, t.type, e);
179
+ this.parsedArguments[t] = v(s, e.type, t);
180
180
  continue;
181
181
  }
182
182
  }
183
- throw new E(e);
183
+ throw new E(t);
184
184
  }
185
185
  }
186
186
  }
@@ -190,17 +190,17 @@ class F {
190
190
  * @returns The typed option value
191
191
  * @throws {Error} If init() has not been called yet
192
192
  */
193
- option(e) {
193
+ option(t) {
194
194
  if (!this.parsedOptions)
195
195
  throw new Error("Options have not been parsed yet. Call init() first.");
196
- return this.parsedOptions[e];
196
+ return this.parsedOptions[t];
197
197
  }
198
- setOption(e, t) {
198
+ setOption(t, e) {
199
199
  if (!this.parsedOptions)
200
200
  throw new Error("Options have not been parsed yet. Call init() first.");
201
- if (!(e in this.options))
202
- throw new b(e, this.options);
203
- this.parsedOptions[e] = t;
201
+ if (!(t in this.options))
202
+ throw new b(t, this.options);
203
+ this.parsedOptions[t] = e;
204
204
  }
205
205
  /**
206
206
  * Retrieves a parsed argument value by name
@@ -208,111 +208,111 @@ class F {
208
208
  * @returns The typed argument value
209
209
  * @throws {Error} If init() has not been called yet
210
210
  */
211
- argument(e) {
211
+ argument(t) {
212
212
  if (!this.parsedArguments)
213
213
  throw new Error("Arguments have not been parsed yet. Call init() first.");
214
- return this.parsedArguments[e];
214
+ return this.parsedArguments[t];
215
215
  }
216
- setArgument(e, t) {
216
+ setArgument(t, e) {
217
217
  if (!this.parsedArguments)
218
218
  throw new Error("Arguments have not been parsed yet. Call init() first.");
219
- if (!(e in this.arguments))
220
- throw new b(e, this.arguments);
221
- this.parsedArguments[e] = t;
219
+ if (!(t in this.arguments))
220
+ throw new b(t, this.arguments);
221
+ this.parsedArguments[t] = e;
222
222
  }
223
223
  // === PRIVATE HELPERS ===
224
224
  /**
225
225
  * Validates that all provided options are recognized
226
226
  * @throws {InvalidOption} If an unknown option is found
227
227
  */
228
- validateUnknownOptions(e) {
229
- const t = /* @__PURE__ */ new Set();
228
+ validateUnknownOptions(t) {
229
+ const e = /* @__PURE__ */ new Set();
230
230
  for (const n in this.options) {
231
- t.add(n);
231
+ e.add(n);
232
232
  const s = g(this.options[n]);
233
233
  for (const r of s.alias)
234
- t.add(r);
234
+ e.add(r);
235
235
  }
236
- for (const n in e)
237
- if (!t.has(n))
236
+ for (const n in t)
237
+ if (!e.has(n))
238
238
  throw new b(n, this.options);
239
239
  }
240
240
  /**
241
241
  * Processes named options from minimist output
242
242
  */
243
- handleOptions(e) {
244
- const t = {};
243
+ handleOptions(t) {
244
+ const e = {};
245
245
  for (const n in this.options) {
246
246
  const s = g(this.options[n]);
247
- t[n] = this.resolveOptionValue(
247
+ e[n] = this.resolveOptionValue(
248
248
  n,
249
249
  s,
250
- e
250
+ t
251
251
  );
252
252
  }
253
- return t;
253
+ return e;
254
254
  }
255
255
  /**
256
256
  * Processes positional arguments from minimist output
257
257
  */
258
- handleArguments(e) {
259
- const t = {}, n = [...e];
258
+ handleArguments(t) {
259
+ const e = {}, n = [...t];
260
260
  for (const s in this.arguments) {
261
261
  const r = g(this.arguments[s]);
262
262
  if (r.variadic) {
263
- t[s] = this.handleVariadicArgument(s, r, n);
263
+ e[s] = this.handleVariadicArgument(s, r, n);
264
264
  continue;
265
265
  }
266
- t[s] = this.resolveArgumentValue(s, r, n.shift());
266
+ e[s] = this.resolveArgumentValue(s, r, n.shift());
267
267
  }
268
- return t;
268
+ return e;
269
269
  }
270
270
  /**
271
271
  * Handles variadic arguments that consume all remaining positional values
272
272
  */
273
- handleVariadicArgument(e, t, n) {
274
- return n.length ? v(n, t.type, e, t.default) : t.default;
273
+ handleVariadicArgument(t, e, n) {
274
+ return n.length ? v(n, e.type, t, e.default) : e.default;
275
275
  }
276
276
  /**
277
277
  * Resolves a single positional argument value with defaults and type conversion
278
278
  * Note: Does not validate required arguments - validation happens in subclass validate() methods
279
279
  */
280
- resolveArgumentValue(e, t, n) {
281
- return n === void 0 ? t.default : v(n, t.type, e, t.default);
280
+ resolveArgumentValue(t, e, n) {
281
+ return n === void 0 ? e.default : v(n, e.type, t, e.default);
282
282
  }
283
283
  /**
284
284
  * Resolves an option value from the parsed option values object
285
285
  * Handles alias resolution, defaults, and type conversion
286
286
  */
287
- resolveOptionValue(e, t, n) {
287
+ resolveOptionValue(t, e, n) {
288
288
  let s;
289
- const r = [e, ...t.alias];
289
+ const r = [t, ...e.alias];
290
290
  for (const o of r)
291
291
  if (o in n) {
292
292
  s = n[o];
293
293
  break;
294
294
  }
295
295
  if (s === void 0) {
296
- if (t.required)
296
+ if (e.required)
297
297
  throw new A({
298
- option: e,
298
+ option: t,
299
299
  reason: "Required option is missing"
300
300
  });
301
- return t.default;
301
+ return e.default;
302
302
  }
303
- return v(s, t.type, e, t.default);
303
+ return v(s, e.type, t, e.default);
304
304
  }
305
305
  optionDefinitions() {
306
- const e = {};
307
- for (const t in this.options)
308
- e[t] = g(this.options[t]);
309
- return e;
306
+ const t = {};
307
+ for (const e in this.options)
308
+ t[e] = g(this.options[e]);
309
+ return t;
310
310
  }
311
311
  argumentDefinitions() {
312
- const e = {};
313
- for (const t in this.arguments)
314
- e[t] = g(this.arguments[t]);
315
- return e;
312
+ const t = {};
313
+ for (const e in this.arguments)
314
+ t[e] = g(this.arguments[e]);
315
+ return t;
316
316
  }
317
317
  availableOptions() {
318
318
  return Object.keys(this.options);
@@ -334,12 +334,12 @@ class F {
334
334
  * @param argDef - The argument's definition for type and description
335
335
  * @returns The user-provided value, or null if none given
336
336
  */
337
- async promptForArgument(e, t) {
338
- if (!Array.isArray(t.type) && !["string", "number", "secret"].includes(t.type))
337
+ async promptForArgument(t, e) {
338
+ if (!Array.isArray(e.type) && !["string", "number", "secret"].includes(e.type))
339
339
  return null;
340
- let n = l`{yellow.bold ${e}} is required`;
341
- return t.description && (n += l`: {gray (${t.description})}`), n += `
342
- `, Array.isArray(t.type) ? (n += l`Please provide one or more values, separated by commas:\n`, await this.io.askForList(
340
+ let n = l`{yellow.bold ${t}} is required`;
341
+ return e.description && (n += l`: {gray (${e.description})}`), n += `
342
+ `, Array.isArray(e.type) ? (n += l`Please provide one or more values, separated by commas:\n`, await this.io.askForList(
343
343
  n,
344
344
  void 0,
345
345
  {
@@ -349,13 +349,13 @@ class F {
349
349
  n,
350
350
  void 0,
351
351
  {
352
- type: t.type === "number" ? "number" : t.type === "secret" ? "password" : "text",
352
+ type: e.type === "number" ? "number" : e.type === "secret" ? "password" : "text",
353
353
  validate: (s) => {
354
- if (t.type === "number") {
354
+ if (e.type === "number") {
355
355
  const r = Number(s);
356
356
  if (isNaN(r))
357
357
  return "Please enter a valid number";
358
- } else if (t.type === "string" && (typeof s != "string" || !s.length))
358
+ } else if (e.type === "string" && (typeof s != "string" || !s.length))
359
359
  return "Please enter a valid text";
360
360
  return !0;
361
361
  }
@@ -373,7 +373,7 @@ class H {
373
373
  default = !1;
374
374
  description = l`Display help for the given command. When no command is given display help for the {green list} command`;
375
375
  async handler() {
376
- const e = this.parser.argumentDefinitions(), t = this.parser.optionDefinitions(), n = Object.entries(e), s = Object.entries(t), r = s.map(([a, d]) => {
376
+ const t = this.parser.argumentDefinitions(), e = this.parser.optionDefinitions(), n = Object.entries(t), s = Object.entries(e), r = s.map(([a, d]) => {
377
377
  const h = Array.isArray(d.alias) ? d.alias : d.alias ? [d.alias] : [];
378
378
  return {
379
379
  name: a,
@@ -424,92 +424,92 @@ class H {
424
424
  }
425
425
  class S {
426
426
  logger;
427
- constructor(e) {
428
- this.logger = e;
427
+ constructor(t) {
428
+ this.logger = t;
429
429
  }
430
430
  /**
431
431
  * Logger methods
432
432
  */
433
- log(...e) {
434
- this.logger.log(...e);
433
+ log(...t) {
434
+ this.logger.log(...t);
435
435
  }
436
- info(...e) {
437
- this.logger.info(...e);
436
+ info(...t) {
437
+ this.logger.info(...t);
438
438
  }
439
- warn(...e) {
440
- this.logger.warn(...e);
439
+ warn(...t) {
440
+ this.logger.warn(...t);
441
441
  }
442
- error(...e) {
443
- this.logger.error(...e);
442
+ error(...t) {
443
+ this.logger.error(...t);
444
444
  }
445
- debug(...e) {
446
- this.logger.debug(...e);
445
+ debug(...t) {
446
+ this.logger.debug(...t);
447
447
  }
448
448
  /**
449
449
  * Prompt utils
450
450
  */
451
- async askForConfirmation(e = "Do you want to continue?", t) {
451
+ async askForConfirmation(t = "Do you want to continue?", e) {
452
452
  return (await y({
453
453
  type: "confirm",
454
454
  name: "value",
455
- message: e,
456
- initial: t ?? !1
455
+ message: t,
456
+ initial: e ?? !1
457
457
  })).value;
458
458
  }
459
- async askForInput(e, t, n) {
459
+ async askForInput(t, e, n) {
460
460
  return (await y({
461
461
  type: "text",
462
462
  name: "value",
463
- message: e,
464
- initial: t,
463
+ message: t,
464
+ initial: e,
465
465
  ...n
466
466
  }))?.value ?? null;
467
467
  }
468
- async askForDate(e, t, n) {
468
+ async askForDate(t, e, n) {
469
469
  return (await y({
470
470
  type: "date",
471
471
  name: "value",
472
- message: e,
473
- initial: t,
472
+ message: t,
473
+ initial: e,
474
474
  ...n
475
475
  }))?.value ?? null;
476
476
  }
477
- async askForList(e, t, n) {
477
+ async askForList(t, e, n) {
478
478
  return (await y({
479
479
  type: "list",
480
480
  name: "value",
481
- message: e,
482
- initial: t,
481
+ message: t,
482
+ initial: e,
483
483
  ...n
484
484
  }))?.value ?? null;
485
485
  }
486
- async askForToggle(e, t, n) {
486
+ async askForToggle(t, e, n) {
487
487
  return (await y({
488
488
  type: "toggle",
489
489
  name: "value",
490
- message: e,
491
- initial: t,
490
+ message: t,
491
+ initial: e,
492
492
  ...n
493
493
  }))?.value ?? null;
494
494
  }
495
- async askForSelect(e, t, n) {
496
- if (t.length === 0)
495
+ async askForSelect(t, e, n) {
496
+ if (e.length === 0)
497
497
  throw new Error("No options provided");
498
498
  const s = [];
499
- for (const o of t)
499
+ for (const o of e)
500
500
  typeof o == "string" ? s.push({ title: o, value: o }) : s.push(o);
501
501
  return (await y({
502
502
  type: "select",
503
503
  name: "value",
504
- message: e,
504
+ message: t,
505
505
  choices: s,
506
506
  ...n
507
507
  }))?.value ?? null;
508
508
  }
509
- newLoader(e = "", t = ["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"], n = 100) {
510
- let s = e, r = null, o = 0;
509
+ newLoader(t = "", e = ["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"], n = 100) {
510
+ let s = t, r = null, o = 0;
511
511
  const u = setInterval(function() {
512
- r && (process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(r.length + 5) + "\r")), r = null), process.stdout.write(new TextEncoder().encode("\r" + t[o++] + " " + s)), o = o % t.length;
512
+ r && (process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(r.length + 5) + "\r")), r = null), process.stdout.write(new TextEncoder().encode("\r" + e[o++] + " " + s)), o = o % e.length;
513
513
  }, n), m = () => {
514
514
  clearInterval(u), process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(s.length + 5) + "\r"));
515
515
  };
@@ -542,18 +542,18 @@ class C {
542
542
  defaultOptions() {
543
543
  return [new H()];
544
544
  }
545
- newCommandParser(e) {
546
- return new F({
547
- io: e.io,
548
- options: e.options,
549
- arguments: e.arguments
545
+ newCommandParser(t) {
546
+ return new k({
547
+ io: t.io,
548
+ options: t.options,
549
+ arguments: t.arguments
550
550
  });
551
551
  }
552
- newCommandIO(e) {
553
- return new S(e.logger);
552
+ newCommandIO(t) {
553
+ return new S(t.logger);
554
554
  }
555
- constructor(e, t) {
556
- this._command = e, this.description = t?.description ?? "", this.group = t?.group;
555
+ constructor(t, e) {
556
+ this._command = t, this.description = e?.description ?? "", this.group = e?.group;
557
557
  const n = this.defaultOptions();
558
558
  if (n.length > 0) {
559
559
  this.tmp = {
@@ -567,37 +567,37 @@ class C {
567
567
  disablePrompting() {
568
568
  return this.disablePromptingFlag = !0, this;
569
569
  }
570
- preHandler(e) {
571
- return this._preHandler = e, this;
570
+ preHandler(t) {
571
+ return this._preHandler = t, this;
572
572
  }
573
- handler(e) {
574
- return this._handler = e, this;
573
+ handler(t) {
574
+ return this._handler = t, this;
575
575
  }
576
- options(e) {
576
+ options(t) {
577
577
  return this.tmp = {
578
578
  options: {
579
579
  ...this.tmp?.options ?? {},
580
- ...e
580
+ ...t
581
581
  },
582
582
  arguments: this.tmp?.arguments ?? {}
583
583
  }, this;
584
584
  }
585
- arguments(e) {
585
+ arguments(t) {
586
586
  return this.tmp = {
587
587
  options: this.tmp?.options ?? {},
588
588
  arguments: {
589
589
  ...this.tmp?.arguments ?? {},
590
- ...e
590
+ ...t
591
591
  }
592
592
  }, this;
593
593
  }
594
- async run(e) {
594
+ async run(t) {
595
595
  if (!this._handler && !this.handle)
596
596
  throw new Error(`No handler defined for command ${this.command || "(unknown)"}`);
597
- let t;
598
- if (this.ctx = e.ctx, this.logger = e.logger, this.io = this.newCommandIO({
599
- logger: e.logger
600
- }), e && "args" in e) {
597
+ let e;
598
+ if (this.ctx = t.ctx, this.logger = t.logger, this.io = this.newCommandIO({
599
+ logger: t.logger
600
+ }), t && "args" in t) {
601
601
  const r = this.tmp?.options ?? {};
602
602
  for (const o of this.defaultOptions())
603
603
  o.option in r || (r[o.option] = o);
@@ -605,18 +605,18 @@ class C {
605
605
  io: this.io,
606
606
  options: r,
607
607
  arguments: this.tmp?.arguments ?? {}
608
- }), t = this.parser.init(e.args);
608
+ }), e = this.parser.init(t.args);
609
609
  for (const o of this.defaultOptions())
610
- if (t.options[o.option] === !0) {
610
+ if (e.options[o.option] === !0) {
611
611
  const u = await o.handler.call(this);
612
612
  if (u && u !== 0)
613
613
  return u;
614
614
  }
615
615
  this.disablePromptingFlag && this.parser.disablePrompting(), await this.parser.validate();
616
616
  } else
617
- t = {
618
- options: e.options,
619
- arguments: e.arguments
617
+ e = {
618
+ options: t.options,
619
+ arguments: t.arguments
620
620
  };
621
621
  const n = this.preHandle ? await this.preHandle() : null;
622
622
  if (n && n !== 0)
@@ -625,29 +625,29 @@ class C {
625
625
  this._handler = this.handle.bind(this);
626
626
  else if (!this._handler)
627
627
  throw new Error(`No handler defined for command ${this.command || "(unknown)"}`);
628
- return await this._handler(e.ctx, t) ?? 0;
628
+ return await this._handler(t.ctx, e) ?? 0;
629
629
  }
630
630
  }
631
- class w extends F {
631
+ class w extends k {
632
632
  command;
633
- constructor(e) {
634
- const t = w.parseSignature(
635
- e.signature,
636
- e.helperDefinitions,
637
- e.defaultOptions
633
+ constructor(t) {
634
+ const e = w.parseSignature(
635
+ t.signature,
636
+ t.helperDefinitions,
637
+ t.defaultOptions
638
638
  );
639
- super({ io: e.io, options: t.options, arguments: t.arguments }), this.command = t.command;
639
+ super({ io: t.io, options: e.options, arguments: e.arguments }), this.command = e.command;
640
640
  }
641
641
  /**
642
642
  * Parses command signature string into command name and parameter schemas
643
643
  * Example: "migrate {name} {--force}" -> { command: "migrate", arguments: {name: ...}, options: {force: ...} }
644
644
  */
645
- static parseSignature(e, t, n) {
646
- const [s, ...r] = e.split(/\{(.*?)\}/g).map((m) => m.trim()).filter(Boolean), o = {}, u = {};
645
+ static parseSignature(t, e, n) {
646
+ const [s, ...r] = t.split(/\{(.*?)\}/g).map((m) => m.trim()).filter(Boolean), o = {}, u = {};
647
647
  for (const m of r) {
648
648
  const { name: p, isOption: a, definition: d } = w.parseParamSignature(
649
649
  m,
650
- t
650
+ e
651
651
  );
652
652
  a ? o[p] = d : u[p] = d;
653
653
  }
@@ -676,8 +676,8 @@ class w extends F {
676
676
  * - {--opt=} -> string option
677
677
  * - {--opt|o} -> option with alias
678
678
  */
679
- static parseParamSignature(e, t) {
680
- let n = e, s = !1;
679
+ static parseParamSignature(t, e) {
680
+ let n = t, s = !1;
681
681
  const r = {
682
682
  required: !0,
683
683
  type: "string",
@@ -697,7 +697,7 @@ class w extends F {
697
697
  const [o, ...u] = n.split("|");
698
698
  n = o.trim(), r.alias = u.map((m) => m.trim());
699
699
  }
700
- return n.startsWith("--") && (s = !0, n = n.slice(2)), r.default === "*" && (r.default = [], r.type = ["string"]), n.endsWith("?") && (r.required = !1, n = n.slice(0, -1)), n.endsWith("*") && (r.type = ["string"], r.variadic = !0, r.default = [], n = n.slice(0, -1)), r.description = r.description ?? t[n] ?? t[`--${n}`], { name: n, isOption: s, definition: r };
700
+ return n.startsWith("--") && (s = !0, n = n.slice(2)), r.default === "*" && (r.default = [], r.type = ["string"]), n.endsWith("?") && (r.required = !1, n = n.slice(0, -1)), n.endsWith("*") && (r.type = ["string"], r.variadic = !0, r.default = [], n = n.slice(0, -1)), r.description = r.description ?? e[n] ?? e[`--${n}`], { name: n, isOption: s, definition: r };
701
701
  }
702
702
  }
703
703
  class z extends C {
@@ -705,9 +705,9 @@ class z extends C {
705
705
  get command() {
706
706
  return this.parser ? this.parser.command : this.signature.split(" ")[0];
707
707
  }
708
- newCommandParser(e) {
708
+ newCommandParser(t) {
709
709
  return new w({
710
- io: e.io,
710
+ io: t.io,
711
711
  signature: this.signature,
712
712
  helperDefinitions: this.helperDefinitions,
713
713
  defaultOptions: this.defaultOptions()
@@ -716,55 +716,55 @@ class z extends C {
716
716
  constructor() {
717
717
  super("");
718
718
  }
719
- option(e, t = null) {
720
- return this.parser instanceof w ? this.parser.option(e) ?? t : t;
719
+ option(t, e = null) {
720
+ return this.parser instanceof w ? this.parser.option(t) ?? e : e;
721
721
  }
722
- argument(e, t = null) {
723
- return this.parser instanceof w ? this.parser.argument(e) ?? t : t;
722
+ argument(t, e = null) {
723
+ return this.parser instanceof w ? this.parser.argument(t) ?? e : e;
724
724
  }
725
725
  // Prompt utils
726
- async askForConfirmation(...e) {
727
- return this.io.askForConfirmation(...e);
726
+ async askForConfirmation(...t) {
727
+ return this.io.askForConfirmation(...t);
728
728
  }
729
- async askForInput(...e) {
730
- return this.io.askForInput(...e);
729
+ async askForInput(...t) {
730
+ return this.io.askForInput(...t);
731
731
  }
732
- async askForSelect(...e) {
733
- return this.io.askForSelect(...e);
732
+ async askForSelect(...t) {
733
+ return this.io.askForSelect(...t);
734
734
  }
735
- newLoader(...e) {
736
- return this.io.newLoader(...e);
735
+ newLoader(...t) {
736
+ return this.io.newLoader(...t);
737
737
  }
738
738
  }
739
739
  class L {
740
740
  level;
741
- constructor(e = {}) {
742
- this.level = e.level ?? "info";
741
+ constructor(t = {}) {
742
+ this.level = t.level ?? "info";
743
743
  }
744
- shouldLog(e) {
745
- const t = ["debug", "info", "warn", "error"], n = t.indexOf(this.level);
746
- return t.indexOf(e) >= n;
744
+ shouldLog(t) {
745
+ const e = ["debug", "info", "warn", "error"], n = e.indexOf(this.level);
746
+ return e.indexOf(t) >= n;
747
747
  }
748
- setLevel(e) {
749
- this.level = e;
748
+ setLevel(t) {
749
+ this.level = t;
750
750
  }
751
751
  getLevel() {
752
752
  return this.level;
753
753
  }
754
- log(...e) {
755
- console.log(...e);
754
+ log(...t) {
755
+ console.log(...t);
756
756
  }
757
- info(...e) {
758
- this.shouldLog("info") && console.log(...e);
757
+ info(...t) {
758
+ this.shouldLog("info") && console.log(...t);
759
759
  }
760
- warn(...e) {
761
- this.shouldLog("warn") && console.warn(...e);
760
+ warn(...t) {
761
+ this.shouldLog("warn") && console.warn(...t);
762
762
  }
763
- error(...e) {
764
- this.shouldLog("error") && console.error(...e);
763
+ error(...t) {
764
+ this.shouldLog("error") && console.error(...t);
765
765
  }
766
- debug(...e) {
767
- this.shouldLog("debug") && console.log(...e);
766
+ debug(...t) {
767
+ this.shouldLog("debug") && console.log(...t);
768
768
  }
769
769
  }
770
770
  class j {
@@ -774,8 +774,8 @@ class j {
774
774
  get CommandIOClass() {
775
775
  return S;
776
776
  }
777
- constructor(e) {
778
- this.logger = e ?? new L(), this.io = new this.CommandIOClass(this.logger);
777
+ constructor(t) {
778
+ this.logger = t ?? new L(), this.io = new this.CommandIOClass(this.logger);
779
779
  }
780
780
  getAvailableCommands() {
781
781
  return Object.keys(this.commands);
@@ -783,62 +783,58 @@ class j {
783
783
  getCommands() {
784
784
  return Object.values(this.commands);
785
785
  }
786
- importFile = async (e) => (await import(e)).default;
787
- commandResolver = async (e) => {
788
- let t = await this.importFile(e);
789
- if (!t)
790
- throw new Error(`The command at path ${e} does not have a default export.`);
791
- return t?.default && (t = t.default), typeof t == "function" ? new t() : t instanceof C ? t : null;
786
+ importFile = async (t) => (await import(t)).default;
787
+ commandResolver = async (t) => {
788
+ let e = await this.importFile(t);
789
+ if (!e)
790
+ throw new Error(`The command at path ${t} does not have a default export.`);
791
+ return e?.default && (e = e.default), typeof e == "function" ? new e() : e instanceof C ? e : null;
792
792
  };
793
- setCommandResolver(e) {
794
- return this.commandResolver = e, this;
795
- }
796
- setFileImporter(e) {
797
- return this.importFile = e, this;
793
+ withCommandResolver(t) {
794
+ return this.commandResolver = t, this;
798
795
  }
799
- fileCheck = (e) => !0;
800
- setFileCheck(e) {
801
- return this.fileCheck = e, this;
796
+ withFileImporter(t) {
797
+ return this.importFile = t, this;
802
798
  }
803
- registerCommand(e, t = !1) {
804
- const n = e.command;
799
+ registerCommand(t, e = !1) {
800
+ const n = t.command;
805
801
  if (!n)
806
802
  throw new Error("Command signature is invalid, it must have a command name.");
807
- if (!t && this.commands[n])
803
+ if (!e && this.commands[n])
808
804
  throw new Error(`Command ${n} already registered.`);
809
- this.commands[n] = e;
805
+ this.commands[n] = t;
810
806
  }
811
- async loadCommandsPath(e) {
812
- for await (const t of this.listCommandsFiles(e))
807
+ async loadCommandsPath(t) {
808
+ for await (const e of this.listCommandsFiles(t))
813
809
  try {
814
- const n = await this.commandResolver(t);
810
+ const n = await this.commandResolver(e);
815
811
  n instanceof C && this.registerCommand(n);
816
812
  } catch (n) {
817
- throw new Error(`Command ${t} failed to load. ${n}`, {
813
+ throw new Error(`Command ${e} failed to load. ${n}`, {
818
814
  cause: n
819
815
  });
820
816
  }
821
817
  }
822
- async runCommand(e, t, ...n) {
823
- const s = typeof t == "string" ? this.commands[t] : t, r = typeof t == "string" ? t : s.command;
818
+ async runCommand(t, e, ...n) {
819
+ const s = typeof e == "string" ? this.commands[e] : e, r = typeof e == "string" ? e : s.command;
824
820
  if (!s) {
825
821
  const o = await this.suggestCommand(r);
826
- return o ? await this.runCommand(e, o, ...n) : 1;
822
+ return o ? await this.runCommand(t, o, ...n) : 1;
827
823
  }
828
824
  return await s.run({
829
- ctx: e,
825
+ ctx: t,
830
826
  logger: this.logger,
831
827
  args: n
832
828
  }) ?? 0;
833
829
  }
834
- async suggestCommand(e) {
835
- const t = this.getAvailableCommands(), { bestMatch: n, bestMatchIndex: s, ratings: r } = P.findBestMatch(e, t), o = r.filter((u) => u.rating > 0.3).map((u) => u.target);
830
+ async suggestCommand(t) {
831
+ const e = this.getAvailableCommands(), { bestMatch: n, bestMatchIndex: s, ratings: r } = I.findBestMatch(t, e), o = r.filter((u) => u.rating > 0.3).map((u) => u.target);
836
832
  if (n.rating > 0 && o.length <= 1 || n.rating > 0.7 && o.length > 1) {
837
- const u = t[s];
838
- return await this.askRunSimilarCommand(e, u) ? u : null;
833
+ const u = e[s];
834
+ return await this.askRunSimilarCommand(t, u) ? u : null;
839
835
  }
840
836
  if (o.length) {
841
- this.io.error(l`{bgRed ERROR } Command {yellow ${e}} not found.\n`);
837
+ this.io.error(l`{bgRed ERROR } Command {yellow ${t}} not found.\n`);
842
838
  const u = await this.io.askForSelect(
843
839
  l`{green Did you mean to run one of these commands instead?}`,
844
840
  o
@@ -846,17 +842,17 @@ class j {
846
842
  if (u)
847
843
  return u;
848
844
  }
849
- throw new I(e);
845
+ throw new P(t);
850
846
  }
851
- async askRunSimilarCommand(e, t) {
852
- return this.io.error(l`{bgRed ERROR } Command {yellow ${e}} not found.\n`), this.io.askForConfirmation(l`{green Do you want to run {yellow ${t}} instead?} `);
847
+ async askRunSimilarCommand(t, e) {
848
+ return this.io.error(l`{bgRed ERROR } Command {yellow ${t}} not found.\n`), this.io.askForConfirmation(l`{green Do you want to run {yellow ${e}} instead?} `);
853
849
  }
854
- async *listCommandsFiles(e) {
855
- const t = D.readdirSync(e, { withFileTypes: !0 });
856
- for (const n of t) {
857
- const s = R.resolve(e, n.name);
850
+ async *listCommandsFiles(t) {
851
+ const e = D.readdirSync(t, { withFileTypes: !0 });
852
+ for (const n of e) {
853
+ const s = R.resolve(t, n.name);
858
854
  if (n.isDirectory())
859
- yield* this.listCommandsFiles(R.resolve(e, n.name));
855
+ yield* this.listCommandsFiles(R.resolve(t, n.name));
860
856
  else {
861
857
  if (!s.endsWith(".ts") && !s.endsWith(".js") && !s.endsWith(".mjs") && !s.endsWith(".cjs"))
862
858
  continue;
@@ -866,22 +862,22 @@ class j {
866
862
  }
867
863
  }
868
864
  class W extends C {
869
- constructor(e) {
865
+ constructor(t) {
870
866
  super("help", {
871
867
  description: l.bold("Show help information about the CLI and its commands")
872
- }), this.opts = e;
868
+ }), this.opts = t;
873
869
  }
874
870
  async handle() {
875
- const e = this.opts.commandRegistry.getCommands(), t = this.opts.cliName ?? "Bob CLI", n = this.opts.cliVersion ?? "0.0.0", s = (await import("./package-D2VbJdgN.js"))?.default?.version ?? "0.0.0";
876
- this.io.log(l`${t} {green ${n}} (core: {yellow ${s}})
871
+ const t = this.opts.commandRegistry.getCommands(), e = this.opts.cliName ?? "Bob CLI", n = this.opts.cliVersion ?? "0.0.0", s = (await import("./package-ODN3iB6L.js"))?.default?.version ?? "0.0.0";
872
+ this.io.log(l`${e} {green ${n}} (core: {yellow ${s}})
877
873
 
878
874
  {yellow Usage}:
879
875
  command [options] [arguments]
880
876
 
881
877
  {yellow Available commands}:
882
878
  `);
883
- const r = Math.max(...e.map((m) => m.command.length)) ?? 0, o = {};
884
- for (const m of e) {
879
+ const r = Math.max(...t.map((m) => m.command.length)) ?? 0, o = {};
880
+ for (const m of t) {
885
881
  const p = m.group ?? m.command.split(":")[0];
886
882
  o[p] || (o[p] = []), o[p].push(m);
887
883
  }
@@ -899,13 +895,13 @@ class W extends C {
899
895
  }
900
896
  class T {
901
897
  logger;
902
- constructor(e) {
903
- this.logger = e;
898
+ constructor(t) {
899
+ this.logger = t;
904
900
  }
905
- handle(e) {
906
- if (e instanceof f)
907
- return e.pretty(this.logger), -1;
908
- throw e;
901
+ handle(t) {
902
+ if (t instanceof f)
903
+ return t.pretty(this.logger), -1;
904
+ throw t;
909
905
  }
910
906
  }
911
907
  class J {
@@ -914,41 +910,44 @@ class J {
914
910
  commandRegistry;
915
911
  exceptionHandler;
916
912
  helpCommand;
917
- newCommandRegistry(e) {
918
- return new j(e.logger);
913
+ newCommandRegistry(t) {
914
+ return new j(t.logger);
919
915
  }
920
- newHelpCommand(e) {
921
- return new W(e);
916
+ newHelpCommand(t) {
917
+ return new W(t);
922
918
  }
923
- newExceptionHandler(e) {
924
- return new T(e.logger);
919
+ newExceptionHandler(t) {
920
+ return new T(t.logger);
925
921
  }
926
- constructor(e = {}) {
927
- this.ctx = e.ctx, this.logger = e.logger ?? new L(), this.commandRegistry = this.newCommandRegistry({
922
+ constructor(t = {}) {
923
+ this.ctx = t.ctx, this.logger = t.logger ?? new L(), this.commandRegistry = this.newCommandRegistry({
928
924
  logger: this.logger
929
925
  }), this.exceptionHandler = this.newExceptionHandler({
930
926
  logger: this.logger
931
927
  }), this.helpCommand = this.newHelpCommand({
932
- cliName: e.name,
933
- cliVersion: e.version,
928
+ cliName: t.name,
929
+ cliVersion: t.version,
934
930
  commandRegistry: this.commandRegistry
935
931
  });
936
932
  }
937
- setCommandResolver(e) {
938
- this.commandRegistry.setCommandResolver(e);
933
+ withCommandResolver(t) {
934
+ return this.commandRegistry.withCommandResolver(t), this;
935
+ }
936
+ withFileImporter(t) {
937
+ return this.commandRegistry.withFileImporter(t), this;
939
938
  }
940
- async withCommands(...e) {
941
- for (const t of e)
942
- typeof t == "string" ? await this.commandRegistry.loadCommandsPath(t) : typeof t == "function" ? this.registerCommand(new t()) : this.registerCommand(t);
939
+ async withCommands(...t) {
940
+ for (const e of t)
941
+ typeof e == "string" ? await this.commandRegistry.loadCommandsPath(e) : typeof e == "function" ? this.registerCommand(new e()) : this.registerCommand(e);
943
942
  }
944
- async runCommand(e, ...t) {
945
- return e ? await this.commandRegistry.runCommand(this.ctx, e, ...t).catch(this.exceptionHandler.handle.bind(this.exceptionHandler)) : await this.runHelpCommand();
943
+ async runCommand(t, ...e) {
944
+ return t ? await this.commandRegistry.runCommand(this.ctx, t, ...e).catch(this.exceptionHandler.handle.bind(this.exceptionHandler)) : await this.runHelpCommand();
946
945
  }
947
946
  async runHelpCommand() {
948
947
  return await this.runCommand(this.helpCommand);
949
948
  }
950
- registerCommand(e) {
951
- this.commandRegistry.registerCommand(e);
949
+ registerCommand(t) {
950
+ this.commandRegistry.registerCommand(t);
952
951
  }
953
952
  }
954
953
  export {
@@ -958,8 +957,8 @@ export {
958
957
  J as Cli,
959
958
  C as Command,
960
959
  S as CommandIO,
961
- I as CommandNotFoundError,
962
- F as CommandParser,
960
+ P as CommandNotFoundError,
961
+ k as CommandParser,
963
962
  j as CommandRegistry,
964
963
  w as CommandSignatureParser,
965
964
  z as CommandWithSignature,