convoker 0.3.4 → 0.4.1

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 (47) hide show
  1. package/LICENSE +1 -1
  2. package/dist/color/index.d.mts +2 -0
  3. package/dist/color/index.mjs +3 -0
  4. package/dist/{color-OlJQTTxb.mjs → color-s-N9yh90.mjs} +7 -41
  5. package/dist/color-s-N9yh90.mjs.map +1 -0
  6. package/dist/command/index.d.mts +5 -0
  7. package/dist/command/index.mjs +9 -0
  8. package/dist/{command-D2UiQBNA.mjs → command-C9QIG--8.mjs} +187 -148
  9. package/dist/command-C9QIG--8.mjs.map +1 -0
  10. package/dist/{index-Dikc5KAP.d.mts → index-C0cH9MIP.d.mts} +4 -3
  11. package/dist/{input-B12iaqb8.d.mts → index-C6iJZTo3.d.mts} +20 -5
  12. package/dist/index-CCQ6jz54.d.mts +58 -0
  13. package/dist/{command-BXmfoT-l.d.mts → index-OUlP1L9o.d.mts} +10 -25
  14. package/dist/index.d.mts +62 -43
  15. package/dist/index.mjs +8 -9
  16. package/dist/input/index.d.mts +3 -0
  17. package/dist/input/index.mjs +4 -0
  18. package/dist/{input-DRy_sVxZ.mjs → input-li13L1uf.mjs} +5 -3
  19. package/dist/input-li13L1uf.mjs.map +1 -0
  20. package/dist/prompt/index.d.mts +3 -3
  21. package/dist/prompt/index.mjs +5 -6
  22. package/dist/prompt/raw.mjs +1 -2
  23. package/dist/{prompt-Cvufljin.mjs → prompt-OXGrAkDf.mjs} +30 -58
  24. package/dist/prompt-OXGrAkDf.mjs.map +1 -0
  25. package/dist/raw-BqvlveTU.d.mts +2 -1
  26. package/dist/{raw--889icsd.mjs → raw-DVT5lw11.mjs} +4 -21
  27. package/dist/raw-DVT5lw11.mjs.map +1 -0
  28. package/dist/{standard-schema-DLeKaehR.d.mts → standard-schema-D1sStgzy.d.mts} +3 -2
  29. package/dist/standard-schema-WhGEzW0C.mjs +32 -0
  30. package/dist/standard-schema-WhGEzW0C.mjs.map +1 -0
  31. package/dist/{utils-ChmY93uA.mjs → theme-Chg3mOhZ.mjs} +36 -13
  32. package/dist/theme-Chg3mOhZ.mjs.map +1 -0
  33. package/dist/theme-EERPMtQU.d.mts +115 -0
  34. package/dist/theme.d.mts +2 -0
  35. package/dist/theme.mjs +4 -0
  36. package/package.json +18 -17
  37. package/dist/color-BuHvMolk.d.mts +0 -158
  38. package/dist/color.d.mts +0 -2
  39. package/dist/color.mjs +0 -4
  40. package/dist/command.d.mts +0 -5
  41. package/dist/command.mjs +0 -10
  42. package/dist/error-C1S1gs8L.mjs +0 -115
  43. package/dist/error.d.mts +0 -5
  44. package/dist/error.mjs +0 -3
  45. package/dist/input.d.mts +0 -3
  46. package/dist/input.mjs +0 -5
  47. package/dist/standard-schema-DBXbMy6L.mjs +0 -17
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 trailfrost
3
+ Copyright (c) 2025 sprucepad
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,2 @@
1
+ import { A as inverse, B as underline, C as cyanBright, D as greenBright, E as green, F as red, H as whiteBright, I as redBright, L as reset, M as magenta, N as magentaBright, O as hidden, P as overline, R as strikethrough, S as cyan, T as gray, U as yellow, V as white, W as yellowBright, _ as black, a as bgCyanBright, b as bold, c as bgGreenBright, d as bgRed, f as bgRedBright, g as bgYellowBright, h as bgYellow, i as bgCyan, j as italic, l as bgMagenta, m as bgWhiteBright, n as bgBlue, o as bgGray, p as bgWhite, r as bgBlueBright, s as bgGreen, t as bgBlack, u as bgMagentaBright, v as blue, w as dim, x as createAnsiColor, y as blueBright, z as supportsColor } from "../index-CCQ6jz54.mjs";
2
+ export { bgBlack, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blue, blueBright, bold, createAnsiColor, cyan, cyanBright, dim, gray, green, greenBright, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, strikethrough, supportsColor, underline, white, whiteBright, yellow, yellowBright };
@@ -0,0 +1,3 @@
1
+ import { A as inverse, B as underline, C as cyan, D as green, E as gray, F as red, H as whiteBright, I as redBright, L as reset, M as magenta, N as magentaBright, O as greenBright, P as overline, R as strikethrough, S as createAnsiColor, T as dim, U as yellow, V as white, W as yellowBright, _ as black, a as bgCyanBright, b as bold, c as bgGreenBright, d as bgRed, f as bgRedBright, g as bgYellowBright, h as bgYellow, i as bgCyan, j as italic, k as hidden, l as bgMagenta, m as bgWhiteBright, n as bgBlue, o as bgGray, p as bgWhite, r as bgBlueBright, s as bgGreen, t as bgBlack, u as bgMagentaBright, v as blue, w as cyanBright, y as blueBright, z as supportsColor } from "../color-s-N9yh90.mjs";
2
+
3
+ export { bgBlack, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blue, blueBright, bold, createAnsiColor, cyan, cyanBright, dim, gray, green, greenBright, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, strikethrough, supportsColor, underline, white, whiteBright, yellow, yellowBright };
@@ -1,9 +1,7 @@
1
1
  import { t as __export } from "./chunk-z5eko27R.mjs";
