@gunshi/bone 0.26.3 → 0.27.0-alpha.2
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 +38 -20
- package/package.json +8 -8
package/lib/index.d.ts
CHANGED
|
@@ -48,13 +48,14 @@ interface ArgToken {
|
|
|
48
48
|
* Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
|
|
49
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
53
|
* Parser Options.
|
|
56
54
|
*/
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/resolver-U72Jg6Ll.d.ts
|
|
57
57
|
//#region src/resolver.d.ts
|
|
58
|
+
|
|
58
59
|
/**
|
|
59
60
|
* An argument schema
|
|
60
61
|
* This schema is similar to the schema of the `node:utils`.
|
|
@@ -142,12 +143,11 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
142
143
|
* @internal
|
|
143
144
|
*/
|
|
144
145
|
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] };
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region ../gunshi/src/plugin/context.d.ts
|
|
148
146
|
/**
|
|
149
147
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
150
148
|
*/
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region ../gunshi/src/plugin/context.d.ts
|
|
151
151
|
/**
|
|
152
152
|
* Type helper to create GunshiParams from extracted args and extensions
|
|
153
153
|
* @internal
|
|
@@ -158,6 +158,7 @@ type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string,
|
|
|
158
158
|
};
|
|
159
159
|
/**
|
|
160
160
|
* Gunshi plugin context interface.
|
|
161
|
+
* @since v0.27.0
|
|
161
162
|
*/
|
|
162
163
|
interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
163
164
|
/**
|
|
@@ -193,16 +194,16 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
193
194
|
*/
|
|
194
195
|
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<ExtractedParams<G, L>>>) => Awaitable<void | string>) => (ctx: Readonly<CommandContext<ExtractedParams<G, L>>>) => Awaitable<void | string>): void;
|
|
195
196
|
}
|
|
196
|
-
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region ../gunshi/src/plugin/core.d.ts
|
|
199
197
|
/**
|
|
200
198
|
* Factory function for creating a plugin context.
|
|
201
199
|
* @param decorators - A {@link Decorators} instance.
|
|
202
200
|
* @returns A new {@link PluginContext} instance.
|
|
203
201
|
*/
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region ../gunshi/src/plugin/core.d.ts
|
|
204
204
|
/**
|
|
205
205
|
* Plugin dependency definition
|
|
206
|
+
* @since v0.27.0
|
|
206
207
|
*/
|
|
207
208
|
interface PluginDependency {
|
|
208
209
|
/**
|
|
@@ -216,17 +217,20 @@ interface PluginDependency {
|
|
|
216
217
|
optional?: boolean;
|
|
217
218
|
}
|
|
218
219
|
/**
|
|
219
|
-
*
|
|
220
|
+
* Plugin function type
|
|
221
|
+
* @since v0.27.0
|
|
220
222
|
*/
|
|
221
223
|
type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<PluginContext<G>>) => Awaitable<void>;
|
|
222
224
|
/**
|
|
223
225
|
* Plugin extension for CommandContext
|
|
226
|
+
* @since v0.27.0
|
|
224
227
|
*/
|
|
225
228
|
|
|
226
229
|
/**
|
|
227
230
|
* Gunshi plugin, which is a function that receives a PluginContext.
|
|
228
231
|
* @param ctx - A {@link PluginContext}.
|
|
229
232
|
* @returns An {@link Awaitable} that resolves when the plugin is loaded.
|
|
233
|
+
* @since v0.27.0
|
|
230
234
|
*/
|
|
231
235
|
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
232
236
|
id: string;
|
|
@@ -234,21 +238,22 @@ type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensio
|
|
|
234
238
|
dependencies?: (PluginDependency | string)[];
|
|
235
239
|
extension?: CommandContextExtension<E>;
|
|
236
240
|
};
|
|
237
|
-
|
|
238
|
-
//#endregion
|
|
239
|
-
//#region ../gunshi/src/types.d.ts
|
|
240
241
|
/**
|
|
241
242
|
* Plugin return type with extension
|
|
242
243
|
* @internal
|
|
243
244
|
*/
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region ../gunshi/src/types.d.ts
|
|
244
247
|
type Awaitable<T> = T | Promise<T>;
|
|
245
248
|
/**
|
|
246
249
|
* Extend command context type. This type is used to extend the command context with additional properties at {@link CommandContext.extensions}.
|
|
250
|
+
* @since v0.27.0
|
|
247
251
|
*/
|
|
248
252
|
type ExtendContext = Record<string, unknown>;
|
|
249
253
|
/**
|
|
250
254
|
* Gunshi unified parameter type.
|
|
251
255
|
* This type combines both argument definitions and command context extensions.
|
|
256
|
+
* @since v0.27.0
|
|
252
257
|
*/
|
|
253
258
|
interface GunshiParams<P extends {
|
|
254
259
|
args?: Args;
|
|
@@ -272,11 +277,13 @@ interface GunshiParams<P extends {
|
|
|
272
277
|
}
|
|
273
278
|
/**
|
|
274
279
|
* Default Gunshi parameters
|
|
280
|
+
* @since v0.27.0
|
|
275
281
|
*/
|
|
276
282
|
type DefaultGunshiParams = GunshiParams;
|
|
277
283
|
/**
|
|
278
284
|
* Generic constraint for command-related types.
|
|
279
285
|
* This type constraint allows both GunshiParams and objects with extensions.
|
|
286
|
+
* @since v0.27.0
|
|
280
287
|
*/
|
|
281
288
|
type GunshiParamsConstraint = GunshiParams<any> | {
|
|
282
289
|
extensions: ExtendContext;
|
|
@@ -378,16 +385,19 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
378
385
|
/**
|
|
379
386
|
* Hook that runs before any command execution
|
|
380
387
|
* @see {@link CliOptions.onBeforeCommand}
|
|
388
|
+
* @since v0.27.0
|
|
381
389
|
*/
|
|
382
390
|
onBeforeCommand: ((ctx: Readonly<CommandContext<G>>) => Awaitable<void>) | undefined;
|
|
383
391
|
/**
|
|
384
392
|
* Hook that runs after successful command execution
|
|
385
393
|
* @see {@link CliOptions.onAfterCommand}
|
|
394
|
+
* @since v0.27.0
|
|
386
395
|
*/
|
|
387
|
-
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string |
|
|
396
|
+
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>) | undefined;
|
|
388
397
|
/**
|
|
389
398
|
* Hook that runs when a command throws an error
|
|
390
399
|
* @see {@link CliOptions.onErrorCommand}
|
|
400
|
+
* @since v0.27.0
|
|
391
401
|
*/
|
|
392
402
|
onErrorCommand: ((ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>) | undefined;
|
|
393
403
|
}
|
|
@@ -450,23 +460,27 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
450
460
|
renderValidationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
|
|
451
461
|
/**
|
|
452
462
|
* User plugins.
|
|
463
|
+
* @since v0.27.0
|
|
453
464
|
*/
|
|
454
465
|
plugins?: Plugin[];
|
|
455
466
|
/**
|
|
456
467
|
* Hook that runs before any command execution
|
|
457
468
|
* @param ctx - The command context
|
|
469
|
+
* @since v0.27.0
|
|
458
470
|
*/
|
|
459
471
|
onBeforeCommand?: (ctx: Readonly<CommandContext<G>>) => Awaitable<void>;
|
|
460
472
|
/**
|
|
461
473
|
* Hook that runs after successful command execution
|
|
462
474
|
* @param ctx - The command context
|
|
463
475
|
* @param result - The command execution result
|
|
476
|
+
* @since v0.27.0
|
|
464
477
|
*/
|
|
465
|
-
onAfterCommand?: (ctx: Readonly<CommandContext<G>>, result: string |
|
|
478
|
+
onAfterCommand?: (ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>;
|
|
466
479
|
/**
|
|
467
480
|
* Hook that runs when a command throws an error
|
|
468
481
|
* @param ctx - The command context
|
|
469
482
|
* @param error - The error thrown during execution
|
|
483
|
+
* @since v0.27.0
|
|
470
484
|
*/
|
|
471
485
|
onErrorCommand?: (ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>;
|
|
472
486
|
}
|
|
@@ -545,7 +559,8 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
545
559
|
*/
|
|
546
560
|
log: (message?: any, ...optionalParams: any[]) => void;
|
|
547
561
|
/**
|
|
548
|
-
*
|
|
562
|
+
* Command context extensions.
|
|
563
|
+
* @since v0.27.0
|
|
549
564
|
*/
|
|
550
565
|
extensions: keyof ExtractExtensions<G> extends never ? undefined : ExtractExtensions<G>;
|
|
551
566
|
/**
|
|
@@ -556,10 +571,12 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
556
571
|
}
|
|
557
572
|
/**
|
|
558
573
|
* CommandContextCore type (base type without extensions)
|
|
574
|
+
* @since v0.27.0
|
|
559
575
|
*/
|
|
560
576
|
type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams> = Readonly<CommandContext<G>>;
|
|
561
577
|
/**
|
|
562
578
|
* Command context extension
|
|
579
|
+
* @since v0.27.0
|
|
563
580
|
*/
|
|
564
581
|
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
565
582
|
readonly key: symbol;
|
|
@@ -629,7 +646,7 @@ type CommandExamplesFetcher<G extends GunshiParamsConstraint = DefaultGunshiPara
|
|
|
629
646
|
* @param ctx A {@link CommandContext | command context}
|
|
630
647
|
* @returns void or string (for CLI output)
|
|
631
648
|
*/
|
|
632
|
-
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<
|
|
649
|
+
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>;
|
|
633
650
|
/**
|
|
634
651
|
* Command loader.
|
|
635
652
|
* A function that returns a command or command runner.
|
|
@@ -642,14 +659,16 @@ type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = ()
|
|
|
642
659
|
* A function that wraps a command runner to add or modify its behavior.
|
|
643
660
|
* @param baseRunner The base command runner to decorate
|
|
644
661
|
* @returns The decorated command runner
|
|
662
|
+
* @since v0.27.0
|
|
645
663
|
*/
|
|
646
|
-
type CommandDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRunner: (ctx: Readonly<CommandContext<G>>) => Awaitable<
|
|
664
|
+
type CommandDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRunner: (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>) => (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>;
|
|
647
665
|
/**
|
|
648
666
|
* Renderer decorator type.
|
|
649
667
|
* A function that wraps a base renderer to add or modify its behavior.
|
|
650
668
|
* @param baseRenderer The base renderer function to decorate
|
|
651
669
|
* @param ctx The command context
|
|
652
670
|
* @returns The decorated result
|
|
671
|
+
* @since v0.27.0
|
|
653
672
|
*/
|
|
654
673
|
type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>) => Promise<T>, ctx: Readonly<CommandContext<G>>) => Promise<T>;
|
|
655
674
|
/**
|
|
@@ -659,9 +678,9 @@ type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams
|
|
|
659
678
|
* @param ctx The command context
|
|
660
679
|
* @param error The aggregate error containing validation errors
|
|
661
680
|
* @returns The decorated result
|
|
681
|
+
* @since v0.27.0
|
|
662
682
|
*/
|
|
663
683
|
type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>;
|
|
664
|
-
|
|
665
684
|
//#endregion
|
|
666
685
|
//#region ../gunshi/src/cli/bone.d.ts
|
|
667
686
|
/**
|
|
@@ -694,6 +713,5 @@ declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiPa
|
|
|
694
713
|
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
695
714
|
*/
|
|
696
715
|
declare function cli<G extends GunshiParams = DefaultGunshiParams>(argv: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
697
|
-
|
|
698
716
|
//#endregion
|
|
699
717
|
export { ArgSchema, ArgToken, ArgValues, Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, RendererDecorator, ValidationErrorsDecorator, cli };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/bone",
|
|
3
3
|
"description": "gunshi minimum",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0-alpha.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"deno": "^2.
|
|
55
|
-
"jsr": "^0.13.
|
|
54
|
+
"deno": "^2.4.0",
|
|
55
|
+
"jsr": "^0.13.5",
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
57
|
"publint": "^0.3.12",
|
|
58
|
-
"tsdown": "^0.12.
|
|
59
|
-
"@gunshi/definition": "0.
|
|
60
|
-
"@gunshi/plugin-
|
|
61
|
-
"@gunshi/plugin-
|
|
62
|
-
"gunshi": "0.
|
|
58
|
+
"tsdown": "^0.12.9",
|
|
59
|
+
"@gunshi/definition": "0.27.0-alpha.2",
|
|
60
|
+
"@gunshi/plugin-global": "0.27.0-alpha.2",
|
|
61
|
+
"@gunshi/plugin-renderer": "0.27.0-alpha.2",
|
|
62
|
+
"gunshi": "0.27.0-alpha.2"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsdown",
|