convoker 0.1.0 → 0.3.0
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/README.md +2 -2
- package/dist/chunks/{error-Cj2qDfOl.js → error-CyKscMUD.js} +5 -5
- package/dist/chunks/{index-G2nVXKup.js → index-BluQjWvw.js} +2 -2
- package/dist/chunks/{input-COjWPD53.js → input-WNu16aNE.js} +38 -35
- package/dist/chunks/{standard-schema-Dn3nwAxU.js → standard-schema-BHKzvwIS.js} +1 -1
- package/dist/command.d.ts +48 -20
- package/dist/command.js +220 -169
- package/dist/error.d.ts +78 -46
- package/dist/error.js +6 -6
- package/dist/index.d.ts +58 -30
- package/dist/index.js +3 -3
- package/dist/input.d.ts +6 -2
- package/dist/input.js +2 -2
- package/dist/prompt.js +3 -3
- package/package.json +1 -1
package/dist/command.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { D as
|
|
2
|
-
import { s as
|
|
3
|
-
import { m as
|
|
4
|
-
import { M as
|
|
5
|
-
import { P as
|
|
6
|
-
async function
|
|
7
|
-
if (
|
|
8
|
-
const { Writable:
|
|
9
|
-
return
|
|
1
|
+
import { D as V, b, c as v, g as O } from "./chunks/color-CiruG_zQ.js";
|
|
2
|
+
import { s as R } from "./chunks/index-BluQjWvw.js";
|
|
3
|
+
import { m as z, i as A, b as j, a as P } from "./chunks/utils-DdmSEjLc.js";
|
|
4
|
+
import { M as U, a as J, T as N, C as K, H as L, U as x } from "./chunks/error-CyKscMUD.js";
|
|
5
|
+
import { P as q, c as G, O as F } from "./chunks/input-WNu16aNE.js";
|
|
6
|
+
async function Q() {
|
|
7
|
+
if (j && process.stdout?.writable) {
|
|
8
|
+
const { Writable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
|
|
9
|
+
return r.toWeb(process.stdout);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
12
|
-
write(
|
|
13
|
-
console.log(String(
|
|
11
|
+
return A && Deno.stdout?.writable ? Deno.stdout.writable : P && Bun.stdout ? Bun.stdout : new WritableStream({
|
|
12
|
+
write(r) {
|
|
13
|
+
console.log(String(r));
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
async function
|
|
18
|
-
if (
|
|
19
|
-
const { Writable:
|
|
20
|
-
return
|
|
17
|
+
async function X() {
|
|
18
|
+
if (j && process.stderr?.writable) {
|
|
19
|
+
const { Writable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
|
|
20
|
+
return r.toWeb(process.stderr);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
23
|
-
write(
|
|
24
|
-
console.error(String(
|
|
22
|
+
return A && Deno.stderr?.writable ? Deno.stderr.writable : P && Bun.stderr ? Bun.stderr : new WritableStream({
|
|
23
|
+
write(r) {
|
|
24
|
+
console.error(String(r));
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
async function
|
|
29
|
-
if (
|
|
30
|
-
const { Readable:
|
|
31
|
-
return
|
|
28
|
+
async function Y() {
|
|
29
|
+
if (j && process.stdin?.readable) {
|
|
30
|
+
const { Readable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
|
|
31
|
+
return r.toWeb(process.stdin);
|
|
32
32
|
}
|
|
33
|
-
return
|
|
34
|
-
start(
|
|
35
|
-
|
|
33
|
+
return A && Deno.stdin?.readable ? Deno.stdin.readable : P ? Bun.stdin.stream() : new ReadableStream({
|
|
34
|
+
start(r) {
|
|
35
|
+
r.close();
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
let m =
|
|
40
|
-
function
|
|
41
|
-
m =
|
|
39
|
+
let m = V, g;
|
|
40
|
+
function H(r) {
|
|
41
|
+
m = r;
|
|
42
42
|
}
|
|
43
|
-
async function
|
|
44
|
-
g =
|
|
43
|
+
async function _(r) {
|
|
44
|
+
g = z(
|
|
45
45
|
{
|
|
46
46
|
format: "text",
|
|
47
|
-
stdout: await
|
|
48
|
-
stderr: await
|
|
49
|
-
stdin: await
|
|
47
|
+
stdout: await Q(),
|
|
48
|
+
stderr: await X(),
|
|
49
|
+
stdin: await Y()
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
r
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
async function
|
|
55
|
-
await
|
|
54
|
+
async function Z() {
|
|
55
|
+
await _({});
|
|
56
56
|
}
|
|
57
|
-
function S(
|
|
58
|
-
const e = (/* @__PURE__ */ new Date()).toISOString(),
|
|
57
|
+
function S(r, ...t) {
|
|
58
|
+
const e = (/* @__PURE__ */ new Date()).toISOString(), n = t.map((i) => typeof i == "string" ? i : JSON.stringify(i, null, 2)).join(" ");
|
|
59
59
|
switch (g.format) {
|
|
60
60
|
case "json":
|
|
61
|
-
return JSON.stringify({ timestamp: e, level:
|
|
61
|
+
return JSON.stringify({ timestamp: e, level: r, message: n }) + `
|
|
62
62
|
`;
|
|
63
63
|
case "xml":
|
|
64
64
|
return `<log>
|
|
65
65
|
<timestamp>${e}</timestamp>
|
|
66
|
-
<level>${
|
|
67
|
-
<message>${
|
|
66
|
+
<level>${r}</level>
|
|
67
|
+
<message>${n}</message>
|
|
68
68
|
</log>
|
|
69
69
|
`;
|
|
70
70
|
case "yaml":
|
|
71
71
|
return `- timestamp: ${e}
|
|
72
|
-
level: ${
|
|
73
|
-
message: "${
|
|
72
|
+
level: ${r}
|
|
73
|
+
message: "${n.replace(/"/g, '\\"')}"
|
|
74
74
|
`;
|
|
75
75
|
case "csv":
|
|
76
|
-
return `"${e}","${
|
|
76
|
+
return `"${e}","${r}","${n.replace(/"/g, '""')}"
|
|
77
77
|
`;
|
|
78
78
|
case "text":
|
|
79
79
|
default:
|
|
80
|
-
return `[${e}] [${
|
|
80
|
+
return `[${e}] [${r.toUpperCase()}] ${n}
|
|
81
81
|
`;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
function E(
|
|
85
|
-
switch (
|
|
84
|
+
function E(r, t) {
|
|
85
|
+
switch (r) {
|
|
86
86
|
case "trace":
|
|
87
87
|
return m.secondary ? m.secondary(t) : t;
|
|
88
88
|
case "info":
|
|
@@ -97,54 +97,54 @@ function E(n, t) {
|
|
|
97
97
|
return t;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
async function k(
|
|
101
|
-
const e =
|
|
100
|
+
async function k(r, t) {
|
|
101
|
+
const e = r.getWriter();
|
|
102
102
|
try {
|
|
103
103
|
await e.write(t);
|
|
104
104
|
} finally {
|
|
105
105
|
e.releaseLock();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
async function
|
|
109
|
-
const t = S("trace", ...
|
|
108
|
+
async function ee(...r) {
|
|
109
|
+
const t = S("trace", ...r), e = E("trace", t);
|
|
110
110
|
await k(g.stdout, e);
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
113
|
-
const t = S("info", ...
|
|
112
|
+
async function te(...r) {
|
|
113
|
+
const t = S("info", ...r), e = E("info", t);
|
|
114
114
|
await k(g.stdout, e);
|
|
115
115
|
}
|
|
116
|
-
async function
|
|
117
|
-
const t = S("warn", ...
|
|
116
|
+
async function ne(...r) {
|
|
117
|
+
const t = S("warn", ...r), e = E("warn", t);
|
|
118
118
|
await k(g.stdout, e);
|
|
119
119
|
}
|
|
120
|
-
async function
|
|
121
|
-
const t = S("error", ...
|
|
120
|
+
async function re(...r) {
|
|
121
|
+
const t = S("error", ...r), e = E("error", t);
|
|
122
122
|
await k(g.stderr, e);
|
|
123
123
|
}
|
|
124
|
-
async function
|
|
125
|
-
const t = S("fatal", ...
|
|
126
|
-
await k(g.stderr, e),
|
|
124
|
+
async function se(...r) {
|
|
125
|
+
const t = S("fatal", ...r), e = E("fatal", t);
|
|
126
|
+
await k(g.stderr, e), A ? Deno.exit(-1) : (j || P) && process.exit(-1);
|
|
127
127
|
}
|
|
128
|
-
const
|
|
128
|
+
const de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
129
129
|
__proto__: null,
|
|
130
|
-
error:
|
|
131
|
-
fatal:
|
|
132
|
-
info:
|
|
133
|
-
setConfig:
|
|
134
|
-
setTheme:
|
|
135
|
-
setup:
|
|
136
|
-
trace:
|
|
137
|
-
warn:
|
|
130
|
+
error: re,
|
|
131
|
+
fatal: se,
|
|
132
|
+
info: te,
|
|
133
|
+
setConfig: _,
|
|
134
|
+
setTheme: H,
|
|
135
|
+
setup: Z,
|
|
136
|
+
trace: ee,
|
|
137
|
+
warn: ne
|
|
138
138
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
139
|
-
class
|
|
139
|
+
class B {
|
|
140
140
|
/**
|
|
141
141
|
* Creates a new command.
|
|
142
142
|
* @param names The names (aliases).
|
|
143
143
|
* @param desc The description.
|
|
144
144
|
* @param version The version.
|
|
145
145
|
*/
|
|
146
|
-
constructor(t, e,
|
|
147
|
-
this.$children = /* @__PURE__ */ new Map(), this.$allowUnknownOptions = !1, this.$input = {}, this.$fn = void 0, this.$errorFn = void 0, this.$names = Array.isArray(t) ? t : [t], this.$description = e, this.$version =
|
|
146
|
+
constructor(t, e, n) {
|
|
147
|
+
this.$children = /* @__PURE__ */ new Map(), this.$allowUnknownOptions = !1, this.$allowSurpassArgLimit = !1, this.$input = {}, this.$fn = void 0, this.$middlewares = [], this.$errorFn = void 0, this.$names = Array.isArray(t) ? t : [t], this.$description = e, this.$version = n;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Adds a set of aliases to this command.
|
|
@@ -178,6 +178,14 @@ class F {
|
|
|
178
178
|
input(t) {
|
|
179
179
|
return this.$input = t, this;
|
|
180
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Adds a chain of middlewares.
|
|
183
|
+
* @param fns The middlewares to use.
|
|
184
|
+
* @returns this
|
|
185
|
+
*/
|
|
186
|
+
use(...t) {
|
|
187
|
+
return this.$middlewares.push(...t), this;
|
|
188
|
+
}
|
|
181
189
|
/**
|
|
182
190
|
* Sets the action function for this command.
|
|
183
191
|
* @param fn The action.
|
|
@@ -202,17 +210,17 @@ class F {
|
|
|
202
210
|
add(t) {
|
|
203
211
|
t.$parent = this;
|
|
204
212
|
const e = { command: t, alias: t.$names[0] };
|
|
205
|
-
for (let
|
|
206
|
-
|
|
213
|
+
for (let n = 0; n < t.$names.length; n++)
|
|
214
|
+
n === 0 && this.$children.set(t.$names[n], { command: t }), this.$children.set(t.$names[n], e);
|
|
207
215
|
return this;
|
|
208
216
|
}
|
|
209
|
-
subCommand(t, e,
|
|
217
|
+
subCommand(t, e, n) {
|
|
210
218
|
if (typeof e == "function") {
|
|
211
|
-
const
|
|
212
|
-
return e(
|
|
219
|
+
const a = new B(t);
|
|
220
|
+
return e(a), this.add(a), this;
|
|
213
221
|
}
|
|
214
|
-
const
|
|
215
|
-
return this.add(
|
|
222
|
+
const i = new B(t, e, n);
|
|
223
|
+
return this.add(i), i;
|
|
216
224
|
}
|
|
217
225
|
/**
|
|
218
226
|
* Allows unknown options.
|
|
@@ -227,81 +235,89 @@ class F {
|
|
|
227
235
|
* @returns A parse result.
|
|
228
236
|
*/
|
|
229
237
|
async parse(t) {
|
|
230
|
-
let e = this,
|
|
231
|
-
const
|
|
232
|
-
function u
|
|
233
|
-
const l =
|
|
234
|
-
return l ? l.value : (!e.$allowUnknownOptions && !
|
|
238
|
+
let e = this, n = !1;
|
|
239
|
+
const i = {}, a = [], f = {}, s = [], c = e.buildInputMap();
|
|
240
|
+
function d(u, o) {
|
|
241
|
+
const l = c.get(u);
|
|
242
|
+
return l ? l.value : (!e.$allowUnknownOptions && !o && s.push(new x(e, u)), null);
|
|
235
243
|
}
|
|
236
|
-
function
|
|
237
|
-
|
|
244
|
+
function h(u, o, l) {
|
|
245
|
+
o.$kind === "boolean" ? f[u] = "true" : l !== void 0 && (f[u] = l);
|
|
238
246
|
}
|
|
239
|
-
let
|
|
240
|
-
for (let
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
const [l, w] =
|
|
247
|
+
let p = !1, W = !1;
|
|
248
|
+
for (let u = 0; u < t.length; u++) {
|
|
249
|
+
const o = t[u];
|
|
250
|
+
if (o.startsWith("--")) {
|
|
251
|
+
const [l, w] = o.slice(2).split("=");
|
|
244
252
|
let y = !1;
|
|
245
|
-
l === "help" ? (
|
|
246
|
-
const $ =
|
|
247
|
-
$ && (w === void 0 ?
|
|
253
|
+
l === "help" ? (W = !0, y = !0) : l === "version" && (p = !0, y = !0);
|
|
254
|
+
const $ = d(l, y);
|
|
255
|
+
$ && (w === void 0 ? h(
|
|
248
256
|
l,
|
|
249
257
|
$,
|
|
250
|
-
$.$kind === "boolean" ? void 0 : t[++
|
|
251
|
-
) :
|
|
252
|
-
} else if (
|
|
253
|
-
const [l, w] =
|
|
258
|
+
$.$kind === "boolean" ? void 0 : t[++u]
|
|
259
|
+
) : h(l, $, w));
|
|
260
|
+
} else if (o.startsWith("-")) {
|
|
261
|
+
const [l, w] = o.slice(1).split("="), y = l.split("");
|
|
254
262
|
let $ = w;
|
|
255
263
|
for (const D of y) {
|
|
256
|
-
let
|
|
257
|
-
D === "h" ? (
|
|
258
|
-
const
|
|
259
|
-
|
|
264
|
+
let C = !1;
|
|
265
|
+
D === "h" ? (W = !0, C = !0) : D === "V" && (p = !0, C = !0);
|
|
266
|
+
const T = d(D, C);
|
|
267
|
+
T && (T.$kind !== "boolean" && $ === void 0 && ($ = t[++u]), h(D, T, $), $ = void 0);
|
|
260
268
|
}
|
|
261
269
|
} else
|
|
262
|
-
e.$children.has(
|
|
270
|
+
e.$children.has(o) && !n ? (e = e.$children.get(o).command, e.$theme && (R(e.$theme), H(e.$theme))) : (n = !0, a.push(o));
|
|
263
271
|
}
|
|
264
|
-
let
|
|
265
|
-
for (const
|
|
266
|
-
const
|
|
272
|
+
let M = 0;
|
|
273
|
+
for (const u in e.$input) {
|
|
274
|
+
const o = e.$input[u];
|
|
267
275
|
let l;
|
|
268
|
-
if (
|
|
269
|
-
l =
|
|
276
|
+
if (o instanceof q)
|
|
277
|
+
o.$list ? (l = a.slice(M), M = a.length, !e.$allowSurpassArgLimit && l.length === 0 && o.$required && s.push(new U(e, u, o))) : (l = a[M++], l === void 0 && o.$required && s.push(new U(e, u, o)));
|
|
270
278
|
else
|
|
271
|
-
for (const w of
|
|
272
|
-
if (
|
|
273
|
-
l =
|
|
279
|
+
for (const w of o.$names)
|
|
280
|
+
if (f[w] !== void 0) {
|
|
281
|
+
l = o.$list ? f[w].split(o.$separator ?? ",") : f[w];
|
|
274
282
|
break;
|
|
275
283
|
}
|
|
276
|
-
l !== void 0 ?
|
|
284
|
+
l !== void 0 ? i[u] = await G(o.$kind, l) : o.$default !== void 0 ? i[u] = o.$default : o.$required && (o instanceof F ? s.push(new J(e, u, o)) : s.push(new U(e, u, o)));
|
|
277
285
|
}
|
|
278
|
-
|
|
279
|
-
|
|
286
|
+
const I = a.slice(M);
|
|
287
|
+
return !e.$allowSurpassArgLimit && I.length > 0 && s.push(new N(e)), {
|
|
288
|
+
input: i,
|
|
280
289
|
command: e,
|
|
281
290
|
errors: s,
|
|
282
|
-
isVersion:
|
|
283
|
-
isHelp:
|
|
291
|
+
isVersion: p,
|
|
292
|
+
isHelp: W
|
|
284
293
|
};
|
|
285
294
|
}
|
|
286
295
|
buildInputMap(t) {
|
|
287
296
|
const e = /* @__PURE__ */ new Map();
|
|
288
|
-
let
|
|
289
|
-
for (const
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
e.set(
|
|
297
|
+
let n = 0;
|
|
298
|
+
for (const i in this.$input) {
|
|
299
|
+
const a = this.$input[i];
|
|
300
|
+
if (a instanceof q)
|
|
301
|
+
e.set(n++, { value: a, key: i });
|
|
293
302
|
else
|
|
294
|
-
for (const
|
|
295
|
-
e.set(
|
|
303
|
+
for (const f of a.$names)
|
|
304
|
+
e.set(f, { value: a, key: i });
|
|
296
305
|
}
|
|
297
306
|
if (!t)
|
|
298
|
-
for (const [
|
|
299
|
-
e.set(
|
|
300
|
-
for (const [, { command:
|
|
301
|
-
for (const [
|
|
302
|
-
e.set(
|
|
307
|
+
for (const [i, a] of this.$parent?.buildInputMap() ?? [])
|
|
308
|
+
e.set(i, a);
|
|
309
|
+
for (const [, { command: i }] of this.$children)
|
|
310
|
+
for (const [a, f] of i.buildInputMap(!0))
|
|
311
|
+
e.set(a, f);
|
|
303
312
|
return e;
|
|
304
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Allows surpassing the amount of arguments specified.
|
|
316
|
+
* @returns this
|
|
317
|
+
*/
|
|
318
|
+
allowSurpassArgLimit() {
|
|
319
|
+
return this.$allowSurpassArgLimit = !0, this;
|
|
320
|
+
}
|
|
305
321
|
/**
|
|
306
322
|
* Gets the full command path (name including parents).
|
|
307
323
|
* @returns The full command path.
|
|
@@ -319,51 +335,51 @@ class F {
|
|
|
319
335
|
*/
|
|
320
336
|
defaultErrorScreen(t) {
|
|
321
337
|
let e = !1;
|
|
322
|
-
const
|
|
338
|
+
const n = [];
|
|
323
339
|
for (const s of t)
|
|
324
|
-
s instanceof
|
|
325
|
-
if (
|
|
340
|
+
s instanceof K ? (s instanceof L || s.print(), e = !0) : n.push(s);
|
|
341
|
+
if (n.length) throw n[0];
|
|
326
342
|
if (!e) return;
|
|
327
|
-
const
|
|
343
|
+
const i = (s, c) => s.padEnd(c, " ");
|
|
328
344
|
console.log(
|
|
329
|
-
`${b("usage:")} ${v(this.fullCommandPath())} ${
|
|
345
|
+
`${b("usage:")} ${v(this.fullCommandPath())} ${O("[options] [arguments]")}`
|
|
330
346
|
), this.$description && console.log(`${this.$description}`), this.$version && console.log(`${b("version")} ${this.$version}`);
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
347
|
+
const a = Object.entries(this.$input).filter(([, s]) => s instanceof F).map(([s, c]) => ({ key: s, entry: c }));
|
|
348
|
+
if (a.length > 0) {
|
|
333
349
|
console.log(b("options:"));
|
|
334
350
|
const s = Math.max(
|
|
335
|
-
...
|
|
351
|
+
...a.map(({ entry: c }) => c.$names.join(", ").length)
|
|
336
352
|
);
|
|
337
|
-
for (const { entry:
|
|
338
|
-
const
|
|
339
|
-
console.log(
|
|
353
|
+
for (const { entry: c } of a) {
|
|
354
|
+
const d = c.$names.map((p) => p.length === 1 ? `-${p}` : `--${p}`).join(", "), h = ` ${v(i(d, s + 4))}${O(c.$description ?? "")}`;
|
|
355
|
+
console.log(h);
|
|
340
356
|
}
|
|
341
357
|
}
|
|
342
|
-
const
|
|
358
|
+
const f = Object.entries(this.$input).filter(([, s]) => s instanceof q).map(([s, c]) => ({
|
|
343
359
|
key: s,
|
|
344
|
-
entry:
|
|
360
|
+
entry: c
|
|
345
361
|
}));
|
|
346
|
-
if (
|
|
362
|
+
if (f.length > 0) {
|
|
347
363
|
console.log(b("arguments:"));
|
|
348
|
-
const s = Math.max(...
|
|
349
|
-
for (const { key:
|
|
350
|
-
const
|
|
351
|
-
console.log(
|
|
364
|
+
const s = Math.max(...f.map(({ key: c }) => c.length));
|
|
365
|
+
for (const { key: c, entry: d } of f) {
|
|
366
|
+
const h = d.$required ? `<${c}>` : `[${c}]`, p = ` ${v(i(h, s + 4))}${O(d.$description ?? "")}`;
|
|
367
|
+
console.log(p);
|
|
352
368
|
}
|
|
353
369
|
}
|
|
354
370
|
if (this.$children.size > 0) {
|
|
355
371
|
console.log(b("sub commands:"));
|
|
356
372
|
const s = Array.from(
|
|
357
373
|
new Map(
|
|
358
|
-
[...this.$children.values()].map((
|
|
359
|
-
|
|
360
|
-
|
|
374
|
+
[...this.$children.values()].map((d) => [
|
|
375
|
+
d.command.$names[0],
|
|
376
|
+
d.command
|
|
361
377
|
])
|
|
362
378
|
).values()
|
|
363
|
-
),
|
|
364
|
-
for (const
|
|
365
|
-
const
|
|
366
|
-
console.log(
|
|
379
|
+
), c = Math.max(...s.map((d) => d.$names[0].length));
|
|
380
|
+
for (const d of s) {
|
|
381
|
+
const h = ` ${v(i(d.$names[0], c + 4))}${O(d.$description) ?? ""}`;
|
|
382
|
+
console.log(h);
|
|
367
383
|
}
|
|
368
384
|
console.log(), console.log(
|
|
369
385
|
`run '${v(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`
|
|
@@ -377,10 +393,10 @@ class F {
|
|
|
377
393
|
* @returns this
|
|
378
394
|
*/
|
|
379
395
|
async handleErrors(t, e) {
|
|
380
|
-
let
|
|
381
|
-
for (; !
|
|
382
|
-
|
|
383
|
-
return
|
|
396
|
+
let n = this;
|
|
397
|
+
for (; !n.$errorFn && n.$parent; )
|
|
398
|
+
n = n.$parent;
|
|
399
|
+
return n.$errorFn ? await n.$errorFn(n, t, e ?? {}) : this.defaultErrorScreen(t), this;
|
|
384
400
|
}
|
|
385
401
|
/**
|
|
386
402
|
* Runs a command.
|
|
@@ -391,25 +407,60 @@ class F {
|
|
|
391
407
|
t || (t = typeof Bun < "u" ? Bun.argv.slice(2) : typeof Deno < "u" ? Deno.args : process.argv.slice(2));
|
|
392
408
|
const e = await this.parse(t);
|
|
393
409
|
if (e.isHelp)
|
|
394
|
-
return e.command.handleErrors([new
|
|
410
|
+
return e.command.handleErrors([new L(e.command)]), this;
|
|
395
411
|
if (e.isVersion)
|
|
396
412
|
return console.log(
|
|
397
413
|
`${e.command.fullCommandPath()} version ${e.command.$version}`
|
|
398
414
|
), this;
|
|
399
415
|
try {
|
|
400
|
-
e.errors.length > 0
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
416
|
+
if (e.errors.length > 0)
|
|
417
|
+
await e.command.handleErrors(e.errors, e.input);
|
|
418
|
+
else if (!e.command.$fn)
|
|
419
|
+
await e.command.handleErrors(
|
|
420
|
+
[new L(e.command), ...e.errors],
|
|
421
|
+
e.input
|
|
422
|
+
);
|
|
423
|
+
else {
|
|
424
|
+
const n = oe(e.command);
|
|
425
|
+
n.length > 0 ? await ie(n)(e.input, async () => {
|
|
426
|
+
await e.command.$fn?.(e.input);
|
|
427
|
+
}) : await e.command.$fn(e.input);
|
|
428
|
+
}
|
|
429
|
+
} catch (n) {
|
|
430
|
+
n instanceof Error || console.warn(
|
|
431
|
+
"[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior."
|
|
432
|
+
), await e.command.handleErrors([n]);
|
|
408
433
|
}
|
|
409
434
|
return this;
|
|
410
435
|
}
|
|
411
436
|
}
|
|
437
|
+
function oe(r) {
|
|
438
|
+
const t = [];
|
|
439
|
+
let e = r;
|
|
440
|
+
for (; e; )
|
|
441
|
+
e.$middlewares.length && t.unshift(...e.$middlewares), e = e.$parent;
|
|
442
|
+
return t;
|
|
443
|
+
}
|
|
444
|
+
function ie(r) {
|
|
445
|
+
return (t, e) => {
|
|
446
|
+
let n = -1;
|
|
447
|
+
const i = (a) => {
|
|
448
|
+
if (a <= n)
|
|
449
|
+
return Promise.reject(new Error("next() called multiple times"));
|
|
450
|
+
n = a;
|
|
451
|
+
const f = r[a];
|
|
452
|
+
if (!f)
|
|
453
|
+
return e ? e() : Promise.resolve();
|
|
454
|
+
try {
|
|
455
|
+
return Promise.resolve(f(t, () => i(a + 1)));
|
|
456
|
+
} catch (s) {
|
|
457
|
+
return Promise.reject(s);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
return i(0);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
412
463
|
export {
|
|
413
|
-
|
|
414
|
-
|
|
464
|
+
B as Command,
|
|
465
|
+
de as l
|
|
415
466
|
};
|