convoker 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/chunk-z5eko27R.mjs +13 -0
  2. package/dist/color-BuHvMolk.d.mts +158 -0
  3. package/dist/color-OlJQTTxb.mjs +172 -0
  4. package/dist/color.d.mts +2 -0
  5. package/dist/color.mjs +4 -0
  6. package/dist/command-BXmfoT-l.d.mts +331 -0
  7. package/dist/command-D2UiQBNA.mjs +583 -0
  8. package/dist/command.d.mts +5 -0
  9. package/dist/command.mjs +10 -0
  10. package/dist/error-C1S1gs8L.mjs +115 -0
  11. package/dist/error.d.mts +5 -0
  12. package/dist/error.mjs +3 -0
  13. package/dist/index-Dikc5KAP.d.mts +199 -0
  14. package/dist/index.d.mts +73 -0
  15. package/dist/index.mjs +10 -0
  16. package/dist/input-B12iaqb8.d.mts +187 -0
  17. package/dist/input-DRy_sVxZ.mjs +174 -0
  18. package/dist/input.d.mts +3 -0
  19. package/dist/input.mjs +5 -0
  20. package/dist/prompt/index.d.mts +5 -0
  21. package/dist/prompt/index.mjs +8 -0
  22. package/dist/prompt/raw.d.mts +2 -0
  23. package/dist/prompt/raw.mjs +4 -0
  24. package/dist/prompt-Cvufljin.mjs +248 -0
  25. package/dist/raw--889icsd.mjs +105 -0
  26. package/dist/raw-BqvlveTU.d.mts +37 -0
  27. package/dist/standard-schema-DBXbMy6L.mjs +17 -0
  28. package/dist/standard-schema-DLeKaehR.d.mts +58 -0
  29. package/dist/utils-ChmY93uA.mjs +45 -0
  30. package/package.json +24 -19
  31. package/dist/color.d.ts +0 -153
  32. package/dist/color.js +0 -143
  33. package/dist/command.d.ts +0 -218
  34. package/dist/command.js +0 -531
  35. package/dist/error.d.ts +0 -107
  36. package/dist/error.js +0 -100
  37. package/dist/index.d.ts +0 -6
  38. package/dist/index.js +0 -6
  39. package/dist/input.d.ts +0 -182
  40. package/dist/input.js +0 -185
  41. package/dist/log.d.ts +0 -61
  42. package/dist/log.js +0 -216
  43. package/dist/prompt/index.d.ts +0 -193
  44. package/dist/prompt/index.js +0 -273
  45. package/dist/prompt/raw.d.ts +0 -32
  46. package/dist/prompt/raw.js +0 -105
  47. package/dist/standard-schema.d.ts +0 -62
  48. package/dist/standard-schema.js +0 -16
  49. package/dist/utils.d.ts +0 -30
  50. package/dist/utils.js +0 -56
