convoker 0.1.0 → 0.2.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-CBR2veuf.js} +3 -3
- package/dist/chunks/{index-G2nVXKup.js → index-D7JQKzRX.js} +2 -2
- package/dist/chunks/{input-COjWPD53.js → input-BfYvlWdG.js} +38 -35
- package/dist/chunks/{standard-schema-Dn3nwAxU.js → standard-schema-CFxVDMhv.js} +1 -1
- package/dist/command.d.ts +30 -22
- package/dist/command.js +180 -176
- package/dist/error.d.ts +60 -48
- package/dist/error.js +6 -6
- package/dist/index.d.ts +37 -29
- 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/README.md
CHANGED
|
@@ -9,7 +9,7 @@ class n extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
class o extends Error {
|
|
11
11
|
/**
|
|
12
|
-
* Creates a new
|
|
12
|
+
* Creates a new Convoker error.
|
|
13
13
|
* @param message The message.
|
|
14
14
|
* @param command The command.
|
|
15
15
|
*/
|
|
@@ -75,18 +75,18 @@ class d extends o {
|
|
|
75
75
|
}
|
|
76
76
|
const l = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
77
77
|
__proto__: null,
|
|
78
|
+
ConvokerError: o,
|
|
78
79
|
HelpAskedError: i,
|
|
79
80
|
InputValidationError: n,
|
|
80
|
-
LunarCLIError: o,
|
|
81
81
|
MissingRequiredArgumentError: d,
|
|
82
82
|
MissingRequiredOptionError: c,
|
|
83
83
|
TooManyArgumentsError: a,
|
|
84
84
|
UnknownOptionError: u
|
|
85
85
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
86
86
|
export {
|
|
87
|
+
o as C,
|
|
87
88
|
i as H,
|
|
88
89
|
n as I,
|
|
89
|
-
o as L,
|
|
90
90
|
c as M,
|
|
91
91
|
a as T,
|
|
92
92
|
u as U,
|
|
@@ -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-CFxVDMhv.js";
|
|
3
|
+
import { I as f } from "./error-CBR2veuf.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;
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import { v as
|
|
2
|
-
async function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { v as o } from "./standard-schema-CFxVDMhv.js";
|
|
2
|
+
async function a(r, t) {
|
|
3
|
+
async function i(e) {
|
|
4
|
+
if (typeof r == "string")
|
|
5
|
+
switch (r) {
|
|
6
|
+
case "boolean":
|
|
7
|
+
return e === "true";
|
|
8
|
+
case "bigint":
|
|
9
|
+
return BigInt(e);
|
|
10
|
+
case "number":
|
|
11
|
+
return parseFloat(e);
|
|
12
|
+
case "string":
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
return o(r, e);
|
|
16
|
+
}
|
|
17
|
+
return Array.isArray(t) ? await Promise.all(t.map((u) => i(u))) : i(t);
|
|
15
18
|
}
|
|
16
|
-
class
|
|
19
|
+
class n {
|
|
17
20
|
/**
|
|
18
21
|
* Creates a new option.
|
|
19
22
|
* @param kind The type of this option.
|
|
20
23
|
* @param names The names of this option.
|
|
21
24
|
*/
|
|
22
|
-
constructor(t,
|
|
23
|
-
this.$required = !0, this.$list = !1, this.$kind = t, this.$names =
|
|
25
|
+
constructor(t, i) {
|
|
26
|
+
this.$required = !0, this.$list = !1, this.$kind = t, this.$names = i.map((e) => e.replace(/^-+/, ""));
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Makes this option a list.
|
|
27
30
|
* @returns this
|
|
28
31
|
*/
|
|
29
|
-
list() {
|
|
30
|
-
return this.$list = !0, this;
|
|
32
|
+
list(t) {
|
|
33
|
+
return this.$list = !0, this.$separator = t ?? this.$separator, this;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Makes this option required.
|
|
@@ -60,7 +63,7 @@ class i {
|
|
|
60
63
|
return this.$description = t, this;
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
class
|
|
66
|
+
class s {
|
|
64
67
|
/**
|
|
65
68
|
* Creates a new positional argument.
|
|
66
69
|
* @param kind The positional argument.
|
|
@@ -106,30 +109,30 @@ class e {
|
|
|
106
109
|
return this.$description = t, this;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
|
-
function
|
|
110
|
-
return new
|
|
112
|
+
function c(r, ...t) {
|
|
113
|
+
return new n(r, t);
|
|
111
114
|
}
|
|
112
115
|
function h(r) {
|
|
113
|
-
return new
|
|
116
|
+
return new s(r);
|
|
114
117
|
}
|
|
115
|
-
function
|
|
116
|
-
return new
|
|
118
|
+
function l(r) {
|
|
119
|
+
return new s(r);
|
|
117
120
|
}
|
|
118
121
|
const d = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
119
122
|
__proto__: null,
|
|
120
|
-
Option:
|
|
121
|
-
Positional:
|
|
122
|
-
argument:
|
|
123
|
-
convert:
|
|
124
|
-
option:
|
|
123
|
+
Option: n,
|
|
124
|
+
Positional: s,
|
|
125
|
+
argument: l,
|
|
126
|
+
convert: a,
|
|
127
|
+
option: c,
|
|
125
128
|
positional: h
|
|
126
129
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
127
130
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
n as O,
|
|
132
|
+
s as P,
|
|
133
|
+
l as a,
|
|
134
|
+
a as c,
|
|
132
135
|
d as i,
|
|
133
|
-
|
|
136
|
+
c as o,
|
|
134
137
|
h as p
|
|
135
138
|
};
|
package/dist/command.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ export declare class Command<T extends Input = Input> {
|
|
|
45
45
|
* If this command allows unknown options.
|
|
46
46
|
*/
|
|
47
47
|
$allowUnknownOptions: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* If you should be able to surpass the amount of positional arguments defined in the input.
|
|
50
|
+
*/
|
|
51
|
+
$allowSurpassArgLimit: boolean;
|
|
48
52
|
/**
|
|
49
53
|
* The input this command takes.
|
|
50
54
|
*/
|
|
@@ -170,6 +174,26 @@ export declare interface CommandAlias<T extends Input = Input> {
|
|
|
170
174
|
alias?: string;
|
|
171
175
|
}
|
|
172
176
|
|
|
177
|
+
/**
|
|
178
|
+
* A Convoker-related error. These are usually handled by default.
|
|
179
|
+
*/
|
|
180
|
+
declare class ConvokerError extends Error {
|
|
181
|
+
/**
|
|
182
|
+
* The command this error happened on.
|
|
183
|
+
*/
|
|
184
|
+
command: Command<any>;
|
|
185
|
+
/**
|
|
186
|
+
* Creates a new Convoker error.
|
|
187
|
+
* @param message The message.
|
|
188
|
+
* @param command The command.
|
|
189
|
+
*/
|
|
190
|
+
constructor(message: string, command: Command<any>);
|
|
191
|
+
/**
|
|
192
|
+
* Prints the error's message.
|
|
193
|
+
*/
|
|
194
|
+
print(): void;
|
|
195
|
+
}
|
|
196
|
+
|
|
173
197
|
/**
|
|
174
198
|
* Command error handler.
|
|
175
199
|
*/
|
|
@@ -203,26 +227,6 @@ declare interface Input {
|
|
|
203
227
|
*/
|
|
204
228
|
declare type Kind = BasicKind | StandardSchemaV1<any, any>;
|
|
205
229
|
|
|
206
|
-
/**
|
|
207
|
-
* A LunarCLI-related error. These are usually handled by default.
|
|
208
|
-
*/
|
|
209
|
-
declare class LunarCLIError extends Error {
|
|
210
|
-
/**
|
|
211
|
-
* The command this error happened on.
|
|
212
|
-
*/
|
|
213
|
-
command: Command<any>;
|
|
214
|
-
/**
|
|
215
|
-
* Creates a new LunarCLI error.
|
|
216
|
-
* @param message The message.
|
|
217
|
-
* @param command The command.
|
|
218
|
-
*/
|
|
219
|
-
constructor(message: string, command: Command<any>);
|
|
220
|
-
/**
|
|
221
|
-
* Prints the error's message.
|
|
222
|
-
*/
|
|
223
|
-
print(): void;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
230
|
/**
|
|
227
231
|
* An option.
|
|
228
232
|
*/
|
|
@@ -251,6 +255,10 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
251
255
|
* If this option is a list.
|
|
252
256
|
*/
|
|
253
257
|
$list: TList;
|
|
258
|
+
/**
|
|
259
|
+
* A separator if this option is a list.
|
|
260
|
+
*/
|
|
261
|
+
$separator: string | undefined;
|
|
254
262
|
/**
|
|
255
263
|
* Creates a new option.
|
|
256
264
|
* @param kind The type of this option.
|
|
@@ -261,7 +269,7 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
261
269
|
* Makes this option a list.
|
|
262
270
|
* @returns this
|
|
263
271
|
*/
|
|
264
|
-
list(): Option_2<TKind, TRequired, true>;
|
|
272
|
+
list(separator?: string): Option_2<TKind, TRequired, true>;
|
|
265
273
|
/**
|
|
266
274
|
* Makes this option required.
|
|
267
275
|
* @returns this
|
|
@@ -301,7 +309,7 @@ export declare interface ParseResult<T extends Input> {
|
|
|
301
309
|
/**
|
|
302
310
|
* Errors collected during parsing.
|
|
303
311
|
*/
|
|
304
|
-
errors:
|
|
312
|
+
errors: ConvokerError[];
|
|
305
313
|
/**
|
|
306
314
|
* If this should result in displaying the version of the command.
|
|
307
315
|
*/
|
package/dist/command.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import { D as
|
|
2
|
-
import { s as
|
|
3
|
-
import { m as
|
|
4
|
-
import {
|
|
5
|
-
import { P as B, c as
|
|
6
|
-
async function
|
|
1
|
+
import { D as V, b, c as v, g as O } from "./chunks/color-CiruG_zQ.js";
|
|
2
|
+
import { s as q } from "./chunks/index-D7JQKzRX.js";
|
|
3
|
+
import { m as R, i as A, b as W, a as j } from "./chunks/utils-DdmSEjLc.js";
|
|
4
|
+
import { T as H, M as z, a as N, C as J, H as P, U as K } from "./chunks/error-CBR2veuf.js";
|
|
5
|
+
import { P as B, c as G, O as _ } from "./chunks/input-BfYvlWdG.js";
|
|
6
|
+
async function Q() {
|
|
7
7
|
if (W && process.stdout?.writable) {
|
|
8
|
-
const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((
|
|
8
|
+
const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((e) => e._);
|
|
9
9
|
return n.toWeb(process.stdout);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return A && Deno.stdout?.writable ? Deno.stdout.writable : j && Bun.stdout ? Bun.stdout : new WritableStream({
|
|
12
12
|
write(n) {
|
|
13
13
|
console.log(String(n));
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
async function
|
|
17
|
+
async function X() {
|
|
18
18
|
if (W && process.stderr?.writable) {
|
|
19
|
-
const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((
|
|
19
|
+
const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((e) => e._);
|
|
20
20
|
return n.toWeb(process.stderr);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return A && Deno.stderr?.writable ? Deno.stderr.writable : j && Bun.stderr ? Bun.stderr : new WritableStream({
|
|
23
23
|
write(n) {
|
|
24
24
|
console.error(String(n));
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
async function
|
|
28
|
+
async function Y() {
|
|
29
29
|
if (W && process.stdin?.readable) {
|
|
30
|
-
const { Readable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((
|
|
30
|
+
const { Readable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((e) => e._);
|
|
31
31
|
return n.toWeb(process.stdin);
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return A && Deno.stdin?.readable ? Deno.stdin.readable : j ? Bun.stdin.stream() : new ReadableStream({
|
|
34
34
|
start(n) {
|
|
35
35
|
n.close();
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
let m =
|
|
39
|
+
let m = V, g;
|
|
40
40
|
function I(n) {
|
|
41
41
|
m = n;
|
|
42
42
|
}
|
|
43
|
-
async function
|
|
44
|
-
g =
|
|
43
|
+
async function L(n) {
|
|
44
|
+
g = R(
|
|
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
|
n
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
async function
|
|
55
|
-
await
|
|
54
|
+
async function Z() {
|
|
55
|
+
await L({});
|
|
56
56
|
}
|
|
57
|
-
function S(n, ...
|
|
58
|
-
const
|
|
57
|
+
function S(n, ...e) {
|
|
58
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), r = e.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: t, level: n, message: r }) + `
|
|
62
62
|
`;
|
|
63
63
|
case "xml":
|
|
64
64
|
return `<log>
|
|
65
|
-
<timestamp>${
|
|
65
|
+
<timestamp>${t}</timestamp>
|
|
66
66
|
<level>${n}</level>
|
|
67
67
|
<message>${r}</message>
|
|
68
68
|
</log>
|
|
69
69
|
`;
|
|
70
70
|
case "yaml":
|
|
71
|
-
return `- timestamp: ${
|
|
71
|
+
return `- timestamp: ${t}
|
|
72
72
|
level: ${n}
|
|
73
73
|
message: "${r.replace(/"/g, '\\"')}"
|
|
74
74
|
`;
|
|
75
75
|
case "csv":
|
|
76
|
-
return `"${
|
|
76
|
+
return `"${t}","${n}","${r.replace(/"/g, '""')}"
|
|
77
77
|
`;
|
|
78
78
|
case "text":
|
|
79
79
|
default:
|
|
80
|
-
return `[${
|
|
80
|
+
return `[${t}] [${n.toUpperCase()}] ${r}
|
|
81
81
|
`;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
function E(n,
|
|
84
|
+
function E(n, e) {
|
|
85
85
|
switch (n) {
|
|
86
86
|
case "trace":
|
|
87
|
-
return m.secondary ? m.secondary(
|
|
87
|
+
return m.secondary ? m.secondary(e) : e;
|
|
88
88
|
case "info":
|
|
89
|
-
return m.info ? m.info(
|
|
89
|
+
return m.info ? m.info(e) : e;
|
|
90
90
|
case "warn":
|
|
91
|
-
return m.warning ? m.warning(
|
|
91
|
+
return m.warning ? m.warning(e) : e;
|
|
92
92
|
case "error":
|
|
93
|
-
return m.error ? m.error(
|
|
93
|
+
return m.error ? m.error(e) : e;
|
|
94
94
|
case "fatal":
|
|
95
|
-
return m.error ? m.error(m.styles?.bold?.(
|
|
95
|
+
return m.error ? m.error(m.styles?.bold?.(e) ?? e) : e;
|
|
96
96
|
default:
|
|
97
|
-
return
|
|
97
|
+
return e;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
async function k(n,
|
|
101
|
-
const
|
|
100
|
+
async function k(n, e) {
|
|
101
|
+
const t = n.getWriter();
|
|
102
102
|
try {
|
|
103
|
-
await
|
|
103
|
+
await t.write(e);
|
|
104
104
|
} finally {
|
|
105
|
-
|
|
105
|
+
t.releaseLock();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
async function Z(...n) {
|
|
109
|
-
const t = S("trace", ...n), e = E("trace", t);
|
|
110
|
-
await k(g.stdout, e);
|
|
111
|
-
}
|
|
112
108
|
async function x(...n) {
|
|
113
|
-
const
|
|
114
|
-
await k(g.stdout,
|
|
109
|
+
const e = S("trace", ...n), t = E("trace", e);
|
|
110
|
+
await k(g.stdout, t);
|
|
115
111
|
}
|
|
116
112
|
async function tt(...n) {
|
|
117
|
-
const
|
|
118
|
-
await k(g.stdout,
|
|
113
|
+
const e = S("info", ...n), t = E("info", e);
|
|
114
|
+
await k(g.stdout, t);
|
|
119
115
|
}
|
|
120
116
|
async function et(...n) {
|
|
121
|
-
const
|
|
122
|
-
await k(g.
|
|
117
|
+
const e = S("warn", ...n), t = E("warn", e);
|
|
118
|
+
await k(g.stdout, t);
|
|
123
119
|
}
|
|
124
120
|
async function nt(...n) {
|
|
125
|
-
const
|
|
126
|
-
await k(g.stderr,
|
|
121
|
+
const e = S("error", ...n), t = E("error", e);
|
|
122
|
+
await k(g.stderr, t);
|
|
123
|
+
}
|
|
124
|
+
async function rt(...n) {
|
|
125
|
+
const e = S("fatal", ...n), t = E("fatal", e);
|
|
126
|
+
await k(g.stderr, t), A ? Deno.exit(-1) : (W || j) && process.exit(-1);
|
|
127
127
|
}
|
|
128
128
|
const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
129
129
|
__proto__: null,
|
|
130
|
-
error:
|
|
131
|
-
fatal:
|
|
132
|
-
info:
|
|
133
|
-
setConfig:
|
|
130
|
+
error: nt,
|
|
131
|
+
fatal: rt,
|
|
132
|
+
info: tt,
|
|
133
|
+
setConfig: L,
|
|
134
134
|
setTheme: I,
|
|
135
|
-
setup:
|
|
136
|
-
trace:
|
|
137
|
-
warn:
|
|
135
|
+
setup: Z,
|
|
136
|
+
trace: x,
|
|
137
|
+
warn: et
|
|
138
138
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
139
139
|
class F {
|
|
140
140
|
/**
|
|
@@ -143,76 +143,76 @@ class F {
|
|
|
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.$input = {}, this.$fn = void 0, this.$errorFn = void 0, this.$names = Array.isArray(
|
|
146
|
+
constructor(e, t, r) {
|
|
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(e) ? e : [e], this.$description = t, this.$version = r;
|
|
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(...e) {
|
|
155
|
+
return this.$names.concat(e), 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(e) {
|
|
163
|
+
return this.$description = e, 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(e) {
|
|
171
|
+
return this.$version = e, 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(e) {
|
|
179
|
+
return this.$input = e, this;
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Sets the action function for this command.
|
|
183
183
|
* @param fn The action.
|
|
184
184
|
* @returns this
|
|
185
185
|
*/
|
|
186
|
-
action(
|
|
187
|
-
return this.$fn =
|
|
186
|
+
action(e) {
|
|
187
|
+
return this.$fn = e, this;
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* Sets the error function for this command.
|
|
191
191
|
* @param fn The error handler.
|
|
192
192
|
* @returns this
|
|
193
193
|
*/
|
|
194
|
-
error(
|
|
195
|
-
return this.$errorFn =
|
|
194
|
+
error(e) {
|
|
195
|
+
return this.$errorFn = e, this;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* Adds an existing command to this.
|
|
199
199
|
* @param command The command.
|
|
200
200
|
* @returns this
|
|
201
201
|
*/
|
|
202
|
-
add(
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
for (let r = 0; r <
|
|
206
|
-
r === 0 && this.$children.set(
|
|
202
|
+
add(e) {
|
|
203
|
+
e.$parent = this;
|
|
204
|
+
const t = { command: e, alias: e.$names[0] };
|
|
205
|
+
for (let r = 0; r < e.$names.length; r++)
|
|
206
|
+
r === 0 && this.$children.set(e.$names[r], { command: e }), this.$children.set(e.$names[r], t);
|
|
207
207
|
return this;
|
|
208
208
|
}
|
|
209
|
-
subCommand(
|
|
210
|
-
if (typeof
|
|
211
|
-
const
|
|
212
|
-
return
|
|
209
|
+
subCommand(e, t, r) {
|
|
210
|
+
if (typeof t == "function") {
|
|
211
|
+
const a = new F(e);
|
|
212
|
+
return t(a), this.add(a), this;
|
|
213
213
|
}
|
|
214
|
-
const
|
|
215
|
-
return this.add(
|
|
214
|
+
const i = new F(e, t, r);
|
|
215
|
+
return this.add(i), i;
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Allows unknown options.
|
|
@@ -226,129 +226,133 @@ class F {
|
|
|
226
226
|
* @param argv The arguments to parse.
|
|
227
227
|
* @returns A parse result.
|
|
228
228
|
*/
|
|
229
|
-
async parse(
|
|
230
|
-
let
|
|
231
|
-
const
|
|
232
|
-
function u(f,
|
|
233
|
-
const l =
|
|
234
|
-
return l ? l.value : (!
|
|
229
|
+
async parse(e) {
|
|
230
|
+
let t = this, r = !1;
|
|
231
|
+
const i = {}, a = [], d = {}, s = [], c = t.buildInputMap();
|
|
232
|
+
function u(f, o) {
|
|
233
|
+
const l = c.get(f);
|
|
234
|
+
return l ? l.value : (!t.$allowUnknownOptions && !o && s.push(new K(t, f)), null);
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
|
|
236
|
+
function h(f, o, l) {
|
|
237
|
+
o.$kind === "boolean" ? d[f] = "true" : l !== void 0 && (d[f] = l);
|
|
238
238
|
}
|
|
239
|
-
let
|
|
240
|
-
for (let f = 0; f <
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
const [l, w] =
|
|
239
|
+
let p = !1, C = !1;
|
|
240
|
+
for (let f = 0; f < e.length; f++) {
|
|
241
|
+
const o = e[f];
|
|
242
|
+
if (o.startsWith("--")) {
|
|
243
|
+
const [l, w] = o.slice(2).split("=");
|
|
244
244
|
let y = !1;
|
|
245
|
-
l === "help" ? (C = !0, y = !0) : l === "version" && (
|
|
245
|
+
l === "help" ? (C = !0, y = !0) : l === "version" && (p = !0, y = !0);
|
|
246
246
|
const $ = u(l, y);
|
|
247
|
-
$ && (w === void 0 ?
|
|
247
|
+
$ && (w === void 0 ? h(
|
|
248
248
|
l,
|
|
249
249
|
$,
|
|
250
|
-
$.$kind === "boolean" ? void 0 :
|
|
251
|
-
) :
|
|
252
|
-
} else if (
|
|
253
|
-
const [l, w] =
|
|
250
|
+
$.$kind === "boolean" ? void 0 : e[++f]
|
|
251
|
+
) : h(l, $, w));
|
|
252
|
+
} else if (o.startsWith("-")) {
|
|
253
|
+
const [l, w] = o.slice(1).split("="), y = l.split("");
|
|
254
254
|
let $ = w;
|
|
255
255
|
for (const D of y) {
|
|
256
|
-
let
|
|
257
|
-
D === "h" ? (C = !0,
|
|
258
|
-
const
|
|
259
|
-
|
|
256
|
+
let T = !1;
|
|
257
|
+
D === "h" ? (C = !0, T = !0) : D === "V" && (p = !0, T = !0);
|
|
258
|
+
const U = u(D, T);
|
|
259
|
+
U && (U.$kind !== "boolean" && $ === void 0 && ($ = e[++f]), h(D, U, $), $ = void 0);
|
|
260
260
|
}
|
|
261
261
|
} else
|
|
262
|
-
|
|
262
|
+
t.$children.has(o) && !r ? (t = t.$children.get(o).command, t.$theme && (q(t.$theme), I(t.$theme))) : (r = !0, a.push(o));
|
|
263
263
|
}
|
|
264
|
-
let
|
|
265
|
-
for (const f in
|
|
266
|
-
const
|
|
264
|
+
let M = 0;
|
|
265
|
+
for (const f in t.$input) {
|
|
266
|
+
const o = t.$input[f];
|
|
267
267
|
let l;
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
if (o instanceof B) {
|
|
269
|
+
if (o.$list) {
|
|
270
|
+
if (l = a.slice(M), M = a.length, !t.$allowSurpassArgLimit && l.length === 0)
|
|
271
|
+
throw new H(t);
|
|
272
|
+
} else if (l = a[M++], M > a.length && !t.$allowSurpassArgLimit)
|
|
273
|
+
throw new H(t);
|
|
274
|
+
} else
|
|
275
|
+
for (const w of o.$names)
|
|
272
276
|
if (d[w] !== void 0) {
|
|
273
|
-
l = d[w];
|
|
277
|
+
l = o.$list ? d[w] : d[w].split(o.$separator ?? ",");
|
|
274
278
|
break;
|
|
275
279
|
}
|
|
276
|
-
l !== void 0 ?
|
|
280
|
+
l !== void 0 ? i[f] = await G(o.$kind, l) : o.$default !== void 0 ? i[f] = o.$default : o.$required && (o instanceof _ ? s.push(new z(t, f, o)) : s.push(new N(t, f, o)));
|
|
277
281
|
}
|
|
278
282
|
return {
|
|
279
|
-
input:
|
|
280
|
-
command:
|
|
283
|
+
input: i,
|
|
284
|
+
command: t,
|
|
281
285
|
errors: s,
|
|
282
|
-
isVersion:
|
|
286
|
+
isVersion: p,
|
|
283
287
|
isHelp: C
|
|
284
288
|
};
|
|
285
289
|
}
|
|
286
|
-
buildInputMap(
|
|
287
|
-
const
|
|
290
|
+
buildInputMap(e) {
|
|
291
|
+
const t = /* @__PURE__ */ new Map();
|
|
288
292
|
let r = 0;
|
|
289
|
-
for (const
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
+
for (const i in this.$input) {
|
|
294
|
+
const a = this.$input[i];
|
|
295
|
+
if (a instanceof B)
|
|
296
|
+
t.set(r++, { value: a, key: i });
|
|
293
297
|
else
|
|
294
|
-
for (const d of
|
|
295
|
-
|
|
298
|
+
for (const d of a.$names)
|
|
299
|
+
t.set(d, { value: a, key: i });
|
|
296
300
|
}
|
|
297
|
-
if (!
|
|
298
|
-
for (const [
|
|
299
|
-
|
|
300
|
-
for (const [, { command:
|
|
301
|
-
for (const [
|
|
302
|
-
|
|
303
|
-
return
|
|
301
|
+
if (!e)
|
|
302
|
+
for (const [i, a] of this.$parent?.buildInputMap() ?? [])
|
|
303
|
+
t.set(i, a);
|
|
304
|
+
for (const [, { command: i }] of this.$children)
|
|
305
|
+
for (const [a, d] of i.buildInputMap(!0))
|
|
306
|
+
t.set(a, d);
|
|
307
|
+
return t;
|
|
304
308
|
}
|
|
305
309
|
/**
|
|
306
310
|
* Gets the full command path (name including parents).
|
|
307
311
|
* @returns The full command path.
|
|
308
312
|
*/
|
|
309
313
|
fullCommandPath() {
|
|
310
|
-
const
|
|
311
|
-
let
|
|
312
|
-
for (;
|
|
313
|
-
|
|
314
|
-
return
|
|
314
|
+
const e = [];
|
|
315
|
+
let t = this;
|
|
316
|
+
for (; t; )
|
|
317
|
+
e.unshift(t.$names[0]), t = t.$parent;
|
|
318
|
+
return e.join(" ");
|
|
315
319
|
}
|
|
316
320
|
/**
|
|
317
321
|
* The default error screen.
|
|
318
322
|
* @param errors The errors.
|
|
319
323
|
*/
|
|
320
|
-
defaultErrorScreen(
|
|
321
|
-
let
|
|
324
|
+
defaultErrorScreen(e) {
|
|
325
|
+
let t = !1;
|
|
322
326
|
const r = [];
|
|
323
|
-
for (const s of
|
|
324
|
-
s instanceof
|
|
327
|
+
for (const s of e)
|
|
328
|
+
s instanceof J ? (s instanceof P || s.print(), t = !0) : r.push(s);
|
|
325
329
|
if (r.length) throw r[0];
|
|
326
|
-
if (!
|
|
327
|
-
const
|
|
330
|
+
if (!t) return;
|
|
331
|
+
const i = (s, c) => s.padEnd(c, " ");
|
|
328
332
|
console.log(
|
|
329
|
-
`${b("usage:")} ${v(this.fullCommandPath())} ${
|
|
333
|
+
`${b("usage:")} ${v(this.fullCommandPath())} ${O("[options] [arguments]")}`
|
|
330
334
|
), this.$description && console.log(`${this.$description}`), this.$version && console.log(`${b("version")} ${this.$version}`);
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
335
|
+
const a = Object.entries(this.$input).filter(([, s]) => s instanceof _).map(([s, c]) => ({ key: s, entry: c }));
|
|
336
|
+
if (a.length > 0) {
|
|
333
337
|
console.log(b("options:"));
|
|
334
338
|
const s = Math.max(
|
|
335
|
-
...
|
|
339
|
+
...a.map(({ entry: c }) => c.$names.join(", ").length)
|
|
336
340
|
);
|
|
337
|
-
for (const { entry:
|
|
338
|
-
const u =
|
|
339
|
-
console.log(
|
|
341
|
+
for (const { entry: c } of a) {
|
|
342
|
+
const u = c.$names.map((p) => p.length === 1 ? `-${p}` : `--${p}`).join(", "), h = ` ${v(i(u, s + 4))}${O(c.$description ?? "")}`;
|
|
343
|
+
console.log(h);
|
|
340
344
|
}
|
|
341
345
|
}
|
|
342
|
-
const d = Object.entries(this.$input).filter(([, s]) => s instanceof B).map(([s,
|
|
346
|
+
const d = Object.entries(this.$input).filter(([, s]) => s instanceof B).map(([s, c]) => ({
|
|
343
347
|
key: s,
|
|
344
|
-
entry:
|
|
348
|
+
entry: c
|
|
345
349
|
}));
|
|
346
350
|
if (d.length > 0) {
|
|
347
351
|
console.log(b("arguments:"));
|
|
348
|
-
const s = Math.max(...d.map(({ key:
|
|
349
|
-
for (const { key:
|
|
350
|
-
const
|
|
351
|
-
console.log(
|
|
352
|
+
const s = Math.max(...d.map(({ key: c }) => c.length));
|
|
353
|
+
for (const { key: c, entry: u } of d) {
|
|
354
|
+
const h = u.$required ? `<${c}>` : `[${c}]`, p = ` ${v(i(h, s + 4))}${O(u.$description ?? "")}`;
|
|
355
|
+
console.log(p);
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
358
|
if (this.$children.size > 0) {
|
|
@@ -360,10 +364,10 @@ class F {
|
|
|
360
364
|
u.command
|
|
361
365
|
])
|
|
362
366
|
).values()
|
|
363
|
-
),
|
|
367
|
+
), c = Math.max(...s.map((u) => u.$names[0].length));
|
|
364
368
|
for (const u of s) {
|
|
365
|
-
const
|
|
366
|
-
console.log(
|
|
369
|
+
const h = ` ${v(i(u.$names[0], c + 4))}${O(u.$description) ?? ""}`;
|
|
370
|
+
console.log(h);
|
|
367
371
|
}
|
|
368
372
|
console.log(), console.log(
|
|
369
373
|
`run '${v(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`
|
|
@@ -376,35 +380,35 @@ class F {
|
|
|
376
380
|
* @param input The parsed input, if possible.
|
|
377
381
|
* @returns this
|
|
378
382
|
*/
|
|
379
|
-
async handleErrors(
|
|
383
|
+
async handleErrors(e, t) {
|
|
380
384
|
let r = this;
|
|
381
385
|
for (; !r.$errorFn && r.$parent; )
|
|
382
386
|
r = r.$parent;
|
|
383
|
-
return r.$errorFn ? await r.$errorFn(r,
|
|
387
|
+
return r.$errorFn ? await r.$errorFn(r, e, t ?? {}) : this.defaultErrorScreen(e), this;
|
|
384
388
|
}
|
|
385
389
|
/**
|
|
386
390
|
* Runs a command.
|
|
387
391
|
* @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.
|
|
388
392
|
* @returns this
|
|
389
393
|
*/
|
|
390
|
-
async run(
|
|
391
|
-
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
394
|
-
return
|
|
395
|
-
if (
|
|
394
|
+
async run(e) {
|
|
395
|
+
e || (e = typeof Bun < "u" ? Bun.argv.slice(2) : typeof Deno < "u" ? Deno.args : process.argv.slice(2));
|
|
396
|
+
const t = await this.parse(e);
|
|
397
|
+
if (t.isHelp)
|
|
398
|
+
return t.command.handleErrors([new P(t.command)]), this;
|
|
399
|
+
if (t.isVersion)
|
|
396
400
|
return console.log(
|
|
397
|
-
`${
|
|
401
|
+
`${t.command.fullCommandPath()} version ${t.command.$version}`
|
|
398
402
|
), this;
|
|
399
403
|
try {
|
|
400
|
-
|
|
401
|
-
[new
|
|
402
|
-
|
|
404
|
+
t.errors.length > 0 ? await t.command.handleErrors(t.errors, t.input) : t.command.$fn ? await t.command.$fn(t.input) : await t.command.handleErrors(
|
|
405
|
+
[new P(t.command), ...t.errors],
|
|
406
|
+
t.input
|
|
403
407
|
);
|
|
404
408
|
} catch (r) {
|
|
405
409
|
r instanceof Error || console.warn(
|
|
406
|
-
"[
|
|
407
|
-
), await
|
|
410
|
+
"[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior."
|
|
411
|
+
), await t.command.handleErrors([r]);
|
|
408
412
|
}
|
|
409
413
|
return this;
|
|
410
414
|
}
|
package/dist/error.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ declare class Command<T extends Input = Input> {
|
|
|
50
50
|
* If this command allows unknown options.
|
|
51
51
|
*/
|
|
52
52
|
$allowUnknownOptions: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* If you should be able to surpass the amount of positional arguments defined in the input.
|
|
55
|
+
*/
|
|
56
|
+
$allowSurpassArgLimit: boolean;
|
|
53
57
|
/**
|
|
54
58
|
* The input this command takes.
|
|
55
59
|
*/
|
|
@@ -175,6 +179,46 @@ declare interface CommandAlias<T extends Input = Input> {
|
|
|
175
179
|
alias?: string;
|
|
176
180
|
}
|
|
177
181
|
|
|
182
|
+
/**
|
|
183
|
+
* A Convoker-related error. These are usually handled by default.
|
|
184
|
+
*/
|
|
185
|
+
export declare class ConvokerError extends Error {
|
|
186
|
+
/**
|
|
187
|
+
* The command this error happened on.
|
|
188
|
+
*/
|
|
189
|
+
command: Command<any>;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new Convoker error.
|
|
192
|
+
* @param message The message.
|
|
193
|
+
* @param command The command.
|
|
194
|
+
*/
|
|
195
|
+
constructor(message: string, command: Command<any>);
|
|
196
|
+
/**
|
|
197
|
+
* Prints the error's message.
|
|
198
|
+
*/
|
|
199
|
+
print(): void;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* A Convoker-related error. These are usually handled by default.
|
|
204
|
+
*/
|
|
205
|
+
declare class ConvokerError_2 extends Error {
|
|
206
|
+
/**
|
|
207
|
+
* The command this error happened on.
|
|
208
|
+
*/
|
|
209
|
+
command: Command<any>;
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new Convoker error.
|
|
212
|
+
* @param message The message.
|
|
213
|
+
* @param command The command.
|
|
214
|
+
*/
|
|
215
|
+
constructor(message: string, command: Command<any>);
|
|
216
|
+
/**
|
|
217
|
+
* Prints the error's message.
|
|
218
|
+
*/
|
|
219
|
+
print(): void;
|
|
220
|
+
}
|
|
221
|
+
|
|
178
222
|
/**
|
|
179
223
|
* Command error handler.
|
|
180
224
|
*/
|
|
@@ -183,7 +227,7 @@ declare type ErrorFn<T extends Input> = (command: Command<T>, errors: Error[], i
|
|
|
183
227
|
/**
|
|
184
228
|
* When the user asks for help.
|
|
185
229
|
*/
|
|
186
|
-
export declare class HelpAskedError extends
|
|
230
|
+
export declare class HelpAskedError extends ConvokerError {
|
|
187
231
|
/**
|
|
188
232
|
* Creates a new help asked error.
|
|
189
233
|
* @param command The command.
|
|
@@ -239,47 +283,7 @@ declare type Kind = BasicKind | StandardSchemaV1<any, any>;
|
|
|
239
283
|
*/
|
|
240
284
|
declare type Kind_2 = BasicKind_2 | StandardSchemaV1_2<any, any>;
|
|
241
285
|
|
|
242
|
-
|
|
243
|
-
* A LunarCLI-related error. These are usually handled by default.
|
|
244
|
-
*/
|
|
245
|
-
export declare class LunarCLIError extends Error {
|
|
246
|
-
/**
|
|
247
|
-
* The command this error happened on.
|
|
248
|
-
*/
|
|
249
|
-
command: Command<any>;
|
|
250
|
-
/**
|
|
251
|
-
* Creates a new LunarCLI error.
|
|
252
|
-
* @param message The message.
|
|
253
|
-
* @param command The command.
|
|
254
|
-
*/
|
|
255
|
-
constructor(message: string, command: Command<any>);
|
|
256
|
-
/**
|
|
257
|
-
* Prints the error's message.
|
|
258
|
-
*/
|
|
259
|
-
print(): void;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* A LunarCLI-related error. These are usually handled by default.
|
|
264
|
-
*/
|
|
265
|
-
declare class LunarCLIError_2 extends Error {
|
|
266
|
-
/**
|
|
267
|
-
* The command this error happened on.
|
|
268
|
-
*/
|
|
269
|
-
command: Command<any>;
|
|
270
|
-
/**
|
|
271
|
-
* Creates a new LunarCLI error.
|
|
272
|
-
* @param message The message.
|
|
273
|
-
* @param command The command.
|
|
274
|
-
*/
|
|
275
|
-
constructor(message: string, command: Command<any>);
|
|
276
|
-
/**
|
|
277
|
-
* Prints the error's message.
|
|
278
|
-
*/
|
|
279
|
-
print(): void;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export declare class MissingRequiredArgumentError extends LunarCLIError {
|
|
286
|
+
export declare class MissingRequiredArgumentError extends ConvokerError {
|
|
283
287
|
/**
|
|
284
288
|
* The argument key.
|
|
285
289
|
*/
|
|
@@ -300,7 +304,7 @@ export declare class MissingRequiredArgumentError extends LunarCLIError {
|
|
|
300
304
|
/**
|
|
301
305
|
* When a required option is missing.
|
|
302
306
|
*/
|
|
303
|
-
export declare class MissingRequiredOptionError extends
|
|
307
|
+
export declare class MissingRequiredOptionError extends ConvokerError {
|
|
304
308
|
/**
|
|
305
309
|
* The option key.
|
|
306
310
|
*/
|
|
@@ -346,6 +350,10 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
346
350
|
* If this option is a list.
|
|
347
351
|
*/
|
|
348
352
|
$list: TList;
|
|
353
|
+
/**
|
|
354
|
+
* A separator if this option is a list.
|
|
355
|
+
*/
|
|
356
|
+
$separator: string | undefined;
|
|
349
357
|
/**
|
|
350
358
|
* Creates a new option.
|
|
351
359
|
* @param kind The type of this option.
|
|
@@ -356,7 +364,7 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
356
364
|
* Makes this option a list.
|
|
357
365
|
* @returns this
|
|
358
366
|
*/
|
|
359
|
-
list(): Option_2<TKind, TRequired, true>;
|
|
367
|
+
list(separator?: string): Option_2<TKind, TRequired, true>;
|
|
360
368
|
/**
|
|
361
369
|
* Makes this option required.
|
|
362
370
|
* @returns this
|
|
@@ -409,6 +417,10 @@ declare class Option_2_2<TKind extends Kind_2, TRequired extends boolean = true,
|
|
|
409
417
|
* If this option is a list.
|
|
410
418
|
*/
|
|
411
419
|
$list: TList;
|
|
420
|
+
/**
|
|
421
|
+
* A separator if this option is a list.
|
|
422
|
+
*/
|
|
423
|
+
$separator: string | undefined;
|
|
412
424
|
/**
|
|
413
425
|
* Creates a new option.
|
|
414
426
|
* @param kind The type of this option.
|
|
@@ -419,7 +431,7 @@ declare class Option_2_2<TKind extends Kind_2, TRequired extends boolean = true,
|
|
|
419
431
|
* Makes this option a list.
|
|
420
432
|
* @returns this
|
|
421
433
|
*/
|
|
422
|
-
list(): Option_2_2<TKind, TRequired, true>;
|
|
434
|
+
list(separator?: string): Option_2_2<TKind, TRequired, true>;
|
|
423
435
|
/**
|
|
424
436
|
* Makes this option required.
|
|
425
437
|
* @returns this
|
|
@@ -459,7 +471,7 @@ declare interface ParseResult<T extends Input> {
|
|
|
459
471
|
/**
|
|
460
472
|
* Errors collected during parsing.
|
|
461
473
|
*/
|
|
462
|
-
errors:
|
|
474
|
+
errors: ConvokerError_2[];
|
|
463
475
|
/**
|
|
464
476
|
* If this should result in displaying the version of the command.
|
|
465
477
|
*/
|
|
@@ -795,7 +807,7 @@ declare interface Theme {
|
|
|
795
807
|
/**
|
|
796
808
|
* When you pass too many arguments.
|
|
797
809
|
*/
|
|
798
|
-
export declare class TooManyArgumentsError extends
|
|
810
|
+
export declare class TooManyArgumentsError extends ConvokerError {
|
|
799
811
|
/**
|
|
800
812
|
* Creates a new too many arguments error.
|
|
801
813
|
* @param command The command.
|
|
@@ -816,7 +828,7 @@ declare type TypeOf_2<T extends Kind_2> = T extends StandardSchemaV1_2<any, infe
|
|
|
816
828
|
/**
|
|
817
829
|
* When you pass an unknown option, when unknown options aren't allowed.
|
|
818
830
|
*/
|
|
819
|
-
export declare class UnknownOptionError extends
|
|
831
|
+
export declare class UnknownOptionError extends ConvokerError {
|
|
820
832
|
/**
|
|
821
833
|
* The option key.
|
|
822
834
|
*/
|
package/dist/error.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as n, H as s, I as a, a as e, M as i, T as t, U as E } from "./chunks/error-CBR2veuf.js";
|
|
2
2
|
export {
|
|
3
|
-
n as
|
|
4
|
-
s as
|
|
5
|
-
a as
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
n as ConvokerError,
|
|
4
|
+
s as HelpAskedError,
|
|
5
|
+
a as InputValidationError,
|
|
6
|
+
e as MissingRequiredArgumentError,
|
|
7
|
+
i as MissingRequiredOptionError,
|
|
8
8
|
t as TooManyArgumentsError,
|
|
9
9
|
E as UnknownOptionError
|
|
10
10
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,10 @@ export declare class Command<T extends Input = Input> {
|
|
|
178
178
|
* If this command allows unknown options.
|
|
179
179
|
*/
|
|
180
180
|
$allowUnknownOptions: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* If you should be able to surpass the amount of positional arguments defined in the input.
|
|
183
|
+
*/
|
|
184
|
+
$allowSurpassArgLimit: boolean;
|
|
181
185
|
/**
|
|
182
186
|
* The input this command takes.
|
|
183
187
|
*/
|
|
@@ -330,7 +334,27 @@ declare interface ConfirmOpts extends BaseOpts<boolean> {
|
|
|
330
334
|
* @param value The value to convert.
|
|
331
335
|
* @returns The converted value.
|
|
332
336
|
*/
|
|
333
|
-
declare function convert<TKind extends Kind>(kind: TKind, value: string): Promise<TypeOf<TKind
|
|
337
|
+
declare function convert<TKind extends Kind>(kind: TKind, value: string | string[]): Promise<TypeOf<TKind> | TypeOf<TKind>[]>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A Convoker-related error. These are usually handled by default.
|
|
341
|
+
*/
|
|
342
|
+
declare class ConvokerError extends Error {
|
|
343
|
+
/**
|
|
344
|
+
* The command this error happened on.
|
|
345
|
+
*/
|
|
346
|
+
command: Command<any>;
|
|
347
|
+
/**
|
|
348
|
+
* Creates a new Convoker error.
|
|
349
|
+
* @param message The message.
|
|
350
|
+
* @param command The command.
|
|
351
|
+
*/
|
|
352
|
+
constructor(message: string, command: Command<any>);
|
|
353
|
+
/**
|
|
354
|
+
* Prints the error's message.
|
|
355
|
+
*/
|
|
356
|
+
print(): void;
|
|
357
|
+
}
|
|
334
358
|
|
|
335
359
|
/**
|
|
336
360
|
* Creates a function that wraps a string in ANSI codes.
|
|
@@ -398,7 +422,7 @@ declare interface EditorOpts extends BaseOpts<string> {
|
|
|
398
422
|
export declare namespace error {
|
|
399
423
|
export {
|
|
400
424
|
InputValidationError,
|
|
401
|
-
|
|
425
|
+
ConvokerError,
|
|
402
426
|
HelpAskedError,
|
|
403
427
|
TooManyArgumentsError,
|
|
404
428
|
UnknownOptionError,
|
|
@@ -433,7 +457,7 @@ declare const greenBright: (input: any) => string;
|
|
|
433
457
|
/**
|
|
434
458
|
* When the user asks for help.
|
|
435
459
|
*/
|
|
436
|
-
declare class HelpAskedError extends
|
|
460
|
+
declare class HelpAskedError extends ConvokerError {
|
|
437
461
|
/**
|
|
438
462
|
* Creates a new help asked error.
|
|
439
463
|
* @param command The command.
|
|
@@ -549,31 +573,11 @@ declare interface LogConfig {
|
|
|
549
573
|
stdin: ReadableStream<string>;
|
|
550
574
|
}
|
|
551
575
|
|
|
552
|
-
/**
|
|
553
|
-
* A LunarCLI-related error. These are usually handled by default.
|
|
554
|
-
*/
|
|
555
|
-
declare class LunarCLIError extends Error {
|
|
556
|
-
/**
|
|
557
|
-
* The command this error happened on.
|
|
558
|
-
*/
|
|
559
|
-
command: Command<any>;
|
|
560
|
-
/**
|
|
561
|
-
* Creates a new LunarCLI error.
|
|
562
|
-
* @param message The message.
|
|
563
|
-
* @param command The command.
|
|
564
|
-
*/
|
|
565
|
-
constructor(message: string, command: Command<any>);
|
|
566
|
-
/**
|
|
567
|
-
* Prints the error's message.
|
|
568
|
-
*/
|
|
569
|
-
print(): void;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
576
|
declare const magenta: (input: any) => string;
|
|
573
577
|
|
|
574
578
|
declare const magentaBright: (input: any) => string;
|
|
575
579
|
|
|
576
|
-
declare class MissingRequiredArgumentError extends
|
|
580
|
+
declare class MissingRequiredArgumentError extends ConvokerError {
|
|
577
581
|
/**
|
|
578
582
|
* The argument key.
|
|
579
583
|
*/
|
|
@@ -594,7 +598,7 @@ declare class MissingRequiredArgumentError extends LunarCLIError {
|
|
|
594
598
|
/**
|
|
595
599
|
* When a required option is missing.
|
|
596
600
|
*/
|
|
597
|
-
declare class MissingRequiredOptionError extends
|
|
601
|
+
declare class MissingRequiredOptionError extends ConvokerError {
|
|
598
602
|
/**
|
|
599
603
|
* The option key.
|
|
600
604
|
*/
|
|
@@ -655,6 +659,10 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
655
659
|
* If this option is a list.
|
|
656
660
|
*/
|
|
657
661
|
$list: TList;
|
|
662
|
+
/**
|
|
663
|
+
* A separator if this option is a list.
|
|
664
|
+
*/
|
|
665
|
+
$separator: string | undefined;
|
|
658
666
|
/**
|
|
659
667
|
* Creates a new option.
|
|
660
668
|
* @param kind The type of this option.
|
|
@@ -665,7 +673,7 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
665
673
|
* Makes this option a list.
|
|
666
674
|
* @returns this
|
|
667
675
|
*/
|
|
668
|
-
list(): Option_2<TKind, TRequired, true>;
|
|
676
|
+
list(separator?: string): Option_2<TKind, TRequired, true>;
|
|
669
677
|
/**
|
|
670
678
|
* Makes this option required.
|
|
671
679
|
* @returns this
|
|
@@ -707,7 +715,7 @@ export declare interface ParseResult<T extends Input> {
|
|
|
707
715
|
/**
|
|
708
716
|
* Errors collected during parsing.
|
|
709
717
|
*/
|
|
710
|
-
errors:
|
|
718
|
+
errors: ConvokerError[];
|
|
711
719
|
/**
|
|
712
720
|
* If this should result in displaying the version of the command.
|
|
713
721
|
*/
|
|
@@ -1142,7 +1150,7 @@ declare interface Theme {
|
|
|
1142
1150
|
/**
|
|
1143
1151
|
* When you pass too many arguments.
|
|
1144
1152
|
*/
|
|
1145
|
-
declare class TooManyArgumentsError extends
|
|
1153
|
+
declare class TooManyArgumentsError extends ConvokerError {
|
|
1146
1154
|
/**
|
|
1147
1155
|
* Creates a new too many arguments error.
|
|
1148
1156
|
* @param command The command.
|
|
@@ -1166,7 +1174,7 @@ declare const underline: (input: any) => string;
|
|
|
1166
1174
|
/**
|
|
1167
1175
|
* When you pass an unknown option, when unknown options aren't allowed.
|
|
1168
1176
|
*/
|
|
1169
|
-
declare class UnknownOptionError extends
|
|
1177
|
+
declare class UnknownOptionError extends ConvokerError {
|
|
1170
1178
|
/**
|
|
1171
1179
|
* The option key.
|
|
1172
1180
|
*/
|
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-CBR2veuf.js";
|
|
3
|
+
import { i as f } from "./chunks/input-BfYvlWdG.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-D7JQKzRX.js";
|
|
6
6
|
export {
|
|
7
7
|
m as Command,
|
|
8
8
|
s as color,
|
package/dist/input.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type BasicKind = "boolean" | "string" | "number" | "bigint";
|
|
|
16
16
|
* @param value The value to convert.
|
|
17
17
|
* @returns The converted value.
|
|
18
18
|
*/
|
|
19
|
-
export declare function convert<TKind extends Kind>(kind: TKind, value: string): Promise<TypeOf<TKind
|
|
19
|
+
export declare function convert<TKind extends Kind>(kind: TKind, value: string | string[]): Promise<TypeOf<TKind> | TypeOf<TKind>[]>;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Infers a TypeScript type from an option or positional.
|
|
@@ -82,6 +82,10 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
82
82
|
* If this option is a list.
|
|
83
83
|
*/
|
|
84
84
|
$list: TList;
|
|
85
|
+
/**
|
|
86
|
+
* A separator if this option is a list.
|
|
87
|
+
*/
|
|
88
|
+
$separator: string | undefined;
|
|
85
89
|
/**
|
|
86
90
|
* Creates a new option.
|
|
87
91
|
* @param kind The type of this option.
|
|
@@ -92,7 +96,7 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
|
|
|
92
96
|
* Makes this option a list.
|
|
93
97
|
* @returns this
|
|
94
98
|
*/
|
|
95
|
-
list(): Option_2<TKind, TRequired, true>;
|
|
99
|
+
list(separator?: string): Option_2<TKind, TRequired, true>;
|
|
96
100
|
/**
|
|
97
101
|
* Makes this option required.
|
|
98
102
|
* @returns this
|
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-CFxVDMhv.js";
|
|
2
|
+
import { O as t, P as i, a as n, c as p, o as r, p as e } from "./chunks/input-BfYvlWdG.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-CFxVDMhv.js";
|
|
3
|
+
import "./chunks/error-CBR2veuf.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-D7JQKzRX.js";
|
|
7
7
|
export {
|
|
8
8
|
i as confirm,
|
|
9
9
|
c as editor,
|