bob-core 3.0.0-beta.1 → 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-supL7Tgp.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/lib/types.d.ts +1 -1
- package/dist/cjs/src/options/HelpOption.d.ts +4 -2
- package/dist/esm/{package-BNru0kNU.js → package-DtqoIUbm.js} +4 -3
- 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 +279 -251
- package/dist/esm/src/lib/types.d.ts +1 -1
- package/dist/esm/src/options/HelpOption.d.ts +4 -2
- package/package.json +4 -3
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
|
"⠰",
|
|
@@ -744,23 +767,30 @@ function Se(e = "", t = [
|
|
|
744
767
|
"⠋",
|
|
745
768
|
"⠉"
|
|
746
769
|
], n = 100) {
|
|
747
|
-
let r = e, i = null, a =
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
770
|
+
let r = e, i = null, a = e.length, o = 0, s = (e) => {
|
|
771
|
+
let t = process.stdout.columns || 80, n = e + 2, r = Math.max(1, Math.ceil(n / t));
|
|
772
|
+
if (process.stdout.isTTY && process.stdout.clearLine && process.stdout.moveCursor) {
|
|
773
|
+
r > 1 && process.stdout.moveCursor(0, -(r - 1));
|
|
774
|
+
for (let e = 0; e < r; e++) process.stdout.cursorTo(0), process.stdout.clearLine(1), e < r - 1 && process.stdout.moveCursor(0, 1);
|
|
775
|
+
r > 1 && process.stdout.moveCursor(0, -(r - 1)), process.stdout.cursorTo(0);
|
|
776
|
+
} else process.stdout.write("\r" + " ".repeat(e + 5) + "\r");
|
|
777
|
+
}, c = setInterval(function() {
|
|
778
|
+
i !== null && (s(Math.max(i.length, r.length)), i = null), process.stdout.write("\r" + t[o++] + " " + r), o %= t.length;
|
|
779
|
+
}, n), l = () => {
|
|
780
|
+
clearInterval(c), s(a);
|
|
751
781
|
};
|
|
752
782
|
return {
|
|
753
|
-
[Symbol.dispose]:
|
|
754
|
-
[Symbol.asyncDispose]:
|
|
783
|
+
[Symbol.dispose]: l,
|
|
784
|
+
[Symbol.asyncDispose]: l,
|
|
755
785
|
updateText: (e) => {
|
|
756
|
-
i = r, r = e;
|
|
786
|
+
i = r, r = e, a = Math.max(a, e.length);
|
|
757
787
|
},
|
|
758
|
-
stop:
|
|
788
|
+
stop: l
|
|
759
789
|
};
|
|
760
790
|
}
|
|
761
791
|
//#endregion
|
|
762
792
|
//#region src/ux/progressBar.ts
|
|
763
|
-
function
|
|
793
|
+
function ke(e, t) {
|
|
764
794
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
765
795
|
if (o) return;
|
|
766
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}`;
|
|
@@ -782,7 +812,7 @@ function Ce(e, t) {
|
|
|
782
812
|
}
|
|
783
813
|
//#endregion
|
|
784
814
|
//#region src/ux/table.ts
|
|
785
|
-
function
|
|
815
|
+
function Ae(t, n) {
|
|
786
816
|
if (t.length === 0) return;
|
|
787
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) => {
|
|
788
818
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -808,71 +838,71 @@ function we(t, n) {
|
|
|
808
838
|
}
|
|
809
839
|
//#endregion
|
|
810
840
|
//#region src/ux/index.ts
|
|
811
|
-
var
|
|
841
|
+
var Y = class {
|
|
812
842
|
askForConfirmation(e, t) {
|
|
813
|
-
return
|
|
843
|
+
return G(e, t);
|
|
814
844
|
}
|
|
815
845
|
askForInput(e, t) {
|
|
816
|
-
return
|
|
846
|
+
return ye(e, t);
|
|
817
847
|
}
|
|
818
848
|
askForPassword(e, t) {
|
|
819
|
-
return
|
|
849
|
+
return Se(e, t);
|
|
820
850
|
}
|
|
821
851
|
askForNumber(e, t) {
|
|
822
|
-
return
|
|
852
|
+
return xe(e, t);
|
|
823
853
|
}
|
|
824
854
|
askForSelect(e, t, n) {
|
|
825
|
-
return
|
|
855
|
+
return Te(e, t, n);
|
|
826
856
|
}
|
|
827
857
|
askForCheckbox(e, t, n) {
|
|
828
|
-
return
|
|
858
|
+
return W(e, t, n);
|
|
829
859
|
}
|
|
830
860
|
askForSearch(e, t, n) {
|
|
831
|
-
return
|
|
861
|
+
return we(e, t, n);
|
|
832
862
|
}
|
|
833
863
|
askForList(e, t) {
|
|
834
|
-
return
|
|
864
|
+
return be(e, t);
|
|
835
865
|
}
|
|
836
866
|
askForToggle(e, t) {
|
|
837
|
-
return
|
|
867
|
+
return Ee(e, t);
|
|
838
868
|
}
|
|
839
869
|
askForEditor(e, t) {
|
|
840
|
-
return
|
|
870
|
+
return K(e, t);
|
|
841
871
|
}
|
|
842
872
|
askForRawList(e, t, n) {
|
|
843
|
-
return
|
|
873
|
+
return Ce(e, t, n);
|
|
844
874
|
}
|
|
845
875
|
askForExpand(e, t, n) {
|
|
846
|
-
return
|
|
876
|
+
return q(e, t, n);
|
|
847
877
|
}
|
|
848
878
|
askForFile(e, t) {
|
|
849
|
-
return
|
|
879
|
+
return J(e, {
|
|
850
880
|
...t,
|
|
851
881
|
type: "file"
|
|
852
882
|
});
|
|
853
883
|
}
|
|
854
884
|
askForDirectory(e, t) {
|
|
855
|
-
return
|
|
885
|
+
return J(e, {
|
|
856
886
|
...t,
|
|
857
887
|
type: "directory"
|
|
858
888
|
});
|
|
859
889
|
}
|
|
860
890
|
askForFileSelector(e, t) {
|
|
861
|
-
return
|
|
891
|
+
return J(e, t);
|
|
862
892
|
}
|
|
863
893
|
keyValue(e, t) {
|
|
864
|
-
return
|
|
894
|
+
return De(e, t);
|
|
865
895
|
}
|
|
866
896
|
table(e, t) {
|
|
867
|
-
return
|
|
897
|
+
return Ae(e, t);
|
|
868
898
|
}
|
|
869
899
|
newProgressBar(e, t) {
|
|
870
|
-
return
|
|
900
|
+
return ke(e, t);
|
|
871
901
|
}
|
|
872
902
|
newLoader(e, t, n) {
|
|
873
|
-
return
|
|
903
|
+
return Oe(e, t, n);
|
|
874
904
|
}
|
|
875
|
-
},
|
|
905
|
+
}, X = class {
|
|
876
906
|
static $type = "BobCommand";
|
|
877
907
|
static command = "";
|
|
878
908
|
static description = "";
|
|
@@ -890,9 +920,9 @@ var X = class {
|
|
|
890
920
|
logger;
|
|
891
921
|
ux;
|
|
892
922
|
parser;
|
|
893
|
-
static baseFlags = { help:
|
|
923
|
+
static baseFlags = { help: H };
|
|
894
924
|
newCommandParser(e) {
|
|
895
|
-
return new
|
|
925
|
+
return new k({
|
|
896
926
|
ux: e.ux,
|
|
897
927
|
ctx: e.ctx,
|
|
898
928
|
flags: e.flags,
|
|
@@ -901,7 +931,7 @@ var X = class {
|
|
|
901
931
|
});
|
|
902
932
|
}
|
|
903
933
|
newUX() {
|
|
904
|
-
return new
|
|
934
|
+
return new Y();
|
|
905
935
|
}
|
|
906
936
|
async run(e) {
|
|
907
937
|
let t = this.constructor;
|
|
@@ -950,22 +980,22 @@ var X = class {
|
|
|
950
980
|
};
|
|
951
981
|
//#endregion
|
|
952
982
|
//#region src/lib/helpers.ts
|
|
953
|
-
function
|
|
983
|
+
function je(e) {
|
|
954
984
|
return typeof e == "object" && !!e && "$type" in e && e.$type === "BobError";
|
|
955
985
|
}
|
|
956
|
-
function
|
|
957
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
986
|
+
function Z(e) {
|
|
987
|
+
return typeof e == "function" ? e.prototype instanceof X || e.$type === "BobCommand" : !1;
|
|
958
988
|
}
|
|
959
989
|
//#endregion
|
|
960
990
|
//#region src/CommandRegistry.ts
|
|
961
|
-
var
|
|
991
|
+
var Q = class {
|
|
962
992
|
commands = {};
|
|
963
993
|
aliases = {};
|
|
964
994
|
ux;
|
|
965
995
|
logger;
|
|
966
996
|
stringSimilarity;
|
|
967
997
|
constructor(e) {
|
|
968
|
-
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();
|
|
969
999
|
}
|
|
970
1000
|
getAvailableCommands() {
|
|
971
1001
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -976,7 +1006,7 @@ var Ee = class {
|
|
|
976
1006
|
importFile = async (e) => (await import(e)).default;
|
|
977
1007
|
commandResolver = async (e) => {
|
|
978
1008
|
let t = await this.importFile(e);
|
|
979
|
-
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;
|
|
980
1010
|
};
|
|
981
1011
|
withCommandResolver(e) {
|
|
982
1012
|
return this.commandResolver = e, this;
|
|
@@ -985,7 +1015,7 @@ var Ee = class {
|
|
|
985
1015
|
return this.importFile = e, this;
|
|
986
1016
|
}
|
|
987
1017
|
registerCommand(e, t = !1) {
|
|
988
|
-
if (!
|
|
1018
|
+
if (!Z(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
989
1019
|
let n = e.command;
|
|
990
1020
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
991
1021
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1000,7 +1030,7 @@ var Ee = class {
|
|
|
1000
1030
|
async loadCommandsPath(e) {
|
|
1001
1031
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1002
1032
|
let e = await this.commandResolver(t);
|
|
1003
|
-
|
|
1033
|
+
Z(e) && this.registerCommand(e);
|
|
1004
1034
|
} catch (e) {
|
|
1005
1035
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1006
1036
|
}
|
|
@@ -1012,10 +1042,10 @@ var Ee = class {
|
|
|
1012
1042
|
if (!i) {
|
|
1013
1043
|
let r = await this.suggestCommand(t);
|
|
1014
1044
|
if (r) return await this.runCommand(e, r, ...n);
|
|
1015
|
-
throw new
|
|
1045
|
+
throw new y(t);
|
|
1016
1046
|
}
|
|
1017
1047
|
r = new i();
|
|
1018
|
-
} else r =
|
|
1048
|
+
} else r = Z(t) ? new t() : t;
|
|
1019
1049
|
return await r.run({
|
|
1020
1050
|
ctx: e,
|
|
1021
1051
|
logger: this.logger,
|
|
@@ -1028,15 +1058,11 @@ var Ee = class {
|
|
|
1028
1058
|
let e = n[i];
|
|
1029
1059
|
return await this.askRunSimilarCommand(t, e) ? e : null;
|
|
1030
1060
|
}
|
|
1031
|
-
if (o.length) {
|
|
1032
|
-
|
|
1033
|
-
let n = await this.ux.askForSelect(e.green("Did you mean to run one of these commands instead?"), o);
|
|
1034
|
-
if (n) return n;
|
|
1035
|
-
}
|
|
1036
|
-
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);
|
|
1037
1063
|
}
|
|
1038
1064
|
async askRunSimilarCommand(t, n) {
|
|
1039
|
-
return this.
|
|
1065
|
+
return this.ux.askForConfirmation(`${e.red("unknown command")} ${e.bold.yellow(`'${t}'`)} ${e.dim("—")} did you mean ${e.bold.green(`'${n}'`)}?`);
|
|
1040
1066
|
}
|
|
1041
1067
|
async *listCommandsFiles(e) {
|
|
1042
1068
|
let r = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
@@ -1049,23 +1075,25 @@ var Ee = class {
|
|
|
1049
1075
|
}
|
|
1050
1076
|
}
|
|
1051
1077
|
}
|
|
1052
|
-
},
|
|
1078
|
+
}, Me = class {
|
|
1053
1079
|
logger;
|
|
1054
1080
|
constructor(e) {
|
|
1055
1081
|
this.logger = e;
|
|
1056
1082
|
}
|
|
1057
1083
|
handle(e) {
|
|
1058
|
-
if (
|
|
1084
|
+
if (je(e)) return e.pretty(this.logger), -1;
|
|
1059
1085
|
throw e;
|
|
1060
1086
|
}
|
|
1061
|
-
},
|
|
1087
|
+
}, Ne, Pe = class extends X {
|
|
1062
1088
|
static command = "help";
|
|
1063
1089
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1064
1090
|
constructor(e) {
|
|
1065
1091
|
super(), this.opts = e;
|
|
1066
1092
|
}
|
|
1067
1093
|
async handle() {
|
|
1068
|
-
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0"
|
|
1094
|
+
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0";
|
|
1095
|
+
Ne ??= (await import("../package-DtqoIUbm.js"))?.default?.version ?? "0.0.0";
|
|
1096
|
+
let i = Ne;
|
|
1069
1097
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1070
1098
|
|
|
1071
1099
|
${e.yellow("Usage")}:
|
|
@@ -1087,25 +1115,25 @@ ${e.yellow("Available commands")}:
|
|
|
1087
1115
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1088
1116
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1089
1117
|
for (let t of i) {
|
|
1090
|
-
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)));
|
|
1091
1119
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1092
1120
|
}
|
|
1093
1121
|
}
|
|
1094
1122
|
}
|
|
1095
|
-
},
|
|
1123
|
+
}, Fe = class {
|
|
1096
1124
|
ctx;
|
|
1097
1125
|
logger;
|
|
1098
1126
|
commandRegistry;
|
|
1099
1127
|
exceptionHandler;
|
|
1100
1128
|
helpCommand;
|
|
1101
1129
|
newCommandRegistry(e) {
|
|
1102
|
-
return new
|
|
1130
|
+
return new Q(e);
|
|
1103
1131
|
}
|
|
1104
1132
|
newHelpCommand(e) {
|
|
1105
|
-
return new
|
|
1133
|
+
return new Pe(e);
|
|
1106
1134
|
}
|
|
1107
1135
|
newExceptionHandler(e) {
|
|
1108
|
-
return new
|
|
1136
|
+
return new Me(e.logger);
|
|
1109
1137
|
}
|
|
1110
1138
|
constructor(e = {}) {
|
|
1111
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({
|
|
@@ -1163,27 +1191,27 @@ ${e.yellow("Available commands")}:
|
|
|
1163
1191
|
}
|
|
1164
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}`];
|
|
1165
1193
|
let u;
|
|
1166
|
-
return u = r ? s ?
|
|
1194
|
+
return u = r ? s ? B.boolean({
|
|
1167
1195
|
description: i,
|
|
1168
1196
|
alias: o,
|
|
1169
1197
|
...a === void 0 ? {} : { default: a }
|
|
1170
|
-
}) : c ?
|
|
1198
|
+
}) : c ? B.string({
|
|
1171
1199
|
description: i,
|
|
1172
1200
|
alias: o,
|
|
1173
1201
|
multiple: !0,
|
|
1174
1202
|
...l ? { required: !0 } : {},
|
|
1175
1203
|
default: a ?? []
|
|
1176
|
-
}) :
|
|
1204
|
+
}) : B.string({
|
|
1177
1205
|
description: i,
|
|
1178
1206
|
alias: o,
|
|
1179
1207
|
...l ? { required: !0 } : {},
|
|
1180
1208
|
...a === void 0 ? {} : { default: a }
|
|
1181
|
-
}) : c ?
|
|
1209
|
+
}) : c ? z.string({
|
|
1182
1210
|
description: i,
|
|
1183
1211
|
multiple: !0,
|
|
1184
1212
|
...l ? { required: !0 } : {},
|
|
1185
1213
|
default: a ?? []
|
|
1186
|
-
}) :
|
|
1214
|
+
}) : z.string({
|
|
1187
1215
|
description: i,
|
|
1188
1216
|
...l ? { required: !0 } : {},
|
|
1189
1217
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1193,7 +1221,7 @@ ${e.yellow("Available commands")}:
|
|
|
1193
1221
|
definition: u
|
|
1194
1222
|
};
|
|
1195
1223
|
}
|
|
1196
|
-
},
|
|
1224
|
+
}, Ie = class extends X {
|
|
1197
1225
|
static signature = "";
|
|
1198
1226
|
static helperDefinitions = {};
|
|
1199
1227
|
static get command() {
|
|
@@ -1221,4 +1249,4 @@ ${e.yellow("Available commands")}:
|
|
|
1221
1249
|
}
|
|
1222
1250
|
};
|
|
1223
1251
|
//#endregion
|
|
1224
|
-
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 };
|