@@ -0,0 +1,583 @@
1
+ import { t as __export } from "./chunk-z5eko27R.mjs";
2
+ import { i as merge, n as isDeno, r as isNode, t as isBun } from "./utils-ChmY93uA.mjs";
3
+ import { O as gray, t as DEFAULT_THEME, w as cyan, x as bold } from "./color-OlJQTTxb.mjs";
4
+ import { a as MissingRequiredOptionError, i as MissingRequiredArgumentError, n as HelpAskedError, o as TooManyArgumentsError, s as UnknownOptionError, t as ConvokerError } from "./error-C1S1gs8L.mjs";
5
+ import { c as setTheme } from "./prompt-Cvufljin.mjs";
6
+ import { i as convert, n as Positional, t as Option } from "./input-DRy_sVxZ.mjs";
7
+
8
+ //#region src/log.ts
9
+ var log_exports = /* @__PURE__ */ __export({
10
+ error: () => error,
11
+ fatal: () => fatal,
12
+ info: () => info,
13
+ setConfig: () => setConfig,
14
+ setTheme: () => setTheme$1,
15
+ setup: () => setup,
16
+ trace: () => trace,
17
+ warn: () => warn
18
+ });
19
+ /**
20
+ * Gets the default stdout, in a cross-runtime way.
21
+ * @returns The default stdout.
22
+ */
23
+ async function getDefaultStdout() {
24
+ if (isNode && process.stdout?.writable) {
25
+ const { Writable } = await import("node:stream");
26
+ return Writable.toWeb(process.stdout);
27
+ }
28
+ if (isDeno && Deno.stdout?.writable) return Deno.stdout.writable;
29
+ if (isBun && Bun.stdout) return Bun.stdout;
30
+ return new WritableStream({ write(chunk) {
31
+ console.log(String(chunk));
32
+ } });
33
+ }
34
+ /**
35
+ * Gets the default stderr, in a cross-runtime way.
36
+ * @returns The default stderr.
37
+ */
38
+ async function getDefaultStderr() {
39
+ if (isNode && process.stderr?.writable) {
40
+ const { Writable } = await import("node:stream");
41
+ return Writable.toWeb(process.stderr);
42
+ }
43
+ if (isDeno && Deno.stderr?.writable) return Deno.stderr.writable;
44
+ if (isBun && Bun.stderr) return Bun.stderr;
45
+ return new WritableStream({ write(chunk) {
46
+ console.error(String(chunk));
47
+ } });
48
+ }
49
+ /**
50
+ * Gets the default stdin, in a cross-runtime way.
51
+ * @returns The default stdin.
52
+ */
53
+ async function getDefaultStdin() {
54
+ if (isNode && process.stdin?.readable) {
55
+ const { Readable } = await import("node:stream");
56
+ return Readable.toWeb(process.stdin);
57
+ }
58
+ if (isDeno && Deno.stdin?.readable) return Deno.stdin.readable;
59
+ if (isBun) return Bun.stdin.stream();
60
+ return new ReadableStream({ start(controller) {
61
+ controller.close();
62
+ } });
63
+ }
64
+ let theme = DEFAULT_THEME;
65
+ let config = void 0;
66
+ /**
67
+ * Sets a new theme.
68
+ * @param t The theme.
69
+ */
70
+ function setTheme$1(t) {
71
+ theme = t;
72
+ }
73
+ /**
74
+ * Sets new configuration.
75
+ * @param c The config.
76
+ */
77
+ async function setConfig(c) {
78
+ config = merge({
79
+ format: "text",
80
+ stdout: await getDefaultStdout(),
81
+ stderr: await getDefaultStderr(),
82
+ stdin: await getDefaultStdin()
83
+ }, c);
84
+ }
85
+ /**
86
+ * Sets default configuration.
87
+ */
88
+ async function setup() {
89
+ await setConfig({});
90
+ }
91
+ /**
92
+ * Formats a message to the correct format.
93
+ * @param level The level of mesage.
94
+ * @param msgs The messages to format.
95
+ * @returns The formatted message.
96
+ */
97
+ function formatMessages(level, ...msgs) {
98
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
99
+ const msg = msgs.map((m) => typeof m === "string" ? m : JSON.stringify(m, null, 2)).join(" ");
100
+ switch (config.format) {
101
+ case "json": return JSON.stringify({
102
+ timestamp,
103
+ level,
104
+ message: msg
105
+ }) + "\n";
106
+ case "xml": return `<log>
107
+ <timestamp>${timestamp}</timestamp>
108
+ <level>${level}</level>
109
+ <message>${msg}</message>
110
+ </log>\n`;
111
+ case "yaml": return `- timestamp: ${timestamp}
112
+ level: ${level}
113
+ message: "${msg.replace(/"/g, "\\\"")}"\n`;
114
+ case "csv": return `"${timestamp}","${level}","${msg.replace(/"/g, "\"\"")}"\n`;
115
+ case "text":
116
+ default: return `[${timestamp}] [${level.toUpperCase()}] ${msg}\n`;
117
+ }
118
+ }
119
+ /**
120
+ * Colorizes text.
121
+ * @param level The log level.
122
+ * @param text The text to colorize.
123
+ * @returns The colorized text.
124
+ */
125
+ function colorize(level, text) {
126
+ switch (level) {
127
+ case "trace": return theme.secondary ? theme.secondary(text) : text;
128
+ case "info": return theme.info ? theme.info(text) : text;
129
+ case "warn": return theme.warning ? theme.warning(text) : text;
130
+ case "error": return theme.error ? theme.error(text) : text;
131
+ case "fatal": return theme.error ? theme.error(theme.styles?.bold?.(text) ?? text) : text;
132
+ default: return text;
133
+ }
134
+ }
135
+ /**
136
+ * Writes to a stream.
137
+ * @param stream The stream to write to.
138
+ * @param msg The message to write.
139
+ */
140
+ async function writeToStream(stream, msg) {
141
+ const writer = stream.getWriter();
142
+ try {
143
+ await writer.write(msg);
144
+ } finally {
145
+ writer.releaseLock();
146
+ }
147
+ }
148
+ /**
149
+ * Prints debug information.
150
+ * @param msgs The messages to write.
151
+ */
152
+ async function trace(...msgs) {
153
+ const colored = colorize("trace", formatMessages("trace", ...msgs));
154
+ await writeToStream(config.stdout, colored);
155
+ }
156
+ /**
157
+ * Prints information.
158
+ * @param msgs The messages to write.
159
+ */
160
+ async function info(...msgs) {
161
+ const colored = colorize("info", formatMessages("info", ...msgs));
162
+ await writeToStream(config.stdout, colored);
163
+ }
164
+ /**
165
+ * Prints warnings.
166
+ * @param msgs The messages to write.
167
+ */
168
+ async function warn(...msgs) {
169
+ const colored = colorize("warn", formatMessages("warn", ...msgs));
170
+ await writeToStream(config.stdout, colored);
171
+ }
172
+ /**
173
+ * Prints errors.
174
+ * @param msgs The messages to write.
175
+ */
176
+ async function error(...msgs) {
177
+ const colored = colorize("error", formatMessages("error", ...msgs));
178
+ await writeToStream(config.stderr, colored);
179
+ }
180
+ /**
181
+ * Prints errors and exits.
182
+ * @param msgs The messages to write.
183
+ */
184
+ async function fatal(...msgs) {
185
+ const colored = colorize("fatal", formatMessages("fatal", ...msgs));
186
+ await writeToStream(config.stderr, colored);
187
+ if (isDeno) Deno.exit(-1);
188
+ else if (isNode || isBun) process.exit(-1);
189
+ }
190
+
191
+ //#endregion
192
+ //#region src/command.ts
193
+ /**
194
+ * A command.
195
+ */
196
+ var Command = class Command {
197
+ /**
198
+ * Creates a new command.
199
+ * @param names The names (aliases).
200
+ * @param desc The description.
201
+ * @param version The version.
202
+ */
203
+ constructor(names, desc, version) {
204
+ this.$children = /* @__PURE__ */ new Map();
205
+ this.$allowUnknownOptions = false;
206
+ this.$allowSurpassArgLimit = false;
207
+ this.$input = {};
208
+ this.$fn = void 0;
209
+ this.$middlewares = [];
210
+ this.$errorFn = void 0;
211
+ this.$names = Array.isArray(names) ? names : [names];
212
+ this.$description = desc;
213
+ this.$version = version;
214
+ }
215
+ /**
216
+ * Adds a set of aliases to this command.
217
+ * @param aliases The aliases to add.
218
+ * @returns this
219
+ */
220
+ alias(...aliases) {
221
+ this.$names.concat(aliases);
222
+ this.$parent?.add(this);
223
+ return this;
224
+ }
225
+ /**
226
+ * Adds a description to this command.
227
+ * @param desc The description.
228
+ * @returns this
229
+ */
230
+ description(desc) {
231
+ this.$description = desc;
232
+ return this;
233
+ }
234
+ /**
235
+ * Adds a version to this command.
236
+ * @param version The version.
237
+ * @returns this
238
+ */
239
+ version(version) {
240
+ this.$version = version;
241
+ return this;
242
+ }
243
+ /**
244
+ * Sets the input for this command.
245
+ * @param version The input.
246
+ * @returns this
247
+ */
248
+ input(input) {
249
+ this.$input = input;
250
+ return this;
251
+ }
252
+ /**
253
+ * Adds a chain of middlewares.
254
+ * @param fns The middlewares to use.
255
+ * @returns this
256
+ */
257
+ use(...fns) {
258
+ this.$middlewares.push(...fns);
259
+ return this;
260
+ }
261
+ /**
262
+ * Sets the action function for this command.
263
+ * @param fn The action.
264
+ * @returns this
265
+ */
266
+ action(fn) {
267
+ this.$fn = fn;
268
+ return this;
269
+ }
270
+ /**
271
+ * Sets the error function for this command.
272
+ * @param fn The error handler.
273
+ * @returns this
274
+ */
275
+ error(fn) {
276
+ this.$errorFn = fn;
277
+ return this;
278
+ }
279
+ /**
280
+ * Adds an existing command to this.
281
+ * @param command The command.
282
+ * @returns this
283
+ */
284
+ add(command) {
285
+ command.$parent = this;
286
+ const alias = {
287
+ command,
288
+ alias: command.$names[0]
289
+ };
290
+ for (let i = 0; i < command.$names.length; i++) {
291
+ if (i === 0) this.$children.set(command.$names[i], { command });
292
+ this.$children.set(command.$names[i], alias);
293
+ }
294
+ return this;
295
+ }
296
+ subCommand(names, descOrBuilder, version) {
297
+ if (typeof descOrBuilder === "function") {
298
+ const command$1 = new Command(names);
299
+ descOrBuilder(command$1);
300
+ this.add(command$1);
301
+ return this;
302
+ }
303
+ const command = new Command(names, descOrBuilder, version);
304
+ this.add(command);
305
+ return command;
306
+ }
307
+ /**
308
+ * Allows unknown options.
309
+ * @returns this
310
+ */
311
+ allowUnknownOptions() {
312
+ this.$allowUnknownOptions = true;
313
+ return this;
314
+ }
315
+ /**
316
+ * Parses a set of command-line arguments.
317
+ * @param argv The arguments to parse.
318
+ * @returns A parse result.
319
+ */
320
+ async parse(argv) {
321
+ let command = this;
322
+ let found = false;
323
+ const input = {};
324
+ const args = [];
325
+ const opts = {};
326
+ const errors = [];
327
+ const map = command.buildInputMap();
328
+ function getOption(key, isSpecial) {
329
+ const entry = map.get(key);
330
+ if (!entry) {
331
+ if (!command.$allowUnknownOptions && !isSpecial) errors.push(new UnknownOptionError(command, key));
332
+ return null;
333
+ }
334
+ return entry.value;
335
+ }
336
+ function setOption(key, option, value) {
337
+ if (option.$kind === "boolean") opts[key] = "true";
338
+ else if (value !== void 0) opts[key] = value;
339
+ }
340
+ let isVersion = false;
341
+ let isHelp = false;
342
+ for (let i = 0; i < argv.length; i++) {
343
+ const arg = argv[i];
344
+ if (arg.startsWith("--")) {
345
+ const [key, value] = arg.slice(2).split("=");
346
+ let isSpecial = false;
347
+ if (key === "help") {
348
+ isHelp = true;
349
+ isSpecial = true;
350
+ } else if (key === "version") {
351
+ isVersion = true;
352
+ isSpecial = true;
353
+ }
354
+ const option = getOption(key, isSpecial);
355
+ if (option) if (value === void 0) setOption(key, option, option.$kind === "boolean" ? void 0 : argv[++i]);
356
+ else setOption(key, option, value);
357
+ } else if (arg.startsWith("-")) {
358
+ const [shortKeys, value] = arg.slice(1).split("=");
359
+ const chars = shortKeys.split("");
360
+ let usedValue = value;
361
+ for (const char of chars) {
362
+ let isSpecial = false;
363
+ if (char === "h") {
364
+ isHelp = true;
365
+ isSpecial = true;
366
+ } else if (char === "V") {
367
+ isVersion = true;
368
+ isSpecial = true;
369
+ }
370
+ const option = getOption(char, isSpecial);
371
+ if (!option) continue;
372
+ if (option.$kind !== "boolean" && usedValue === void 0) usedValue = argv[++i];
373
+ setOption(char, option, usedValue);
374
+ usedValue = void 0;
375
+ }
376
+ } else if (command.$children.has(arg) && !found) {
377
+ command = command.$children.get(arg).command;
378
+ if (command.$theme) {
379
+ setTheme(command.$theme);
380
+ setTheme$1(command.$theme);
381
+ }
382
+ } else {
383
+ found = true;
384
+ args.push(arg);
385
+ }
386
+ }
387
+ let index = 0;
388
+ for (const key in command.$input) {
389
+ const entry = command.$input[key];
390
+ let rawValue;
391
+ if (entry instanceof Positional) if (entry.$list) {
392
+ rawValue = args.slice(index);
393
+ index = args.length;
394
+ if (!command.$allowSurpassArgLimit && rawValue.length === 0 && entry.$required) errors.push(new MissingRequiredArgumentError(command, key, entry));
395
+ } else {
396
+ rawValue = args[index++];
397
+ if (rawValue === void 0 && entry.$required) errors.push(new MissingRequiredArgumentError(command, key, entry));
398
+ }
399
+ else for (const name of entry.$names) if (opts[name] !== void 0) {
400
+ rawValue = entry.$list ? opts[name].split(entry.$separator ?? ",") : opts[name];
401
+ break;
402
+ }
403
+ if (rawValue !== void 0) input[key] = await convert(entry.$kind, rawValue);
404
+ else if (entry.$default !== void 0) input[key] = entry.$default;
405
+ else if (entry.$required) if (entry instanceof Option) errors.push(new MissingRequiredOptionError(command, key, entry));
406
+ else errors.push(new MissingRequiredArgumentError(command, key, entry));
407
+ }
408
+ const remainingArgs = args.slice(index);
409
+ if (!command.$allowSurpassArgLimit && remainingArgs.length > 0) errors.push(new TooManyArgumentsError(command));
410
+ return {
411
+ input,
412
+ command,
413
+ errors,
414
+ isVersion,
415
+ isHelp
416
+ };
417
+ }
418
+ buildInputMap(ignoreParentMap) {
419
+ const map = /* @__PURE__ */ new Map();
420
+ let i = 0;
421
+ for (const key in this.$input) {
422
+ const value = this.$input[key];
423
+ if (value instanceof Positional) map.set(i++, {
424
+ value,
425
+ key
426
+ });
427
+ else for (const name of value.$names) map.set(name, {
428
+ value,
429
+ key
430
+ });
431
+ }
432
+ if (!ignoreParentMap) for (const [key, entry] of this.$parent?.buildInputMap() ?? []) map.set(key, entry);
433
+ for (const [, { command }] of this.$children) for (const [key, entry] of command.buildInputMap(true)) map.set(key, entry);
434
+ return map;
435
+ }
436
+ /**
437
+ * Allows surpassing the amount of arguments specified.
438
+ * @returns this
439
+ */
440
+ allowSurpassArgLimit() {
441
+ this.$allowSurpassArgLimit = true;
442
+ return this;
443
+ }
444
+ /**
445
+ * Gets the full command path (name including parents).
446
+ * @returns The full command path.
447
+ */
448
+ fullCommandPath() {
449
+ const names = [];
450
+ let cmd = this;
451
+ while (cmd) {
452
+ names.unshift(cmd.$names[0]);
453
+ cmd = cmd.$parent;
454
+ }
455
+ return names.join(" ");
456
+ }
457
+ /**
458
+ * The default error screen.
459
+ * @param errors The errors.
460
+ */
461
+ defaultErrorScreen(errors) {
462
+ let printHelpScreen = false;
463
+ const nonCliErrors = [];
464
+ for (const error$1 of errors) if (error$1 instanceof ConvokerError) {
465
+ if (!(error$1 instanceof HelpAskedError)) error$1.print();
466
+ printHelpScreen = true;
467
+ } else nonCliErrors.push(error$1);
468
+ if (nonCliErrors.length) throw nonCliErrors[0];
469
+ if (!printHelpScreen) return;
470
+ const pad = (s, len) => s.padEnd(len, " ");
471
+ console.log(`${bold("usage:")} ${cyan(this.fullCommandPath())} ${gray("[options] [arguments]")}`);
472
+ if (this.$description) console.log(`${this.$description}`);
473
+ if (this.$version) console.log(`${bold("version")} ${this.$version}`);
474
+ const opts = Object.entries(this.$input).filter(([, entry]) => entry instanceof Option).map(([key, entry]) => ({
475
+ key,
476
+ entry
477
+ }));
478
+ if (opts.length > 0) {
479
+ console.log(bold("options:"));
480
+ const longest = Math.max(...opts.map(({ entry }) => entry.$names.join(", ").length));
481
+ for (const { entry } of opts) {
482
+ const line = ` ${cyan(pad(entry.$names.map((n) => n.length === 1 ? `-${n}` : `--${n}`).join(", "), longest + 4))}${gray(entry.$description ?? "")}`;
483
+ console.log(line);
484
+ }
485
+ }
486
+ const positionals = Object.entries(this.$input).filter(([, entry]) => entry instanceof Positional).map(([key, entry]) => ({
487
+ key,
488
+ entry
489
+ }));
490
+ if (positionals.length > 0) {
491
+ console.log(bold("arguments:"));
492
+ const longest = Math.max(...positionals.map(({ key }) => key.length));
493
+ for (const { key, entry } of positionals) {
494
+ const line = ` ${cyan(pad(entry.$required ? `<${key}>` : `[${key}]`, longest + 4))}${gray(entry.$description ?? "")}`;
495
+ console.log(line);
496
+ }
497
+ }
498
+ if (this.$children.size > 0) {
499
+ console.log(bold("sub commands:"));
500
+ const deduped = Array.from(new Map([...this.$children.values()].map((a) => [a.command.$names[0], a.command])).values());
501
+ const longest = Math.max(...deduped.map((c) => c.$names[0].length));
502
+ for (const cmd of deduped) {
503
+ const line = ` ${cyan(pad(cmd.$names[0], longest + 4))}${gray(cmd.$description) ?? ""}`;
504
+ console.log(line);
505
+ }
506
+ console.log();
507
+ console.log(`run '${cyan(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`);
508
+ }
509
+ }
510
+ /**
511
+ * Handles a set of errors.
512
+ * @param errors The errors to handle.
513
+ * @param input The parsed input, if possible.
514
+ * @returns this
515
+ */
516
+ async handleErrors(errors, input) {
517
+ let command = this;
518
+ while (!command.$errorFn && command.$parent) command = command.$parent;
519
+ if (command.$errorFn) await command.$errorFn(command, errors, input ?? {});
520
+ else this.defaultErrorScreen(errors);
521
+ return this;
522
+ }
523
+ /**
524
+ * Runs a command.
525
+ * @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.
526
+ * @returns this
527
+ */
528
+ async run(argv) {
529
+ if (!argv) argv = typeof Bun !== "undefined" ? Bun.argv.slice(2) : typeof Deno !== "undefined" ? Deno.args : process.argv.slice(2);
530
+ const result = await this.parse(argv);
531
+ if (result.isHelp) {
532
+ result.command.handleErrors([new HelpAskedError(result.command)]);
533
+ return this;
534
+ } else if (result.isVersion) {
535
+ console.log(`${result.command.fullCommandPath()} version ${result.command.$version}`);
536
+ return this;
537
+ }
538
+ try {
539
+ if (result.errors.length > 0) await result.command.handleErrors(result.errors, result.input);
540
+ else if (!result.command.$fn) await result.command.handleErrors([new HelpAskedError(result.command), ...result.errors], result.input);
541
+ else {
542
+ const middlewares = collectMiddlewares(result.command);
543
+ if (middlewares.length > 0) await compose(middlewares)(result.input, async () => {
544
+ await result.command.$fn?.(result.input);
545
+ });
546
+ else await result.command.$fn(result.input);
547
+ }
548
+ } catch (e) {
549
+ if (!(e instanceof Error)) console.warn("[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior.");
550
+ await result.command.handleErrors([e]);
551
+ }
552
+ return this;
553
+ }
554
+ };
555
+ function collectMiddlewares(cmd) {
556
+ const middlewares = [];
557
+ let current = cmd;
558
+ while (current) {
559
+ if (current.$middlewares.length) middlewares.unshift(...current.$middlewares);
560
+ current = current.$parent;
561
+ }
562
+ return middlewares;
563
+ }
564
+ function compose(mws) {
565
+ return (input, finalNext) => {
566
+ let index = -1;
567
+ const dispatch = (i) => {
568
+ if (i <= index) return Promise.reject(/* @__PURE__ */ new Error("next() called multiple times"));
569
+ index = i;
570
+ const fn = mws[i];
571
+ if (!fn) return finalNext ? finalNext() : Promise.resolve();
572
+ try {
573
+ return Promise.resolve(fn(input, () => dispatch(i + 1)));
574
+ } catch (err) {
575
+ return Promise.reject(err);
576
+ }
577
+ };
578
+ return dispatch(0);
579
+ };
580
+ }
581
+
582
+ //#endregion
583
+ export { log_exports as n, Command as t };
@@ -0,0 +1,5 @@
1
+ import "./color-BuHvMolk.mjs";
2
+ import "./standard-schema-DLeKaehR.mjs";
3
+ import "./input-B12iaqb8.mjs";
4
+ import { a as ErrorFn, i as CommandAlias, n as Builder, o as MiddlewareFn, r as Command, s as ParseResult, t as ActionFn } from "./command-BXmfoT-l.mjs";
5
+ export { ActionFn, Builder, Command, CommandAlias, ErrorFn, MiddlewareFn, ParseResult };
@@ -0,0 +1,10 @@
1
+ import "./utils-ChmY93uA.mjs";
2
+ import "./color-OlJQTTxb.mjs";
3
+ import "./error-C1S1gs8L.mjs";
4
+ import "./standard-schema-DBXbMy6L.mjs";
5
+ import "./raw--889icsd.mjs";
6
+ import "./prompt-Cvufljin.mjs";
7
+ import { t as Command } from "./command-D2UiQBNA.mjs";
8
+ import "./input-DRy_sVxZ.mjs";
9
+
10
+ export { Command };
@@ -0,0 +1,115 @@
1
+ import { t as __export } from "./chunk-z5eko27R.mjs";
2
+
3
+ //#region src/error.ts
4
+ var error_exports = /* @__PURE__ */ __export({
5
+ ConvokerError: () => ConvokerError,
6
+ HelpAskedError: () => HelpAskedError,
7
+ InputValidationError: () => InputValidationError,
8
+ MissingRequiredArgumentError: () => MissingRequiredArgumentError,
9
+ MissingRequiredOptionError: () => MissingRequiredOptionError,
10
+ TooManyArgumentsError: () => TooManyArgumentsError,
11
+ UnknownOptionError: () => UnknownOptionError
12
+ });
13
+ /**
14
+ * Thrown when the command fails to validate an input.
15
+ */
16
+ var InputValidationError = class extends Error {
17
+ /**
18
+ * Creates a new input validation error.
19
+ * @param messages The messages.
20
+ */
21
+ constructor(messages) {
22
+ super(`Validation failed: ${messages.join(", ")}`);
23
+ this.messages = messages;
24
+ }
25
+ };
26
+ /**
27
+ * A Convoker-related error. These are usually handled by default.
28
+ */
29
+ var ConvokerError = class extends Error {
30
+ /**
31
+ * Creates a new Convoker error.
32
+ * @param message The message.
33
+ * @param command The command.
34
+ */
35
+ constructor(message, command) {
36
+ super(message);
37
+ this.command = command;
38
+ }
39
+ /**
40
+ * Prints the error's message.
41
+ */
42
+ print() {
43
+ console.error(this.message);
44
+ }
45
+ };
46
+ /**
47
+ * When the user asks for help.
48
+ */
49
+ var HelpAskedError = class extends ConvokerError {
50
+ /**
51
+ * Creates a new help asked error.
52
+ * @param command The command.
53
+ */
54
+ constructor(command) {
55
+ super("user asked for help!", command);
56
+ }
57
+ };
58
+ /**
59
+ * When you pass too many arguments.
60
+ */
61
+ var TooManyArgumentsError = class extends ConvokerError {
62
+ /**
63
+ * Creates a new too many arguments error.
64
+ * @param command The command.
65
+ */
66
+ constructor(command) {
67
+ super("too many arguments!", command);
68
+ }
69
+ };
70
+ /**
71
+ * When you pass an unknown option, when unknown options aren't allowed.
72
+ */
73
+ var UnknownOptionError = class extends ConvokerError {
74
+ /**
75
+ * Creates a new unknown option error.
76
+ * @param command The command.
77
+ * @param key The key.
78
+ */
79
+ constructor(command, key) {
80
+ super(`unknown option: ${key}!`, command);
81
+ this.key = key;
82
+ }
83
+ };
84
+ /**
85
+ * When a required option is missing.
86
+ */
87
+ var MissingRequiredOptionError = class extends ConvokerError {
88
+ /**
89
+ * Creates a new missing required option error.
90
+ * @param command The command.
91
+ * @param key The key.
92
+ * @param entry The entry.
93
+ */
94
+ constructor(command, key, entry) {
95
+ super(`missing required option: ${key}!`, command);
96
+ this.key = key;
97
+ this.entry = entry;
98
+ }
99
+ };
100
+ var MissingRequiredArgumentError = class extends ConvokerError {
101
+ /**
102
+ * Creates a new missing required argument error.
103
+ * @param command The command.
104
+ * @param key The key.
105
+ * @param entry The entry.
106
+ */
107
+ constructor(command, key, entry) {
108
+ super(`missing required positional argument: ${key}!`, command);
109
+ this.key = key;
110
+ this.entry = entry;
111
+ }
112
+ };
113
+
114
+ //#endregion
115
+ export { MissingRequiredOptionError as a, error_exports as c, MissingRequiredArgumentError as i, HelpAskedError as n, TooManyArgumentsError as o, InputValidationError as r, UnknownOptionError as s, ConvokerError as t };