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,316 @@
1
+ import { n as Theme } from "./index-BtbthYjp.mjs";
2
+ import { i as Input, o as Option, r as InferInput, s as Positional } from "./index-ClhbwSD8.mjs";
3
+
4
+ //#region src/command/error.d.ts
5
+
6
+ /**
7
+ * A Convoker-related error. These are usually handled by default.
8
+ */
9
+ declare class ConvokerError extends Error {
10
+ /**
11
+ * The command this error happened on.
12
+ */
13
+ command: Command<any>;
14
+ /**
15
+ * Creates a new Convoker error.
16
+ * @param message The message.
17
+ * @param command The command.
18
+ */
19
+ constructor(message: string, command: Command<any>);
20
+ /**
21
+ * Prints the error's message.
22
+ */
23
+ print(): void;
24
+ }
25
+ /**
26
+ * When the user asks for help.
27
+ */
28
+ declare class HelpAskedError extends ConvokerError {
29
+ /**
30
+ * Creates a new help asked error.
31
+ * @param command The command.
32
+ */
33
+ constructor(command: Command<any>);
34
+ }
35
+ /**
36
+ * When you pass too many arguments.
37
+ */
38
+ declare class TooManyArgumentsError extends ConvokerError {
39
+ /**
40
+ * Creates a new too many arguments error.
41
+ * @param command The command.
42
+ */
43
+ constructor(command: Command<any>);
44
+ }
45
+ /**
46
+ * When you pass an unknown option, when unknown options aren't allowed.
47
+ */
48
+ declare class UnknownOptionError extends ConvokerError {
49
+ /**
50
+ * The option key.
51
+ */
52
+ key: string;
53
+ /**
54
+ * Creates a new unknown option error.
55
+ * @param command The command.
56
+ * @param key The key.
57
+ */
58
+ constructor(command: Command<any>, key: string);
59
+ }
60
+ /**
61
+ * When a required option is missing.
62
+ */
63
+ declare class MissingRequiredOptionError extends ConvokerError {
64
+ /**
65
+ * The option key.
66
+ */
67
+ key: string;
68
+ /**
69
+ * The option entry.
70
+ */
71
+ entry: Option<any, any, any>;
72
+ /**
73
+ * Creates a new missing required option error.
74
+ * @param command The command.
75
+ * @param key The key.
76
+ * @param entry The entry.
77
+ */
78
+ constructor(command: Command<any>, key: string, entry: Option<any, any, any>);
79
+ }
80
+ declare class MissingRequiredArgumentError extends ConvokerError {
81
+ /**
82
+ * The argument key.
83
+ */
84
+ key: string;
85
+ /**
86
+ * The argument entry.
87
+ */
88
+ entry: Positional<any, any, any>;
89
+ /**
90
+ * Creates a new missing required argument error.
91
+ * @param command The command.
92
+ * @param key The key.
93
+ * @param entry The entry.
94
+ */
95
+ constructor(command: Command<any>, key: string, entry: Positional<any, any, any>);
96
+ }
97
+ //#endregion
98
+ //#region src/command/index.d.ts
99
+ /**
100
+ * What the command is an alias for.
101
+ */
102
+ interface CommandAlias<T extends Input = Input> {
103
+ /**
104
+ * A pointer to the command.
105
+ */
106
+ command: Command<T>;
107
+ /**
108
+ * The name of the command this is an alias for.
109
+ */
110
+ alias?: string;
111
+ }
112
+ /**
113
+ * The result of the `Command.parse` function.
114
+ */
115
+ interface ParseResult<T extends Input> {
116
+ /**
117
+ * A pointer to the command to run.
118
+ */
119
+ command: Command<T>;
120
+ /**
121
+ * The input to pass into the command.
122
+ */
123
+ input: InferInput<T>;
124
+ /**
125
+ * Errors collected during parsing.
126
+ */
127
+ errors: ConvokerError[];
128
+ /**
129
+ * If this should result in displaying the version of the command.
130
+ */
131
+ isVersion: boolean;
132
+ /**
133
+ * If this should result in displaying a help screen.
134
+ */
135
+ isHelp: boolean;
136
+ }
137
+ /**
138
+ * Command action function.
139
+ */
140
+ type ActionFn<T extends Input> = (input: InferInput<T>) => any | Promise<any>;
141
+ /**
142
+ * Command middleware function.
143
+ */
144
+ type MiddlewareFn<T extends Input = Input> = (input: InferInput<T>, next: () => Promise<any>) => any | Promise<any>;
145
+ /**
146
+ * Command error handler.
147
+ */
148
+ type ErrorFn<T extends Input> = (command: Command<T>, errors: Error[], input: Partial<InferInput<T>>) => void | Promise<void>;
149
+ /**
150
+ * Builder for commands.
151
+ */
152
+ type Builder = (c: Command<any>) => Command<any> | void;
153
+ /**
154
+ * A command.
155
+ */
156
+ declare class Command<T extends Input = Input> {
157
+ /**
158
+ * The names (aliases) of this command.
159
+ */
160
+ $names: string[];
161
+ /**
162
+ * The description of this command.
163
+ */
164
+ $description: string | undefined;
165
+ /**
166
+ * The theme of this command
167
+ */
168
+ $theme: Theme | undefined;
169
+ /**
170
+ * The version of this command.
171
+ */
172
+ $version: string | undefined;
173
+ /**
174
+ * The children of this command.
175
+ */
176
+ $children: Map<string, CommandAlias>;
177
+ /**
178
+ * The parent of this command.
179
+ */
180
+ $parent: Command<any> | undefined;
181
+ /**
182
+ * If this command allows unknown options.
183
+ */
184
+ $allowUnknownOptions: boolean;
185
+ /**
186
+ * If you should be able to surpass the amount of positional arguments defined in the input.
187
+ */
188
+ $allowSurpassArgLimit: boolean;
189
+ /**
190
+ * The input this command takes.
191
+ */
192
+ $input: T;
193
+ /**
194
+ * The action function of this command.
195
+ */
196
+ $fn: ActionFn<T> | undefined;
197
+ /**
198
+ * The middlewares associated with this command.
199
+ */
200
+ $middlewares: MiddlewareFn<T>[];
201
+ /**
202
+ * The error handler of this command.
203
+ */
204
+ $errorFn: ErrorFn<T> | undefined;
205
+ /**
206
+ * Creates a new command.
207
+ * @param names The names (aliases).
208
+ * @param desc The description.
209
+ * @param version The version.
210
+ */
211
+ constructor(names: string | string[], desc?: string, version?: string);
212
+ /**
213
+ * Adds a set of aliases to this command.
214
+ * @param aliases The aliases to add.
215
+ * @returns this
216
+ */
217
+ alias(...aliases: string[]): this;
218
+ /**
219
+ * Adds a description to this command.
220
+ * @param desc The description.
221
+ * @returns this
222
+ */
223
+ description(desc: string): this;
224
+ /**
225
+ * Adds a version to this command.
226
+ * @param version The version.
227
+ * @returns this
228
+ */
229
+ version(version: string): this;
230
+ /**
231
+ * Sets the input for this command.
232
+ * @param version The input.
233
+ * @returns this
234
+ */
235
+ input<TInput extends Input>(input: TInput): Command<TInput>;
236
+ /**
237
+ * Adds a chain of middlewares.
238
+ * @param fns The middlewares to use.
239
+ * @returns this
240
+ */
241
+ use(...fns: MiddlewareFn<T>[]): this;
242
+ /**
243
+ * Sets the action function for this command.
244
+ * @param fn The action.
245
+ * @returns this
246
+ */
247
+ action(fn: ActionFn<T>): this;
248
+ /**
249
+ * Sets the error function for this command.
250
+ * @param fn The error handler.
251
+ * @returns this
252
+ */
253
+ error(fn: ErrorFn<T>): this;
254
+ /**
255
+ * Adds existing commands to this.
256
+ * @param commands The commands.
257
+ * @returns this
258
+ */
259
+ add(...commands: Command<any>[]): this;
260
+ /**
261
+ * Creates a new subcommand and adds it.
262
+ * @param names The aliases of the subcommand.
263
+ * @param builder A builder to create the command.
264
+ */
265
+ subCommand(names: string | string[], builder: Builder): this;
266
+ /**
267
+ * Creates a new subcommand and adds it.
268
+ * @param names The aliases of the subcommand.
269
+ * @param desc The description of the subcommand.
270
+ * @param version The version of the subcommand.
271
+ */
272
+ subCommand(names: string | string[], desc?: string, version?: string): Command<any>;
273
+ /**
274
+ * Allows unknown options.
275
+ * @returns this
276
+ */
277
+ allowUnknownOptions(): this;
278
+ /**
279
+ * Parses a set of command-line arguments.
280
+ * @param argv The arguments to parse.
281
+ * @returns A parse result.
282
+ */
283
+ parse(argv: string[]): Promise<ParseResult<T>>;
284
+ private buildInputMap;
285
+ /**
286
+ * Allows surpassing the amount of arguments specified.
287
+ * @returns this
288
+ */
289
+ allowSurpassArgLimit(): this;
290
+ /**
291
+ * Gets the full command path (name including parents).
292
+ * @returns The full command path.
293
+ */
294
+ fullCommandPath(): string;
295
+ /**
296
+ * The default error screen.
297
+ * @param errors The errors.
298
+ */
299
+ defaultErrorScreen(errors: Error[]): void;
300
+ /**
301
+ * Handles a set of errors.
302
+ * @param errors The errors to handle.
303
+ * @param input The parsed input, if possible.
304
+ * @returns this
305
+ */
306
+ handleErrors(errors: Error[], input?: Partial<InferInput<T>>): Promise<this>;
307
+ /**
308
+ * Runs a command.
309
+ * @param argv The arguments to run the command with. Defaults to your runtime's `argv` equivalent.
310
+ * @returns this
311
+ */
312
+ run(argv?: string[]): Promise<this>;
313
+ }
314
+ //#endregion
315
+ export { ErrorFn as a, ConvokerError as c, MissingRequiredOptionError as d, TooManyArgumentsError as f, CommandAlias as i, HelpAskedError as l, Builder as n, MiddlewareFn as o, UnknownOptionError as p, Command as r, ParseResult as s, ActionFn as t, MissingRequiredArgumentError as u };
316
+ //# sourceMappingURL=index-Cnx4H4D-.d.mts.map
@@ -0,0 +1,37 @@
1
+ import { J as DeepPartial, M as index_d_exports, n as Theme } from "./index-BtbthYjp.mjs";
2
+ import "./standard-schema-DXS-QnwX.mjs";
3
+ import { d as index_d_exports$1 } from "./index-ClhbwSD8.mjs";
4
+ import { a as ErrorFn, c as ConvokerError, d as MissingRequiredOptionError, f as TooManyArgumentsError, i as CommandAlias, l as HelpAskedError, n as Builder, o as MiddlewareFn, p as UnknownOptionError, r as Command, s as ParseResult, t as ActionFn, u as MissingRequiredArgumentError } from "./index-Cnx4H4D-.mjs";
5
+ import "./raw-cqTp2vds.mjs";
6
+ import { d as index_d_exports$3 } from "./index-BYLskLxk.mjs";
7
+ import Stream from "node:stream";
8
+
9
+ //#region src/log/error.d.ts
10
+ declare class WriteError extends Error {
11
+ constructor(streamName: string);
12
+ }
13
+ declare namespace index_d_exports$2 {
14
+ export { Config, DEFAULT_CONFIG, WriteError, error, fatal, info, setConfig, setTheme, trace, warn };
15
+ }
16
+ declare function setTheme(theme: Theme): void;
17
+ interface Config {
18
+ format: "text" | "json";
19
+ stdout: Stream.Writable;
20
+ stderr: Stream.Writable;
21
+ jsonSpace: number;
22
+ }
23
+ declare const DEFAULT_CONFIG: Config;
24
+ declare function setConfig({
25
+ theme,
26
+ ...cfg
27
+ }: DeepPartial<Config> & {
28
+ theme?: Theme;
29
+ }): void;
30
+ declare function trace(...msgs: any[]): void;
31
+ declare function info(...msgs: any[]): void;
32
+ declare function warn(...msgs: any[]): void;
33
+ declare function error(...msgs: any[]): void;
34
+ declare function fatal(...msgs: any[]): void;
35
+ //#endregion
36
+ export { ActionFn, Builder, Command, CommandAlias, ConvokerError, ErrorFn, HelpAskedError, MiddlewareFn, MissingRequiredArgumentError, MissingRequiredOptionError, ParseResult, TooManyArgumentsError, UnknownOptionError, index_d_exports as color, index_d_exports$1 as i, index_d_exports$2 as log, index_d_exports$3 as prompt };
37
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,92 @@
1
+ import { t as __export } from "./chunk-z5eko27R.mjs";
2
+ import { S as color_exports, q as merge, t as DEFAULT_THEME } from "./color-DiZvJ0Fc.mjs";
3
+ import "./standard-schema-DTuaYJjO.mjs";
4
+ import "./raw-DEtZFeMv.mjs";
5
+ import { a as prompt_exports } from "./prompt-a5Ix_Hyc.mjs";
6
+ import { a as MissingRequiredOptionError, i as MissingRequiredArgumentError, n as ConvokerError, o as TooManyArgumentsError, r as HelpAskedError, s as UnknownOptionError, t as Command } from "./command-8P8qXJ2o.mjs";
7
+ import { a as input_exports } from "./input-XUsy1LCQ.mjs";
8
+ import process from "node:process";
9
+
10
+ //#region src/log/error.ts
11
+ var WriteError = class extends Error {
12
+ constructor(streamName) {
13
+ super(`Could not write to \`${streamName}\`.`);
14
+ }
15
+ };
16
+
17
+ //#endregion
18
+ //#region src/log/index.ts
19
+ var log_exports = /* @__PURE__ */ __export({
20
+ DEFAULT_CONFIG: () => DEFAULT_CONFIG,
21
+ WriteError: () => WriteError,
22
+ error: () => error,
23
+ fatal: () => fatal,
24
+ info: () => info,
25
+ setConfig: () => setConfig,
26
+ setTheme: () => setTheme,
27
+ trace: () => trace,
28
+ warn: () => warn
29
+ });
30
+ let th = DEFAULT_THEME;
31
+ function setTheme(theme) {
32
+ th = theme;
33
+ }
34
+ const DEFAULT_CONFIG = {
35
+ format: "text",
36
+ stderr: process.stderr,
37
+ stdout: process.stdout,
38
+ jsonSpace: 2
39
+ };
40
+ let config = DEFAULT_CONFIG;
41
+ function setConfig({ theme,...cfg }) {
42
+ config = merge(DEFAULT_CONFIG, cfg);
43
+ th = theme ?? th;
44
+ }
45
+ function trace(...msgs) {
46
+ const str = format(msgs, "TRACE");
47
+ if (!config.stdout.write(str)) throw new WriteError("stdout");
48
+ }
49
+ function info(...msgs) {
50
+ const str = format(msgs, "INFO");
51
+ if (!config.stdout.write(str)) throw new WriteError("stdout");
52
+ }
53
+ function warn(...msgs) {
54
+ const str = format(msgs, "WARN");
55
+ if (!config.stderr.write(th.warning(str))) throw new WriteError("stderr");
56
+ }
57
+ function error(...msgs) {
58
+ const str = format(msgs, "ERROR");
59
+ if (!config.stderr.write(str)) throw new WriteError("stderr");
60
+ }
61
+ function fatal(...msgs) {
62
+ const str = format(msgs, "FATAL");
63
+ if (!config.stderr.write(str)) throw new WriteError("stderr");
64
+ process.exit(-1);
65
+ }
66
+ function format(msgs, level) {
67
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
68
+ const msg = msgs.map((m) => typeof m === "string" ? m : JSON.stringify(m, null, config.jsonSpace)).join(" ");
69
+ switch (config.format) {
70
+ case "json": return colorize(JSON.stringify({
71
+ timestamp,
72
+ level,
73
+ message: msg
74
+ }) + "\n", level);
75
+ case "text":
76
+ default: return colorize(`[${timestamp}] [${th.symbols[level] ?? level}] ${msg}\n`, level);
77
+ }
78
+ }
79
+ function colorize(str, level) {
80
+ switch (level) {
81
+ case "TRACE": return th.secondary(str);
82
+ case "WARN": return th.warning(str);
83
+ case "ERROR": return th.error(str);
84
+ case "FATAL": return th.styles?.bold ? th.styles.bold(th.error(str)) : th.error(str);
85
+ case "INFO":
86
+ default: return th.info?.(str) ?? str;
87
+ }
88
+ }
89
+
90
+ //#endregion
91
+ export { Command, ConvokerError, HelpAskedError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError, color_exports as color, input_exports as i, log_exports as log, prompt_exports as prompt };
92
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["th: Theme","DEFAULT_CONFIG: Config","config: Config"],"sources":["../src/log/error.ts","../src/log/index.ts"],"sourcesContent":["export class WriteError extends Error {\n constructor(streamName: string) {\n super(`Could not write to \\`${streamName}\\`.`);\n }\n}\n","import Stream from \"node:stream\";\nimport process from \"node:process\";\nimport { DEFAULT_THEME, type Theme } from \"@/color\";\nimport { DeepPartial, merge } from \"@/utils\";\nimport { WriteError } from \"./error\";\n\nlet th: Theme = DEFAULT_THEME;\n\nexport function setTheme(theme: Theme) {\n th = theme;\n}\n\nexport interface Config {\n format: \"text\" | \"json\";\n stdout: Stream.Writable;\n stderr: Stream.Writable;\n jsonSpace: number;\n}\n\nexport const DEFAULT_CONFIG: Config = {\n format: \"text\",\n stderr: process.stderr,\n stdout: process.stdout,\n jsonSpace: 2,\n};\n\nlet config: Config = DEFAULT_CONFIG;\n\nexport function setConfig({\n theme,\n ...cfg\n}: DeepPartial<Config> & { theme?: Theme }) {\n config = merge(DEFAULT_CONFIG, cfg);\n th = theme ?? th;\n}\n\nexport function trace(...msgs: any[]) {\n const str = format(msgs, \"TRACE\");\n if (!config.stdout.write(str)) {\n throw new WriteError(\"stdout\");\n }\n}\n\nexport function info(...msgs: any[]) {\n const str = format(msgs, \"INFO\");\n if (!config.stdout.write(str)) {\n throw new WriteError(\"stdout\");\n }\n}\n\nexport function warn(...msgs: any[]) {\n const str = format(msgs, \"WARN\");\n if (!config.stderr.write(th.warning(str))) {\n throw new WriteError(\"stderr\");\n }\n}\n\nexport function error(...msgs: any[]) {\n const str = format(msgs, \"ERROR\");\n if (!config.stderr.write(str)) {\n throw new WriteError(\"stderr\");\n }\n}\n\nexport function fatal(...msgs: any[]) {\n const str = format(msgs, \"FATAL\");\n if (!config.stderr.write(str)) {\n throw new WriteError(\"stderr\");\n }\n\n process.exit(-1);\n}\n\nexport * from \"./error\";\n\nfunction format(msgs: any[], level: string): string {\n const timestamp = new Date().toISOString();\n const msg = msgs\n .map((m) =>\n typeof m === \"string\" ? m : JSON.stringify(m, null, config.jsonSpace),\n )\n .join(\" \");\n switch (config.format) {\n case \"json\":\n return colorize(\n JSON.stringify({ timestamp, level, message: msg }) + \"\\n\",\n level,\n );\n case \"text\":\n default:\n return colorize(\n `[${timestamp}] [${(th.symbols as any)[level] ?? level}] ${msg}\\n`,\n level,\n );\n }\n}\n\nfunction colorize(str: string, level: string) {\n switch (level) {\n case \"TRACE\":\n return th.secondary(str);\n case \"WARN\":\n return th.warning(str);\n case \"ERROR\":\n return th.error(str);\n case \"FATAL\":\n return th.styles?.bold ? th.styles.bold(th.error(str)) : th.error(str);\n case \"INFO\":\n default:\n return th.info?.(str) ?? str;\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAa,aAAb,cAAgC,MAAM;CACpC,YAAY,YAAoB;AAC9B,QAAM,wBAAwB,WAAW,KAAK;;;;;;;;;;;;;;;;;ACIlD,IAAIA,KAAY;AAEhB,SAAgB,SAAS,OAAc;AACrC,MAAK;;AAUP,MAAaC,iBAAyB;CACpC,QAAQ;CACR,QAAQ,QAAQ;CAChB,QAAQ,QAAQ;CAChB,WAAW;CACZ;AAED,IAAIC,SAAiB;AAErB,SAAgB,UAAU,EACxB,MACA,GAAG,OACuC;AAC1C,UAAS,MAAM,gBAAgB,IAAI;AACnC,MAAK,SAAS;;AAGhB,SAAgB,MAAM,GAAG,MAAa;CACpC,MAAM,MAAM,OAAO,MAAM,QAAQ;AACjC,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,CAC3B,OAAM,IAAI,WAAW,SAAS;;AAIlC,SAAgB,KAAK,GAAG,MAAa;CACnC,MAAM,MAAM,OAAO,MAAM,OAAO;AAChC,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,CAC3B,OAAM,IAAI,WAAW,SAAS;;AAIlC,SAAgB,KAAK,GAAG,MAAa;CACnC,MAAM,MAAM,OAAO,MAAM,OAAO;AAChC,KAAI,CAAC,OAAO,OAAO,MAAM,GAAG,QAAQ,IAAI,CAAC,CACvC,OAAM,IAAI,WAAW,SAAS;;AAIlC,SAAgB,MAAM,GAAG,MAAa;CACpC,MAAM,MAAM,OAAO,MAAM,QAAQ;AACjC,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,CAC3B,OAAM,IAAI,WAAW,SAAS;;AAIlC,SAAgB,MAAM,GAAG,MAAa;CACpC,MAAM,MAAM,OAAO,MAAM,QAAQ;AACjC,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,CAC3B,OAAM,IAAI,WAAW,SAAS;AAGhC,SAAQ,KAAK,GAAG;;AAKlB,SAAS,OAAO,MAAa,OAAuB;CAClD,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAC1C,MAAM,MAAM,KACT,KAAK,MACJ,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,GAAG,MAAM,OAAO,UAAU,CACtE,CACA,KAAK,IAAI;AACZ,SAAQ,OAAO,QAAf;EACE,KAAK,OACH,QAAO,SACL,KAAK,UAAU;GAAE;GAAW;GAAO,SAAS;GAAK,CAAC,GAAG,MACrD,MACD;EACH,KAAK;EACL,QACE,QAAO,SACL,IAAI,UAAU,KAAM,GAAG,QAAgB,UAAU,MAAM,IAAI,IAAI,KAC/D,MACD;;;AAIP,SAAS,SAAS,KAAa,OAAe;AAC5C,SAAQ,OAAR;EACE,KAAK,QACH,QAAO,GAAG,UAAU,IAAI;EAC1B,KAAK,OACH,QAAO,GAAG,QAAQ,IAAI;EACxB,KAAK,QACH,QAAO,GAAG,MAAM,IAAI;EACtB,KAAK,QACH,QAAO,GAAG,QAAQ,OAAO,GAAG,OAAO,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,GAAG,MAAM,IAAI;EACxE,KAAK;EACL,QACE,QAAO,GAAG,OAAO,IAAI,IAAI"}
@@ -0,0 +1,3 @@
1
+ import "../standard-schema-DXS-QnwX.mjs";
2
+ import { a as Kind, c as TypeOf, f as option, i as Input, l as argument, m as InputValidationError, n as InferEntry, o as Option, p as positional, r as InferInput, s as Positional, t as BasicKind, u as convert } from "../index-ClhbwSD8.mjs";
3
+ export { BasicKind, InferEntry, InferInput, Input, InputValidationError, Kind, Option, Positional, TypeOf, argument, convert, option, positional };
@@ -0,0 +1,4 @@
1
+ import { n as InputValidationError } from "../standard-schema-DTuaYJjO.mjs";
2
+ import { i as convert, n as Positional, o as option, r as argument, s as positional, t as Option } from "../input-XUsy1LCQ.mjs";
3
+
4
+ export { InputValidationError, Option, Positional, argument, convert, option, positional };
@@ -0,0 +1,176 @@
1
+ import { t as __export } from "./chunk-z5eko27R.mjs";
2
+ import { n as InputValidationError, t as validate } from "./standard-schema-DTuaYJjO.mjs";
3
+
4
+ //#region src/input/index.ts
5
+ var input_exports = /* @__PURE__ */ __export({
6
+ InputValidationError: () => InputValidationError,
7
+ Option: () => Option,
8
+ Positional: () => Positional,
9
+ argument: () => argument,
10
+ convert: () => convert,
11
+ option: () => option,
12
+ positional: () => positional
13
+ });
14
+ /**
15
+ * Converts a value from a Kind to a TypeScript type.
16
+ * @param kind The kind to convert to.
17
+ * @param value The value to convert.
18
+ * @returns The converted value.
19
+ */
20
+ async function convert(kind, value) {
21
+ async function convertOne(val) {
22
+ if (typeof kind === "string") switch (kind) {
23
+ case "boolean": return val === "true";
24
+ case "bigint": return BigInt(val);
25
+ case "number": return parseFloat(val);
26
+ case "string": return val;
27
+ }
28
+ return validate(kind, val);
29
+ }
30
+ if (Array.isArray(value)) return await Promise.all(value.map((v) => convertOne(v)));
31
+ return convertOne(value);
32
+ }
33
+ /**
34
+ * An option.
35
+ */
36
+ var Option = class {
37
+ /**
38
+ * Creates a new option.
39
+ * @param kind The type of this option.
40
+ * @param names The names of this option.
41
+ */
42
+ constructor(kind, names) {
43
+ this.$required = true;
44
+ this.$list = false;
45
+ this.$kind = kind;
46
+ this.$names = names.map((name) => name.replace(/^-+/, ""));
47
+ }
48
+ /**
49
+ * Makes this option a list.
50
+ * @returns this
51
+ */
52
+ list(separator) {
53
+ this.$list = true;
54
+ this.$separator = separator ?? this.$separator;
55
+ return this;
56
+ }
57
+ /**
58
+ * Makes this option required.
59
+ * @returns this
60
+ */
61
+ required() {
62
+ this.$required = true;
63
+ return this;
64
+ }
65
+ /**
66
+ * Makes this option optional.
67
+ * @returns this
68
+ */
69
+ optional() {
70
+ this.$required = false;
71
+ return this;
72
+ }
73
+ /**
74
+ * Sets a default value.
75
+ * @param value The default value.
76
+ * @returns this
77
+ */
78
+ default(value) {
79
+ this.$default = value;
80
+ return this;
81
+ }
82
+ /**
83
+ * Sets a description.
84
+ * @param desc The description.
85
+ * @returns this
86
+ */
87
+ description(desc) {
88
+ this.$description = desc;
89
+ return this;
90
+ }
91
+ };
92
+ /**
93
+ * A positional argument.
94
+ */
95
+ var Positional = class {
96
+ /**
97
+ * Creates a new positional argument.
98
+ * @param kind The positional argument.
99
+ */
100
+ constructor(kind) {
101
+ this.$required = true;
102
+ this.$list = false;
103
+ this.$kind = kind;
104
+ }
105
+ /**
106
+ * Makes this argument a list.
107
+ * @returns this
108
+ */
109
+ list() {
110
+ this.$list = true;
111
+ return this;
112
+ }
113
+ /**
114
+ * Makes this argument required.
115
+ * @returns this
116
+ */
117
+ required() {
118
+ this.$required = true;
119
+ return this;
120
+ }
121
+ /**
122
+ * Makes this argument optional.
123
+ * @returns this
124
+ */
125
+ optional() {
126
+ this.$required = false;
127
+ return this;
128
+ }
129
+ /**
130
+ * Sets a default value.
131
+ * @param value The default value.
132
+ * @returns this
133
+ */
134
+ default(value) {
135
+ this.$default = value;
136
+ return this;
137
+ }
138
+ /**
139
+ * Sets a description.
140
+ * @param desc The description.
141
+ * @returns this
142
+ */
143
+ description(desc) {
144
+ this.$description = desc;
145
+ return this;
146
+ }
147
+ };
148
+ /**
149
+ * Creates a new option.
150
+ * @param kind The kind of option.
151
+ * @param names The names of the option.
152
+ * @returns A new option.
153
+ */
154
+ function option(kind, ...names) {
155
+ return new Option(kind, names);
156
+ }
157
+ /**
158
+ * Creates a new positional argument.
159
+ * @param kind The kind of positional argument.
160
+ * @returns A new positional argument.
161
+ */
162
+ function positional(kind) {
163
+ return new Positional(kind);
164
+ }
165
+ /**
166
+ * Creates a new positional argument.
167
+ * @param kind The kind of positional argument.
168
+ * @returns A new positional argument.
169
+ */
170
+ function argument(kind) {
171
+ return new Positional(kind);
172
+ }
173
+
174
+ //#endregion
175
+ export { input_exports as a, convert as i, Positional as n, option as o, argument as r, positional as s, Option as t };
176
+ //# sourceMappingURL=input-XUsy1LCQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-XUsy1LCQ.mjs","names":[],"sources":["../src/input/index.ts"],"sourcesContent":["import { validate, type StandardSchemaV1 } from \"./standard-schema\";\n\n/**\n * An input object.\n */\nexport interface Input {\n [x: string]: Option<any, any, any> | Positional<any, any, any>;\n}\n\n/**\n * A basic input type.\n */\nexport type BasicKind = \"boolean\" | \"string\" | \"number\" | \"bigint\";\n/**\n * An input type.\n */\nexport type Kind = BasicKind | StandardSchemaV1<any, any>;\n\n/**\n * Converts a Kind to a TypeScript type.\n */\nexport type TypeOf<T extends Kind> =\n T extends StandardSchemaV1<any, infer Out>\n ? Out\n : T extends \"boolean\"\n ? boolean\n : T extends \"string\"\n ? string\n : T extends \"number\"\n ? number\n : T extends \"bigint\"\n ? bigint\n : never;\n\n/**\n * Infers TypeScript types from an input object.\n */\nexport type InferInput<T extends Input> = {\n [K in keyof T]: InferEntry<T[K]>;\n};\n\n/**\n * Infers a TypeScript type from an option or positional.\n */\nexport type InferEntry<T> = T extends {\n $kind: infer TKind extends Kind;\n $required: infer Required;\n $list: infer List;\n}\n ? List extends true\n ? Required extends true\n ? TypeOf<TKind>[]\n : TypeOf<TKind>[] | undefined\n : Required extends true\n ? TypeOf<TKind>\n : TypeOf<TKind> | undefined\n : never;\n\n/**\n * Converts a value from a Kind to a TypeScript type.\n * @param kind The kind to convert to.\n * @param value The value to convert.\n * @returns The converted value.\n */\nexport async function convert<TKind extends Kind>(\n kind: TKind,\n value: string | string[],\n): Promise<TypeOf<TKind> | TypeOf<TKind>[]> {\n // Helper for single value conversion\n async function convertOne(val: string): Promise<TypeOf<TKind>> {\n if (typeof kind === \"string\") {\n switch (kind) {\n case \"boolean\":\n return (val === \"true\") as any;\n case \"bigint\":\n return BigInt(val) as any;\n case \"number\":\n return parseFloat(val) as any;\n case \"string\":\n return val as any;\n }\n }\n // Otherwise, Standard Schema\n return validate(kind, val);\n }\n\n // If list → map each item\n if (Array.isArray(value)) {\n const results = await Promise.all(value.map((v) => convertOne(v)));\n return results as any;\n }\n\n // Single value case\n return convertOne(value);\n}\n\n/**\n * An option.\n */\nexport class Option<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The kind of this option.\n */\n $kind: TKind;\n /**\n * The aliases of this option.\n */\n $names: string[];\n /**\n * The description of this option.\n */\n $description: string | undefined;\n /**\n * The default value of this option.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * If this option is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this option is a list.\n */\n $list: TList = false as TList;\n /**\n * A separator if this option is a list.\n */\n $separator: string | undefined;\n\n /**\n * Creates a new option.\n * @param kind The type of this option.\n * @param names The names of this option.\n */\n constructor(kind: TKind, names: string[]) {\n this.$kind = kind;\n this.$names = names.map((name) => name.replace(/^-+/, \"\"));\n }\n\n /**\n * Makes this option a list.\n * @returns this\n */\n list(separator?: string): Option<TKind, TRequired, true> {\n this.$list = true as TList;\n this.$separator = separator ?? this.$separator;\n return this as any;\n }\n\n /**\n * Makes this option required.\n * @returns this\n */\n required(): Option<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this option optional.\n * @returns this\n */\n optional(): Option<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\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/**\n * A positional argument.\n */\nexport class Positional<\n TKind extends Kind,\n TRequired extends boolean = true,\n TList extends boolean = false,\n> {\n /**\n * The type of this argument.\n */\n $kind: TKind;\n /**\n * The default value of this argument.\n */\n $default: TypeOf<TKind> | undefined;\n /**\n * The description of this argument.\n */\n $description: string | undefined;\n /**\n * If this argument is required.\n */\n $required: TRequired = true as TRequired;\n /**\n * If this argument is a list.\n */\n $list: TList = false as TList;\n\n /**\n * Creates a new positional argument.\n * @param kind The positional argument.\n */\n constructor(kind: TKind) {\n this.$kind = kind;\n }\n\n /**\n * Makes this argument a list.\n * @returns this\n */\n list(): Positional<TKind, TRequired, true> {\n this.$list = true as TList;\n return this as any;\n }\n\n /**\n * Makes this argument required.\n * @returns this\n */\n required(): Positional<TKind, true, TList> {\n this.$required = true as TRequired;\n return this as any;\n }\n\n /**\n * Makes this argument optional.\n * @returns this\n */\n optional(): Positional<TKind, false, TList> {\n this.$required = false as TRequired;\n return this as any;\n }\n\n /**\n * Sets a default value.\n * @param value The default value.\n * @returns this\n */\n default(value: TypeOf<TKind>): this {\n this.$default = value;\n return this;\n }\n\n /**\n * Sets a description.\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/**\n * Creates a new option.\n * @param kind The kind of option.\n * @param names The names of the option.\n * @returns A new option.\n */\nexport function option<T extends Kind>(kind: T, ...names: string[]): Option<T> {\n return new Option(kind, names);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function positional<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\n/**\n * Creates a new positional argument.\n * @param kind The kind of positional argument.\n * @returns A new positional argument.\n */\nexport function argument<T extends Kind>(kind: T): Positional<T> {\n return new Positional(kind);\n}\n\nexport * from \"./error\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgEA,eAAsB,QACpB,MACA,OAC0C;CAE1C,eAAe,WAAW,KAAqC;AAC7D,MAAI,OAAO,SAAS,SAClB,SAAQ,MAAR;GACE,KAAK,UACH,QAAQ,QAAQ;GAClB,KAAK,SACH,QAAO,OAAO,IAAI;GACpB,KAAK,SACH,QAAO,WAAW,IAAI;GACxB,KAAK,SACH,QAAO;;AAIb,SAAO,SAAS,MAAM,IAAI;;AAI5B,KAAI,MAAM,QAAQ,MAAM,CAEtB,QADgB,MAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,WAAW,EAAE,CAAC,CAAC;AAKpE,QAAO,WAAW,MAAM;;;;;AAM1B,IAAa,SAAb,MAIE;;;;;;CAmCA,YAAY,MAAa,OAAiB;mBAfnB;eAIR;AAYb,OAAK,QAAQ;AACb,OAAK,SAAS,MAAM,KAAK,SAAS,KAAK,QAAQ,OAAO,GAAG,CAAC;;;;;;CAO5D,KAAK,WAAoD;AACvD,OAAK,QAAQ;AACb,OAAK,aAAa,aAAa,KAAK;AACpC,SAAO;;;;;;CAOT,WAAuC;AACrC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAAwC;AACtC,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;AAOX,IAAa,aAAb,MAIE;;;;;CA0BA,YAAY,MAAa;mBAVF;eAIR;AAOb,OAAK,QAAQ;;;;;;CAOf,OAA2C;AACzC,OAAK,QAAQ;AACb,SAAO;;;;;;CAOT,WAA2C;AACzC,OAAK,YAAY;AACjB,SAAO;;;;;;CAOT,WAA4C;AAC1C,OAAK,YAAY;AACjB,SAAO;;;;;;;CAQT,QAAQ,OAA4B;AAClC,OAAK,WAAW;AAChB,SAAO;;;;;;;CAQT,YAAY,MAAoB;AAC9B,OAAK,eAAe;AACpB,SAAO;;;;;;;;;AAUX,SAAgB,OAAuB,MAAS,GAAG,OAA4B;AAC7E,QAAO,IAAI,OAAO,MAAM,MAAM;;;;;;;AAQhC,SAAgB,WAA2B,MAAwB;AACjE,QAAO,IAAI,WAAW,KAAK;;;;;;;AAQ7B,SAAgB,SAAyB,MAAwB;AAC/D,QAAO,IAAI,WAAW,KAAK"}
@@ -0,0 +1,5 @@
1
+ import "../index-BtbthYjp.mjs";
2
+ import "../standard-schema-DXS-QnwX.mjs";
3
+ import { i as raw_d_exports } from "../raw-cqTp2vds.mjs";
4
+ import { _ as text, a as SearchOpts, c as TextOpts, f as multiselect, g as setTheme, h as select, i as PasswordOpts, l as confirm, m as search, n as ConfirmOpts, o as SelectOption, p as password, r as EditorOpts, s as SelectOpts, t as BaseOpts, u as editor } from "../index-BYLskLxk.mjs";
5
+ export { BaseOpts, ConfirmOpts, EditorOpts, PasswordOpts, SearchOpts, SelectOption, SelectOpts, TextOpts, confirm, editor, multiselect, password, raw_d_exports as raw, search, select, setTheme, text };
@@ -0,0 +1,6 @@
1
+ import "../color-DiZvJ0Fc.mjs";
2
+ import "../standard-schema-DTuaYJjO.mjs";
3
+ import { i as raw_exports } from "../raw-DEtZFeMv.mjs";
4
+ import { c as setTheme, i as password, l as text, n as editor, o as search, r as multiselect, s as select, t as confirm } from "../prompt-a5Ix_Hyc.mjs";
5
+
6
+ export { confirm, editor, multiselect, password, raw_exports as raw, search, select, setTheme, text };
@@ -0,0 +1,2 @@
1
+ import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-cqTp2vds.mjs";
2
+ export { clearLines, cursorDown, cursorUp, readKey, readLine };
@@ -0,0 +1,3 @@
1
+ import { a as readKey, n as cursorDown, o as readLine, r as cursorUp, t as clearLines } from "../raw-DEtZFeMv.mjs";
2
+
3
+ export { clearLines, cursorDown, cursorUp, readKey, readLine };