2
- import { i as merge } from "./utils-ChmY93uA.mjs";
3
2
 
4
- //#region src/color.ts
3
+ //#region src/color/index.ts
5
4
  var color_exports = /* @__PURE__ */ __export({
6
- DEFAULT_THEME: () => DEFAULT_THEME,
7
5
  bgBlack: () => bgBlack,
8
6
  bgBlue: () => bgBlue,
9
7
  bgBlueBright: () => bgBlueBright,
@@ -27,7 +25,6 @@ var color_exports = /* @__PURE__ */ __export({
27
25
  createAnsiColor: () => createAnsiColor,
28
26
  cyan: () => cyan,
29
27
  cyanBright: () => cyanBright,
30
- defineTheme: () => defineTheme,
31
28
  dim: () => dim,
32
29
  gray: () => gray,
33
30
  green: () => green,
@@ -70,14 +67,10 @@ function detectColorSupport() {
70
67
  ].some((k) => k in env) || env.CI_NAME === "codeship") return true;
71
68
  return false;
72
69
  }
73
- if (typeof Deno !== "undefined" && Deno.noColor !== void 0) return !Deno.noColor;
74
- if (typeof process !== "undefined" && process.stdout) {
75
- const term = env.TERM || "";
76
- if ((env.COLORTERM || "").length > 0) return true;
77
- if (term === "dumb") return false;
78
- return /(color|ansi|cygwin|xterm|vt100)/i.test(term);
79
- }
80
- return false;
70
+ const term = env.TERM || "";
71
+ if ((env.COLORTERM || "").length > 0) return true;
72
+ if (term === "dumb") return false;
73
+ return /(color|ansi|cygwin|xterm|vt100)/i.test(term);
81
74
  }
82
75
  /**
83
76
  * If the runtime supports color.
@@ -139,34 +132,7 @@ const bgBlueBright = createAnsiColor(104, 49);
139
132
  const bgMagentaBright = createAnsiColor(105, 49);
140
133
  const bgCyanBright = createAnsiColor(106, 49);
141
134
  const bgWhiteBright = createAnsiColor(107, 49);
142
- /**
143
- * The default theme.
144
- */
145
- const DEFAULT_THEME = {
146
- primary: cyan,
147
- secondary: gray,
148
- success: green,
149
- warning: yellow,
150
- error: red,
151
- symbols: {
152
- success: "✔",
153
- error: "✖",
154
- warning: "⚠"
155
- },
156
- styles: {
157
- bold,
158
- italic,
159
- underline
160
- }
161
- };
162
- /**
163
- * Defines a theme.
164
- * @param theme The (partial) theme.
165
- * @returns The theme, merged with the default theme.
166
- */
167
- function defineTheme(theme) {
168
- return merge(DEFAULT_THEME, theme);
169
- }
170
135
 
171
136
  //#endregion
172
- export { greenBright as A, strikethrough as B, createAnsiColor as C, dim as D, defineTheme as E, magentaBright as F, yellow as G, underline as H, overline as I, yellowBright as K, red as L, inverse as M, italic as N, gray as O, magenta as P, redBright as R, color_exports as S, cyanBright as T, white as U, supportsColor as V, whiteBright as W, bgYellowBright as _, bgCyan as a, blueBright as b, bgGreen as c, bgMagentaBright as d, bgRed as f, bgYellow as g, bgWhiteBright as h, bgBlueBright as i, hidden as j, green as k, bgGreenBright as l, bgWhite as m, bgBlack as n, bgCyanBright as o, bgRedBright as p, bgBlue as r, bgGray as s, DEFAULT_THEME as t, bgMagenta as u, black as v, cyan as w, bold as x, blue as y, reset as z };
137
+ export { inverse as A, underline as B, cyan as C, green as D, gray as E, red as F, whiteBright as H, redBright as I, reset as L, magenta as M, magentaBright as N, greenBright as O, overline as P, strikethrough as R, createAnsiColor as S, dim as T, yellow as U, white as V, yellowBright as W, black as _, bgCyanBright as a, bold as b, bgGreenBright as c, bgRed as d, bgRedBright as f, bgYellowBright as g, bgYellow as h, bgCyan as i, italic as j, hidden as k, bgMagenta as l, bgWhiteBright as m, bgBlue as n, bgGray as o, bgWhite as p, bgBlueBright as r, bgGreen as s, bgBlack as t, bgMagentaBright as u, blue as v, cyanBright as w, color_exports as x, blueBright as y, supportsColor as z };
138
+ //# sourceMappingURL=color-s-N9yh90.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-s-N9yh90.mjs","names":[],"sources":["../src/color/index.ts"],"sourcesContent":["/**\n * Detects if the runtime supports colored output.\n * @returns If the runtime supports colored output.\n */\nfunction detectColorSupport() {\n // If running in a browser-like environment, return false\n if (typeof window !== \"undefined\" && typeof window.document !== \"undefined\") {\n return false;\n }\n\n const env = typeof process !== \"undefined\" ? (process.env ?? {}) : {};\n\n // Force-disable colors if NO_COLOR is set\n if (\"NO_COLOR\" in env) return false;\n\n // Force-enable if FORCE_COLOR is set\n if (\"FORCE_COLOR\" in env) return true;\n\n // Check for CI systems that support color\n if (\"CI\" in env) {\n if (\n [\n \"TRAVIS\",\n \"CIRCLECI\",\n \"APPVEYOR\",\n \"GITLAB_CI\",\n \"GITHUB_ACTIONS\",\n \"BUILDKITE\",\n \"DRONE\",\n ].some((k) => k in env) ||\n env.CI_NAME === \"codeship\"\n ) {\n return true;\n }\n return false;\n }\n\n const term = env.TERM || \"\";\n const colorterm = env.COLORTERM || \"\";\n\n if (colorterm.length > 0) return true;\n if (term === \"dumb\") return false;\n\n return /(color|ansi|cygwin|xterm|vt100)/i.test(term);\n}\n\n/**\n * If the runtime supports color.\n */\nexport const supportsColor = detectColorSupport();\n\n/**\n * Creates a function that wraps a string in ANSI codes.\n * @param open The opening ANSI code.\n * @param close The closing ANSI code.\n * @returns A function that wraps the string in ANSI codes.\n */\nexport function createAnsiColor(\n open: number,\n close: number,\n): (input: any) => string {\n const openCode = `\\u001b[${open}m`;\n const closeCode = `\\u001b[${close}m`;\n\n if (!supportsColor) return (input) => input + \"\";\n\n return (input) => {\n if (!input) return openCode + closeCode;\n\n const str = input + \"\";\n // replace any existing close codes with reopen\n const replaced = str.replace(\n new RegExp(`\\u001b\\\\[${close}m`, \"g\"),\n closeCode + openCode,\n );\n return openCode + replaced + closeCode;\n };\n}\n\nexport const reset = createAnsiColor(0, 0);\nexport const bold = createAnsiColor(1, 22);\nexport const dim = createAnsiColor(2, 22);\nexport const italic = createAnsiColor(3, 23);\nexport const underline = createAnsiColor(4, 24);\nexport const overline = createAnsiColor(53, 55);\nexport const inverse = createAnsiColor(7, 27);\nexport const hidden = createAnsiColor(8, 28);\nexport const strikethrough = createAnsiColor(9, 29);\n\nexport const black = createAnsiColor(30, 39);\nexport const red = createAnsiColor(31, 39);\nexport const green = createAnsiColor(32, 39);\nexport const yellow = createAnsiColor(33, 39);\nexport const blue = createAnsiColor(34, 39);\nexport const magenta = createAnsiColor(35, 39);\nexport const cyan = createAnsiColor(36, 39);\nexport const white = createAnsiColor(37, 39);\nexport const gray = createAnsiColor(90, 39);\n\nexport const bgBlack = createAnsiColor(40, 49);\nexport const bgRed = createAnsiColor(41, 49);\nexport const bgGreen = createAnsiColor(42, 49);\nexport const bgYellow = createAnsiColor(43, 49);\nexport const bgBlue = createAnsiColor(44, 49);\nexport const bgMagenta = createAnsiColor(45, 49);\nexport const bgCyan = createAnsiColor(46, 49);\nexport const bgWhite = createAnsiColor(47, 49);\nexport const bgGray = createAnsiColor(100, 49);\n\nexport const redBright = createAnsiColor(91, 39);\nexport const greenBright = createAnsiColor(92, 39);\nexport const yellowBright = createAnsiColor(93, 39);\nexport const blueBright = createAnsiColor(94, 39);\nexport const magentaBright = createAnsiColor(95, 39);\nexport const cyanBright = createAnsiColor(96, 39);\nexport const whiteBright = createAnsiColor(97, 39);\n\nexport const bgRedBright = createAnsiColor(101, 49);\nexport const bgGreenBright = createAnsiColor(102, 49);\nexport const bgYellowBright = createAnsiColor(103, 49);\nexport const bgBlueBright = createAnsiColor(104, 49);\nexport const bgMagentaBright = createAnsiColor(105, 49);\nexport const bgCyanBright = createAnsiColor(106, 49);\nexport const bgWhiteBright = createAnsiColor(107, 49);\n"],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+ import "../theme-EERPMtQU.mjs";
2
+ import "../standard-schema-D1sStgzy.mjs";
3
+ import "../index-C6iJZTo3.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-OUlP1L9o.mjs";
5
+ export { ActionFn, Builder, Command, CommandAlias, ConvokerError, ErrorFn, HelpAskedError, MiddlewareFn, MissingRequiredArgumentError, MissingRequiredOptionError, ParseResult, TooManyArgumentsError, UnknownOptionError };
@@ -0,0 +1,9 @@
1
+ import "../color-s-N9yh90.mjs";
2
+ import "../theme-Chg3mOhZ.mjs";
3
+ import "../standard-schema-WhGEzW0C.mjs";
4
+ import "../raw-DVT5lw11.mjs";
5
+ import "../prompt-OXGrAkDf.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-C9QIG--8.mjs";
7
+ import "../input-li13L1uf.mjs";
8
+
9
+ export { Command, ConvokerError, HelpAskedError, MissingRequiredArgumentError, MissingRequiredOptionError, TooManyArgumentsError, UnknownOptionError };
@@ -1,195 +1,232 @@
1
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";
2
+ import { C as cyan, E as gray, b as bold } from "./color-s-N9yh90.mjs";
3
+ import { r as merge, t as DEFAULT_THEME } from "./theme-Chg3mOhZ.mjs";
4
+ import { c as setTheme } from "./prompt-OXGrAkDf.mjs";
5
+ import { i as convert, n as Positional, t as Option } from "./input-li13L1uf.mjs";
6
+ import process from "node:process";
7
7
 
8
- //#region src/log.ts
8
+ //#region src/log/error.ts
9
+ /**
10
+ * Error for when logs fail to write to stdout/stderr.
11
+ */
12
+ var WriteError = class extends Error {
13
+ /**
14
+ * Creates a new error for stream writes.
15
+ * @param streamName The name of the stream.
16
+ */
17
+ constructor(streamName) {
18
+ super(`Could not write to \`${streamName}\`.`);
19
+ }
20
+ };
21
+
22
+ //#endregion
23
+ //#region src/log/index.ts
9
24
  var log_exports = /* @__PURE__ */ __export({
25
+ DEFAULT_CONFIG: () => DEFAULT_CONFIG,
26
+ WriteError: () => WriteError,
10
27
  error: () => error,
11
28
  fatal: () => fatal,
12
29
  info: () => info,
13
30
  setConfig: () => setConfig,
14
31
  setTheme: () => setTheme$1,
15
- setup: () => setup,
16
32
  trace: () => trace,
17
33
  warn: () => warn
18
34
  });
35
+ let th = DEFAULT_THEME;
19
36
  /**
20
- * Gets the default stdout, in a cross-runtime way.
21
- * @returns The default stdout.
37
+ * Sets the theme for logs.
38
+ * @param theme The theme to set.
22
39
  */
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
- } });
40
+ function setTheme$1(theme) {
41
+ th = theme;
33
42
  }
