bob-core 3.0.0-beta.2 → 3.0.0-beta.3
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/cjs/{package-BI6Z9-0r.cjs → package-Chbq4tyH.cjs} +1 -1
- package/dist/cjs/src/args/index.d.ts +56 -31
- package/dist/cjs/src/errors/renderError.d.ts +9 -0
- package/dist/cjs/src/flags/boolean.d.ts +7 -2
- package/dist/cjs/src/flags/custom.d.ts +7 -5
- package/dist/cjs/src/flags/directory.d.ts +13 -8
- package/dist/cjs/src/flags/file.d.ts +13 -8
- package/dist/cjs/src/flags/helpers.d.ts +1 -0
- package/dist/cjs/src/flags/index.d.ts +63 -33
- package/dist/cjs/src/flags/number.d.ts +16 -11
- package/dist/cjs/src/flags/string.d.ts +7 -2
- package/dist/cjs/src/flags/url.d.ts +7 -2
- package/dist/cjs/src/index.js +5 -5
- package/dist/cjs/src/options/HelpOption.d.ts +4 -2
- package/dist/esm/{package-BLXL_OAz.js → package-DtqoIUbm.js} +2 -2
- package/dist/esm/src/args/index.d.ts +56 -31
- package/dist/esm/src/errors/renderError.d.ts +9 -0
- package/dist/esm/src/flags/boolean.d.ts +7 -2
- package/dist/esm/src/flags/custom.d.ts +7 -5
- package/dist/esm/src/flags/directory.d.ts +13 -8
- package/dist/esm/src/flags/file.d.ts +13 -8
- package/dist/esm/src/flags/helpers.d.ts +1 -0
- package/dist/esm/src/flags/index.d.ts +63 -33
- package/dist/esm/src/flags/number.d.ts +16 -11
- package/dist/esm/src/flags/string.d.ts +7 -2
- package/dist/esm/src/flags/url.d.ts +7 -2
- package/dist/esm/src/index.js +263 -244
- package/dist/esm/src/options/HelpOption.d.ts +4 -2
- package/package.json +2 -2
package/dist/esm/src/index.js
CHANGED
|
@@ -67,91 +67,118 @@ var m = class {
|
|
|
67
67
|
}
|
|
68
68
|
}, g = class extends Error {
|
|
69
69
|
$type = "BobError";
|
|
70
|
-
}
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/errors/renderError.ts
|
|
73
|
+
function _(t) {
|
|
74
|
+
return e.bold.yellow(`'${t}'`);
|
|
75
|
+
}
|
|
76
|
+
var te = /\x1b\[[0-9;]*m/g;
|
|
77
|
+
function ne(e) {
|
|
78
|
+
return e.replace(te, "").length;
|
|
79
|
+
}
|
|
80
|
+
function v(t, n) {
|
|
81
|
+
let { title: r, details: i, hint: a } = n, o = i && i.length > 0 || a != null, s = e.dim("│"), c = e.dim("└─");
|
|
82
|
+
if (t.log(""), t.log(` ${e.red("error:")} ${r}`), o) {
|
|
83
|
+
if (t.log(` ${s}`), i && i.length > 0) {
|
|
84
|
+
let e = i.map(([e]) => ne(e)), n = Math.max(...e);
|
|
85
|
+
for (let r = 0; r < i.length; r++) {
|
|
86
|
+
let [a, o] = i[r], c = " ".repeat(n - e[r]);
|
|
87
|
+
t.log(` ${s} ${a}${c} ${o}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
a == null ? t.log(` ${s}`) : (t.log(` ${s}`), t.log(` ${c} try: ${a}`));
|
|
91
|
+
}
|
|
92
|
+
t.log("");
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/errors/CommandNotFoundError.ts
|
|
96
|
+
var y = class extends g {
|
|
71
97
|
constructor(e) {
|
|
72
98
|
super(`Command "${e}" not found.`), this.command = e;
|
|
73
99
|
}
|
|
74
|
-
pretty(
|
|
75
|
-
|
|
100
|
+
pretty(e) {
|
|
101
|
+
v(e, { title: `command ${_(this.command)} not found` });
|
|
76
102
|
}
|
|
77
|
-
}
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/flags/helpers.ts
|
|
106
|
+
function b(t, n) {
|
|
107
|
+
let r = "multiple" in n && n.multiple, i = `${e.yellow.bold(t)} is required`;
|
|
108
|
+
return n.description && (i += `: ${e.gray(`(${n.description})`)}`), i += ` ${e.green(`(${n.type}${r ? "[]" : ""})`)}\n`, i;
|
|
109
|
+
}
|
|
110
|
+
function x(e) {
|
|
111
|
+
return e == null ? [] : typeof e == "string" ? [e] : e;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/errors/InvalidFlag.ts
|
|
115
|
+
var S = class extends g {
|
|
78
116
|
constructor(e, t = {}) {
|
|
79
117
|
super(`Flag ${e} is not recognized`), this.flag = e, this.flagsSchema = t;
|
|
80
118
|
}
|
|
81
119
|
pretty(t) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
description: t.description || "",
|
|
91
|
-
typeDisplay: r
|
|
92
|
-
};
|
|
93
|
-
}), i = Math.max(...r.map((e) => e.nameWithAlias.length));
|
|
94
|
-
for (let n of r) {
|
|
95
|
-
let r = " ".repeat(i - n.nameWithAlias.length + 2);
|
|
96
|
-
t.log(` ${e.green(n.nameWithAlias)}${r}${n.description} ${e.dim(`(${n.typeDisplay})`)}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
t.log("");
|
|
120
|
+
let n = Object.entries(this.flagsSchema).map(([t, n]) => {
|
|
121
|
+
let r = x(n.alias), i = `--${t}${r.length > 0 ? r.map((e) => `, -${e}`).join("") : ""}`, a = n.type === "option" && "options" in n && n.options ? n.options.join(" | ") : n.type, o = n.description ?? "", s = o ? `${o} ${e.dim(`(${a})`)}` : e.dim(`(${a})`);
|
|
122
|
+
return [e.cyan(i), s];
|
|
123
|
+
});
|
|
124
|
+
v(t, {
|
|
125
|
+
title: `flag ${_(this.flag)} is not recognized`,
|
|
126
|
+
details: n
|
|
127
|
+
});
|
|
100
128
|
}
|
|
101
|
-
},
|
|
129
|
+
}, C = class extends g {
|
|
102
130
|
constructor(e) {
|
|
103
131
|
super(`Argument "${e}" is required.`), this.argument = e;
|
|
104
132
|
}
|
|
105
|
-
pretty(
|
|
106
|
-
|
|
133
|
+
pretty(e) {
|
|
134
|
+
v(e, { title: `argument ${_(this.argument)} is required` });
|
|
107
135
|
}
|
|
108
|
-
},
|
|
136
|
+
}, w = class extends g {
|
|
109
137
|
constructor(e) {
|
|
110
138
|
super(`Flag "${e}" is required.`), this.flag = e;
|
|
111
139
|
}
|
|
112
|
-
pretty(
|
|
113
|
-
|
|
140
|
+
pretty(e) {
|
|
141
|
+
v(e, { title: `flag ${_(this.flag)} is required` });
|
|
114
142
|
}
|
|
115
|
-
},
|
|
143
|
+
}, T = class extends g {
|
|
116
144
|
constructor(e, t) {
|
|
117
145
|
let n = `Argument "${e.arg}" value is invalid.`;
|
|
118
146
|
e.reason ? n += ` Reason: ${e.reason}` : n += ` Value: "${e.value}"`, super(n), this.detail = e, this.argDefinition = t;
|
|
119
147
|
}
|
|
120
148
|
pretty(t) {
|
|
121
149
|
let n = [];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
t.log("");
|
|
150
|
+
this.detail.value != null && n.push([e.dim("value"), e.yellow(`"${this.detail.value}"`)]), this.detail.reason != null && n.push([e.dim("reason"), this.detail.reason]), this.argDefinition?.help != null && n.push([e.dim("help"), e.green(this.argDefinition.help)]), v(t, {
|
|
151
|
+
title: `argument ${_(this.detail.arg)} is invalid`,
|
|
152
|
+
details: n
|
|
153
|
+
});
|
|
128
154
|
}
|
|
129
|
-
},
|
|
155
|
+
}, E = class extends g {
|
|
130
156
|
constructor(e, t) {
|
|
131
157
|
let n = `Flag "${e.flag}" value is invalid.`;
|
|
132
158
|
e.reason ? n += ` Reason: ${e.reason}` : n += ` Value: "${e.value}"`, super(n), this.param = e, this.flagDefinition = t;
|
|
133
159
|
}
|
|
134
160
|
pretty(t) {
|
|
135
161
|
let n = [];
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
t.log("");
|
|
162
|
+
this.param.value != null && n.push([e.dim("value"), e.yellow(`"${this.param.value}"`)]), this.param.reason != null && n.push([e.dim("reason"), this.param.reason]), this.flagDefinition?.help != null && n.push([e.dim("help"), e.green(this.flagDefinition.help)]), v(t, {
|
|
163
|
+
title: `flag ${_(this.param.flag)} is invalid`,
|
|
164
|
+
details: n
|
|
165
|
+
});
|
|
142
166
|
}
|
|
143
|
-
},
|
|
167
|
+
}, D = class extends g {
|
|
144
168
|
constructor(e, t) {
|
|
145
169
|
super(`Too many arguments provided. Expected ${e}, got ${t}.`), this.expected = e, this.received = t;
|
|
146
170
|
}
|
|
147
171
|
pretty(t) {
|
|
148
|
-
|
|
172
|
+
v(t, {
|
|
173
|
+
title: "too many arguments",
|
|
174
|
+
details: [[e.dim("expected"), e.green(String(this.expected))], [e.dim("received"), e.bold.yellow(String(this.received))]]
|
|
175
|
+
});
|
|
149
176
|
}
|
|
150
|
-
},
|
|
177
|
+
}, O = class extends Error {
|
|
151
178
|
constructor(e) {
|
|
152
179
|
super(e);
|
|
153
180
|
}
|
|
154
|
-
},
|
|
181
|
+
}, k = class {
|
|
155
182
|
flags;
|
|
156
183
|
parsedFlags = null;
|
|
157
184
|
args;
|
|
@@ -179,7 +206,7 @@ var m = class {
|
|
|
179
206
|
}
|
|
180
207
|
async setFlag(e, t) {
|
|
181
208
|
if (!this.parsedFlags) throw Error("Flags have not been parsed yet. Call init() first.");
|
|
182
|
-
if (!(e in this.flags)) throw new
|
|
209
|
+
if (!(e in this.flags)) throw new S(e, this.flags);
|
|
183
210
|
this.parsedFlags[e] = t;
|
|
184
211
|
}
|
|
185
212
|
argument(e, t) {
|
|
@@ -188,7 +215,7 @@ var m = class {
|
|
|
188
215
|
}
|
|
189
216
|
async setArgument(e, t) {
|
|
190
217
|
if (!this.parsedArgs) throw Error("Arguments have not been parsed yet. Call init() first.");
|
|
191
|
-
if (!(e in this.args)) throw new
|
|
218
|
+
if (!(e in this.args)) throw new T({
|
|
192
219
|
arg: e,
|
|
193
220
|
reason: `Argument "${e}" is not recognized`
|
|
194
221
|
});
|
|
@@ -204,7 +231,7 @@ var m = class {
|
|
|
204
231
|
let n = this.flags[e], r = Array.isArray(n.alias) ? n.alias : n.alias ? [n.alias] : [];
|
|
205
232
|
for (let e of r) t.add(e);
|
|
206
233
|
}
|
|
207
|
-
for (let n in e) if (!t.has(n)) throw new
|
|
234
|
+
for (let n in e) if (!t.has(n)) throw new S(n, this.flags);
|
|
208
235
|
}
|
|
209
236
|
async handleOptions(e) {
|
|
210
237
|
let t = {};
|
|
@@ -221,7 +248,7 @@ var m = class {
|
|
|
221
248
|
}
|
|
222
249
|
t[e] = await this.parseValue(n.shift(), r, "arg", { name: e });
|
|
223
250
|
}
|
|
224
|
-
if (this.shouldRejectExtraArguments && n.length > 0) throw new
|
|
251
|
+
if (this.shouldRejectExtraArguments && n.length > 0) throw new D(r, r + n.length);
|
|
225
252
|
return t;
|
|
226
253
|
}
|
|
227
254
|
async resolveFlagValue(e, t, n) {
|
|
@@ -249,20 +276,20 @@ var m = class {
|
|
|
249
276
|
ux: this.ux,
|
|
250
277
|
ctx: this.opts.ctx,
|
|
251
278
|
definition: t,
|
|
252
|
-
cmd: this.opts.cmd ??
|
|
279
|
+
cmd: this.opts.cmd ?? X
|
|
253
280
|
};
|
|
254
281
|
}
|
|
255
282
|
async safeParse(e, t, n, r) {
|
|
256
283
|
try {
|
|
257
284
|
return t.parse(e, this.buildOpts(r?.name ?? "", t));
|
|
258
285
|
} catch (t) {
|
|
259
|
-
if (t instanceof
|
|
286
|
+
if (t instanceof E || t instanceof T || !r) throw t;
|
|
260
287
|
let i = t instanceof Error ? t.message : String(t);
|
|
261
|
-
throw n === "flag" ? new
|
|
288
|
+
throw n === "flag" ? new E({
|
|
262
289
|
flag: r.name,
|
|
263
290
|
value: e,
|
|
264
291
|
reason: i
|
|
265
|
-
}) : new
|
|
292
|
+
}) : new T({
|
|
266
293
|
arg: r.name,
|
|
267
294
|
value: e,
|
|
268
295
|
reason: i
|
|
@@ -273,10 +300,10 @@ var m = class {
|
|
|
273
300
|
for (let r in e) {
|
|
274
301
|
let i = e[r], a = t?.[r], o = this.isEmptyValue(a);
|
|
275
302
|
if (i.required && o) {
|
|
276
|
-
if (!this.shouldPromptForMissingFlags) throw n === "flag" ? new
|
|
303
|
+
if (!this.shouldPromptForMissingFlags) throw n === "flag" ? new w(r) : new C(r);
|
|
277
304
|
let e = await this.promptFor(r, i);
|
|
278
305
|
if (e != null && t) a = await this.parseValue(e, i, n, { name: r }), t[r] = a;
|
|
279
|
-
else throw n === "flag" ? new
|
|
306
|
+
else throw n === "flag" ? new w(r) : new C(r);
|
|
280
307
|
}
|
|
281
308
|
}
|
|
282
309
|
}
|
|
@@ -295,92 +322,88 @@ var m = class {
|
|
|
295
322
|
};
|
|
296
323
|
//#endregion
|
|
297
324
|
//#region src/flags/custom.ts
|
|
298
|
-
function
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
//#region src/flags/helpers.ts
|
|
309
|
-
function D(t, n) {
|
|
310
|
-
let r = "multiple" in n && n.multiple, i = `${e.yellow.bold(t)} is required`;
|
|
311
|
-
return n.description && (i += `: ${e.gray(`(${n.description})`)}`), i += ` ${e.green(`(${n.type}${r ? "[]" : ""})`)}\n`, i;
|
|
325
|
+
function A(e) {
|
|
326
|
+
function t(t) {
|
|
327
|
+
return {
|
|
328
|
+
type: "custom",
|
|
329
|
+
default: e?.multiple || t?.multiple ? [] : null,
|
|
330
|
+
...e,
|
|
331
|
+
...t
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return t;
|
|
312
335
|
}
|
|
313
336
|
//#endregion
|
|
314
337
|
//#region src/shared/parsers.ts
|
|
315
|
-
function
|
|
338
|
+
function re(e) {
|
|
316
339
|
if (typeof e == "boolean") throw Error(`Expected a string, got boolean "${e}"`);
|
|
317
340
|
return String(e);
|
|
318
341
|
}
|
|
319
|
-
function
|
|
342
|
+
function ie(e, t) {
|
|
320
343
|
let n = typeof e == "number" ? e : Number(e);
|
|
321
|
-
if (isNaN(n)) throw new
|
|
322
|
-
if (t?.min !== void 0 && n < t.min) throw new
|
|
323
|
-
if (t?.max !== void 0 && n > t.max) throw new
|
|
344
|
+
if (isNaN(n)) throw new O("must be a valid number");
|
|
345
|
+
if (t?.min !== void 0 && n < t.min) throw new O(`is below minimum ${t.min}`);
|
|
346
|
+
if (t?.max !== void 0 && n > t.max) throw new O(`exceeds maximum ${t.max}`);
|
|
324
347
|
return n;
|
|
325
348
|
}
|
|
326
|
-
function
|
|
349
|
+
function ae(e) {
|
|
327
350
|
if (typeof e == "boolean") return e;
|
|
328
351
|
let t = String(e).toLowerCase();
|
|
329
352
|
if (t === "true" || t === "1") return !0;
|
|
330
353
|
if (t === "false" || t === "0") return !1;
|
|
331
|
-
throw new
|
|
354
|
+
throw new O(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`);
|
|
332
355
|
}
|
|
333
|
-
function
|
|
356
|
+
function oe(e, t) {
|
|
334
357
|
let n = String(e);
|
|
335
|
-
if (!t.includes(n)) throw new
|
|
358
|
+
if (!t.includes(n)) throw new O(`must be one of: ${t.map((e) => `"${e}"`).join(", ")}`);
|
|
336
359
|
return n;
|
|
337
360
|
}
|
|
338
|
-
function
|
|
361
|
+
function se(e, n) {
|
|
339
362
|
let r = String(e);
|
|
340
|
-
if (n?.exists && !t.existsSync(r)) throw new
|
|
363
|
+
if (n?.exists && !t.existsSync(r)) throw new O("file does not exist");
|
|
341
364
|
return r;
|
|
342
365
|
}
|
|
343
|
-
function
|
|
366
|
+
function ce(e, n) {
|
|
344
367
|
let r = String(e);
|
|
345
368
|
if (n?.exists) try {
|
|
346
|
-
if (!t.lstatSync(r).isDirectory()) throw new
|
|
369
|
+
if (!t.lstatSync(r).isDirectory()) throw new O("directory does not exist");
|
|
347
370
|
} catch (e) {
|
|
348
|
-
throw e instanceof
|
|
371
|
+
throw e instanceof O ? e : new O("directory does not exist");
|
|
349
372
|
}
|
|
350
373
|
return r;
|
|
351
374
|
}
|
|
352
|
-
function
|
|
375
|
+
function le(e) {
|
|
353
376
|
try {
|
|
354
377
|
return new URL(String(e));
|
|
355
378
|
} catch {
|
|
356
|
-
throw new
|
|
379
|
+
throw new O(`Invalid URL: "${e}"`);
|
|
357
380
|
}
|
|
358
381
|
}
|
|
359
382
|
//#endregion
|
|
360
383
|
//#region src/flags/boolean.ts
|
|
361
|
-
var
|
|
384
|
+
var ue = A({
|
|
362
385
|
default: !1,
|
|
363
|
-
parse: (e) =>
|
|
386
|
+
parse: (e) => ae(e),
|
|
364
387
|
ask: async (e) => {
|
|
365
|
-
let t =
|
|
388
|
+
let t = b(e.name, e.definition);
|
|
366
389
|
return await e.ux.askForToggle(t);
|
|
367
390
|
},
|
|
368
391
|
type: "boolean"
|
|
369
392
|
});
|
|
370
393
|
//#endregion
|
|
371
394
|
//#region src/shared/ask-helpers.ts
|
|
372
|
-
function
|
|
395
|
+
function j(e, t) {
|
|
373
396
|
return (n) => {
|
|
374
397
|
if ((n == null || typeof n == "string" && n.trim() === "") && e.required) return "This value is required";
|
|
375
398
|
try {
|
|
376
399
|
e.parse(n, t);
|
|
377
400
|
} catch (e) {
|
|
378
|
-
return e instanceof
|
|
401
|
+
return e instanceof O ? e.message : "Invalid value";
|
|
379
402
|
}
|
|
380
403
|
return !0;
|
|
381
404
|
};
|
|
382
405
|
}
|
|
383
|
-
function
|
|
406
|
+
function M(e, t) {
|
|
384
407
|
return (n) => {
|
|
385
408
|
if ((n == null || n.trim() === "") && e.required) return "Please enter at least one value";
|
|
386
409
|
for (let r of n.split(",")) {
|
|
@@ -388,36 +411,36 @@ function k(e, t) {
|
|
|
388
411
|
if (n !== "") try {
|
|
389
412
|
e.parse(n, t);
|
|
390
413
|
} catch (e) {
|
|
391
|
-
return e instanceof
|
|
414
|
+
return e instanceof O ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
392
415
|
}
|
|
393
416
|
}
|
|
394
417
|
return !0;
|
|
395
418
|
};
|
|
396
419
|
}
|
|
397
|
-
async function
|
|
398
|
-
let t = e.definition, n = "multiple" in t && t.multiple, r =
|
|
420
|
+
async function de(e) {
|
|
421
|
+
let t = e.definition, n = "multiple" in t && t.multiple, r = b(e.name, t);
|
|
399
422
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
400
423
|
separator: ",",
|
|
401
|
-
validate:
|
|
402
|
-
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate:
|
|
424
|
+
validate: M(t, e)
|
|
425
|
+
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate: j(t, e) }) : await e.ux.askForInput(r, { validate: j(t, e) });
|
|
403
426
|
}
|
|
404
|
-
async function
|
|
405
|
-
let t = e.definition, n = "multiple" in t && t.multiple, r =
|
|
427
|
+
async function fe(e) {
|
|
428
|
+
let t = e.definition, n = "multiple" in t && t.multiple, r = b(e.name, t);
|
|
406
429
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
407
430
|
separator: ",",
|
|
408
|
-
validate:
|
|
431
|
+
validate: M(t, e)
|
|
409
432
|
}) : await e.ux.askForNumber(r, { validate: (n) => {
|
|
410
433
|
if (n === void 0 && t.required) return "This value is required";
|
|
411
434
|
if (n !== void 0) try {
|
|
412
435
|
t.parse(String(n), e);
|
|
413
436
|
} catch (e) {
|
|
414
|
-
return e instanceof
|
|
437
|
+
return e instanceof O ? e.message : "Invalid value";
|
|
415
438
|
}
|
|
416
439
|
return !0;
|
|
417
440
|
} });
|
|
418
441
|
}
|
|
419
|
-
async function
|
|
420
|
-
let t = e.definition, n = "multiple" in t && t.multiple, r =
|
|
442
|
+
async function pe(e) {
|
|
443
|
+
let t = e.definition, n = "multiple" in t && t.multiple, r = b(e.name, t);
|
|
421
444
|
if (t.type !== "option") return null;
|
|
422
445
|
let i = t.options.map((e) => ({
|
|
423
446
|
name: e,
|
|
@@ -425,86 +448,86 @@ async function de(e) {
|
|
|
425
448
|
}));
|
|
426
449
|
return n ? await e.ux.askForCheckbox(r, i) : await e.ux.askForSelect(r, i);
|
|
427
450
|
}
|
|
428
|
-
async function
|
|
429
|
-
let t =
|
|
451
|
+
async function me(e) {
|
|
452
|
+
let t = b(e.name, e.definition);
|
|
430
453
|
return e.ux.askForFile(t, { basePath: process.cwd() });
|
|
431
454
|
}
|
|
432
|
-
async function
|
|
433
|
-
let t =
|
|
455
|
+
async function he(e) {
|
|
456
|
+
let t = b(e.name, e.definition);
|
|
434
457
|
return e.ux.askForDirectory(t, { basePath: process.cwd() });
|
|
435
458
|
}
|
|
436
|
-
async function
|
|
437
|
-
let t =
|
|
438
|
-
return await e.ux.askForInput(t, { validate:
|
|
459
|
+
async function ge(e) {
|
|
460
|
+
let t = b(e.name, e.definition);
|
|
461
|
+
return await e.ux.askForInput(t, { validate: j(e.definition, e) });
|
|
439
462
|
}
|
|
440
463
|
//#endregion
|
|
441
464
|
//#region src/flags/directory.ts
|
|
442
|
-
var
|
|
443
|
-
parse: (e, t) =>
|
|
444
|
-
ask:
|
|
465
|
+
var N = A({
|
|
466
|
+
parse: (e, t) => ce(e, { exists: t.definition.exists }),
|
|
467
|
+
ask: he,
|
|
445
468
|
type: "directory"
|
|
446
|
-
}),
|
|
447
|
-
parse: (e, t) =>
|
|
448
|
-
ask:
|
|
469
|
+
}), P = A({
|
|
470
|
+
parse: (e, t) => se(e, { exists: t.definition.exists }),
|
|
471
|
+
ask: me,
|
|
449
472
|
type: "file"
|
|
450
|
-
}),
|
|
451
|
-
parse: (e, t) =>
|
|
473
|
+
}), F = A({
|
|
474
|
+
parse: (e, t) => ie(e, {
|
|
452
475
|
min: t.definition.min,
|
|
453
476
|
max: t.definition.max
|
|
454
477
|
}),
|
|
455
|
-
ask:
|
|
478
|
+
ask: fe,
|
|
456
479
|
type: "number"
|
|
457
480
|
});
|
|
458
481
|
//#endregion
|
|
459
482
|
//#region src/flags/option.ts
|
|
460
|
-
function
|
|
461
|
-
return
|
|
462
|
-
parse: (e, t) =>
|
|
463
|
-
ask:
|
|
483
|
+
function I(e) {
|
|
484
|
+
return A({
|
|
485
|
+
parse: (e, t) => oe(e, t.definition.options),
|
|
486
|
+
ask: pe,
|
|
464
487
|
...e,
|
|
465
488
|
type: "option"
|
|
466
489
|
})();
|
|
467
490
|
}
|
|
468
491
|
//#endregion
|
|
469
492
|
//#region src/flags/string.ts
|
|
470
|
-
var
|
|
471
|
-
parse: (e) =>
|
|
472
|
-
ask:
|
|
493
|
+
var L = A({
|
|
494
|
+
parse: (e) => re(e),
|
|
495
|
+
ask: de,
|
|
473
496
|
type: "string"
|
|
474
|
-
}),
|
|
475
|
-
parse: (e) =>
|
|
476
|
-
ask:
|
|
497
|
+
}), R = A({
|
|
498
|
+
parse: (e) => le(e),
|
|
499
|
+
ask: ge,
|
|
477
500
|
type: "url"
|
|
478
|
-
}),
|
|
479
|
-
string:
|
|
480
|
-
number:
|
|
481
|
-
option:
|
|
482
|
-
file:
|
|
483
|
-
directory:
|
|
484
|
-
url:
|
|
485
|
-
custom:
|
|
486
|
-
},
|
|
487
|
-
string:
|
|
488
|
-
number:
|
|
489
|
-
boolean:
|
|
490
|
-
option:
|
|
491
|
-
file:
|
|
492
|
-
directory:
|
|
493
|
-
url:
|
|
494
|
-
custom:
|
|
501
|
+
}), z = {
|
|
502
|
+
string: L,
|
|
503
|
+
number: F,
|
|
504
|
+
option: I,
|
|
505
|
+
file: P,
|
|
506
|
+
directory: N,
|
|
507
|
+
url: R,
|
|
508
|
+
custom: A
|
|
509
|
+
}, B = {
|
|
510
|
+
string: L,
|
|
511
|
+
number: F,
|
|
512
|
+
boolean: ue,
|
|
513
|
+
option: I,
|
|
514
|
+
file: P,
|
|
515
|
+
directory: N,
|
|
516
|
+
url: R,
|
|
517
|
+
custom: A
|
|
495
518
|
};
|
|
496
519
|
//#endregion
|
|
497
520
|
//#region src/lib/string.ts
|
|
498
|
-
function
|
|
521
|
+
function V(e) {
|
|
499
522
|
return Array(e + 5).join(" ");
|
|
500
523
|
}
|
|
501
524
|
//#endregion
|
|
502
525
|
//#region src/options/HelpOption.ts
|
|
503
|
-
function
|
|
526
|
+
function _e(e) {
|
|
504
527
|
let t = e.type;
|
|
505
528
|
return t === "option" && "options" in e && e.options ? `enum: ${e.options.join("|")}` : t ?? "custom";
|
|
506
529
|
}
|
|
507
|
-
var
|
|
530
|
+
var H = B.boolean({
|
|
508
531
|
alias: ["h"],
|
|
509
532
|
handler: (t, n) => {
|
|
510
533
|
if (!t) return { shouldStop: !1 };
|
|
@@ -512,7 +535,7 @@ var z = L.boolean({
|
|
|
512
535
|
...r.baseFlags,
|
|
513
536
|
...r.flags
|
|
514
537
|
}, o = Object.entries(i), s = Object.entries(a), c = s.map(([e, t]) => {
|
|
515
|
-
let n =
|
|
538
|
+
let n = x(t.alias);
|
|
516
539
|
return {
|
|
517
540
|
name: e,
|
|
518
541
|
...t,
|
|
@@ -524,7 +547,7 @@ var z = L.boolean({
|
|
|
524
547
|
if (o.length > 0) {
|
|
525
548
|
console.log(`\n${e.yellow("Arguments")}:`);
|
|
526
549
|
for (let [t, n] of o) {
|
|
527
|
-
let r =
|
|
550
|
+
let r = V(f - t.length), i = ` ${e.green(t)} ${r} ${n.description ?? "\b"}`;
|
|
528
551
|
if (n.default !== void 0 && !n.required) {
|
|
529
552
|
let t = typeof n.default == "function" ? "[function]" : n.multiple ? JSON.stringify(n.default) : n.default;
|
|
530
553
|
i += ` ${e.yellow(`[default: ${t}]`)}`;
|
|
@@ -535,8 +558,8 @@ var z = L.boolean({
|
|
|
535
558
|
if (s.length > 0) {
|
|
536
559
|
console.log(`\n${e.yellow("Options")}:`);
|
|
537
560
|
for (let t of c) {
|
|
538
|
-
let n =
|
|
539
|
-
if (t.type && (r += ` ${e.white(`(${
|
|
561
|
+
let n = V(f - t.flagWithAlias.length), r = ` ${e.green(t.flagWithAlias)} ${n} ${t.description ?? "\b"}`;
|
|
562
|
+
if (t.type && (r += ` ${e.white(`(${_e(t)})`)}`), t.default !== void 0 && !t.required) {
|
|
540
563
|
let n = typeof t.default == "function" ? "(function)" : t.default;
|
|
541
564
|
r += ` ${e.yellow(`[default: ${n}]`)}`;
|
|
542
565
|
}
|
|
@@ -552,22 +575,22 @@ var z = L.boolean({
|
|
|
552
575
|
}
|
|
553
576
|
return { shouldStop: !0 };
|
|
554
577
|
}
|
|
555
|
-
}),
|
|
578
|
+
}), ve = class extends Error {
|
|
556
579
|
name = "ExitPromptError";
|
|
557
580
|
};
|
|
558
581
|
//#endregion
|
|
559
582
|
//#region src/ux/helpers.ts
|
|
560
|
-
async function
|
|
583
|
+
async function U(e, t) {
|
|
561
584
|
try {
|
|
562
585
|
return await e();
|
|
563
586
|
} catch (e) {
|
|
564
|
-
if (e instanceof
|
|
587
|
+
if (e instanceof ve || e instanceof Error && e.name === "ExitPromptError") return t;
|
|
565
588
|
throw e;
|
|
566
589
|
}
|
|
567
590
|
}
|
|
568
591
|
//#endregion
|
|
569
592
|
//#region src/ux/askForCheckbox.ts
|
|
570
|
-
async function
|
|
593
|
+
async function W(e, t, n) {
|
|
571
594
|
if (t.length === 0) throw Error("No options provided");
|
|
572
595
|
let r = t.map((e) => typeof e == "string" ? {
|
|
573
596
|
name: e,
|
|
@@ -579,7 +602,7 @@ async function V(e, t, n) {
|
|
|
579
602
|
checked: e.checked,
|
|
580
603
|
description: e.description
|
|
581
604
|
});
|
|
582
|
-
return
|
|
605
|
+
return U(() => i({
|
|
583
606
|
message: e,
|
|
584
607
|
choices: r,
|
|
585
608
|
required: n?.required,
|
|
@@ -591,8 +614,8 @@ async function V(e, t, n) {
|
|
|
591
614
|
}
|
|
592
615
|
//#endregion
|
|
593
616
|
//#region src/ux/askForConfirmation.ts
|
|
594
|
-
async function
|
|
595
|
-
return
|
|
617
|
+
async function G(e = "Do you want to continue?", t) {
|
|
618
|
+
return U(() => a({
|
|
596
619
|
message: e,
|
|
597
620
|
default: t?.default ?? !1,
|
|
598
621
|
transformer: t?.transformer
|
|
@@ -600,8 +623,8 @@ async function H(e = "Do you want to continue?", t) {
|
|
|
600
623
|
}
|
|
601
624
|
//#endregion
|
|
602
625
|
//#region src/ux/askForEditor.ts
|
|
603
|
-
async function
|
|
604
|
-
return
|
|
626
|
+
async function K(e, t) {
|
|
627
|
+
return U(() => o({
|
|
605
628
|
message: e,
|
|
606
629
|
default: t?.default,
|
|
607
630
|
postfix: t?.postfix,
|
|
@@ -611,8 +634,8 @@ async function U(e, t) {
|
|
|
611
634
|
}
|
|
612
635
|
//#endregion
|
|
613
636
|
//#region src/ux/askForExpand.ts
|
|
614
|
-
async function
|
|
615
|
-
return
|
|
637
|
+
async function q(e, t, n) {
|
|
638
|
+
return U(() => s({
|
|
616
639
|
message: e,
|
|
617
640
|
choices: t,
|
|
618
641
|
default: n?.default
|
|
@@ -620,8 +643,8 @@ async function W(e, t, n) {
|
|
|
620
643
|
}
|
|
621
644
|
//#endregion
|
|
622
645
|
//#region src/ux/askForFileSelector.ts
|
|
623
|
-
async function
|
|
624
|
-
return
|
|
646
|
+
async function J(e, t) {
|
|
647
|
+
return U(async () => {
|
|
625
648
|
let n = await ee({
|
|
626
649
|
message: e,
|
|
627
650
|
basePath: t?.basePath,
|
|
@@ -636,8 +659,8 @@ async function G(e, t) {
|
|
|
636
659
|
}
|
|
637
660
|
//#endregion
|
|
638
661
|
//#region src/ux/askForInput.ts
|
|
639
|
-
async function
|
|
640
|
-
return
|
|
662
|
+
async function ye(e, t) {
|
|
663
|
+
return U(() => c({
|
|
641
664
|
message: e,
|
|
642
665
|
default: t?.default,
|
|
643
666
|
required: t?.required,
|
|
@@ -647,9 +670,9 @@ async function K(e, t) {
|
|
|
647
670
|
}
|
|
648
671
|
//#endregion
|
|
649
672
|
//#region src/ux/askForList.ts
|
|
650
|
-
async function
|
|
673
|
+
async function be(e, t) {
|
|
651
674
|
let n = t?.separator ?? ",";
|
|
652
|
-
return
|
|
675
|
+
return U(async () => (await c({
|
|
653
676
|
message: e,
|
|
654
677
|
default: t?.default,
|
|
655
678
|
validate: t?.validate
|
|
@@ -657,8 +680,8 @@ async function q(e, t) {
|
|
|
657
680
|
}
|
|
658
681
|
//#endregion
|
|
659
682
|
//#region src/ux/askForNumber.ts
|
|
660
|
-
async function
|
|
661
|
-
return
|
|
683
|
+
async function xe(e, t) {
|
|
684
|
+
return U(async () => await l({
|
|
662
685
|
message: e,
|
|
663
686
|
default: t?.default,
|
|
664
687
|
required: t?.required,
|
|
@@ -670,8 +693,8 @@ async function J(e, t) {
|
|
|
670
693
|
}
|
|
671
694
|
//#endregion
|
|
672
695
|
//#region src/ux/askForPassword.ts
|
|
673
|
-
async function
|
|
674
|
-
return
|
|
696
|
+
async function Se(e, t) {
|
|
697
|
+
return U(() => u({
|
|
675
698
|
message: e,
|
|
676
699
|
mask: t?.mask,
|
|
677
700
|
validate: t?.validate
|
|
@@ -679,8 +702,8 @@ async function _e(e, t) {
|
|
|
679
702
|
}
|
|
680
703
|
//#endregion
|
|
681
704
|
//#region src/ux/askForRawList.ts
|
|
682
|
-
async function
|
|
683
|
-
return
|
|
705
|
+
async function Ce(e, t, n) {
|
|
706
|
+
return U(() => d({
|
|
684
707
|
message: e,
|
|
685
708
|
choices: t,
|
|
686
709
|
loop: n?.loop
|
|
@@ -688,8 +711,8 @@ async function ve(e, t, n) {
|
|
|
688
711
|
}
|
|
689
712
|
//#endregion
|
|
690
713
|
//#region src/ux/askForSearch.ts
|
|
691
|
-
async function
|
|
692
|
-
return
|
|
714
|
+
async function we(e, t, n) {
|
|
715
|
+
return U(() => f({
|
|
693
716
|
message: e,
|
|
694
717
|
source: t,
|
|
695
718
|
pageSize: n?.pageSize,
|
|
@@ -698,13 +721,13 @@ async function ye(e, t, n) {
|
|
|
698
721
|
}
|
|
699
722
|
//#endregion
|
|
700
723
|
//#region src/ux/askForSelect.ts
|
|
701
|
-
async function
|
|
724
|
+
async function Te(e, t, n) {
|
|
702
725
|
if (t.length === 0) throw Error("No options provided");
|
|
703
726
|
let r = t.map((e) => typeof e == "string" ? {
|
|
704
727
|
name: e,
|
|
705
728
|
value: e
|
|
706
729
|
} : e);
|
|
707
|
-
return
|
|
730
|
+
return U(() => p({
|
|
708
731
|
message: e,
|
|
709
732
|
choices: r,
|
|
710
733
|
default: n?.default,
|
|
@@ -714,9 +737,9 @@ async function be(e, t, n) {
|
|
|
714
737
|
}
|
|
715
738
|
//#endregion
|
|
716
739
|
//#region src/ux/askForToggle.ts
|
|
717
|
-
async function
|
|
740
|
+
async function Ee(e, t) {
|
|
718
741
|
let n = t?.active ?? "Yes", r = t?.inactive ?? "No";
|
|
719
|
-
return
|
|
742
|
+
return U(() => a({
|
|
720
743
|
message: e,
|
|
721
744
|
default: t?.default ?? !1,
|
|
722
745
|
transformer: (e) => e ? n : r
|
|
@@ -724,7 +747,7 @@ async function Y(e, t) {
|
|
|
724
747
|
}
|
|
725
748
|
//#endregion
|
|
726
749
|
//#region src/ux/keyValue.ts
|
|
727
|
-
function
|
|
750
|
+
function De(t, n) {
|
|
728
751
|
let r = n?.separator ?? ": ", i = n?.keyStyle ?? e.bold, a = Array.isArray(t) ? t : Object.entries(t);
|
|
729
752
|
if (a.length === 0) return;
|
|
730
753
|
let o = Math.max(...a.map(([e]) => e.length));
|
|
@@ -732,7 +755,7 @@ function xe(t, n) {
|
|
|
732
755
|
}
|
|
733
756
|
//#endregion
|
|
734
757
|
//#region src/ux/loader.ts
|
|
735
|
-
function
|
|
758
|
+
function Oe(e = "", t = [
|
|
736
759
|
"⠙",
|
|
737
760
|
"⠘",
|
|
738
761
|
"⠰",
|
|
@@ -767,7 +790,7 @@ function Se(e = "", t = [
|
|
|
767
790
|
}
|
|
768
791
|
//#endregion
|
|
769
792
|
//#region src/ux/progressBar.ts
|
|
770
|
-
function
|
|
793
|
+
function ke(e, t) {
|
|
771
794
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
772
795
|
if (o) return;
|
|
773
796
|
let t = e <= 0 ? 1 : Math.min(a / e, 1), s = Math.round(t * n), c = `${r.repeat(s) + i.repeat(n - s)} ${Math.round(t * 100)}% ${a}/${e}`;
|
|
@@ -789,7 +812,7 @@ function Ce(e, t) {
|
|
|
789
812
|
}
|
|
790
813
|
//#endregion
|
|
791
814
|
//#region src/ux/table.ts
|
|
792
|
-
function
|
|
815
|
+
function Ae(t, n) {
|
|
793
816
|
if (t.length === 0) return;
|
|
794
817
|
let r = n ?? Object.keys(t[0]).map((e) => ({ key: e })), i = r.map((e) => e.header ?? e.key.toUpperCase()), a = r.map((e, n) => {
|
|
795
818
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -815,71 +838,71 @@ function we(t, n) {
|
|
|
815
838
|
}
|
|
816
839
|
//#endregion
|
|
817
840
|
//#region src/ux/index.ts
|
|
818
|
-
var
|
|
841
|
+
var Y = class {
|
|
819
842
|
askForConfirmation(e, t) {
|
|
820
|
-
return
|
|
843
|
+
return G(e, t);
|
|
821
844
|
}
|
|
822
845
|
askForInput(e, t) {
|
|
823
|
-
return
|
|
846
|
+
return ye(e, t);
|
|
824
847
|
}
|
|
825
848
|
askForPassword(e, t) {
|
|
826
|
-
return
|
|
849
|
+
return Se(e, t);
|
|
827
850
|
}
|
|
828
851
|
askForNumber(e, t) {
|
|
829
|
-
return
|
|
852
|
+
return xe(e, t);
|
|
830
853
|
}
|
|
831
854
|
askForSelect(e, t, n) {
|
|
832
|
-
return
|
|
855
|
+
return Te(e, t, n);
|
|
833
856
|
}
|
|
834
857
|
askForCheckbox(e, t, n) {
|
|
835
|
-
return
|
|
858
|
+
return W(e, t, n);
|
|
836
859
|
}
|
|
837
860
|
askForSearch(e, t, n) {
|
|
838
|
-
return
|
|
861
|
+
return we(e, t, n);
|
|
839
862
|
}
|
|
840
863
|
askForList(e, t) {
|
|
841
|
-
return
|
|
864
|
+
return be(e, t);
|
|
842
865
|
}
|
|
843
866
|
askForToggle(e, t) {
|
|
844
|
-
return
|
|
867
|
+
return Ee(e, t);
|
|
845
868
|
}
|
|
846
869
|
askForEditor(e, t) {
|
|
847
|
-
return
|
|
870
|
+
return K(e, t);
|
|
848
871
|
}
|
|
849
872
|
askForRawList(e, t, n) {
|
|
850
|
-
return
|
|
873
|
+
return Ce(e, t, n);
|
|
851
874
|
}
|
|
852
875
|
askForExpand(e, t, n) {
|
|
853
|
-
return
|
|
876
|
+
return q(e, t, n);
|
|
854
877
|
}
|
|
855
878
|
askForFile(e, t) {
|
|
856
|
-
return
|
|
879
|
+
return J(e, {
|
|
857
880
|
...t,
|
|
858
881
|
type: "file"
|
|
859
882
|
});
|
|
860
883
|
}
|
|
861
884
|
askForDirectory(e, t) {
|
|
862
|
-
return
|
|
885
|
+
return J(e, {
|
|
863
886
|
...t,
|
|
864
887
|
type: "directory"
|
|
865
888
|
});
|
|
866
889
|
}
|
|
867
890
|
askForFileSelector(e, t) {
|
|
868
|
-
return
|
|
891
|
+
return J(e, t);
|
|
869
892
|
}
|
|
870
893
|
keyValue(e, t) {
|
|
871
|
-
return
|
|
894
|
+
return De(e, t);
|
|
872
895
|
}
|
|
873
896
|
table(e, t) {
|
|
874
|
-
return
|
|
897
|
+
return Ae(e, t);
|
|
875
898
|
}
|
|
876
899
|
newProgressBar(e, t) {
|
|
877
|
-
return
|
|
900
|
+
return ke(e, t);
|
|
878
901
|
}
|
|
879
902
|
newLoader(e, t, n) {
|
|
880
|
-
return
|
|
903
|
+
return Oe(e, t, n);
|
|
881
904
|
}
|
|
882
|
-
},
|
|
905
|
+
}, X = class {
|
|
883
906
|
static $type = "BobCommand";
|
|
884
907
|
static command = "";
|
|
885
908
|
static description = "";
|
|
@@ -897,9 +920,9 @@ var X = class {
|
|
|
897
920
|
logger;
|
|
898
921
|
ux;
|
|
899
922
|
parser;
|
|
900
|
-
static baseFlags = { help:
|
|
923
|
+
static baseFlags = { help: H };
|
|
901
924
|
newCommandParser(e) {
|
|
902
|
-
return new
|
|
925
|
+
return new k({
|
|
903
926
|
ux: e.ux,
|
|
904
927
|
ctx: e.ctx,
|
|
905
928
|
flags: e.flags,
|
|
@@ -908,7 +931,7 @@ var X = class {
|
|
|
908
931
|
});
|
|
909
932
|
}
|
|
910
933
|
newUX() {
|
|
911
|
-
return new
|
|
934
|
+
return new Y();
|
|
912
935
|
}
|
|
913
936
|
async run(e) {
|
|
914
937
|
let t = this.constructor;
|
|
@@ -957,22 +980,22 @@ var X = class {
|
|
|
957
980
|
};
|
|
958
981
|
//#endregion
|
|
959
982
|
//#region src/lib/helpers.ts
|
|
960
|
-
function
|
|
983
|
+
function je(e) {
|
|
961
984
|
return typeof e == "object" && !!e && "$type" in e && e.$type === "BobError";
|
|
962
985
|
}
|
|
963
|
-
function
|
|
964
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
986
|
+
function Z(e) {
|
|
987
|
+
return typeof e == "function" ? e.prototype instanceof X || e.$type === "BobCommand" : !1;
|
|
965
988
|
}
|
|
966
989
|
//#endregion
|
|
967
990
|
//#region src/CommandRegistry.ts
|
|
968
|
-
var
|
|
991
|
+
var Q = class {
|
|
969
992
|
commands = {};
|
|
970
993
|
aliases = {};
|
|
971
994
|
ux;
|
|
972
995
|
logger;
|
|
973
996
|
stringSimilarity;
|
|
974
997
|
constructor(e) {
|
|
975
|
-
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new
|
|
998
|
+
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new Y(), this.stringSimilarity = e?.stringSimilarity ?? new h();
|
|
976
999
|
}
|
|
977
1000
|
getAvailableCommands() {
|
|
978
1001
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -983,7 +1006,7 @@ var Ee = class {
|
|
|
983
1006
|
importFile = async (e) => (await import(e)).default;
|
|
984
1007
|
commandResolver = async (e) => {
|
|
985
1008
|
let t = await this.importFile(e);
|
|
986
|
-
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" &&
|
|
1009
|
+
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" && Z(t) ? t : null) : null;
|
|
987
1010
|
};
|
|
988
1011
|
withCommandResolver(e) {
|
|
989
1012
|
return this.commandResolver = e, this;
|
|
@@ -992,7 +1015,7 @@ var Ee = class {
|
|
|
992
1015
|
return this.importFile = e, this;
|
|
993
1016
|
}
|
|
994
1017
|
registerCommand(e, t = !1) {
|
|
995
|
-
if (!
|
|
1018
|
+
if (!Z(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
996
1019
|
let n = e.command;
|
|
997
1020
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
998
1021
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1007,7 +1030,7 @@ var Ee = class {
|
|
|
1007
1030
|
async loadCommandsPath(e) {
|
|
1008
1031
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1009
1032
|
let e = await this.commandResolver(t);
|
|
1010
|
-
|
|
1033
|
+
Z(e) && this.registerCommand(e);
|
|
1011
1034
|
} catch (e) {
|
|
1012
1035
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1013
1036
|
}
|
|
@@ -1019,10 +1042,10 @@ var Ee = class {
|
|
|
1019
1042
|
if (!i) {
|
|
1020
1043
|
let r = await this.suggestCommand(t);
|
|
1021
1044
|
if (r) return await this.runCommand(e, r, ...n);
|
|
1022
|
-
throw new
|
|
1045
|
+
throw new y(t);
|
|
1023
1046
|
}
|
|
1024
1047
|
r = new i();
|
|
1025
|
-
} else r =
|
|
1048
|
+
} else r = Z(t) ? new t() : t;
|
|
1026
1049
|
return await r.run({
|
|
1027
1050
|
ctx: e,
|
|
1028
1051
|
logger: this.logger,
|
|
@@ -1035,15 +1058,11 @@ var Ee = class {
|
|
|
1035
1058
|
let e = n[i];
|
|
1036
1059
|
return await this.askRunSimilarCommand(t, e) ? e : null;
|
|
1037
1060
|
}
|
|
1038
|
-
if (o.length) {
|
|
1039
|
-
|
|
1040
|
-
let n = await this.ux.askForSelect(e.green("Did you mean to run one of these commands instead?"), o);
|
|
1041
|
-
if (n) return n;
|
|
1042
|
-
}
|
|
1043
|
-
throw new _(t);
|
|
1061
|
+
if (o.length) return await this.ux.askForSelect(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean one of these?`, o) || null;
|
|
1062
|
+
throw new y(t);
|
|
1044
1063
|
}
|
|
1045
1064
|
async askRunSimilarCommand(t, n) {
|
|
1046
|
-
return this.
|
|
1065
|
+
return this.ux.askForConfirmation(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean ${e.bold.green(`'${n}'`)}?`);
|
|
1047
1066
|
}
|
|
1048
1067
|
async *listCommandsFiles(e) {
|
|
1049
1068
|
let r = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
@@ -1056,16 +1075,16 @@ var Ee = class {
|
|
|
1056
1075
|
}
|
|
1057
1076
|
}
|
|
1058
1077
|
}
|
|
1059
|
-
},
|
|
1078
|
+
}, Me = class {
|
|
1060
1079
|
logger;
|
|
1061
1080
|
constructor(e) {
|
|
1062
1081
|
this.logger = e;
|
|
1063
1082
|
}
|
|
1064
1083
|
handle(e) {
|
|
1065
|
-
if (
|
|
1084
|
+
if (je(e)) return e.pretty(this.logger), -1;
|
|
1066
1085
|
throw e;
|
|
1067
1086
|
}
|
|
1068
|
-
},
|
|
1087
|
+
}, Ne, Pe = class extends X {
|
|
1069
1088
|
static command = "help";
|
|
1070
1089
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1071
1090
|
constructor(e) {
|
|
@@ -1073,8 +1092,8 @@ var Ee = class {
|
|
|
1073
1092
|
}
|
|
1074
1093
|
async handle() {
|
|
1075
1094
|
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0";
|
|
1076
|
-
|
|
1077
|
-
let i =
|
|
1095
|
+
Ne ??= (await import("../package-DtqoIUbm.js"))?.default?.version ?? "0.0.0";
|
|
1096
|
+
let i = Ne;
|
|
1078
1097
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1079
1098
|
|
|
1080
1099
|
${e.yellow("Usage")}:
|
|
@@ -1096,25 +1115,25 @@ ${e.yellow("Available commands")}:
|
|
|
1096
1115
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1097
1116
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1098
1117
|
for (let t of i) {
|
|
1099
|
-
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i =
|
|
1118
|
+
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i = V(a - (t.command.length + (t.aliases.length > 0 ? ` (${t.aliases.join(", ")})`.length : 0)));
|
|
1100
1119
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1101
1120
|
}
|
|
1102
1121
|
}
|
|
1103
1122
|
}
|
|
1104
|
-
},
|
|
1123
|
+
}, Fe = class {
|
|
1105
1124
|
ctx;
|
|
1106
1125
|
logger;
|
|
1107
1126
|
commandRegistry;
|
|
1108
1127
|
exceptionHandler;
|
|
1109
1128
|
helpCommand;
|
|
1110
1129
|
newCommandRegistry(e) {
|
|
1111
|
-
return new
|
|
1130
|
+
return new Q(e);
|
|
1112
1131
|
}
|
|
1113
1132
|
newHelpCommand(e) {
|
|
1114
|
-
return new
|
|
1133
|
+
return new Pe(e);
|
|
1115
1134
|
}
|
|
1116
1135
|
newExceptionHandler(e) {
|
|
1117
|
-
return new
|
|
1136
|
+
return new Me(e.logger);
|
|
1118
1137
|
}
|
|
1119
1138
|
constructor(e = {}) {
|
|
1120
1139
|
this.ctx = e.ctx, this.logger = e.logger ?? new m(), this.commandRegistry = this.newCommandRegistry({ logger: this.logger }), this.exceptionHandler = this.newExceptionHandler({ logger: this.logger }), this.helpCommand = this.newHelpCommand({
|
|
@@ -1172,27 +1191,27 @@ ${e.yellow("Available commands")}:
|
|
|
1172
1191
|
}
|
|
1173
1192
|
n.startsWith("--") && (r = !0, n = n.slice(2)), n.endsWith("?") && (l = !1, n = n.slice(0, -1)), n.endsWith("*") && (c = !0, a = [], n = n.slice(0, -1)), i = i ?? t[n] ?? t[`--${n}`];
|
|
1174
1193
|
let u;
|
|
1175
|
-
return u = r ? s ?
|
|
1194
|
+
return u = r ? s ? B.boolean({
|
|
1176
1195
|
description: i,
|
|
1177
1196
|
alias: o,
|
|
1178
1197
|
...a === void 0 ? {} : { default: a }
|
|
1179
|
-
}) : c ?
|
|
1198
|
+
}) : c ? B.string({
|
|
1180
1199
|
description: i,
|
|
1181
1200
|
alias: o,
|
|
1182
1201
|
multiple: !0,
|
|
1183
1202
|
...l ? { required: !0 } : {},
|
|
1184
1203
|
default: a ?? []
|
|
1185
|
-
}) :
|
|
1204
|
+
}) : B.string({
|
|
1186
1205
|
description: i,
|
|
1187
1206
|
alias: o,
|
|
1188
1207
|
...l ? { required: !0 } : {},
|
|
1189
1208
|
...a === void 0 ? {} : { default: a }
|
|
1190
|
-
}) : c ?
|
|
1209
|
+
}) : c ? z.string({
|
|
1191
1210
|
description: i,
|
|
1192
1211
|
multiple: !0,
|
|
1193
1212
|
...l ? { required: !0 } : {},
|
|
1194
1213
|
default: a ?? []
|
|
1195
|
-
}) :
|
|
1214
|
+
}) : z.string({
|
|
1196
1215
|
description: i,
|
|
1197
1216
|
...l ? { required: !0 } : {},
|
|
1198
1217
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1202,7 +1221,7 @@ ${e.yellow("Available commands")}:
|
|
|
1202
1221
|
definition: u
|
|
1203
1222
|
};
|
|
1204
1223
|
}
|
|
1205
|
-
},
|
|
1224
|
+
}, Ie = class extends X {
|
|
1206
1225
|
static signature = "";
|
|
1207
1226
|
static helperDefinitions = {};
|
|
1208
1227
|
static get command() {
|
|
@@ -1230,4 +1249,4 @@ ${e.yellow("Available commands")}:
|
|
|
1230
1249
|
}
|
|
1231
1250
|
};
|
|
1232
1251
|
//#endregion
|
|
1233
|
-
export {
|
|
1252
|
+
export { z as Args, T as BadCommandArgument, E as BadCommandFlag, g as BobError, Fe as Cli, X as Command, y as CommandNotFoundError, k as CommandParser, Q as CommandRegistry, $ as CommandSignatureParser, Ie as CommandWithSignature, Me as ExceptionHandler, B as Flags, H as HelpCommandFlag, S as InvalidFlag, m as Logger, C as MissingRequiredArgumentValue, w as MissingRequiredFlagValue, h as StringSimilarity, D as TooManyArguments, Y as UX, O as ValidationError, W as askForCheckbox, G as askForConfirmation, K as askForEditor, q as askForExpand, J as askForFileSelector, ye as askForInput, be as askForList, xe as askForNumber, Se as askForPassword, Ce as askForRawList, we as askForSearch, Te as askForSelect, Ee as askForToggle, De as keyValue, Oe as newLoader, ke as newProgressBar, Ae as table, U as withCancelHandling };
|