bob-core 3.0.0-beta.2 → 3.0.0-beta.4
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-BYPkkzPN.cjs} +1 -1
- package/dist/cjs/src/HelpFlag.d.ts +12 -0
- 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.d.ts +0 -1
- package/dist/cjs/src/index.js +5 -5
- package/dist/esm/{package-BLXL_OAz.js → package-LkysKcR6.js} +2 -2
- package/dist/esm/src/HelpFlag.d.ts +12 -0
- 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.d.ts +0 -1
- package/dist/esm/src/index.js +265 -245
- package/package.json +2 -2
- package/dist/cjs/src/options/HelpOption.d.ts +0 -9
- package/dist/cjs/src/options/index.d.ts +0 -1
- package/dist/esm/src/options/HelpOption.d.ts +0 -9
- package/dist/esm/src/options/index.d.ts +0 -1
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,94 +448,95 @@ 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
|
-
//#region src/
|
|
503
|
-
function
|
|
525
|
+
//#region src/HelpFlag.ts
|
|
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 ve = B.boolean({
|
|
508
531
|
alias: ["h"],
|
|
532
|
+
description: "Displays help information about the command",
|
|
509
533
|
handler: (t, n) => {
|
|
510
534
|
if (!t) return { shouldStop: !1 };
|
|
511
535
|
let r = n.cmd, i = r.args, a = {
|
|
512
536
|
...r.baseFlags,
|
|
513
537
|
...r.flags
|
|
514
538
|
}, o = Object.entries(i), s = Object.entries(a), c = s.map(([e, t]) => {
|
|
515
|
-
let n =
|
|
539
|
+
let n = x(t.alias);
|
|
516
540
|
return {
|
|
517
541
|
name: e,
|
|
518
542
|
...t,
|
|
@@ -524,7 +548,7 @@ var z = L.boolean({
|
|
|
524
548
|
if (o.length > 0) {
|
|
525
549
|
console.log(`\n${e.yellow("Arguments")}:`);
|
|
526
550
|
for (let [t, n] of o) {
|
|
527
|
-
let r =
|
|
551
|
+
let r = V(f - t.length), i = ` ${e.green(t)} ${r} ${n.description ?? "\b"}`;
|
|
528
552
|
if (n.default !== void 0 && !n.required) {
|
|
529
553
|
let t = typeof n.default == "function" ? "[function]" : n.multiple ? JSON.stringify(n.default) : n.default;
|
|
530
554
|
i += ` ${e.yellow(`[default: ${t}]`)}`;
|
|
@@ -535,8 +559,8 @@ var z = L.boolean({
|
|
|
535
559
|
if (s.length > 0) {
|
|
536
560
|
console.log(`\n${e.yellow("Options")}:`);
|
|
537
561
|
for (let t of c) {
|
|
538
|
-
let n =
|
|
539
|
-
if (t.type && (r += ` ${e.white(`(${
|
|
562
|
+
let n = V(f - t.flagWithAlias.length), r = ` ${e.green(t.flagWithAlias)} ${n} ${t.description ?? "\b"}`;
|
|
563
|
+
if (t.type && (r += ` ${e.white(`(${_e(t)})`)}`), t.default !== void 0 && !t.required) {
|
|
540
564
|
let n = typeof t.default == "function" ? "(function)" : t.default;
|
|
541
565
|
r += ` ${e.yellow(`[default: ${n}]`)}`;
|
|
542
566
|
}
|
|
@@ -552,22 +576,22 @@ var z = L.boolean({
|
|
|
552
576
|
}
|
|
553
577
|
return { shouldStop: !0 };
|
|
554
578
|
}
|
|
555
|
-
}),
|
|
579
|
+
}), ye = class extends Error {
|
|
556
580
|
name = "ExitPromptError";
|
|
557
581
|
};
|
|
558
582
|
//#endregion
|
|
559
583
|
//#region src/ux/helpers.ts
|
|
560
|
-
async function
|
|
584
|
+
async function H(e, t) {
|
|
561
585
|
try {
|
|
562
586
|
return await e();
|
|
563
587
|
} catch (e) {
|
|
564
|
-
if (e instanceof
|
|
588
|
+
if (e instanceof ye || e instanceof Error && e.name === "ExitPromptError") return t;
|
|
565
589
|
throw e;
|
|
566
590
|
}
|
|
567
591
|
}
|
|
568
592
|
//#endregion
|
|
569
593
|
//#region src/ux/askForCheckbox.ts
|
|
570
|
-
async function
|
|
594
|
+
async function U(e, t, n) {
|
|
571
595
|
if (t.length === 0) throw Error("No options provided");
|
|
572
596
|
let r = t.map((e) => typeof e == "string" ? {
|
|
573
597
|
name: e,
|
|
@@ -579,7 +603,7 @@ async function V(e, t, n) {
|
|
|
579
603
|
checked: e.checked,
|
|
580
604
|
description: e.description
|
|
581
605
|
});
|
|
582
|
-
return
|
|
606
|
+
return H(() => i({
|
|
583
607
|
message: e,
|
|
584
608
|
choices: r,
|
|
585
609
|
required: n?.required,
|
|
@@ -591,8 +615,8 @@ async function V(e, t, n) {
|
|
|
591
615
|
}
|
|
592
616
|
//#endregion
|
|
593
617
|
//#region src/ux/askForConfirmation.ts
|
|
594
|
-
async function
|
|
595
|
-
return
|
|
618
|
+
async function W(e = "Do you want to continue?", t) {
|
|
619
|
+
return H(() => a({
|
|
596
620
|
message: e,
|
|
597
621
|
default: t?.default ?? !1,
|
|
598
622
|
transformer: t?.transformer
|
|
@@ -600,8 +624,8 @@ async function H(e = "Do you want to continue?", t) {
|
|
|
600
624
|
}
|
|
601
625
|
//#endregion
|
|
602
626
|
//#region src/ux/askForEditor.ts
|
|
603
|
-
async function
|
|
604
|
-
return
|
|
627
|
+
async function G(e, t) {
|
|
628
|
+
return H(() => o({
|
|
605
629
|
message: e,
|
|
606
630
|
default: t?.default,
|
|
607
631
|
postfix: t?.postfix,
|
|
@@ -611,8 +635,8 @@ async function U(e, t) {
|
|
|
611
635
|
}
|
|
612
636
|
//#endregion
|
|
613
637
|
//#region src/ux/askForExpand.ts
|
|
614
|
-
async function
|
|
615
|
-
return
|
|
638
|
+
async function K(e, t, n) {
|
|
639
|
+
return H(() => s({
|
|
616
640
|
message: e,
|
|
617
641
|
choices: t,
|
|
618
642
|
default: n?.default
|
|
@@ -620,8 +644,8 @@ async function W(e, t, n) {
|
|
|
620
644
|
}
|
|
621
645
|
//#endregion
|
|
622
646
|
//#region src/ux/askForFileSelector.ts
|
|
623
|
-
async function
|
|
624
|
-
return
|
|
647
|
+
async function q(e, t) {
|
|
648
|
+
return H(async () => {
|
|
625
649
|
let n = await ee({
|
|
626
650
|
message: e,
|
|
627
651
|
basePath: t?.basePath,
|
|
@@ -636,8 +660,8 @@ async function G(e, t) {
|
|
|
636
660
|
}
|
|
637
661
|
//#endregion
|
|
638
662
|
//#region src/ux/askForInput.ts
|
|
639
|
-
async function
|
|
640
|
-
return
|
|
663
|
+
async function J(e, t) {
|
|
664
|
+
return H(() => c({
|
|
641
665
|
message: e,
|
|
642
666
|
default: t?.default,
|
|
643
667
|
required: t?.required,
|
|
@@ -647,9 +671,9 @@ async function K(e, t) {
|
|
|
647
671
|
}
|
|
648
672
|
//#endregion
|
|
649
673
|
//#region src/ux/askForList.ts
|
|
650
|
-
async function
|
|
674
|
+
async function be(e, t) {
|
|
651
675
|
let n = t?.separator ?? ",";
|
|
652
|
-
return
|
|
676
|
+
return H(async () => (await c({
|
|
653
677
|
message: e,
|
|
654
678
|
default: t?.default,
|
|
655
679
|
validate: t?.validate
|
|
@@ -657,8 +681,8 @@ async function q(e, t) {
|
|
|
657
681
|
}
|
|
658
682
|
//#endregion
|
|
659
683
|
//#region src/ux/askForNumber.ts
|
|
660
|
-
async function
|
|
661
|
-
return
|
|
684
|
+
async function xe(e, t) {
|
|
685
|
+
return H(async () => await l({
|
|
662
686
|
message: e,
|
|
663
687
|
default: t?.default,
|
|
664
688
|
required: t?.required,
|
|
@@ -670,8 +694,8 @@ async function J(e, t) {
|
|
|
670
694
|
}
|
|
671
695
|
//#endregion
|
|
672
696
|
//#region src/ux/askForPassword.ts
|
|
673
|
-
async function
|
|
674
|
-
return
|
|
697
|
+
async function Se(e, t) {
|
|
698
|
+
return H(() => u({
|
|
675
699
|
message: e,
|
|
676
700
|
mask: t?.mask,
|
|
677
701
|
validate: t?.validate
|
|
@@ -679,8 +703,8 @@ async function _e(e, t) {
|
|
|
679
703
|
}
|
|
680
704
|
//#endregion
|
|
681
705
|
//#region src/ux/askForRawList.ts
|
|
682
|
-
async function
|
|
683
|
-
return
|
|
706
|
+
async function Ce(e, t, n) {
|
|
707
|
+
return H(() => d({
|
|
684
708
|
message: e,
|
|
685
709
|
choices: t,
|
|
686
710
|
loop: n?.loop
|
|
@@ -688,8 +712,8 @@ async function ve(e, t, n) {
|
|
|
688
712
|
}
|
|
689
713
|
//#endregion
|
|
690
714
|
//#region src/ux/askForSearch.ts
|
|
691
|
-
async function
|
|
692
|
-
return
|
|
715
|
+
async function we(e, t, n) {
|
|
716
|
+
return H(() => f({
|
|
693
717
|
message: e,
|
|
694
718
|
source: t,
|
|
695
719
|
pageSize: n?.pageSize,
|
|
@@ -698,13 +722,13 @@ async function ye(e, t, n) {
|
|
|
698
722
|
}
|
|
699
723
|
//#endregion
|
|
700
724
|
//#region src/ux/askForSelect.ts
|
|
701
|
-
async function
|
|
725
|
+
async function Te(e, t, n) {
|
|
702
726
|
if (t.length === 0) throw Error("No options provided");
|
|
703
727
|
let r = t.map((e) => typeof e == "string" ? {
|
|
704
728
|
name: e,
|
|
705
729
|
value: e
|
|
706
730
|
} : e);
|
|
707
|
-
return
|
|
731
|
+
return H(() => p({
|
|
708
732
|
message: e,
|
|
709
733
|
choices: r,
|
|
710
734
|
default: n?.default,
|
|
@@ -714,9 +738,9 @@ async function be(e, t, n) {
|
|
|
714
738
|
}
|
|
715
739
|
//#endregion
|
|
716
740
|
//#region src/ux/askForToggle.ts
|
|
717
|
-
async function
|
|
741
|
+
async function Ee(e, t) {
|
|
718
742
|
let n = t?.active ?? "Yes", r = t?.inactive ?? "No";
|
|
719
|
-
return
|
|
743
|
+
return H(() => a({
|
|
720
744
|
message: e,
|
|
721
745
|
default: t?.default ?? !1,
|
|
722
746
|
transformer: (e) => e ? n : r
|
|
@@ -724,7 +748,7 @@ async function Y(e, t) {
|
|
|
724
748
|
}
|
|
725
749
|
//#endregion
|
|
726
750
|
//#region src/ux/keyValue.ts
|
|
727
|
-
function
|
|
751
|
+
function De(t, n) {
|
|
728
752
|
let r = n?.separator ?? ": ", i = n?.keyStyle ?? e.bold, a = Array.isArray(t) ? t : Object.entries(t);
|
|
729
753
|
if (a.length === 0) return;
|
|
730
754
|
let o = Math.max(...a.map(([e]) => e.length));
|
|
@@ -732,7 +756,7 @@ function xe(t, n) {
|
|
|
732
756
|
}
|
|
733
757
|
//#endregion
|
|
734
758
|
//#region src/ux/loader.ts
|
|
735
|
-
function
|
|
759
|
+
function Oe(e = "", t = [
|
|
736
760
|
"⠙",
|
|
737
761
|
"⠘",
|
|
738
762
|
"⠰",
|
|
@@ -767,7 +791,7 @@ function Se(e = "", t = [
|
|
|
767
791
|
}
|
|
768
792
|
//#endregion
|
|
769
793
|
//#region src/ux/progressBar.ts
|
|
770
|
-
function
|
|
794
|
+
function ke(e, t) {
|
|
771
795
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
772
796
|
if (o) return;
|
|
773
797
|
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 +813,7 @@ function Ce(e, t) {
|
|
|
789
813
|
}
|
|
790
814
|
//#endregion
|
|
791
815
|
//#region src/ux/table.ts
|
|
792
|
-
function
|
|
816
|
+
function Ae(t, n) {
|
|
793
817
|
if (t.length === 0) return;
|
|
794
818
|
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
819
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -815,71 +839,71 @@ function we(t, n) {
|
|
|
815
839
|
}
|
|
816
840
|
//#endregion
|
|
817
841
|
//#region src/ux/index.ts
|
|
818
|
-
var
|
|
842
|
+
var Y = class {
|
|
819
843
|
askForConfirmation(e, t) {
|
|
820
|
-
return
|
|
844
|
+
return W(e, t);
|
|
821
845
|
}
|
|
822
846
|
askForInput(e, t) {
|
|
823
|
-
return
|
|
847
|
+
return J(e, t);
|
|
824
848
|
}
|
|
825
849
|
askForPassword(e, t) {
|
|
826
|
-
return
|
|
850
|
+
return Se(e, t);
|
|
827
851
|
}
|
|
828
852
|
askForNumber(e, t) {
|
|
829
|
-
return
|
|
853
|
+
return xe(e, t);
|
|
830
854
|
}
|
|
831
855
|
askForSelect(e, t, n) {
|
|
832
|
-
return
|
|
856
|
+
return Te(e, t, n);
|
|
833
857
|
}
|
|
834
858
|
askForCheckbox(e, t, n) {
|
|
835
|
-
return
|
|
859
|
+
return U(e, t, n);
|
|
836
860
|
}
|
|
837
861
|
askForSearch(e, t, n) {
|
|
838
|
-
return
|
|
862
|
+
return we(e, t, n);
|
|
839
863
|
}
|
|
840
864
|
askForList(e, t) {
|
|
841
|
-
return
|
|
865
|
+
return be(e, t);
|
|
842
866
|
}
|
|
843
867
|
askForToggle(e, t) {
|
|
844
|
-
return
|
|
868
|
+
return Ee(e, t);
|
|
845
869
|
}
|
|
846
870
|
askForEditor(e, t) {
|
|
847
|
-
return
|
|
871
|
+
return G(e, t);
|
|
848
872
|
}
|
|
849
873
|
askForRawList(e, t, n) {
|
|
850
|
-
return
|
|
874
|
+
return Ce(e, t, n);
|
|
851
875
|
}
|
|
852
876
|
askForExpand(e, t, n) {
|
|
853
|
-
return
|
|
877
|
+
return K(e, t, n);
|
|
854
878
|
}
|
|
855
879
|
askForFile(e, t) {
|
|
856
|
-
return
|
|
880
|
+
return q(e, {
|
|
857
881
|
...t,
|
|
858
882
|
type: "file"
|
|
859
883
|
});
|
|
860
884
|
}
|
|
861
885
|
askForDirectory(e, t) {
|
|
862
|
-
return
|
|
886
|
+
return q(e, {
|
|
863
887
|
...t,
|
|
864
888
|
type: "directory"
|
|
865
889
|
});
|
|
866
890
|
}
|
|
867
891
|
askForFileSelector(e, t) {
|
|
868
|
-
return
|
|
892
|
+
return q(e, t);
|
|
869
893
|
}
|
|
870
894
|
keyValue(e, t) {
|
|
871
|
-
return
|
|
895
|
+
return De(e, t);
|
|
872
896
|
}
|
|
873
897
|
table(e, t) {
|
|
874
|
-
return
|
|
898
|
+
return Ae(e, t);
|
|
875
899
|
}
|
|
876
900
|
newProgressBar(e, t) {
|
|
877
|
-
return
|
|
901
|
+
return ke(e, t);
|
|
878
902
|
}
|
|
879
903
|
newLoader(e, t, n) {
|
|
880
|
-
return
|
|
904
|
+
return Oe(e, t, n);
|
|
881
905
|
}
|
|
882
|
-
},
|
|
906
|
+
}, X = class {
|
|
883
907
|
static $type = "BobCommand";
|
|
884
908
|
static command = "";
|
|
885
909
|
static description = "";
|
|
@@ -897,9 +921,9 @@ var X = class {
|
|
|
897
921
|
logger;
|
|
898
922
|
ux;
|
|
899
923
|
parser;
|
|
900
|
-
static baseFlags = { help:
|
|
924
|
+
static baseFlags = { help: ve };
|
|
901
925
|
newCommandParser(e) {
|
|
902
|
-
return new
|
|
926
|
+
return new k({
|
|
903
927
|
ux: e.ux,
|
|
904
928
|
ctx: e.ctx,
|
|
905
929
|
flags: e.flags,
|
|
@@ -908,7 +932,7 @@ var X = class {
|
|
|
908
932
|
});
|
|
909
933
|
}
|
|
910
934
|
newUX() {
|
|
911
|
-
return new
|
|
935
|
+
return new Y();
|
|
912
936
|
}
|
|
913
937
|
async run(e) {
|
|
914
938
|
let t = this.constructor;
|
|
@@ -957,22 +981,22 @@ var X = class {
|
|
|
957
981
|
};
|
|
958
982
|
//#endregion
|
|
959
983
|
//#region src/lib/helpers.ts
|
|
960
|
-
function
|
|
984
|
+
function je(e) {
|
|
961
985
|
return typeof e == "object" && !!e && "$type" in e && e.$type === "BobError";
|
|
962
986
|
}
|
|
963
|
-
function
|
|
964
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
987
|
+
function Z(e) {
|
|
988
|
+
return typeof e == "function" ? e.prototype instanceof X || e.$type === "BobCommand" : !1;
|
|
965
989
|
}
|
|
966
990
|
//#endregion
|
|
967
991
|
//#region src/CommandRegistry.ts
|
|
968
|
-
var
|
|
992
|
+
var Q = class {
|
|
969
993
|
commands = {};
|
|
970
994
|
aliases = {};
|
|
971
995
|
ux;
|
|
972
996
|
logger;
|
|
973
997
|
stringSimilarity;
|
|
974
998
|
constructor(e) {
|
|
975
|
-
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new
|
|
999
|
+
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new Y(), this.stringSimilarity = e?.stringSimilarity ?? new h();
|
|
976
1000
|
}
|
|
977
1001
|
getAvailableCommands() {
|
|
978
1002
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -983,7 +1007,7 @@ var Ee = class {
|
|
|
983
1007
|
importFile = async (e) => (await import(e)).default;
|
|
984
1008
|
commandResolver = async (e) => {
|
|
985
1009
|
let t = await this.importFile(e);
|
|
986
|
-
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" &&
|
|
1010
|
+
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" && Z(t) ? t : null) : null;
|
|
987
1011
|
};
|
|
988
1012
|
withCommandResolver(e) {
|
|
989
1013
|
return this.commandResolver = e, this;
|
|
@@ -992,7 +1016,7 @@ var Ee = class {
|
|
|
992
1016
|
return this.importFile = e, this;
|
|
993
1017
|
}
|
|
994
1018
|
registerCommand(e, t = !1) {
|
|
995
|
-
if (!
|
|
1019
|
+
if (!Z(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
996
1020
|
let n = e.command;
|
|
997
1021
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
998
1022
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1007,7 +1031,7 @@ var Ee = class {
|
|
|
1007
1031
|
async loadCommandsPath(e) {
|
|
1008
1032
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1009
1033
|
let e = await this.commandResolver(t);
|
|
1010
|
-
|
|
1034
|
+
Z(e) && this.registerCommand(e);
|
|
1011
1035
|
} catch (e) {
|
|
1012
1036
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1013
1037
|
}
|
|
@@ -1019,10 +1043,10 @@ var Ee = class {
|
|
|
1019
1043
|
if (!i) {
|
|
1020
1044
|
let r = await this.suggestCommand(t);
|
|
1021
1045
|
if (r) return await this.runCommand(e, r, ...n);
|
|
1022
|
-
throw new
|
|
1046
|
+
throw new y(t);
|
|
1023
1047
|
}
|
|
1024
1048
|
r = new i();
|
|
1025
|
-
} else r =
|
|
1049
|
+
} else r = Z(t) ? new t() : t;
|
|
1026
1050
|
return await r.run({
|
|
1027
1051
|
ctx: e,
|
|
1028
1052
|
logger: this.logger,
|
|
@@ -1035,15 +1059,11 @@ var Ee = class {
|
|
|
1035
1059
|
let e = n[i];
|
|
1036
1060
|
return await this.askRunSimilarCommand(t, e) ? e : null;
|
|
1037
1061
|
}
|
|
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);
|
|
1062
|
+
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;
|
|
1063
|
+
throw new y(t);
|
|
1044
1064
|
}
|
|
1045
1065
|
async askRunSimilarCommand(t, n) {
|
|
1046
|
-
return this.
|
|
1066
|
+
return this.ux.askForConfirmation(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean ${e.bold.green(`'${n}'`)}?`);
|
|
1047
1067
|
}
|
|
1048
1068
|
async *listCommandsFiles(e) {
|
|
1049
1069
|
let r = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
@@ -1056,16 +1076,16 @@ var Ee = class {
|
|
|
1056
1076
|
}
|
|
1057
1077
|
}
|
|
1058
1078
|
}
|
|
1059
|
-
},
|
|
1079
|
+
}, Me = class {
|
|
1060
1080
|
logger;
|
|
1061
1081
|
constructor(e) {
|
|
1062
1082
|
this.logger = e;
|
|
1063
1083
|
}
|
|
1064
1084
|
handle(e) {
|
|
1065
|
-
if (
|
|
1085
|
+
if (je(e)) return e.pretty(this.logger), -1;
|
|
1066
1086
|
throw e;
|
|
1067
1087
|
}
|
|
1068
|
-
},
|
|
1088
|
+
}, Ne, Pe = class extends X {
|
|
1069
1089
|
static command = "help";
|
|
1070
1090
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1071
1091
|
constructor(e) {
|
|
@@ -1073,8 +1093,8 @@ var Ee = class {
|
|
|
1073
1093
|
}
|
|
1074
1094
|
async handle() {
|
|
1075
1095
|
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 =
|
|
1096
|
+
Ne ??= (await import("../package-LkysKcR6.js"))?.default?.version ?? "0.0.0";
|
|
1097
|
+
let i = Ne;
|
|
1078
1098
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1079
1099
|
|
|
1080
1100
|
${e.yellow("Usage")}:
|
|
@@ -1096,25 +1116,25 @@ ${e.yellow("Available commands")}:
|
|
|
1096
1116
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1097
1117
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1098
1118
|
for (let t of i) {
|
|
1099
|
-
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i =
|
|
1119
|
+
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
1120
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1101
1121
|
}
|
|
1102
1122
|
}
|
|
1103
1123
|
}
|
|
1104
|
-
},
|
|
1124
|
+
}, Fe = class {
|
|
1105
1125
|
ctx;
|
|
1106
1126
|
logger;
|
|
1107
1127
|
commandRegistry;
|
|
1108
1128
|
exceptionHandler;
|
|
1109
1129
|
helpCommand;
|
|
1110
1130
|
newCommandRegistry(e) {
|
|
1111
|
-
return new
|
|
1131
|
+
return new Q(e);
|
|
1112
1132
|
}
|
|
1113
1133
|
newHelpCommand(e) {
|
|
1114
|
-
return new
|
|
1134
|
+
return new Pe(e);
|
|
1115
1135
|
}
|
|
1116
1136
|
newExceptionHandler(e) {
|
|
1117
|
-
return new
|
|
1137
|
+
return new Me(e.logger);
|
|
1118
1138
|
}
|
|
1119
1139
|
constructor(e = {}) {
|
|
1120
1140
|
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 +1192,27 @@ ${e.yellow("Available commands")}:
|
|
|
1172
1192
|
}
|
|
1173
1193
|
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
1194
|
let u;
|
|
1175
|
-
return u = r ? s ?
|
|
1195
|
+
return u = r ? s ? B.boolean({
|
|
1176
1196
|
description: i,
|
|
1177
1197
|
alias: o,
|
|
1178
1198
|
...a === void 0 ? {} : { default: a }
|
|
1179
|
-
}) : c ?
|
|
1199
|
+
}) : c ? B.string({
|
|
1180
1200
|
description: i,
|
|
1181
1201
|
alias: o,
|
|
1182
1202
|
multiple: !0,
|
|
1183
1203
|
...l ? { required: !0 } : {},
|
|
1184
1204
|
default: a ?? []
|
|
1185
|
-
}) :
|
|
1205
|
+
}) : B.string({
|
|
1186
1206
|
description: i,
|
|
1187
1207
|
alias: o,
|
|
1188
1208
|
...l ? { required: !0 } : {},
|
|
1189
1209
|
...a === void 0 ? {} : { default: a }
|
|
1190
|
-
}) : c ?
|
|
1210
|
+
}) : c ? z.string({
|
|
1191
1211
|
description: i,
|
|
1192
1212
|
multiple: !0,
|
|
1193
1213
|
...l ? { required: !0 } : {},
|
|
1194
1214
|
default: a ?? []
|
|
1195
|
-
}) :
|
|
1215
|
+
}) : z.string({
|
|
1196
1216
|
description: i,
|
|
1197
1217
|
...l ? { required: !0 } : {},
|
|
1198
1218
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1202,7 +1222,7 @@ ${e.yellow("Available commands")}:
|
|
|
1202
1222
|
definition: u
|
|
1203
1223
|
};
|
|
1204
1224
|
}
|
|
1205
|
-
},
|
|
1225
|
+
}, Ie = class extends X {
|
|
1206
1226
|
static signature = "";
|
|
1207
1227
|
static helperDefinitions = {};
|
|
1208
1228
|
static get command() {
|
|
@@ -1230,4 +1250,4 @@ ${e.yellow("Available commands")}:
|
|
|
1230
1250
|
}
|
|
1231
1251
|
};
|
|
1232
1252
|
//#endregion
|
|
1233
|
-
export {
|
|
1253
|
+
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, S as InvalidFlag, m as Logger, C as MissingRequiredArgumentValue, w as MissingRequiredFlagValue, h as StringSimilarity, D as TooManyArguments, Y as UX, O as ValidationError, U as askForCheckbox, W as askForConfirmation, G as askForEditor, K as askForExpand, q as askForFileSelector, J 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, H as withCancelHandling };
|