convoker 0.3.3 → 0.4.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.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/dist/chunk-z5eko27R.mjs +13 -0
  3. package/dist/color/index.d.mts +2 -0
  4. package/dist/color/index.mjs +3 -0
  5. package/dist/color-DiZvJ0Fc.mjs +201 -0
  6. package/dist/color-DiZvJ0Fc.mjs.map +1 -0
  7. package/dist/command/index.d.mts +5 -0
  8. package/dist/command/index.mjs +8 -0
  9. package/dist/command-8P8qXJ2o.mjs +486 -0
  10. package/dist/command-8P8qXJ2o.mjs.map +1 -0
  11. package/dist/index-BYLskLxk.d.mts +200 -0
  12. package/dist/index-BtbthYjp.d.mts +168 -0
  13. package/dist/index-ClhbwSD8.d.mts +202 -0
  14. package/dist/index-Cnx4H4D-.d.mts +316 -0
  15. package/dist/index.d.mts +37 -0
  16. package/dist/index.mjs +92 -0
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/input/index.d.mts +3 -0
  19. package/dist/input/index.mjs +4 -0
  20. package/dist/input-XUsy1LCQ.mjs +176 -0
  21. package/dist/input-XUsy1LCQ.mjs.map +1 -0
  22. package/dist/prompt/index.d.mts +5 -0
  23. package/dist/prompt/index.mjs +6 -0
  24. package/dist/prompt/raw.d.mts +2 -0
  25. package/dist/prompt/raw.mjs +3 -0
  26. package/dist/prompt-a5Ix_Hyc.mjs +220 -0
  27. package/dist/prompt-a5Ix_Hyc.mjs.map +1 -0
  28. package/dist/raw-DEtZFeMv.mjs +88 -0
  29. package/dist/raw-DEtZFeMv.mjs.map +1 -0
  30. package/dist/raw-cqTp2vds.d.mts +38 -0
  31. package/dist/standard-schema-DTuaYJjO.mjs +32 -0
  32. package/dist/standard-schema-DTuaYJjO.mjs.map +1 -0
  33. package/dist/standard-schema-DXS-QnwX.d.mts +59 -0
  34. package/package.json +24 -26
  35. package/dist/color.d.ts +0 -153
  36. package/dist/color.js +0 -143
  37. package/dist/command.d.ts +0 -218
  38. package/dist/command.js +0 -531
  39. package/dist/error.d.ts +0 -107
  40. package/dist/error.js +0 -100
  41. package/dist/index.d.ts +0 -6
  42. package/dist/index.js +0 -6
  43. package/dist/input.d.ts +0 -182
  44. package/dist/input.js +0 -185
  45. package/dist/log.d.ts +0 -61
  46. package/dist/log.js +0 -216
  47. package/dist/prompt/index.d.ts +0 -193
  48. package/dist/prompt/index.js +0 -273
  49. package/dist/prompt/raw.d.ts +0 -32
  50. package/dist/prompt/raw.js +0 -105
  51. package/dist/standard-schema.d.ts +0 -62
  52. package/dist/standard-schema.js +0 -16
  53. package/dist/utils.d.ts +0 -30
  54. package/dist/utils.js +0 -56
