@gunshi/definition 0.26.3 → 0.27.0-alpha.10
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/lib/index.d.ts +205 -102
- package/lib/index.js +2 -0
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
|
@@ -1,161 +1,198 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.22.0/node_modules/args-tokens/lib/parser-Cbxholql.d.ts
|
|
2
2
|
//#region src/parser.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Entry point of argument parser.
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* forked from `nodejs/node` (`pkgjs/parseargs`)
|
|
9
|
-
* repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
|
|
10
|
-
* code url: https://github.com/nodejs/node/blob/main/lib/internal/util/parse_args/parse_args.js
|
|
11
|
-
*
|
|
12
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
13
|
-
* @license MIT
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Argument token Kind.
|
|
17
|
-
* - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
|
|
18
|
-
* - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
|
19
|
-
* - `positional`: positional token
|
|
20
|
-
*/
|
|
21
|
-
type ArgTokenKind =
|
|
22
|
-
/**
|
|
23
|
-
* Argument token.
|
|
24
|
-
*/
|
|
4
|
+
* Entry point of argument parser.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* forked from `nodejs/node` (`pkgjs/parseargs`)
|
|
9
|
+
* repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
|
|
10
|
+
* code url: https://github.com/nodejs/node/blob/main/lib/internal/util/parse_args/parse_args.js
|
|
11
|
+
*
|
|
12
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
13
|
+
* @license MIT
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Argument token Kind.
|
|
17
|
+
* - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
|
|
18
|
+
* - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
|
19
|
+
* - `positional`: positional token
|
|
20
|
+
*/
|
|
21
|
+
type ArgTokenKind = 'option' | 'option-terminator' | 'positional';
|
|
22
|
+
/**
|
|
23
|
+
* Argument token.
|
|
24
|
+
*/
|
|
25
25
|
interface ArgToken {
|
|
26
26
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
* Argument token kind.
|
|
28
|
+
*/
|
|
29
29
|
kind: ArgTokenKind;
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
* Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1.
|
|
32
|
+
*/
|
|
33
33
|
index: number;
|
|
34
34
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
* Option name, e.g. `--foo` => `foo`, `-x` => `x`.
|
|
36
|
+
*/
|
|
37
37
|
name?: string;
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
* Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`.
|
|
40
|
+
*/
|
|
41
41
|
rawName?: string;
|
|
42
42
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
* Option value, e.g. `--foo=bar` => `bar`, `-x=bar` => `bar`.
|
|
44
|
+
* If the `allowCompatible` option is `true`, short option value will be same as Node.js `parseArgs` behavior.
|
|
45
|
+
*/
|
|
46
46
|
value?: string;
|
|
47
47
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
* Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
|
|
49
|
+
*/
|
|
50
50
|
inlineValue?: boolean;
|
|
51
|
-
}
|
|
52
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/resolver-U72Jg6Ll.d.ts
|
|
53
|
-
|
|
51
|
+
}
|
|
54
52
|
/**
|
|
55
|
-
* Parser Options.
|
|
56
|
-
*/
|
|
53
|
+
* Parser Options.
|
|
54
|
+
*/
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.22.0/node_modules/args-tokens/lib/resolver-BoS-UnqX.d.ts
|
|
57
57
|
//#region src/resolver.d.ts
|
|
58
|
+
|
|
58
59
|
/**
|
|
59
|
-
* An argument schema
|
|
60
|
-
* This schema is similar to the schema of the `node:utils`.
|
|
61
|
-
* difference is that:
|
|
62
|
-
* - `required` property and `description` property are added
|
|
63
|
-
* - `type` is not only 'string' and 'boolean', but also 'number', 'enum', 'positional', 'custom' too.
|
|
64
|
-
* - `default` property type, not support multiple types
|
|
65
|
-
*/
|
|
60
|
+
* An argument schema
|
|
61
|
+
* This schema is similar to the schema of the `node:utils`.
|
|
62
|
+
* difference is that:
|
|
63
|
+
* - `required` property and `description` property are added
|
|
64
|
+
* - `type` is not only 'string' and 'boolean', but also 'number', 'enum', 'positional', 'custom' too.
|
|
65
|
+
* - `default` property type, not support multiple types
|
|
66
|
+
*/
|
|
66
67
|
interface ArgSchema {
|
|
67
68
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
type:
|
|
69
|
+
* Type of argument.
|
|
70
|
+
*/
|
|
71
|
+
type: 'string' | 'boolean' | 'number' | 'enum' | 'positional' | 'custom';
|
|
71
72
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
* A single character alias for the argument.
|
|
74
|
+
*/
|
|
74
75
|
short?: string;
|
|
75
76
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
* A description of the argument.
|
|
78
|
+
*/
|
|
78
79
|
description?: string;
|
|
79
80
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
* Whether the argument is required or not.
|
|
82
|
+
*/
|
|
82
83
|
required?: true;
|
|
83
84
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
* Whether the argument allow multiple values or not.
|
|
86
|
+
*/
|
|
86
87
|
multiple?: true;
|
|
87
88
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
* Whether the negatable option for `boolean` type
|
|
90
|
+
*/
|
|
90
91
|
negatable?: boolean;
|
|
91
92
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
* The allowed values of the argument, and string only. This property is only used when the type is 'enum'.
|
|
94
|
+
*/
|
|
94
95
|
choices?: string[] | readonly string[];
|
|
95
96
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
* The default value of the argument.
|
|
98
|
+
* if the type is 'enum', the default value must be one of the allowed values.
|
|
99
|
+
*/
|
|
99
100
|
default?: string | boolean | number;
|
|
100
101
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
* Whether to convert the argument name to kebab-case.
|
|
103
|
+
*/
|
|
103
104
|
toKebab?: true;
|
|
104
105
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
+
* A function to parse the value of the argument. if the type is 'custom', this function is required.
|
|
107
|
+
* If argument value will be invalid, this function have to throw an error.
|
|
108
|
+
* @param value
|
|
109
|
+
* @returns Parsed value
|
|
110
|
+
* @throws An Error, If the value is invalid. Error type should be `Error` or extends it
|
|
111
|
+
*/
|
|
112
112
|
parse?: (value: string) => any;
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
* An object that contains {@link ArgSchema | argument schema}.
|
|
116
|
-
*/
|
|
115
|
+
* An object that contains {@link ArgSchema | argument schema}.
|
|
116
|
+
*/
|
|
117
117
|
interface Args {
|
|
118
118
|
[option: string]: ArgSchema;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
* An object that contains the values of the arguments.
|
|
122
|
-
*/
|
|
121
|
+
* An object that contains the values of the arguments.
|
|
122
|
+
*/
|
|
123
123
|
type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
|
|
124
124
|
[option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
|
|
125
125
|
};
|
|
126
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
126
|
type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
|
|
128
127
|
/**
|
|
129
|
-
* @internal
|
|
130
|
-
*/
|
|
131
|
-
type ExtractOptionValue<A extends ArgSchema> = A[
|
|
132
|
-
type ResolveOptionValue<A extends ArgSchema, T> = A[
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
type ExtractOptionValue<A extends ArgSchema> = A['type'] extends 'string' ? ResolveOptionValue<A, string> : A['type'] extends 'boolean' ? ResolveOptionValue<A, boolean> : A['type'] extends 'number' ? ResolveOptionValue<A, number> : A['type'] extends 'positional' ? ResolveOptionValue<A, string> : A['type'] extends 'enum' ? A['choices'] extends string[] | readonly string[] ? ResolveOptionValue<A, A['choices'][number]> : never : A['type'] extends 'custom' ? IsFunction<A['parse']> extends true ? ResolveOptionValue<A, ReturnType<NonNullable<A['parse']>>> : never : ResolveOptionValue<A, string | boolean | number>;
|
|
131
|
+
type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T[] : T;
|
|
133
132
|
/**
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V,
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends infer P ? { [K in keyof P]: P[K] } : never;
|
|
137
136
|
/**
|
|
138
|
-
* @internal
|
|
139
|
-
*/
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
140
139
|
type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends keyof ArgSchema> = { [Arg in keyof A as A[Arg][K] extends {} ? Arg : never]: V[Arg] };
|
|
141
140
|
/**
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg][
|
|
141
|
+
* @internal
|
|
142
|
+
*/
|
|
143
|
+
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]['type'] extends 'positional' ? Arg : never]: V[Arg] };
|
|
144
|
+
/**
|
|
145
|
+
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
146
|
+
*/
|
|
145
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Tracks which arguments were explicitly provided by the user.
|
|
150
|
+
*
|
|
151
|
+
* Each property indicates whether the corresponding argument was explicitly
|
|
152
|
+
* provided (true) or is using a default value or not provided (false).
|
|
153
|
+
*/
|
|
154
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
155
|
+
/**
|
|
156
|
+
* Resolve command line arguments.
|
|
157
|
+
* @param args - An arguments that contains {@link ArgSchema | arguments schema}.
|
|
158
|
+
* @param tokens - An array of {@link ArgToken | tokens}.
|
|
159
|
+
* @param resolveArgs - An arguments that contains {@link ResolveArgs | resolve arguments}.
|
|
160
|
+
* @returns An object that contains the values of the arguments, positional arguments, rest arguments, {@link AggregateError | validation errors}, and explicit provision status.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // passed tokens: --port 3000
|
|
165
|
+
*
|
|
166
|
+
* const { values, explicit } = resolveArgs({
|
|
167
|
+
* port: {
|
|
168
|
+
* type: 'number',
|
|
169
|
+
* default: 8080
|
|
170
|
+
* },
|
|
171
|
+
* host: {
|
|
172
|
+
* type: 'string',
|
|
173
|
+
* default: 'localhost'
|
|
174
|
+
* }
|
|
175
|
+
* }, parsedTokens)
|
|
176
|
+
*
|
|
177
|
+
* values.port // 3000
|
|
178
|
+
* values.host // 'localhost'
|
|
179
|
+
*
|
|
180
|
+
* explicit.port // true (explicitly provided)
|
|
181
|
+
* explicit.host // false (not provided, fallback to default)
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
146
184
|
//#endregion
|
|
147
185
|
//#region ../gunshi/src/types.d.ts
|
|
148
|
-
/**
|
|
149
|
-
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
150
|
-
*/
|
|
151
186
|
type Awaitable<T> = T | Promise<T>;
|
|
152
187
|
/**
|
|
153
188
|
* Extend command context type. This type is used to extend the command context with additional properties at {@link CommandContext.extensions}.
|
|
189
|
+
* @since v0.27.0
|
|
154
190
|
*/
|
|
155
191
|
type ExtendContext = Record<string, unknown>;
|
|
156
192
|
/**
|
|
157
193
|
* Gunshi unified parameter type.
|
|
158
194
|
* This type combines both argument definitions and command context extensions.
|
|
195
|
+
* @since v0.27.0
|
|
159
196
|
*/
|
|
160
197
|
interface GunshiParams<P extends {
|
|
161
198
|
args?: Args;
|
|
@@ -179,11 +216,13 @@ interface GunshiParams<P extends {
|
|
|
179
216
|
}
|
|
180
217
|
/**
|
|
181
218
|
* Default Gunshi parameters
|
|
219
|
+
* @since v0.27.0
|
|
182
220
|
*/
|
|
183
221
|
type DefaultGunshiParams = GunshiParams;
|
|
184
222
|
/**
|
|
185
223
|
* Generic constraint for command-related types.
|
|
186
224
|
* This type constraint allows both GunshiParams and objects with extensions.
|
|
225
|
+
* @since v0.27.0
|
|
187
226
|
*/
|
|
188
227
|
type GunshiParamsConstraint = GunshiParams<any> | {
|
|
189
228
|
extensions: ExtendContext;
|
|
@@ -193,6 +232,11 @@ type GunshiParamsConstraint = GunshiParams<any> | {
|
|
|
193
232
|
* @internal
|
|
194
233
|
*/
|
|
195
234
|
type ExtractArgs<G> = G extends GunshiParams<any> ? G['args'] : Args;
|
|
235
|
+
/**
|
|
236
|
+
* Type helper to extract explicitly provided argument flags from G
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
type ExtractArgExplicitlyProvided<G> = ArgExplicitlyProvided<ExtractArgs<G>>;
|
|
196
240
|
/**
|
|
197
241
|
* Type helper to extract extensions from G
|
|
198
242
|
* @internal
|
|
@@ -280,16 +324,19 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
280
324
|
/**
|
|
281
325
|
* Hook that runs before any command execution
|
|
282
326
|
* @see {@link CliOptions.onBeforeCommand}
|
|
327
|
+
* @since v0.27.0
|
|
283
328
|
*/
|
|
284
329
|
onBeforeCommand: ((ctx: Readonly<CommandContext<G>>) => Awaitable<void>) | undefined;
|
|
285
330
|
/**
|
|
286
331
|
* Hook that runs after successful command execution
|
|
287
332
|
* @see {@link CliOptions.onAfterCommand}
|
|
333
|
+
* @since v0.27.0
|
|
288
334
|
*/
|
|
289
|
-
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string |
|
|
335
|
+
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>) | undefined;
|
|
290
336
|
/**
|
|
291
337
|
* Hook that runs when a command throws an error
|
|
292
338
|
* @see {@link CliOptions.onErrorCommand}
|
|
339
|
+
* @since v0.27.0
|
|
293
340
|
*/
|
|
294
341
|
onErrorCommand: ((ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>) | undefined;
|
|
295
342
|
}
|
|
@@ -326,6 +373,15 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
326
373
|
* The command arguments is same {@link Command.args}.
|
|
327
374
|
*/
|
|
328
375
|
args: ExtractArgs<G>;
|
|
376
|
+
/**
|
|
377
|
+
* Whether arguments were explicitly provided by the user.
|
|
378
|
+
*
|
|
379
|
+
* - `true`: The argument was explicitly provided via command line
|
|
380
|
+
* - `false`: The argument was not explicitly provided. This means either:
|
|
381
|
+
* - The value comes from a default value defined in the argument schema
|
|
382
|
+
* - The value is `undefined` (no explicit input and no default value)
|
|
383
|
+
*/
|
|
384
|
+
explicit: ExtractArgExplicitlyProvided<G>;
|
|
329
385
|
/**
|
|
330
386
|
* Command values, that is the values of the command that is executed.
|
|
331
387
|
* Resolve values with `resolveArgs` from command arguments and {@link Command.args}.
|
|
@@ -372,7 +428,8 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
372
428
|
*/
|
|
373
429
|
log: (message?: any, ...optionalParams: any[]) => void;
|
|
374
430
|
/**
|
|
375
|
-
*
|
|
431
|
+
* Command context extensions.
|
|
432
|
+
* @since v0.27.0
|
|
376
433
|
*/
|
|
377
434
|
extensions: keyof ExtractExtensions<G> extends never ? undefined : ExtractExtensions<G>;
|
|
378
435
|
/**
|
|
@@ -383,8 +440,36 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
383
440
|
}
|
|
384
441
|
/**
|
|
385
442
|
* CommandContextCore type (base type without extensions)
|
|
443
|
+
* @since v0.27.0
|
|
386
444
|
*/
|
|
387
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Rendering control options
|
|
448
|
+
* @since v0.27.0
|
|
449
|
+
*/
|
|
450
|
+
interface RenderingOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
451
|
+
/**
|
|
452
|
+
* Header rendering configuration
|
|
453
|
+
* - `null`: Disable rendering
|
|
454
|
+
* - `function`: Use custom renderer
|
|
455
|
+
* - `undefined` (when omitted): Use default renderer
|
|
456
|
+
*/
|
|
457
|
+
header?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
|
|
458
|
+
/**
|
|
459
|
+
* Usage rendering configuration
|
|
460
|
+
* - `null`: Disable rendering
|
|
461
|
+
* - `function`: Use custom renderer
|
|
462
|
+
* - `undefined` (when omitted): Use default renderer
|
|
463
|
+
*/
|
|
464
|
+
usage?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
|
|
465
|
+
/**
|
|
466
|
+
* Validation errors rendering configuration
|
|
467
|
+
* - `null`: Disable rendering
|
|
468
|
+
* - `function`: Use custom renderer
|
|
469
|
+
* - `undefined` (when omitted): Use default renderer
|
|
470
|
+
*/
|
|
471
|
+
validationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
|
|
472
|
+
}
|
|
388
473
|
/**
|
|
389
474
|
* Command interface.
|
|
390
475
|
*/
|
|
@@ -418,6 +503,24 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
418
503
|
* If you will set to `true`, All {@link Command.args} names will be converted to kebab-case.
|
|
419
504
|
*/
|
|
420
505
|
toKebab?: boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Whether this is an internal command.
|
|
508
|
+
* Internal commands are not shown in help usage.
|
|
509
|
+
* @default false
|
|
510
|
+
* @since v0.27.0
|
|
511
|
+
*/
|
|
512
|
+
internal?: boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Whether this command is an entry command.
|
|
515
|
+
* @default undefined
|
|
516
|
+
* @since v0.27.0
|
|
517
|
+
*/
|
|
518
|
+
entry?: boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Rendering control options
|
|
521
|
+
* @since v0.27.0
|
|
522
|
+
*/
|
|
523
|
+
rendering?: RenderingOptions<G>;
|
|
421
524
|
}
|
|
422
525
|
/**
|
|
423
526
|
* Lazy command interface.
|
|
@@ -448,22 +551,23 @@ type CommandExamplesFetcher<G extends GunshiParamsConstraint = DefaultGunshiPara
|
|
|
448
551
|
* @param ctx A {@link CommandContext | command context}
|
|
449
552
|
* @returns void or string (for CLI output)
|
|
450
553
|
*/
|
|
451
|
-
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<
|
|
554
|
+
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>;
|
|
452
555
|
/**
|
|
453
556
|
* Command loader.
|
|
454
557
|
* A function that returns a command or command runner.
|
|
455
558
|
* This is used to lazily load commands.
|
|
456
559
|
* @returns A command or command runner
|
|
457
560
|
*/
|
|
458
|
-
type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = () => Awaitable<Command<G> | CommandRunner<G>>;
|
|
459
|
-
//#region ../gunshi/src/definition.d.ts
|
|
460
|
-
|
|
561
|
+
type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = () => Awaitable<Command<G> | CommandRunner<G>>;
|
|
461
562
|
/**
|
|
462
563
|
* Command decorator.
|
|
463
564
|
* A function that wraps a command runner to add or modify its behavior.
|
|
464
565
|
* @param baseRunner The base command runner to decorate
|
|
465
566
|
* @returns The decorated command runner
|
|
567
|
+
* @since v0.27.0
|
|
466
568
|
*/
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region ../gunshi/src/definition.d.ts
|
|
467
571
|
/**
|
|
468
572
|
* Define a {@link Command | command}
|
|
469
573
|
* @param definition A {@link Command | command} definition
|
|
@@ -560,6 +664,5 @@ declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams>(lo
|
|
|
560
664
|
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
561
665
|
*/
|
|
562
666
|
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams>(loader: CommandLoader<G>, definition: Command<G>): LazyCommand<G>;
|
|
563
|
-
|
|
564
667
|
//#endregion
|
|
565
|
-
export { ArgSchema, ArgValues, Args, Command, CommandLoader, CommandRunner, DefaultGunshiParams, ExtendContext, GunshiParams, LazyCommand, define, lazy };
|
|
668
|
+
export { type ArgSchema, type ArgValues, type Args, type Command, type CommandLoader, type CommandRunner, type DefaultGunshiParams, type ExtendContext, type GunshiParams, type LazyCommand, define, lazy };
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,8 @@ function lazy(loader, definition) {
|
|
|
19
19
|
lazyCommand.description = definition.description;
|
|
20
20
|
lazyCommand.args = definition.args;
|
|
21
21
|
lazyCommand.examples = definition.examples;
|
|
22
|
+
lazyCommand.internal = definition.internal;
|
|
23
|
+
lazyCommand.entry = definition.entry;
|
|
22
24
|
if ("resource" in definition) lazyCommand.resource = definition.resource;
|
|
23
25
|
lazyCommand.toKebab = definition.toKebab;
|
|
24
26
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/definition",
|
|
3
3
|
"description": "utilities for gunshi command definition",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0-alpha.10",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"deno": "^2.
|
|
56
|
-
"jsr": "^0.13.
|
|
55
|
+
"deno": "^2.4.2",
|
|
56
|
+
"jsr": "^0.13.5",
|
|
57
57
|
"jsr-exports-lint": "^0.4.1",
|
|
58
58
|
"publint": "^0.3.12",
|
|
59
|
-
"tsdown": "^0.
|
|
60
|
-
"gunshi": "0.
|
|
59
|
+
"tsdown": "^0.13.0",
|
|
60
|
+
"gunshi": "0.27.0-alpha.10"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|