34
43
  /**
35
- * Gets the default stderr, in a cross-runtime way.
36
- * @returns The default stderr.
44
+ * Default log configuration.
37
45
  */
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
- } });
46
+ const DEFAULT_CONFIG = {
47
+ format: "text",
48
+ stderr: process.stderr,
49
+ stdout: process.stdout,
50
+ jsonSpace: 2
51
+ };
52
+ let config = DEFAULT_CONFIG;
53
+ /**
54
+ * Sets log configuration.
55
+ * @param cfg The configuration, optionally including a theme.
56
+ */
57
+ function setConfig({ theme,...cfg }) {
58
+ config = merge(DEFAULT_CONFIG, cfg);
59
+ th = theme ?? th;
48
60
  }
49
61
  /**
50
- * Gets the default stdin, in a cross-runtime way.
51
- * @returns The default stdin.
62
+ * Prints messages.
63
+ * @param msgs The messages to print.
52
64
  */
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
- } });
65
+ function trace(...msgs) {
66
+ const str = format(msgs, "TRACE");
67
+ if (!config.stdout.write(str)) throw new WriteError("stdout");
68
+ }
69
+ /**
70
+ * Prints messages.
71
+ * @param msgs The messages to print.
72
+ */
73
+ function info(...msgs) {
74
+ const str = format(msgs, "INFO");
75
+ if (!config.stdout.write(str)) throw new WriteError("stdout");
63
76
  }