@@ -0,0 +1,486 @@
1
+ import { O as gray, w as cyan, x as bold } from "./color-DiZvJ0Fc.mjs";
2
+ import { c as setTheme } from "./prompt-a5Ix_Hyc.mjs";
3
+ import { i as convert, n as Positional, t as Option } from "./input-XUsy1LCQ.mjs";
4
+ import process from "node:process";
5
+
6
+ //#region src/command/error.ts
7
+ /**
8
+ * A Convoker-related error. These are usually handled by default.
9
+ */
10
+ var ConvokerError = class extends Error {
11
+ /**
12
+ * Creates a new Convoker error.
13
+ * @param message The message.
14
+ * @param command The command.
15
+ */
16
+ constructor(message, command) {
17
+ super(message);
18
+ this.command = command;
19
+ }
20
+ /**
21
+ * Prints the error's message.
22
+ */
23
+ print() {
24
+ console.error(this.message);
25
+ }
26
+ };
27
+ /**
28
+ * When the user asks for help.
29
+ */
30
+ var HelpAskedError = class extends ConvokerError {
31
+ /**
32
+ * Creates a new help asked error.
33
+ * @param command The command.
34
+ */
35
+ constructor(command) {
36
+ super("user asked for help!", command);
37
+ }
38
+ };
39
+ /**
40
+ * When you pass too many arguments.
41
+ */
42
+ var TooManyArgumentsError = class extends ConvokerError {
43
+ /**
44
+ * Creates a new too many arguments error.
45
+ * @param command The command.
46
+ */
47
+ constructor(command) {
48
+ super("too many arguments!", command);
49
+ }
50
+ };
51
+ /**
52
+ * When you pass an unknown option, when unknown options aren't allowed.
53
+ */
54
+ var UnknownOptionError = class extends ConvokerError {
55
+ /**
56
+ * Creates a new unknown option error.
57
+ * @param command The command.
58
+ * @param key The key.
59
+ */
60
+ constructor(command, key) {
61
+ super(`unknown option: ${key}!`, command);
62
+ this.key = key;
63
+ }
64
+ };
65
+ /**
66
+ * When a required option is missing.
67
+ */
68
+ var MissingRequiredOptionError = class extends ConvokerError {
69
+ /**
70
+ * Creates a new missing required option error.
71
+ * @param command The command.
72
+ * @param key The key.
73
+ * @param entry The entry.
74
+ */
75
+ constructor(command, key, entry) {
76
+ super(`missing required option: ${key}!`, command);
77
+ this.key = key;
78
+ this.entry = entry;
79
+ }
80
+ };
81
+ var MissingRequiredArgumentError = class extends ConvokerError {
82
+ /**
83
+ * Creates a new missing required argument error.
84
+ * @param command The command.
85
+ * @param key The key.
86
+ * @param entry The entry.
87
+ */
88
+ constructor(command, key, entry) {
89
+ super(`missing required positional argument: ${key}!`, command);
90
+ this.key = key;
91
+ this.entry = entry;
92
+ }
93
+ };
94
+
95
+ //#endregion
96
+ //#region src/command/index.ts
97
+ /**
98
+ * A command.
99
+ */
100
+ var Command = class Command {
101
+ /**
102
+ * Creates a new command.
103
+ * @param names The names (aliases).
104
+ * @param desc The description.
105
+ * @param version The version.
106
+ */
107
+ constructor(names, desc, version) {
108
+ this.$children = /* @__PURE__ */ new Map();
109
+ this.$allowUnknownOptions = false;
110
+ this.$allowSurpassArgLimit = false;
111
+ this.$input = {};
112
+ this.$fn = void 0;
113
+ this.$middlewares = [];
114
+ this.$errorFn = void 0;
115
+ this.$names = Array.isArray(names) ? names : [names];
116
+ this.$description = desc;
117
+ this.$version = version;
118
+ }
119
+ /**
120
+ * Adds a set of aliases to this command.
121
+ * @param aliases The aliases to add.
122
+ * @returns this
123
+ */
124
+ alias(...aliases) {
125
+ this.$names.push(...aliases);
126
+ this.$parent?.add(this);
127
+ return this;
128
+ }
129
+ /**
130
+ * Adds a description to this command.
131
+ * @param desc The description.
132
+ * @returns this
133
+ */
134
+ description(desc) {
135
+ this.$description = desc;
136
+ return this;
137
+ }
138
+ /**
139
+ * Adds a version to this command.
140
+ * @param version The version.
141
+ * @returns this
142
+ */
143
+ version(version) {
144
+ this.$version = version;
145
+ return this;
146
+ }
147
+ /**
148
+ * Sets the input for this command.
149
+ * @param version The input.
150
+ * @returns this
151
+ */
152
+ input(input) {
153
+ this.$input = input;
154
+ return this;
155
+ }
156
+ /**
157
+ * Adds a chain of middlewares.
158
+ * @param fns The middlewares to use.
159
+ * @returns this
160
+ */
161
+ use(...fns) {
162
+ this.$middlewares.push(...fns);
163
+ return this;
164
+ }
165
+ /**
166
+ * Sets the action function for this command.
167
+ * @param fn The action.
168
+ * @returns this
169
+ */
170
+ action(fn) {
171
+ this.$fn = fn;
172
+ return this;
173
+ }
174
+ /**
175
+ * Sets the error function for this command.
176
+ * @param fn The error handler.
177
+ * @returns this
178
+ */
179
+ error(fn) {
180
+ this.$errorFn = fn;
181
+ return this;
182
+ }
183
+ /**
184
+ * Adds existing commands to this.
185
+ * @param commands The commands.
186
+ * @returns this
187
+ */
188
+ add(...commands) {
189
+ for (const command of commands) {
190
+ command.$parent = this;
191
+ const alias = {
192
+ command,
193
+ alias: command.$names[0]
194
+ };
195
+ for (let i = 0; i < command.$names.length; i++) {
196
+ if (i === 0) this.$children.set(command.$names[i], { command });
197
+ this.$children.set(command.$names[i], alias);
198
+ }
199
+ }
200
+ return this;
201
+ }
202
+ subCommand(names, descOrBuilder, version) {
203
+ if (typeof descOrBuilder === "function") {
204
+ const command$1 = new Command(names);
205
+ descOrBuilder(command$1);
206
+ this.add(command$1);
207
+ return this;
208
+ }
209
+ const command = new Command(names, descOrBuilder, version);
210
+ this.add(command);
211
+ return command;
212
+ }
213
+ /**
214
+ * Allows unknown options.
215
+ * @returns this
216
+ */
217
+ allowUnknownOptions() {
218
+ this.$allowUnknownOptions = true;
219
+ return this;
220
+ }
221
+ /**
222
+ * Parses a set of command-line arguments.
223
+ * @param argv The arguments to parse.
224
+ * @returns A parse result.
225
+ */
226
+ async parse(argv) {
227
+ let command = this;
228
+ let found = false;
229
+ const input = {};
230
+ const args = [];
231
+ const opts = {};
232
+ const errors = [];
233
+ const map = command.buildInputMap();
234
+ function getOption(key, isSpecial) {
235
+ const entry = map.get(key);
236
+ if (!entry) {
237
+ if (!command.$allowUnknownOptions && !isSpecial) errors.push(new UnknownOptionError(command, key));
238
+ return null;
239
+ }
240
+ return entry.value;
241
+ }
242
+ function setOption(key, option, value) {
243
+ if (option.$kind === "boolean") opts[key] = "true";
244
+ else if (value !== void 0) opts[key] = value;
245
+ }
246
+ let isVersion = false;
247
+ let isHelp = false;
248
+ for (let i = 0; i < argv.length; i++) {
249
+ const arg = argv[i];
250
+ if (arg.startsWith("--")) {
251
+ const [key, value] = arg.slice(2).split("=");
252
+ let isSpecial = false;
253
+ if (key === "help") {
254
+ isHelp = true;
255
+ isSpecial = true;
256
+ } else if (key === "version") {
257
+ isVersion = true;
258
+ isSpecial = true;
259
+ }
260
+ const option = getOption(key, isSpecial);
261
+ if (option) if (value === void 0) setOption(key, option, option.$kind === "boolean" ? void 0 : argv[++i]);
262
+ else setOption(key, option, value);
263
+ } else if (arg.startsWith("-")) {
264
+ const [shortKeys, value] = arg.slice(1).split("=");
265
+ const chars = shortKeys.split("");
266
+ let usedValue = value;
267
+ for (const char of chars) {
268
+ let isSpecial = false;
269
+ if (char === "h") {
270
+ isHelp = true;
271
+ isSpecial = true;
272
+ } else if (char === "V") {
273
+ isVersion = true;
274
+ isSpecial = true;
275
+ }
276
+ const option = getOption(char, isSpecial);
277
+ if (!option) continue;
278
+ if (option.$kind !== "boolean" && usedValue === void 0) usedValue = argv[++i];
279
+ setOption(char, option, usedValue);
280
+ usedValue = void 0;
281
+ }
282
+ } else if (command.$children.has(arg) && !found) {
283
+ command = command.$children.get(arg).command;
284
+ if (command.$theme) setTheme(command.$theme);
285
+ } else {
286
+ found = true;
287
+ args.push(arg);
288
+ }
289
+ }
290
+ let index = 0;
291
+ for (const key in command.$input) {
292
+ const entry = command.$input[key];
293
+ let rawValue;
294
+ if (entry instanceof Positional) if (entry.$list) {
295
+ rawValue = args.slice(index);
296
+ index = args.length;
297
+ if (!command.$allowSurpassArgLimit && rawValue.length === 0 && entry.$required) errors.push(new MissingRequiredArgumentError(command, key, entry));
298
+ } else {
299
+ rawValue = args[index++];
300
+ if (rawValue === void 0 && entry.$required) errors.push(new MissingRequiredArgumentError(command, key, entry));
301
+ }
302
+ else for (const name of entry.$names) if (opts[name] !== void 0) {
303
+ rawValue = entry.$list ? opts[name].split(entry.$separator ?? ",") : opts[name];
304
+ break;
305
+ }
306
+ if (rawValue !== void 0) input[key] = await convert(entry.$kind, rawValue);
307
+ else if (entry.$default !== void 0) input[key] = entry.$default;
308
+ else if (entry.$required) if (entry instanceof Option) errors.push(new MissingRequiredOptionError(command, key, entry));
309
+ else errors.push(new MissingRequiredArgumentError(command, key, entry));
310
+ }
311
+ const remainingArgs = args.slice(index);
312
+ if (!command.$allowSurpassArgLimit && remainingArgs.length > 0) errors.push(new TooManyArgumentsError(command));
313
+ return {
314
+ input,
315
+ command,
316
+ errors,
317
+ isVersion,
318
+ isHelp
319
+ };
320
+ }
321
+ buildInputMap(ignoreParentMap) {
322
+ const map = /* @__PURE__ */ new Map();
323
+ let i = 0;
324
+ for (const key in this.$input) {
325
+ const value = this.$input[key];
326
+ if (value instanceof Positional) map.set(i++, {
327
+ value,
328
+ key
329
+ });
330
+ else for (const name of value.$names) map.set(name, {
331
+ value,
332
+ key
333
+ });
334
+ }
335
+ if (!ignoreParentMap) for (const [key, entry] of this.$parent?.buildInputMap() ?? []) map.set(key, entry);
336
+ for (const [, { command }] of this.$children) for (const [key, entry] of command.buildInputMap(true)) map.set(key, entry);
337
+ return map;
338
+ }
339
+ /**
340
+ * Allows surpassing the amount of arguments specified.
341
+ * @returns this
342
+ */
343
+ allowSurpassArgLimit() {
344
+ this.$allowSurpassArgLimit = true;
345
+ return this;
346
+ }
347
+ /**
348
+ * Gets the full command path (name including parents).
349
+ * @returns The full command path.
350
+ */
351
+ fullCommandPath() {
352
+ const names = [];
353
+ let cmd = this;
354
+ while (cmd) {
355
+ names.unshift(cmd.$names[0]);
356
+ cmd = cmd.$parent;
357
+ }
358
+ return names.join(" ");
359
+ }
360
+ /**
361
+ * The default error screen.
362
+ * @param errors The errors.
363
+ */
364
+ defaultErrorScreen(errors) {
365
+ let printHelpScreen = false;
366
+ const nonCliErrors = [];
367
+ for (const error of errors) if (error instanceof ConvokerError) {
368
+ if (!(error instanceof HelpAskedError)) error.print();
369
+ printHelpScreen = true;
370
+ } else nonCliErrors.push(error);
371
+ if (nonCliErrors.length) throw nonCliErrors[0];
372
+ if (!printHelpScreen) return;
373
+ const pad = (s, len) => s.padEnd(len, " ");
374
+ console.log(`${bold("usage:")} ${cyan(this.fullCommandPath())} ${gray("[options] [arguments]")}`);
375
+ if (this.$description) console.log(`${this.$description}`);
376
+ if (this.$version) console.log(`${bold("version")} ${this.$version}`);
377
+ const opts = Object.entries(this.$input).filter(([, entry]) => entry instanceof Option).map(([key, entry]) => ({
378
+ key,
379
+ entry
380
+ }));
381
+ if (opts.length > 0) {
382
+ console.log(bold("options:"));
383
+ const longest = Math.max(...opts.map(({ entry }) => entry.$names.join(", ").length));
384
+ for (const { entry } of opts) {
385
+ const line = ` ${cyan(pad(entry.$names.map((n) => n.length === 1 ? `-${n}` : `--${n}`).join(", "), longest + 4))}${gray(entry.$description ?? "")}`;
386
+ console.log(line);
387
+ }
388
+ }
389
+ const positionals = Object.entries(this.$input).filter(([, entry]) => entry instanceof Positional).map(([key, entry]) => ({
390
+ key,
391
+ entry
392
+ }));
393
+ if (positionals.length > 0) {
394
+ console.log(bold("arguments:"));
395
+ const longest = Math.max(...positionals.map(({ key }) => key.length));
396
+ for (const { key, entry } of positionals) {
397
+ const line = ` ${cyan(pad(entry.$required ? `<${key}>` : `[${key}]`, longest + 4))}${gray(entry.$description ?? "")}`;
398
+ console.log(line);
399
+ }
400
+ }
401
+ if (this.$children.size > 0) {
402
+ console.log(bold("sub commands:"));
403
+ const deduped = Array.from(new Map([...this.$children.values()].map((a) => [a.command.$names[0], a.command])).values());
404
+ const longest = Math.max(...deduped.map((c) => c.$names[0].length));
405
+ for (const cmd of deduped) {
406
+ const line = ` ${cyan(pad(cmd.$names[0], longest + 4))}${gray(cmd.$description) ?? ""}`;
407
+ console.log(line);
408
+ }
409
+ console.log();
410
+ console.log(`run '${cyan(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`);
411
+ }
412
+ }
413
+ /**
414
+ * Handles a set of errors.
415
+ * @param errors The errors to handle.
416
+ * @param input The parsed input, if possible.
417
+ * @returns this
418
+ */
419
+ async handleErrors(errors, input) {
420
+ let command = this;
421
+ while (!command.$errorFn && command.$parent) command = command.$parent;
422
+ if (command.$errorFn) await command.$errorFn(command, errors, input ?? {});
423
+ else this.defaultErrorScreen(errors);
424
+ return this;
425
+ }
426
+ /**
427
+ * Runs a command.
428
+ * @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.
429
+ * @returns this
430
+ */
431
+ async run(argv) {
432
+ const result = await this.parse(argv ?? process.argv.slice(2));
433
+ if (result.isHelp) {
434
+ result.command.handleErrors([new HelpAskedError(result.command)]);
435
+ return this;
436
+ } else if (result.isVersion) {
437
+ console.log(`${result.command.fullCommandPath()} version ${result.command.$version}`);
438
+ return this;
439
+ }
440
+ try {
441
+ if (result.errors.length > 0) await result.command.handleErrors(result.errors, result.input);
442
+ else if (!result.command.$fn) await result.command.handleErrors([new HelpAskedError(result.command), ...result.errors], result.input);
443
+ else {
444
+ const middlewares = collectMiddlewares(result.command);
445
+ if (middlewares.length > 0) await compose(middlewares)(result.input, async () => {
446
+ await result.command.$fn?.(result.input);
447
+ });
448
+ else await result.command.$fn(result.input);
449
+ }
450
+ } catch (e) {
451
+ if (!(e instanceof Error)) console.warn("[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior.");
452
+ await result.command.handleErrors([e]);
453
+ }
454
+ return this;
455
+ }
456
+ };
457
+ function collectMiddlewares(cmd) {
458
+ const middlewares = [];
459
+ let current = cmd;
460
+ while (current) {
461
+ if (current.$middlewares.length) middlewares.unshift(...current.$middlewares);
462
+ current = current.$parent;
463
+ }
464
+ return middlewares;
465
+ }
466
+ function compose(mws) {
467
+ return (input, finalNext) => {
468
+ let index = -1;
469
+ const dispatch = (i) => {
470
+ if (i <= index) return Promise.reject(/* @__PURE__ */ new Error("next() called multiple times"));
471
+ index = i;
472
+ const fn = mws[i];
473
+ if (!fn) return finalNext ? finalNext() : Promise.resolve();
474
+ try {
475
+ return Promise.resolve(fn(input, () => dispatch(i + 1)));
476
+ } catch (err) {
477
+ return Promise.reject(err);
478
+ }
479
+ };
480
+ return dispatch(0);
481
+ };
482
+ }
483
+
484
+ //#endregion
485
+ export { MissingRequiredOptionError as a, MissingRequiredArgumentError as i, ConvokerError as n, TooManyArgumentsError as o, HelpAskedError as r, UnknownOptionError as s, Command as t };
486
+ //# sourceMappingURL=command-8P8qXJ2o.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-8P8qXJ2o.mjs","names":["command","command: Command<any>","input: Record<string, unknown>","args: string[]","opts: Record<string, string>","errors: ConvokerError[]","usedValue: string | undefined","rawValue: string | string[] | undefined","names: string[]","cmd: Command<any> | undefined","nonCliErrors: Error[]","middlewares: MiddlewareFn<any>[]","current: Command<any> | undefined"],"sources":["../src/command/error.ts","../src/command/index.ts"],"sourcesContent":["import { Positional, Option } from \"@/input\";\nimport { Command } from \".\";\n\n/**\n * A Convoker-related error. These are usually handled by default.\n */\nexport class ConvokerError extends Error {\n /**\n * The command this error happened on.\n */\n command: Command<any>;\n\n /**\n * Creates a new Convoker error.\n * @param message The message.\n * @param command The command.\n */\n constructor(message: string, command: Command<any>) {\n super(message);\n this.command = command;\n }\n\n /**\n * Prints the error's message.\n */\n print() {\n console.error(this.message);\n }\n}\n\n/**\n * When the user asks for help.\n */\nexport class HelpAskedError extends ConvokerError {\n /**\n * Creates a new help asked error.\n * @param command The command.\n */\n constructor(command: Command<any>) {\n super(\"user asked for help!\", command);\n }\n}\n\n/**\n * When you pass too many arguments.\n */\nexport class TooManyArgumentsError extends ConvokerError {\n /**\n * Creates a new too many arguments error.\n * @param command The command.\n */\n constructor(command: Command<any>) {\n super(\"too many arguments!\", command);\n }\n}\n\n/**\n * When you pass an unknown option, when unknown options aren't allowed.\n */\nexport class UnknownOptionError extends ConvokerError {\n /**\n * The option key.\n */\n key: string;\n\n /**\n * Creates a new unknown option error.\n * @param command The command.\n * @param key The key.\n */\n constructor(command: Command<any>, key: string) {\n super(`unknown option: ${key}!`, command);\n this.key = key;\n }\n}\n\n/**\n * When a required option is missing.\n */\nexport class MissingRequiredOptionError extends ConvokerError {\n /**\n * The option key.\n */\n key: string;\n /**\n * The option entry.\n */\n entry: Option<any, any, any>;\n\n /**\n * Creates a new missing required option error.\n * @param command The command.\n * @param key The key.\n * @param entry The entry.\n */\n constructor(\n command: Command<any>,\n key: string,\n entry: Option<any, any, any>,\n ) {\n super(`missing required option: ${key}!`, command);\n this.key = key;\n this.entry = entry;\n }\n}\n\nexport class MissingRequiredArgumentError extends ConvokerError {\n /**\n * The argument key.\n */\n key: string;\n /**\n * The argument entry.\n */\n entry: Positional<any, any, any>;\n\n /**\n * Creates a new missing required argument error.\n * @param command The command.\n * @param key The key.\n * @param entry The entry.\n */\n constructor(\n command: Command<any>,\n key: string,\n entry: Positional<any, any, any>,\n ) {\n super(`missing required positional argument: ${key}!`, command);\n this.key = key;\n this.entry = entry;\n }\n}\n","import process from \"node:process\";\n\nimport { gray, cyan, bold, type Theme } from \"@/color\";\nimport { setTheme as setPromptTheme } from \"@/prompt\";\nimport {\n ConvokerError,\n HelpAskedError,\n MissingRequiredArgumentError,\n MissingRequiredOptionError,\n TooManyArgumentsError,\n UnknownOptionError,\n} from \"./error\";\nimport {\n convert,\n Option,\n Positional,\n type InferInput,\n type Input,\n} from \"@/input\";\n\n/**\n * What the command is an alias for.\n */\nexport interface CommandAlias<T extends Input = Input> {\n /**\n * A pointer to the command.\n */\n command: Command<T>;\n /**\n * The name of the command this is an alias for.\n */\n alias?: string;\n}\n\n/**\n * The result of the `Command.parse` function.\n */\nexport interface ParseResult<T extends Input> {\n /**\n * A pointer to the command to run.\n */\n command: Command<T>;\n /**\n * The input to pass into the command.\n */\n input: InferInput<T>;\n /**\n * Errors collected during parsing.\n */\n errors: ConvokerError[];\n /**\n * If this should result in displaying the version of the command.\n */\n isVersion: boolean;\n /**\n * If this should result in displaying a help screen.\n */\n isHelp: boolean;\n}\n\n/**\n * Command action function.\n */\nexport type ActionFn<T extends Input> = (\n input: InferInput<T>,\n) => any | Promise<any>;\n\n/**\n * Command middleware function.\n */\nexport type MiddlewareFn<T extends Input = Input> = (\n input: InferInput<T>,\n next: () => Promise<any>,\n) => any | Promise<any>;\n\n/**\n * Command error handler.\n */\nexport type ErrorFn<T extends Input> = (\n command: Command<T>,\n errors: Error[],\n input: Partial<InferInput<T>>,\n) => void | Promise<void>;\n\n/**\n * Builder for commands.\n */\nexport type Builder = (c: Command<any>) => Command<any> | void;\n\n/**\n * An input map entry.\n */\ninterface MapEntry {\n /**\n * The key of the map entry.\n */\n key: string;\n /**\n * The value of the map entry.\n */\n value: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A command.\n */\nexport class Command<T extends Input = Input> {\n /**\n * The names (aliases) of this command.\n */\n $names: string[];\n /**\n * The description of this command.\n */\n $description: string | undefined;\n /**\n * The theme of this command\n */\n $theme: Theme | undefined;\n /**\n * The version of this command.\n */\n $version: string | undefined;\n /**\n * The children of this command.\n */\n $children: Map<string, CommandAlias> = new Map();\n /**\n * The parent of this command.\n */\n $parent: Command<any> | undefined;\n /**\n * If this command allows unknown options.\n */\n $allowUnknownOptions: boolean = false;\n /**\n * If you should be able to surpass the amount of positional arguments defined in the input.\n */\n $allowSurpassArgLimit: boolean = false;\n /**\n * The input this command takes.\n */\n $input: T = {} as T;\n /**\n * The action function of this command.\n */\n $fn: ActionFn<T> | undefined = undefined;\n /**\n * The middlewares associated with this command.\n */\n $middlewares: MiddlewareFn<T>[] = [];\n /**\n * The error handler of this command.\n */\n $errorFn: ErrorFn<T> | undefined = undefined;\n\n /**\n * Creates a new command.\n * @param names The names (aliases).\n * @param desc The description.\n * @param version The version.\n */\n constructor(names: string | string[], desc?: string, version?: string) {\n this.$names = Array.isArray(names) ? names : [names];\n this.$description = desc;\n this.$version = version;\n }\n\n /**\n * Adds a set of aliases to this command.\n * @param aliases The aliases to add.\n * @returns this\n */\n alias(...aliases: string[]): this {\n this.$names.push(...aliases);\n this.$parent?.add(this);\n return this;\n }\n\n /**\n * Adds a description to this command.\n * @param desc The description.\n * @returns this\n */\n description(desc: string): this {\n this.$description = desc;\n return this;\n }\n\n /**\n * Adds a version to this command.\n * @param version The version.\n * @returns this\n */\n version(version: string): this {\n this.$version = version;\n return this;\n }\n\n /**\n * Sets the input for this command.\n * @param version The input.\n * @returns this\n */\n input<TInput extends Input>(input: TInput): Command<TInput> {\n this.$input = input as any;\n return this as any;\n }\n\n /**\n * Adds a chain of middlewares.\n * @param fns The middlewares to use.\n * @returns this\n */\n use(...fns: MiddlewareFn<T>[]): this {\n this.$middlewares.push(...fns);\n return this;\n }\n\n /**\n * Sets the action function for this command.\n * @param fn The action.\n * @returns this\n */\n action(fn: ActionFn<T>): this {\n this.$fn = fn;\n return this;\n }\n\n /**\n * Sets the error function for this command.\n * @param fn The error handler.\n * @returns this\n */\n error(fn: ErrorFn<T>): this {\n this.$errorFn = fn;\n return this;\n }\n\n /**\n * Adds existing commands to this.\n * @param commands The commands.\n * @returns this\n */\n add(...commands: Command<any>[]): this {\n for (const command of commands) {\n command.$parent = this;\n const alias = { command, alias: command.$names[0] };\n for (let i = 0; i < command.$names.length; i++) {\n if (i === 0) this.$children.set(command.$names[i], { command });\n this.$children.set(command.$names[i], alias);\n }\n }\n return this;\n }\n\n /**\n * Creates a new subcommand and adds it.\n * @param names The aliases of the subcommand.\n * @param builder A builder to create the command.\n */\n subCommand(names: string | string[], builder: Builder): this;\n /**\n * Creates a new subcommand and adds it.\n * @param names The aliases of the subcommand.\n * @param desc The description of the subcommand.\n * @param version The version of the subcommand.\n */\n subCommand(\n names: string | string[],\n desc?: string,\n version?: string,\n ): Command<any>;\n\n subCommand(\n names: string | string[],\n descOrBuilder?: Builder | string,\n version?: string,\n ): Command<any> {\n if (typeof descOrBuilder === \"function\") {\n const command = new Command(names);\n descOrBuilder(command);\n this.add(command);\n return this;\n }\n\n const command = new Command(names, descOrBuilder, version);\n this.add(command);\n return command;\n }\n\n /**\n * Allows unknown options.\n * @returns this\n */\n allowUnknownOptions(): this {\n this.$allowUnknownOptions = true;\n return this;\n }\n\n /**\n * Parses a set of command-line arguments.\n * @param argv The arguments to parse.\n * @returns A parse result.\n */\n async parse(argv: string[]): Promise<ParseResult<T>> {\n // eslint-disable-next-line -- alias to this is necessary to go through the tree\n let command: Command<any> = this;\n let found = false;\n const input: Record<string, unknown> = {};\n\n const args: string[] = [];\n const opts: Record<string, string> = {};\n\n const errors: ConvokerError[] = [];\n const map = command.buildInputMap();\n\n function getOption(key: string, isSpecial?: boolean) {\n const entry = map.get(key);\n if (!entry) {\n if (!command.$allowUnknownOptions && !isSpecial)\n errors.push(new UnknownOptionError(command, key));\n return null;\n }\n return entry.value as Option<any, any, any>;\n }\n\n function setOption(\n key: string,\n option: Option<any, any, any>,\n value?: string,\n ) {\n if (option.$kind === \"boolean\") {\n opts[key] = \"true\";\n } else if (value !== undefined) {\n opts[key] = value;\n }\n }\n\n let isVersion = false;\n let isHelp = false;\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg.startsWith(\"--\")) {\n // --long[=value] or --long [value]\n const [key, value] = arg.slice(2).split(\"=\");\n\n let isSpecial = false;\n if (key === \"help\") {\n isHelp = true;\n isSpecial = true;\n } else if (key === \"version\") {\n isVersion = true;\n isSpecial = true;\n }\n\n const option = getOption(key, isSpecial);\n if (option) {\n if (value === undefined)\n setOption(\n key,\n option,\n option.$kind === \"boolean\" ? undefined : argv[++i],\n );\n else setOption(key, option, value);\n }\n } else if (arg.startsWith(\"-\")) {\n // -abc or -k[=value] or -k [value]\n const [shortKeys, value] = arg.slice(1).split(\"=\");\n const chars = shortKeys.split(\"\");\n let usedValue: string | undefined = value;\n\n for (const char of chars) {\n let isSpecial = false;\n if (char === \"h\") {\n isHelp = true;\n isSpecial = true;\n } else if (char === \"V\") {\n isVersion = true;\n isSpecial = true;\n }\n\n const option = getOption(char, isSpecial);\n if (!option) continue;\n\n if (option.$kind !== \"boolean\" && usedValue === undefined) {\n usedValue = argv[++i];\n }\n setOption(char, option, usedValue);\n usedValue = undefined; // only first consumes\n }\n } else {\n // positional\n if (command.$children.has(arg) && !found) {\n command = command.$children.get(arg)!.command;\n if (command.$theme) {\n setPromptTheme(command.$theme);\n }\n } else {\n found = true;\n args.push(arg);\n }\n }\n }\n\n // Apply user values, defaults, or enforce required\n let index = 0;\n for (const key in command.$input) {\n const entry = command.$input[key];\n let rawValue: string | string[] | undefined;\n\n if (entry instanceof Positional) {\n if (entry.$list) {\n rawValue = args.slice(index);\n index = args.length;\n if (\n !command.$allowSurpassArgLimit &&\n rawValue.length === 0 &&\n entry.$required\n ) {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n } else {\n rawValue = args[index++];\n if (rawValue === undefined && entry.$required) {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n }\n } else {\n for (const name of entry.$names) {\n if (opts[name] !== undefined) {\n rawValue = entry.$list\n ? opts[name].split(entry.$separator ?? \",\")\n : opts[name];\n break;\n }\n }\n }\n\n if (rawValue !== undefined) {\n input[key] = await convert(entry.$kind, rawValue);\n } else if (entry.$default !== undefined) {\n input[key] = entry.$default;\n } else if (entry.$required) {\n if (entry instanceof Option) {\n errors.push(new MissingRequiredOptionError(command, key, entry));\n } else {\n errors.push(new MissingRequiredArgumentError(command, key, entry));\n }\n }\n }\n\n // Check for too many arguments\n const remainingArgs = args.slice(index);\n if (!command.$allowSurpassArgLimit && remainingArgs.length > 0) {\n errors.push(new TooManyArgumentsError(command));\n }\n\n return {\n input: input as InferInput<T>,\n command,\n errors,\n isVersion,\n isHelp,\n };\n }\n\n private buildInputMap(\n ignoreParentMap?: boolean,\n ): Map<string | number, MapEntry> {\n const map = new Map<string | number, MapEntry>();\n\n let i = 0;\n for (const key in this.$input) {\n const value = this.$input[key];\n if (value instanceof Positional) {\n map.set(i++, { value, key });\n } else {\n for (const name of value.$names) {\n map.set(name, { value, key });\n }\n }\n }\n\n if (!ignoreParentMap) {\n for (const [key, entry] of this.$parent?.buildInputMap() ?? []) {\n map.set(key, entry);\n }\n }\n\n for (const [, { command }] of this.$children) {\n for (const [key, entry] of command.buildInputMap(true)) {\n map.set(key, entry);\n }\n }\n\n return map;\n }\n\n /**\n * Allows surpassing the amount of arguments specified.\n * @returns this\n */\n allowSurpassArgLimit(): this {\n this.$allowSurpassArgLimit = true;\n return this;\n }\n\n /**\n * Gets the full command path (name including parents).\n * @returns The full command path.\n */\n fullCommandPath(): string {\n const names: string[] = [];\n // eslint-disable-next-line -- necessary for traversing up the tree\n let cmd: Command<any> | undefined = this;\n while (cmd) {\n names.unshift(cmd.$names[0]);\n cmd = cmd.$parent;\n }\n return names.join(\" \");\n }\n\n /**\n * The default error screen.\n * @param errors The errors.\n */\n defaultErrorScreen(errors: Error[]) {\n let printHelpScreen = false;\n const nonCliErrors: Error[] = [];\n\n for (const error of errors) {\n if (error instanceof ConvokerError) {\n if (!(error instanceof HelpAskedError)) error.print();\n printHelpScreen = true;\n } else {\n nonCliErrors.push(error);\n }\n }\n\n if (nonCliErrors.length) throw nonCliErrors[0];\n\n if (!printHelpScreen) return;\n const pad = (s: string, len: number) => s.padEnd(len, \" \");\n\n console.log(\n `${bold(\"usage:\")} ${cyan(this.fullCommandPath())} ${gray(\"[options] [arguments]\")}`,\n );\n if (this.$description) {\n console.log(`${this.$description}`);\n }\n\n if (this.$version) {\n console.log(`${bold(\"version\")} ${this.$version}`);\n }\n\n // OPTIONS\n const opts = Object.entries(this.$input)\n .filter(([, entry]) => entry instanceof Option)\n .map(([key, entry]) => ({ key, entry: entry as Option<any, any, any> }));\n\n if (opts.length > 0) {\n console.log(bold(\"options:\"));\n const longest = Math.max(\n ...opts.map(({ entry }) => entry.$names.join(\", \").length),\n );\n for (const { entry } of opts) {\n const names = entry.$names\n .map((n) => (n.length === 1 ? `-${n}` : `--${n}`))\n .join(\", \");\n const line = ` ${cyan(pad(names, longest + 4))}${gray(entry.$description ?? \"\")}`;\n console.log(line);\n }\n }\n\n // POSITIONALS\n const positionals = Object.entries(this.$input)\n .filter(([, entry]) => entry instanceof Positional)\n .map(([key, entry]) => ({\n key,\n entry: entry as Positional<any, any, any>,\n }));\n\n if (positionals.length > 0) {\n console.log(bold(\"arguments:\"));\n const longest = Math.max(...positionals.map(({ key }) => key.length));\n for (const { key, entry } of positionals) {\n const name = entry.$required ? `<${key}>` : `[${key}]`;\n const line = ` ${cyan(pad(name, longest + 4))}${gray(entry.$description ?? \"\")}`;\n console.log(line);\n }\n }\n\n // SUBCOMMANDS\n if (this.$children.size > 0) {\n console.log(bold(\"sub commands:\"));\n const deduped = Array.from(\n new Map(\n [...this.$children.values()].map((a) => [\n a.command.$names[0],\n a.command,\n ]),\n ).values(),\n );\n\n const longest = Math.max(...deduped.map((c) => c.$names[0].length));\n for (const cmd of deduped) {\n const line = ` ${cyan(pad(cmd.$names[0], longest + 4))}${gray(cmd.$description) ?? \"\"}`;\n console.log(line);\n }\n console.log();\n console.log(\n `run '${cyan(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`,\n );\n }\n }\n\n /**\n * Handles a set of errors.\n * @param errors The errors to handle.\n * @param input The parsed input, if possible.\n * @returns this\n */\n async handleErrors(\n errors: Error[],\n input?: Partial<InferInput<T>>,\n ): Promise<this> {\n // eslint-disable-next-line -- necessary for traversing up the tree\n let command: Command<any> = this;\n while (!command.$errorFn && command.$parent) {\n command = command.$parent;\n }\n\n if (command.$errorFn) {\n await command.$errorFn(command, errors, input ?? {});\n } else {\n this.defaultErrorScreen(errors);\n }\n return this;\n }\n\n /**\n * Runs a command.\n * @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.\n * @returns this\n */\n async run(argv?: string[]): Promise<this> {\n const result = await this.parse(argv ?? process.argv.slice(2));\n if (result.isHelp) {\n result.command.handleErrors([new HelpAskedError(result.command)]);\n return this;\n } else if (result.isVersion) {\n console.log(\n `${result.command.fullCommandPath()} version ${result.command.$version}`,\n );\n return this;\n }\n\n try {\n if (result.errors.length > 0) {\n await result.command.handleErrors(result.errors, result.input);\n } else if (!result.command.$fn) {\n await result.command.handleErrors(\n [new HelpAskedError(result.command), ...result.errors],\n result.input,\n );\n } else {\n const middlewares = collectMiddlewares(result.command);\n if (middlewares.length > 0) {\n const runner = compose(middlewares);\n // finalNext calls the command action with the same input\n await runner(result.input, async () => {\n await result.command.$fn?.(result.input);\n });\n } else {\n await result.command.$fn(result.input);\n }\n }\n } catch (e) {\n if (!(e instanceof Error)) {\n console.warn(\n \"[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior.\",\n );\n }\n await result.command.handleErrors([e as Error]);\n }\n return this;\n }\n}\n\nfunction collectMiddlewares(cmd: Command<any>) {\n const middlewares: MiddlewareFn<any>[] = [];\n let current: Command<any> | undefined = cmd;\n while (current) {\n if (current.$middlewares.length) {\n middlewares.unshift(...current.$middlewares);\n }\n current = current.$parent;\n }\n return middlewares;\n}\n\nfunction compose(mws: MiddlewareFn<any>[]) {\n return (input: InferInput<any>, finalNext?: () => Promise<any>) => {\n let index = -1;\n const dispatch = (i: number): Promise<any> => {\n if (i <= index)\n return Promise.reject(new Error(\"next() called multiple times\"));\n index = i;\n const fn = mws[i];\n if (!fn) {\n // when middlewares exhausted call finalNext if provided\n return finalNext ? finalNext() : Promise.resolve();\n }\n try {\n return Promise.resolve(fn(input, () => dispatch(i + 1)));\n } cat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