convoker 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # LunarCLI
1
+ # Convoker
2
2
 
3
3
  A simple, type safe CLI library for TypeScript.
4
4
 
5
5
  ```ts
6
- import { i, Command } from "lunarcli";
6
+ import { i, Command } from "convoker";
7
7
 
8
8
  const program = new Command("calc").description("A basic calculator.");
9
9
 
@@ -9,7 +9,7 @@ class n extends Error {
9
9
  }
10
10
  class o extends Error {
11
11
  /**
12
- * Creates a new LunarCLI error.
12
+ * Creates a new Convoker error.
13
13
  * @param message The message.
14
14
  * @param command The command.
15
15
  */
@@ -75,21 +75,21 @@ class d extends o {
75
75
  }
76
76
  const l = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
77
77
  __proto__: null,
78
+ ConvokerError: o,
78
79
  HelpAskedError: i,
79
80
  InputValidationError: n,
80
- LunarCLIError: o,
81
81
  MissingRequiredArgumentError: d,
82
82
  MissingRequiredOptionError: c,
83
83
  TooManyArgumentsError: a,
84
84
  UnknownOptionError: u
85
85
  }, Symbol.toStringTag, { value: "Module" }));
86
86
  export {
87
+ o as C,
87
88
  i as H,
88
89
  n as I,
89
- o as L,
90
- c as M,
90
+ d as M,
91
91
  a as T,
92
92
  u as U,
93
- d as a,
93
+ c as a,
94
94
  l as e
95
95
  };
@@ -1,6 +1,6 @@
1
1
  import { D as y } from "./color-CiruG_zQ.js";
2
- import { v as p } from "./standard-schema-Dn3nwAxU.js";
3
- import { I as f } from "./error-Cj2qDfOl.js";
2
+ import { v as p } from "./standard-schema-BHKzvwIS.js";
3
+ import { I as f } from "./error-CyKscMUD.js";
4
4
  import { i as $, a as v, b } from "./utils-DdmSEjLc.js";
5
5
  import { r as m, a as g, c as d, b as x, d as D } from "./__vite-browser-external-DQYBmsno.js";
6
6
  let l = y;
@@ -1,33 +1,36 @@
1
- import { v as u } from "./standard-schema-Dn3nwAxU.js";
2
- async function o(r, t) {
3
- if (typeof r == "string")
4
- switch (r) {
5
- case "boolean":
6
- return t === "true";
7
- case "bigint":
8
- return BigInt(t);
9
- case "number":
10
- return parseFloat(t);
11
- case "string":
12
- return t;
13
- }
14
- return u(r, t);
1
+ import { v as o } from "./standard-schema-BHKzvwIS.js";
2
+ async function a(r, t) {
3
+ async function i(e) {
4
+ if (typeof r == "string")
5
+ switch (r) {
6
+ case "boolean":
7
+ return e === "true";
8
+ case "bigint":
9
+ return BigInt(e);
10
+ case "number":
11
+ return parseFloat(e);
12
+ case "string":
13
+ return e;
14
+ }
15
+ return o(r, e);
16
+ }
17
+ return Array.isArray(t) ? await Promise.all(t.map((u) => i(u))) : i(t);
15
18
  }
16
- class i {
19
+ class n {
17
20
  /**
18
21
  * Creates a new option.
19
22
  * @param kind The type of this option.
20
23
  * @param names The names of this option.
21
24
  */
22
- constructor(t, s) {
23
- this.$required = !0, this.$list = !1, this.$kind = t, this.$names = s.map((n) => n.replace(/^-+/, ""));
25
+ constructor(t, i) {
26
+ this.$required = !0, this.$list = !1, this.$kind = t, this.$names = i.map((e) => e.replace(/^-+/, ""));
24
27
  }
25
28
  /**
26
29
  * Makes this option a list.
27
30
  * @returns this
28
31
  */
29
- list() {
30
- return this.$list = !0, this;
32
+ list(t) {
33
+ return this.$list = !0, this.$separator = t ?? this.$separator, this;
31
34
  }
32
35
  /**
33
36
  * Makes this option required.
@@ -60,7 +63,7 @@ class i {
60
63
  return this.$description = t, this;
61
64
  }
62
65
  }
63
- class e {
66
+ class s {
64
67
  /**
65
68
  * Creates a new positional argument.
66
69
  * @param kind The positional argument.
@@ -106,30 +109,30 @@ class e {
106
109
  return this.$description = t, this;
107
110
  }
108
111
  }
109
- function a(r, ...t) {
110
- return new i(r, t);
112
+ function c(r, ...t) {
113
+ return new n(r, t);
111
114
  }
112
115
  function h(r) {
113
- return new e(r);
116
+ return new s(r);
114
117
  }
115
- function c(r) {
116
- return new e(r);
118
+ function l(r) {
119
+ return new s(r);
117
120
  }
118
121
  const d = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
119
122
  __proto__: null,
120
- Option: i,
121
- Positional: e,
122
- argument: c,
123
- convert: o,
124
- option: a,
123
+ Option: n,
124
+ Positional: s,
125
+ argument: l,
126
+ convert: a,
127
+ option: c,
125
128
  positional: h
126
129
  }, Symbol.toStringTag, { value: "Module" }));
127
130
  export {
128
- i as O,
129
- e as P,
130
- c as a,
131
- o as c,
131
+ n as O,
132
+ s as P,
133
+ l as a,
134
+ a as c,
132
135
  d as i,
133
- a as o,
136
+ c as o,
134
137
  h as p
135
138
  };
@@ -1,4 +1,4 @@
1
- import { I as i } from "./error-Cj2qDfOl.js";
1
+ import { I as i } from "./error-CyKscMUD.js";
2
2
  async function o(a, t) {
3
3
  const s = await a["~standard"].validate(t);
4
4
  if (s.issues) {
package/dist/command.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Command action function.
3
3
  */
4
- export declare type ActionFn<T extends Input> = (input: InferInput<T>) => void | Promise<void>;
4
+ export declare type ActionFn<T extends Input> = (input: InferInput<T>) => any | Promise<any>;
5
5
 
6
6
  /**
7
7
  * A basic input type.
@@ -45,6 +45,10 @@ export declare class Command<T extends Input = Input> {
45
45
  * If this command allows unknown options.
46
46
  */
47
47
  $allowUnknownOptions: boolean;
48
+ /**
49
+ * If you should be able to surpass the amount of positional arguments defined in the input.
50
+ */
51
+ $allowSurpassArgLimit: boolean;
48
52
  /**
49
53
  * The input this command takes.
50
54
  */
@@ -53,6 +57,10 @@ export declare class Command<T extends Input = Input> {
53
57
  * The action function of this command.
54
58
  */
55
59
  $fn: ActionFn<T> | undefined;
60
+ /**
61
+ * The middlewares associated with this command.
62
+ */
63
+ $middlewares: MiddlewareFn<T>[];
56
64
  /**
57
65
  * The error handler of this command.
58
66
  */
@@ -88,6 +96,12 @@ export declare class Command<T extends Input = Input> {
88
96
  * @returns this
89
97
  */
90
98
  input<TInput extends Input>(input: TInput): Command<TInput>;
99
+ /**
100
+ * Adds a chain of middlewares.
101
+ * @param fns The middlewares to use.
102
+ * @returns this
103
+ */
104
+ use(...fns: MiddlewareFn<T>[]): this;
91
105
  /**
92
106
  * Sets the action function for this command.
93
107
  * @param fn The action.
@@ -131,6 +145,11 @@ export declare class Command<T extends Input = Input> {
131
145
  */
132
146
  parse(argv: string[]): Promise<ParseResult<T>>;
133
147
  private buildInputMap;
148
+ /**
149
+ * Allows surpassing the amount of arguments specified.
150
+ * @returns this
151
+ */
152
+ allowSurpassArgLimit(): this;
134
153
  /**
135
154
  * Gets the full command path (name including parents).
136
155
  * @returns The full command path.
@@ -170,6 +189,26 @@ export declare interface CommandAlias<T extends Input = Input> {
170
189
  alias?: string;
171
190
  }
172
191
 
192
+ /**
193
+ * A Convoker-related error. These are usually handled by default.
194
+ */
195
+ declare class ConvokerError extends Error {
196
+ /**
197
+ * The command this error happened on.
198
+ */
199
+ command: Command<any>;
200
+ /**
201
+ * Creates a new Convoker error.
202
+ * @param message The message.
203
+ * @param command The command.
204
+ */
205
+ constructor(message: string, command: Command<any>);
206
+ /**
207
+ * Prints the error's message.
208
+ */
209
+ print(): void;
210
+ }
211
+
173
212
  /**
174
213
  * Command error handler.
175
214
  */
@@ -204,24 +243,9 @@ declare interface Input {
204
243
  declare type Kind = BasicKind | StandardSchemaV1<any, any>;
205
244
 
206
245
  /**
207
- * A LunarCLI-related error. These are usually handled by default.
246
+ * Command middleware function.
208
247
  */
209
- declare class LunarCLIError extends Error {
210
- /**
211
- * The command this error happened on.
212
- */
213
- command: Command<any>;
214
- /**
215
- * Creates a new LunarCLI error.
216
- * @param message The message.
217
- * @param command The command.
218
- */
219
- constructor(message: string, command: Command<any>);
220
- /**
221
- * Prints the error's message.
222
- */
223
- print(): void;
224
- }
248
+ export declare type MiddlewareFn<T extends Input = Input> = (input: InferInput<T>, next: () => Promise<any>) => any | Promise<any>;
225
249
 
226
250
  /**
227
251
  * An option.
@@ -251,6 +275,10 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
251
275
  * If this option is a list.
252
276
  */
253
277
  $list: TList;
278
+ /**
279
+ * A separator if this option is a list.
280
+ */
281
+ $separator: string | undefined;
254
282
  /**
255
283
  * Creates a new option.
256
284
  * @param kind The type of this option.
@@ -261,7 +289,7 @@ declare class Option_2<TKind extends Kind, TRequired extends boolean = true, TLi
261
289
  * Makes this option a list.
262
290
  * @returns this
263
291
  */
264
- list(): Option_2<TKind, TRequired, true>;
292
+ list(separator?: string): Option_2<TKind, TRequired, true>;
265
293
  /**
266
294
  * Makes this option required.
267
295
  * @returns this
@@ -301,7 +329,7 @@ export declare interface ParseResult<T extends Input> {
301
329
  /**
302
330
  * Errors collected during parsing.
303
331
  */
304
- errors: LunarCLIError[];
332
+ errors: ConvokerError[];
305
333
  /**
306
334
  * If this should result in displaying the version of the command.
307
335
  */