64
- let theme = DEFAULT_THEME;
65
- let config = void 0;
66
77
  /**
67
- * Sets a new theme.
68
- * @param t The theme.
78
+ * Prints warning messages.
79
+ * @param msgs The messages to print.
69
80
  */
70
- function setTheme$1(t) {
71
- theme = t;
81
+ function warn(...msgs) {
82
+ const str = format(msgs, "WARN");
83
+ if (!config.stderr.write(th.warning(str))) throw new WriteError("stderr");
72
84
  }
73
85
  /**
74
- * Sets new configuration.
75
- * @param c The config.
86
+ * Prints error messages.
87
+ * @param msgs The messages to print.
76
88
  */
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);
89
+ function error(...msgs) {
90
+ const str = format(msgs, "ERROR");
91
+ if (!config.stderr.write(str)) throw new WriteError("stderr");
84
92
  }
85
93
  /**
86
- * Sets default configuration.
94
+ * Prints messages and exits with code -1.
95
+ * @param msgs The messages to print.
87
96
  */
88
- async function setup() {
89
- await setConfig({});
97
+ function fatal(...msgs) {
98
+ const str = format(msgs, "FATAL");
99
+ if (!config.stderr.write(str)) throw new WriteError("stderr");
100
+ process.exit(-1);
90
101
  }
91
102
  /**
92
- * Formats a message to the correct format.
93
- * @param level The level of mesage.
103
+ * Formats a list of messages into a single string.
94
104
  * @param msgs The messages to format.
95
- * @returns The formatted message.
105
+ * @param level The log level.
106
+ * @returns A formatted message.
96
107
  */
97
- function formatMessages(level, ...msgs) {
108
+ function format(msgs, level) {
98
109
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
99
- const msg = msgs.map((m) => typeof m === "string" ? m : JSON.stringify(m, null, 2)).join(" ");
110
+ const msg = msgs.map((m) => typeof m === "string" ? m : JSON.stringify(m, null, config.jsonSpace)).join(" ");
100
111
  switch (config.format) {
101
- case "json": return JSON.stringify({
112
+ case "json": return colorize(JSON.stringify({
102
113
  timestamp,
103
114
  level,
104
115
  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`;
116
+ }) + "\n", level);
115
117
  case "text":
116
- default: return `[${timestamp}] [${level.toUpperCase()}] ${msg}\n`;
118
+ default: return colorize(`[${timestamp}] [${th.symbols[level] ?? level}] ${msg}\n`, level);
117
119
  }
118
120
  }
119
121
  /**
120
- * Colorizes text.
122
+ * Wraps a string in ANSI codes, based on a log level.
123
+ * @param str The string to color.
121
124
  * @param level The log level.
122
- * @param text The text to colorize.
123
- * @returns The colorized text.
125
+ * @returns An ANSI-wrapped string.
124
126
  */
125
- function colorize(level, text) {
127
+ function colorize(str, level) {
126
128
  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;
129
+ case "TRACE": return th.secondary(str);
130
+ case "WARN": return th.warning(str);
131
+ case "ERROR": return th.error(str);
132
+ case "FATAL": return th.styles?.bold ? th.styles.bold(th.error(str)) : th.error(str);
133
+ case "INFO":
134
+ default: return th.info?.(str) ?? str;
133
135
  }
134
136
  }
137
+
138
+ //#endregion
139
+ //#region src/command/error.ts
135
140
  /**
136
- * Writes to a stream.
137
- * @param stream The stream to write to.
138
- * @param msg The message to write.
141
+ * A Convoker-related error. These are usually handled by default.
139
142
  */
140
- async function writeToStream(stream, msg) {
141
- const writer = stream.getWriter();
142
- try {
143
- await writer.write(msg);
144
- } finally {
145
- writer.releaseLock();
143
+ var ConvokerError = class extends Error {
144
+ /**
145
+ * Creates a new Convoker error.
146
+ * @param message The message.
147
+ * @param command The command.
148
+ */
149
+ constructor(message, command) {
150
+ super(message);
151
+ this.command = command;
146
152
  }
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
- }
153
+ /**
154
+ * Prints the error's message.
155
+ */
156
+ print() {
157
+ console.error(this.message);
158
+ }
159
+ };
156
160
  /**
157
- * Prints information.
158
- * @param msgs The messages to write.
161
+ * When the user asks for help.
159
162
  */
160
- async function info(...msgs) {
161
- const colored = colorize("info", formatMessages("info", ...msgs));
162
- await writeToStream(config.stdout, colored);
163
- }
163
+ var HelpAskedError = class extends ConvokerError {
164
+ /**
165
+ * Creates a new help asked error.
166
+ * @param command The command.
167
+ */
168
+ constructor(command) {
169
+ super("user asked for help!", command);
170
+ }
171
+ };
164
172
  /**
165
- * Prints warnings.
166
- * @param msgs The messages to write.
173
+ * When you pass too many arguments.
167
174
  */
168
- async function warn(...msgs) {
169
- const colored = colorize("warn", formatMessages("warn", ...msgs));
170
- await writeToStream(config.stdout, colored);
171
- }
175
+ var TooManyArgumentsError = class extends ConvokerError {
176
+ /**
177
+ * Creates a new too many arguments error.
178
+ * @param command The command.
179
+ */
180
+ constructor(command) {
181
+ super("too many arguments!", command);
182
+ }
183
+ };
172
184
  /**
173
- * Prints errors.
174
- * @param msgs The messages to write.
185
+ * When you pass an unknown option, when unknown options aren't allowed.
175
186
  */
176
- async function error(...msgs) {
177
- const colored = colorize("error", formatMessages("error", ...msgs));
178
- await writeToStream(config.stderr, colored);
179
- }
187
+ var UnknownOptionError = class extends ConvokerError {
188
+ /**
189
+ * Creates a new unknown option error.
190
+ * @param command The command.
191
+ * @param key The key.
192
+ */
193
+ constructor(command, key) {
194
+ super(`unknown option: ${key}!`, command);
195
+ this.key = key;
196
+ }
197
+ };
180
198
  /**
181
- * Prints errors and exits.
182
- * @param msgs The messages to write.
199
+ * When a required option is missing.
183
200
  */
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
- }
201
+ var MissingRequiredOptionError = class extends ConvokerError {
202
+ /**
203
+ * Creates a new missing required option error.
204
+ * @param command The command.
205
+ * @param key The key.
206
+ * @param entry The entry.
207
+ */
208
+ constructor(command, key, entry) {
209
+ super(`missing required option: ${key}!`, command);
210
+ this.key = key;
211
+ this.entry = entry;
212
+ }
213
+ };
214
+ var MissingRequiredArgumentError = class extends ConvokerError {
215
+ /**
216
+ * Creates a new missing required argument error.
217
+ * @param command The command.
218
+ * @param key The key.
219
+ * @param entry The entry.
220
+ */
221
+ constructor(command, key, entry) {
222
+ super(`missing required positional argument: ${key}!`, command);
223
+ this.key = key;
224
+ this.entry = entry;
225
+ }
226
+ };
190
227
 
191
228
  //#endregion
192
- //#region src/command.ts
229
+ //#region src/command/index.ts
193
230
  /**
194
231
  * A command.
195
232
  */
@@ -218,7 +255,7 @@ var Command = class Command {
218
255
  * @returns this
219
256
  */
220
257
  alias(...aliases) {
221
- this.$names.concat(aliases);
258
+ this.$names.push(...aliases);
222
259
  this.$parent?.add(this);
223
260
  return this;
224
261
  }
@@ -277,19 +314,21 @@ var Command = class Command {
277
314
  return this;
278
315
  }
279
316
  /**
280
- * Adds an existing command to this.
281
- * @param command The command.
317
+ * Adds existing commands to this.
318
+ * @param commands The commands.
282
319
  * @returns this
283
320
  */
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);
321
+ add(...commands) {
322
+ for (const command of commands) {
323
+ command.$parent = this;
324
+ const alias = {
325
+ command,
326
+ alias: command.$names[0]
327
+ };
328
+ for (let i = 0; i < command.$names.length; i++) {
329
+ if (i === 0) this.$children.set(command.$names[i], { command });
330
+ this.$children.set(command.$names[i], alias);
331
+ }
293
332
  }
294
333
  return this;
295
334
  }
@@ -526,8 +565,7 @@ var Command = class Command {
526
565
  * @returns this
527
566
  */
528
567
  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);
568
+ const result = await this.parse(argv ?? process.argv.slice(2));
531
569
  if (result.isHelp) {
532
570
  result.command.handleErrors([new HelpAskedError(result.command)]);
533
571
  return this;
@@ -580,4 +618,5 @@ function compose(mws) {
580
618
  }
581
619
 
582
620
  //#endregion
583
- export { log_exports as n, Command as t };
621
+ export { MissingRequiredOptionError as a, log_exports as c, MissingRequiredArgumentError as i, ConvokerError as n, TooManyArgumentsError as o, HelpAskedError as r, UnknownOptionError as s, Command as t };
622
+ //# sourceMappingURL=command-C9QIG--8.mjs.map