convoker 0.2.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/dist/chunks/{error-CBR2veuf.js → error-CyKscMUD.js} +2 -2
- package/dist/chunks/{index-D7JQKzRX.js → index-BluQjWvw.js} +2 -2
- package/dist/chunks/{input-BfYvlWdG.js → input-WNu16aNE.js} +1 -1
- package/dist/chunks/{standard-schema-CFxVDMhv.js → standard-schema-BHKzvwIS.js} +1 -1
- package/dist/command.d.ts +21 -1
- package/dist/command.js +238 -191
- package/dist/error.d.ts +21 -1
- package/dist/error.js +1 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +3 -3
- package/dist/input.js +2 -2
- package/dist/prompt.js +3 -3
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { D as y } from "./color-CiruG_zQ.js";
|
|
2
|
-
import { v as p } from "./standard-schema-
|
|
3
|
-
import { I as f } from "./error-
|
|
2
|
+
import { v as p } from "./standard-schema-BHKzvwIS.js";
|
|
3
|
+
import { I as f } from "./error-CyKscMUD.js";
|
|
4
4
|
import { i as $, a as v, b } from "./utils-DdmSEjLc.js";
|
|
5
5
|
import { r as m, a as g, c as d, b as x, d as D } from "./__vite-browser-external-DQYBmsno.js";
|
|
6
6
|
let l = y;
|
package/dist/command.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command action function.
|
|
3
3
|
*/
|
|
4
|
-
export declare type ActionFn<T extends Input> = (input: InferInput<T>) =>
|
|
4
|
+
export declare type ActionFn<T extends Input> = (input: InferInput<T>) => any | Promise<any>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A basic input type.
|
|
@@ -57,6 +57,10 @@ export declare class Command<T extends Input = Input> {
|
|
|
57
57
|
* The action function of this command.
|
|
58
58
|
*/
|
|
59
59
|
$fn: ActionFn<T> | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The middlewares associated with this command.
|
|
62
|
+
*/
|
|
63
|
+
$middlewares: MiddlewareFn<T>[];
|
|
60
64
|
/**
|
|
61
65
|
* The error handler of this command.
|
|
62
66
|
*/
|
|
@@ -92,6 +96,12 @@ export declare class Command<T extends Input = Input> {
|
|
|
92
96
|
* @returns this
|
|
93
97
|
*/
|
|
94
98
|
input<TInput extends Input>(input: TInput): Command<TInput>;
|
|
99
|
+
/**
|
|
100
|
+
* Adds a chain of middlewares.
|
|
101
|
+
* @param fns The middlewares to use.
|
|
102
|
+
* @returns this
|
|
103
|
+
*/
|
|
104
|
+
use(...fns: MiddlewareFn<T>[]): this;
|
|
95
105
|
/**
|
|
96
106
|
* Sets the action function for this command.
|
|
97
107
|
* @param fn The action.
|
|
@@ -135,6 +145,11 @@ export declare class Command<T extends Input = Input> {
|
|
|
135
145
|
*/
|
|
136
146
|
parse(argv: string[]): Promise<ParseResult<T>>;
|
|
137
147
|
private buildInputMap;
|
|
148
|
+
/**
|
|
149
|
+
* Allows surpassing the amount of arguments specified.
|
|
150
|
+
* @returns this
|
|
151
|
+
*/
|
|
152
|
+
allowSurpassArgLimit(): this;
|
|
138
153
|
/**
|
|
139
154
|
* Gets the full command path (name including parents).
|
|
140
155
|
* @returns The full command path.
|
|
@@ -227,6 +242,11 @@ declare interface Input {
|
|
|
227
242
|
*/
|
|
228
243
|
declare type Kind = BasicKind | StandardSchemaV1<any, any>;
|
|
229
244
|
|
|
245
|
+
/**
|
|
246
|
+
* Command middleware function.
|
|
247
|
+
*/
|
|
248
|
+
export declare type MiddlewareFn<T extends Input = Input> = (input: InferInput<T>, next: () => Promise<any>) => any | Promise<any>;
|
|
249
|
+
|
|
230
250
|
/**
|
|
231
251
|
* An option.
|
|
232
252
|
*/
|
package/dist/command.js
CHANGED
|
@@ -1,217 +1,225 @@
|
|
|
1
1
|
import { D as V, b, c as v, g as O } from "./chunks/color-CiruG_zQ.js";
|
|
2
|
-
import { s as
|
|
3
|
-
import { m as
|
|
4
|
-
import {
|
|
5
|
-
import { P as
|
|
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
6
|
async function Q() {
|
|
7
|
-
if (
|
|
8
|
-
const { Writable:
|
|
9
|
-
return
|
|
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 A && Deno.stdout?.writable ? Deno.stdout.writable :
|
|
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
17
|
async function X() {
|
|
18
|
-
if (
|
|
19
|
-
const { Writable:
|
|
20
|
-
return
|
|
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 A && Deno.stderr?.writable ? Deno.stderr.writable :
|
|
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
28
|
async function Y() {
|
|
29
|
-
if (
|
|
30
|
-
const { Readable:
|
|
31
|
-
return
|
|
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 A && Deno.stdin?.readable ? Deno.stdin.readable :
|
|
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
39
|
let m = V, g;
|
|
40
|
-
function
|
|
41
|
-
m =
|
|
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
47
|
stdout: await Q(),
|
|
48
48
|
stderr: await X(),
|
|
49
49
|
stdin: await Y()
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
r
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
async function Z() {
|
|
55
|
-
await
|
|
55
|
+
await _({});
|
|
56
56
|
}
|
|
57
|
-
function S(
|
|
58
|
-
const
|
|
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:
|
|
61
|
+
return JSON.stringify({ timestamp: e, level: r, message: n }) + `
|
|
62
62
|
`;
|
|
63
63
|
case "xml":
|
|
64
64
|
return `<log>
|
|
65
|
-
<timestamp>${
|
|
66
|
-
<level>${
|
|
67
|
-
<message>${
|
|
65
|
+
<timestamp>${e}</timestamp>
|
|
66
|
+
<level>${r}</level>
|
|
67
|
+
<message>${n}</message>
|
|
68
68
|
</log>
|
|
69
69
|
`;
|
|
70
70
|
case "yaml":
|
|
71
|
-
return `- timestamp: ${
|
|
72
|
-
level: ${
|
|
73
|
-
message: "${
|
|
71
|
+
return `- timestamp: ${e}
|
|
72
|
+
level: ${r}
|
|
73
|
+
message: "${n.replace(/"/g, '\\"')}"
|
|
74
74
|
`;
|
|
75
75
|
case "csv":
|
|
76
|
-
return `"${
|
|
76
|
+
return `"${e}","${r}","${n.replace(/"/g, '""')}"
|
|
77
77
|
`;
|
|
78
78
|
case "text":
|
|
79
79
|
default:
|
|
80
|
-
return `[${
|
|
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
|
-
return m.secondary ? m.secondary(
|
|
87
|
+
return m.secondary ? m.secondary(t) : t;
|
|
88
88
|
case "info":
|
|
89
|
-
return m.info ? m.info(
|
|
89
|
+
return m.info ? m.info(t) : t;
|
|
90
90
|
case "warn":
|
|
91
|
-
return m.warning ? m.warning(
|
|
91
|
+
return m.warning ? m.warning(t) : t;
|
|
92
92
|
case "error":
|
|
93
|
-
return m.error ? m.error(
|
|
93
|
+
return m.error ? m.error(t) : t;
|
|
94
94
|
case "fatal":
|
|
95
|
-
return m.error ? m.error(m.styles?.bold?.(
|
|
95
|
+
return m.error ? m.error(m.styles?.bold?.(t) ?? t) : t;
|
|
96
96
|
default:
|
|
97
|
-
return
|
|
97
|
+
return t;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
async function k(
|
|
101
|
-
const
|
|
100
|
+
async function k(r, t) {
|
|
101
|
+
const e = r.getWriter();
|
|
102
102
|
try {
|
|
103
|
-
await
|
|
103
|
+
await e.write(t);
|
|
104
104
|
} finally {
|
|
105
|
-
|
|
105
|
+
e.releaseLock();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
110
|
-
await k(g.stdout,
|
|
108
|
+
async function ee(...r) {
|
|
109
|
+
const t = S("trace", ...r), e = E("trace", t);
|
|
110
|
+
await k(g.stdout, e);
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
113
|
-
const
|
|
114
|
-
await k(g.stdout,
|
|
112
|
+
async function te(...r) {
|
|
113
|
+
const t = S("info", ...r), e = E("info", t);
|
|
114
|
+
await k(g.stdout, e);
|
|
115
115
|
}
|
|
116
|
-
async function
|
|
117
|
-
const
|
|
118
|
-
await k(g.stdout,
|
|
116
|
+
async function ne(...r) {
|
|
117
|
+
const t = S("warn", ...r), e = E("warn", t);
|
|
118
|
+
await k(g.stdout, e);
|
|
119
119
|
}
|
|
120
|
-
async function
|
|
121
|
-
const
|
|
122
|
-
await k(g.stderr,
|
|
120
|
+
async function re(...r) {
|
|
121
|
+
const t = S("error", ...r), e = E("error", t);
|
|
122
|
+
await k(g.stderr, e);
|
|
123
123
|
}
|
|
124
|
-
async function
|
|
125
|
-
const
|
|
126
|
-
await k(g.stderr,
|
|
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:
|
|
130
|
+
error: re,
|
|
131
|
+
fatal: se,
|
|
132
|
+
info: te,
|
|
133
|
+
setConfig: _,
|
|
134
|
+
setTheme: H,
|
|
135
135
|
setup: Z,
|
|
136
|
-
trace:
|
|
137
|
-
warn:
|
|
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(
|
|
147
|
-
this.$children = /* @__PURE__ */ new Map(), this.$allowUnknownOptions = !1, this.$allowSurpassArgLimit = !1, this.$input = {}, this.$fn = void 0, this.$errorFn = void 0, this.$names = Array.isArray(
|
|
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.
|
|
151
151
|
* @param aliases The aliases to add.
|
|
152
152
|
* @returns this
|
|
153
153
|
*/
|
|
154
|
-
alias(...
|
|
155
|
-
return this.$names.concat(
|
|
154
|
+
alias(...t) {
|
|
155
|
+
return this.$names.concat(t), this.$parent?.add(this), this;
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Adds a description to this command.
|
|
159
159
|
* @param desc The description.
|
|
160
160
|
* @returns this
|
|
161
161
|
*/
|
|
162
|
-
description(
|
|
163
|
-
return this.$description =
|
|
162
|
+
description(t) {
|
|
163
|
+
return this.$description = t, this;
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
166
|
* Adds a version to this command.
|
|
167
167
|
* @param version The version.
|
|
168
168
|
* @returns this
|
|
169
169
|
*/
|
|
170
|
-
version(
|
|
171
|
-
return this.$version =
|
|
170
|
+
version(t) {
|
|
171
|
+
return this.$version = t, this;
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Sets the input for this command.
|
|
175
175
|
* @param version The input.
|
|
176
176
|
* @returns this
|
|
177
177
|
*/
|
|
178
|
-
input(
|
|
179
|
-
return this.$input =
|
|
178
|
+
input(t) {
|
|
179
|
+
return this.$input = t, this;
|
|
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;
|
|
180
188
|
}
|
|
181
189
|
/**
|
|
182
190
|
* Sets the action function for this command.
|
|
183
191
|
* @param fn The action.
|
|
184
192
|
* @returns this
|
|
185
193
|
*/
|
|
186
|
-
action(
|
|
187
|
-
return this.$fn =
|
|
194
|
+
action(t) {
|
|
195
|
+
return this.$fn = t, this;
|
|
188
196
|
}
|
|
189
197
|
/**
|
|
190
198
|
* Sets the error function for this command.
|
|
191
199
|
* @param fn The error handler.
|
|
192
200
|
* @returns this
|
|
193
201
|
*/
|
|
194
|
-
error(
|
|
195
|
-
return this.$errorFn =
|
|
202
|
+
error(t) {
|
|
203
|
+
return this.$errorFn = t, this;
|
|
196
204
|
}
|
|
197
205
|
/**
|
|
198
206
|
* Adds an existing command to this.
|
|
199
207
|
* @param command The command.
|
|
200
208
|
* @returns this
|
|
201
209
|
*/
|
|
202
|
-
add(
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
for (let
|
|
206
|
-
|
|
210
|
+
add(t) {
|
|
211
|
+
t.$parent = this;
|
|
212
|
+
const e = { command: t, alias: t.$names[0] };
|
|
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(
|
|
210
|
-
if (typeof
|
|
211
|
-
const a = new
|
|
212
|
-
return
|
|
217
|
+
subCommand(t, e, n) {
|
|
218
|
+
if (typeof e == "function") {
|
|
219
|
+
const a = new B(t);
|
|
220
|
+
return e(a), this.add(a), this;
|
|
213
221
|
}
|
|
214
|
-
const i = new
|
|
222
|
+
const i = new B(t, e, n);
|
|
215
223
|
return this.add(i), i;
|
|
216
224
|
}
|
|
217
225
|
/**
|
|
@@ -226,132 +234,136 @@ class F {
|
|
|
226
234
|
* @param argv The arguments to parse.
|
|
227
235
|
* @returns A parse result.
|
|
228
236
|
*/
|
|
229
|
-
async parse(
|
|
230
|
-
let
|
|
231
|
-
const i = {}, a = [],
|
|
232
|
-
function u
|
|
233
|
-
const l = c.get(
|
|
234
|
-
return l ? l.value : (!
|
|
237
|
+
async parse(t) {
|
|
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 h(
|
|
237
|
-
o.$kind === "boolean" ?
|
|
244
|
+
function h(u, o, l) {
|
|
245
|
+
o.$kind === "boolean" ? f[u] = "true" : l !== void 0 && (f[u] = l);
|
|
238
246
|
}
|
|
239
|
-
let p = !1,
|
|
240
|
-
for (let
|
|
241
|
-
const o =
|
|
247
|
+
let p = !1, W = !1;
|
|
248
|
+
for (let u = 0; u < t.length; u++) {
|
|
249
|
+
const o = t[u];
|
|
242
250
|
if (o.startsWith("--")) {
|
|
243
251
|
const [l, w] = o.slice(2).split("=");
|
|
244
252
|
let y = !1;
|
|
245
|
-
l === "help" ? (
|
|
246
|
-
const $ =
|
|
253
|
+
l === "help" ? (W = !0, y = !0) : l === "version" && (p = !0, y = !0);
|
|
254
|
+
const $ = d(l, y);
|
|
247
255
|
$ && (w === void 0 ? h(
|
|
248
256
|
l,
|
|
249
257
|
$,
|
|
250
|
-
$.$kind === "boolean" ? void 0 :
|
|
258
|
+
$.$kind === "boolean" ? void 0 : t[++u]
|
|
251
259
|
) : h(l, $, w));
|
|
252
260
|
} else if (o.startsWith("-")) {
|
|
253
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
|
-
|
|
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
272
|
let M = 0;
|
|
265
|
-
for (const
|
|
266
|
-
const o =
|
|
273
|
+
for (const u in e.$input) {
|
|
274
|
+
const o = e.$input[u];
|
|
267
275
|
let l;
|
|
268
|
-
if (o instanceof
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
throw new H(t);
|
|
272
|
-
} else if (l = a[M++], M > a.length && !t.$allowSurpassArgLimit)
|
|
273
|
-
throw new H(t);
|
|
274
|
-
} else
|
|
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)));
|
|
278
|
+
else
|
|
275
279
|
for (const w of o.$names)
|
|
276
|
-
if (
|
|
277
|
-
l = o.$list ?
|
|
280
|
+
if (f[w] !== void 0) {
|
|
281
|
+
l = o.$list ? f[w].split(o.$separator ?? ",") : f[w];
|
|
278
282
|
break;
|
|
279
283
|
}
|
|
280
|
-
l !== void 0 ? i[
|
|
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)));
|
|
281
285
|
}
|
|
282
|
-
|
|
286
|
+
const I = a.slice(M);
|
|
287
|
+
return !e.$allowSurpassArgLimit && I.length > 0 && s.push(new N(e)), {
|
|
283
288
|
input: i,
|
|
284
|
-
command:
|
|
289
|
+
command: e,
|
|
285
290
|
errors: s,
|
|
286
291
|
isVersion: p,
|
|
287
|
-
isHelp:
|
|
292
|
+
isHelp: W
|
|
288
293
|
};
|
|
289
294
|
}
|
|
290
|
-
buildInputMap(
|
|
291
|
-
const
|
|
292
|
-
let
|
|
295
|
+
buildInputMap(t) {
|
|
296
|
+
const e = /* @__PURE__ */ new Map();
|
|
297
|
+
let n = 0;
|
|
293
298
|
for (const i in this.$input) {
|
|
294
299
|
const a = this.$input[i];
|
|
295
|
-
if (a instanceof
|
|
296
|
-
|
|
300
|
+
if (a instanceof q)
|
|
301
|
+
e.set(n++, { value: a, key: i });
|
|
297
302
|
else
|
|
298
|
-
for (const
|
|
299
|
-
|
|
303
|
+
for (const f of a.$names)
|
|
304
|
+
e.set(f, { value: a, key: i });
|
|
300
305
|
}
|
|
301
|
-
if (!
|
|
306
|
+
if (!t)
|
|
302
307
|
for (const [i, a] of this.$parent?.buildInputMap() ?? [])
|
|
303
|
-
|
|
308
|
+
e.set(i, a);
|
|
304
309
|
for (const [, { command: i }] of this.$children)
|
|
305
|
-
for (const [a,
|
|
306
|
-
|
|
307
|
-
return
|
|
310
|
+
for (const [a, f] of i.buildInputMap(!0))
|
|
311
|
+
e.set(a, f);
|
|
312
|
+
return e;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Allows surpassing the amount of arguments specified.
|
|
316
|
+
* @returns this
|
|
317
|
+
*/
|
|
318
|
+
allowSurpassArgLimit() {
|
|
319
|
+
return this.$allowSurpassArgLimit = !0, this;
|
|
308
320
|
}
|
|
309
321
|
/**
|
|
310
322
|
* Gets the full command path (name including parents).
|
|
311
323
|
* @returns The full command path.
|
|
312
324
|
*/
|
|
313
325
|
fullCommandPath() {
|
|
314
|
-
const
|
|
315
|
-
let
|
|
316
|
-
for (;
|
|
317
|
-
|
|
318
|
-
return
|
|
326
|
+
const t = [];
|
|
327
|
+
let e = this;
|
|
328
|
+
for (; e; )
|
|
329
|
+
t.unshift(e.$names[0]), e = e.$parent;
|
|
330
|
+
return t.join(" ");
|
|
319
331
|
}
|
|
320
332
|
/**
|
|
321
333
|
* The default error screen.
|
|
322
334
|
* @param errors The errors.
|
|
323
335
|
*/
|
|
324
|
-
defaultErrorScreen(
|
|
325
|
-
let
|
|
326
|
-
const
|
|
327
|
-
for (const s of
|
|
328
|
-
s instanceof
|
|
329
|
-
if (
|
|
330
|
-
if (!
|
|
336
|
+
defaultErrorScreen(t) {
|
|
337
|
+
let e = !1;
|
|
338
|
+
const n = [];
|
|
339
|
+
for (const s of t)
|
|
340
|
+
s instanceof K ? (s instanceof L || s.print(), e = !0) : n.push(s);
|
|
341
|
+
if (n.length) throw n[0];
|
|
342
|
+
if (!e) return;
|
|
331
343
|
const i = (s, c) => s.padEnd(c, " ");
|
|
332
344
|
console.log(
|
|
333
345
|
`${b("usage:")} ${v(this.fullCommandPath())} ${O("[options] [arguments]")}`
|
|
334
346
|
), this.$description && console.log(`${this.$description}`), this.$version && console.log(`${b("version")} ${this.$version}`);
|
|
335
|
-
const a = Object.entries(this.$input).filter(([, s]) => s instanceof
|
|
347
|
+
const a = Object.entries(this.$input).filter(([, s]) => s instanceof F).map(([s, c]) => ({ key: s, entry: c }));
|
|
336
348
|
if (a.length > 0) {
|
|
337
349
|
console.log(b("options:"));
|
|
338
350
|
const s = Math.max(
|
|
339
351
|
...a.map(({ entry: c }) => c.$names.join(", ").length)
|
|
340
352
|
);
|
|
341
353
|
for (const { entry: c } of a) {
|
|
342
|
-
const
|
|
354
|
+
const d = c.$names.map((p) => p.length === 1 ? `-${p}` : `--${p}`).join(", "), h = ` ${v(i(d, s + 4))}${O(c.$description ?? "")}`;
|
|
343
355
|
console.log(h);
|
|
344
356
|
}
|
|
345
357
|
}
|
|
346
|
-
const
|
|
358
|
+
const f = Object.entries(this.$input).filter(([, s]) => s instanceof q).map(([s, c]) => ({
|
|
347
359
|
key: s,
|
|
348
360
|
entry: c
|
|
349
361
|
}));
|
|
350
|
-
if (
|
|
362
|
+
if (f.length > 0) {
|
|
351
363
|
console.log(b("arguments:"));
|
|
352
|
-
const s = Math.max(...
|
|
353
|
-
for (const { key: c, entry:
|
|
354
|
-
const h =
|
|
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 ?? "")}`;
|
|
355
367
|
console.log(p);
|
|
356
368
|
}
|
|
357
369
|
}
|
|
@@ -359,14 +371,14 @@ class F {
|
|
|
359
371
|
console.log(b("sub commands:"));
|
|
360
372
|
const s = Array.from(
|
|
361
373
|
new Map(
|
|
362
|
-
[...this.$children.values()].map((
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
[...this.$children.values()].map((d) => [
|
|
375
|
+
d.command.$names[0],
|
|
376
|
+
d.command
|
|
365
377
|
])
|
|
366
378
|
).values()
|
|
367
|
-
), c = Math.max(...s.map((
|
|
368
|
-
for (const
|
|
369
|
-
const h = ` ${v(i(
|
|
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) ?? ""}`;
|
|
370
382
|
console.log(h);
|
|
371
383
|
}
|
|
372
384
|
console.log(), console.log(
|
|
@@ -380,40 +392,75 @@ class F {
|
|
|
380
392
|
* @param input The parsed input, if possible.
|
|
381
393
|
* @returns this
|
|
382
394
|
*/
|
|
383
|
-
async handleErrors(
|
|
384
|
-
let
|
|
385
|
-
for (; !
|
|
386
|
-
|
|
387
|
-
return
|
|
395
|
+
async handleErrors(t, e) {
|
|
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;
|
|
388
400
|
}
|
|
389
401
|
/**
|
|
390
402
|
* Runs a command.
|
|
391
403
|
* @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.
|
|
392
404
|
* @returns this
|
|
393
405
|
*/
|
|
394
|
-
async run(
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
return
|
|
399
|
-
if (
|
|
406
|
+
async run(t) {
|
|
407
|
+
t || (t = typeof Bun < "u" ? Bun.argv.slice(2) : typeof Deno < "u" ? Deno.args : process.argv.slice(2));
|
|
408
|
+
const e = await this.parse(t);
|
|
409
|
+
if (e.isHelp)
|
|
410
|
+
return e.command.handleErrors([new L(e.command)]), this;
|
|
411
|
+
if (e.isVersion)
|
|
400
412
|
return console.log(
|
|
401
|
-
`${
|
|
413
|
+
`${e.command.fullCommandPath()} version ${e.command.$version}`
|
|
402
414
|
), this;
|
|
403
415
|
try {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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(
|
|
410
431
|
"[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior."
|
|
411
|
-
), await
|
|
432
|
+
), await e.command.handleErrors([n]);
|
|
412
433
|
}
|
|
413
434
|
return this;
|
|
414
435
|
}
|
|
415
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
|
+
}
|
|
416
463
|
export {
|
|
417
|
-
|
|
418
|
-
|
|
464
|
+
B as Command,
|
|
465
|
+
de as l
|
|
419
466
|
};
|
package/dist/error.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command action function.
|
|
3
3
|
*/
|
|
4
|
-
declare type ActionFn<T extends Input> = (input: InferInput<T>) =>
|
|
4
|
+
declare type ActionFn<T extends Input> = (input: InferInput<T>) => any | Promise<any>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A basic input type.
|
|
@@ -62,6 +62,10 @@ declare class Command<T extends Input = Input> {
|
|
|
62
62
|
* The action function of this command.
|
|
63
63
|
*/
|
|
64
64
|
$fn: ActionFn<T> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The middlewares associated with this command.
|
|
67
|
+
*/
|
|
68
|
+
$middlewares: MiddlewareFn<T>[];
|
|
65
69
|
/**
|
|
66
70
|
* The error handler of this command.
|
|
67
71
|
*/
|
|
@@ -97,6 +101,12 @@ declare class Command<T extends Input = Input> {
|
|
|
97
101
|
* @returns this
|
|
98
102
|
*/
|
|
99
103
|
input<TInput extends Input>(input: TInput): Command<TInput>;
|
|
104
|
+
/**
|
|
105
|
+
* Adds a chain of middlewares.
|
|
106
|
+
* @param fns The middlewares to use.
|
|
107
|
+
* @returns this
|
|
108
|
+
*/
|
|
109
|
+
use(...fns: MiddlewareFn<T>[]): this;
|
|
100
110
|
/**
|
|
101
111
|
* Sets the action function for this command.
|
|
102
112
|
* @param fn The action.
|
|
@@ -140,6 +150,11 @@ declare class Command<T extends Input = Input> {
|
|
|
140
150
|
*/
|
|
141
151
|
parse(argv: string[]): Promise<ParseResult<T>>;
|
|
142
152
|
private buildInputMap;
|
|
153
|
+
/**
|
|
154
|
+
* Allows surpassing the amount of arguments specified.
|
|
155
|
+
* @returns this
|
|
156
|
+
*/
|
|
157
|
+
allowSurpassArgLimit(): this;
|
|
143
158
|
/**
|
|
144
159
|
* Gets the full command path (name including parents).
|
|
145
160
|
* @returns The full command path.
|
|
@@ -283,6 +298,11 @@ declare type Kind = BasicKind | StandardSchemaV1<any, any>;
|
|
|
283
298
|
*/
|
|
284
299
|
declare type Kind_2 = BasicKind_2 | StandardSchemaV1_2<any, any>;
|
|
285
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Command middleware function.
|
|
303
|
+
*/
|
|
304
|
+
declare type MiddlewareFn<T extends Input = Input> = (input: InferInput<T>, next: () => Promise<any>) => any | Promise<any>;
|
|
305
|
+
|
|
286
306
|
export declare class MissingRequiredArgumentError extends ConvokerError {
|
|
287
307
|
/**
|
|
288
308
|
* The argument key.
|
package/dist/error.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Theme as Theme_2 } from '../../../../../../../../../../src/color';
|
|
|
4
4
|
/**
|
|
5
5
|
* Command action function.
|
|
6
6
|
*/
|
|
7
|
-
export declare type ActionFn<T extends Input> = (input: InferInput<T>) =>
|
|
7
|
+
export declare type ActionFn<T extends Input> = (input: InferInput<T>) => any | Promise<any>;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a new positional argument.
|
|
@@ -190,6 +190,10 @@ export declare class Command<T extends Input = Input> {
|
|
|
190
190
|
* The action function of this command.
|
|
191
191
|
*/
|
|
192
192
|
$fn: ActionFn<T> | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* The middlewares associated with this command.
|
|
195
|
+
*/
|
|
196
|
+
$middlewares: MiddlewareFn<T>[];
|
|
193
197
|
/**
|
|
194
198
|
* The error handler of this command.
|
|
195
199
|
*/
|
|
@@ -225,6 +229,12 @@ export declare class Command<T extends Input = Input> {
|
|
|
225
229
|
* @returns this
|
|
226
230
|
*/
|
|
227
231
|
input<TInput extends Input>(input: TInput): Command<TInput>;
|
|
232
|
+
/**
|
|
233
|
+
* Adds a chain of middlewares.
|
|
234
|
+
* @param fns The middlewares to use.
|
|
235
|
+
* @returns this
|
|
236
|
+
*/
|
|
237
|
+
use(...fns: MiddlewareFn<T>[]): this;
|
|
228
238
|
/**
|
|
229
239
|
* Sets the action function for this command.
|
|
230
240
|
* @param fn The action.
|
|
@@ -268,6 +278,11 @@ export declare class Command<T extends Input = Input> {
|
|
|
268
278
|
*/
|
|
269
279
|
parse(argv: string[]): Promise<ParseResult<T>>;
|
|
270
280
|
private buildInputMap;
|
|
281
|
+
/**
|
|
282
|
+
* Allows surpassing the amount of arguments specified.
|
|
283
|
+
* @returns this
|
|
284
|
+
*/
|
|
285
|
+
allowSurpassArgLimit(): this;
|
|
271
286
|
/**
|
|
272
287
|
* Gets the full command path (name including parents).
|
|
273
288
|
* @returns The full command path.
|
|
@@ -577,6 +592,11 @@ declare const magenta: (input: any) => string;
|
|
|
577
592
|
|
|
578
593
|
declare const magentaBright: (input: any) => string;
|
|
579
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Command middleware function.
|
|
597
|
+
*/
|
|
598
|
+
export declare type MiddlewareFn<T extends Input = Input> = (input: InferInput<T>, next: () => Promise<any>) => any | Promise<any>;
|
|
599
|
+
|
|
580
600
|
declare class MissingRequiredArgumentError extends ConvokerError {
|
|
581
601
|
/**
|
|
582
602
|
* The argument key.
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command as m, l as e } from "./command.js";
|
|
2
|
-
import { e as a } from "./chunks/error-
|
|
3
|
-
import { i as f } from "./chunks/input-
|
|
2
|
+
import { e as a } from "./chunks/error-CyKscMUD.js";
|
|
3
|
+
import { i as f } from "./chunks/input-WNu16aNE.js";
|
|
4
4
|
import { a as s } from "./chunks/color-CiruG_zQ.js";
|
|
5
|
-
import { i } from "./chunks/index-
|
|
5
|
+
import { i } from "./chunks/index-BluQjWvw.js";
|
|
6
6
|
export {
|
|
7
7
|
m as Command,
|
|
8
8
|
s as color,
|
package/dist/input.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./chunks/standard-schema-
|
|
2
|
-
import { O as t, P as i, a as n, c as p, o as r, p as e } from "./chunks/input-
|
|
1
|
+
import "./chunks/standard-schema-BHKzvwIS.js";
|
|
2
|
+
import { O as t, P as i, a as n, c as p, o as r, p as e } from "./chunks/input-WNu16aNE.js";
|
|
3
3
|
export {
|
|
4
4
|
t as Option,
|
|
5
5
|
i as Positional,
|
package/dist/prompt.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./chunks/color-CiruG_zQ.js";
|
|
2
|
-
import "./chunks/standard-schema-
|
|
3
|
-
import "./chunks/error-
|
|
2
|
+
import "./chunks/standard-schema-BHKzvwIS.js";
|
|
3
|
+
import "./chunks/error-CyKscMUD.js";
|
|
4
4
|
import "./chunks/utils-DdmSEjLc.js";
|
|
5
5
|
import { d as m } from "./chunks/__vite-browser-external-DQYBmsno.js";
|
|
6
|
-
import { c as i, e as c, m as d, p as f, b as l, a as x, s as h, t as w } from "./chunks/index-
|
|
6
|
+
import { c as i, e as c, m as d, p as f, b as l, a as x, s as h, t as w } from "./chunks/index-BluQjWvw.js";
|
|
7
7
|
export {
|
|
8
8
|
i as confirm,
|
|
9
9
|
c as editor,
|