@gunshi/bone 0.27.0-beta.2 → 0.27.0-beta.4
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 +17 -17
- package/lib/index.js +27 -4
- package/package.json +8 -8
package/lib/index.d.ts
CHANGED
|
@@ -484,8 +484,8 @@ type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
|
|
|
484
484
|
*
|
|
485
485
|
* @internal
|
|
486
486
|
*/
|
|
487
|
-
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>;
|
|
488
|
-
type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T[] : T;
|
|
487
|
+
type ExtractOptionValue<A$1 extends ArgSchema> = A$1['type'] extends 'string' ? ResolveOptionValue<A$1, string> : A$1['type'] extends 'boolean' ? ResolveOptionValue<A$1, boolean> : A$1['type'] extends 'number' ? ResolveOptionValue<A$1, number> : A$1['type'] extends 'positional' ? ResolveOptionValue<A$1, string> : A$1['type'] extends 'enum' ? A$1['choices'] extends string[] | readonly string[] ? ResolveOptionValue<A$1, A$1['choices'][number]> : never : A$1['type'] extends 'custom' ? IsFunction<A$1['parse']> extends true ? ResolveOptionValue<A$1, ReturnType<NonNullable<A$1['parse']>>> : never : ResolveOptionValue<A$1, string | boolean | number>;
|
|
488
|
+
type ResolveOptionValue<A$1 extends ArgSchema, T> = A$1['multiple'] extends true ? T[] : T;
|
|
489
489
|
/**
|
|
490
490
|
* Resolved argument values.
|
|
491
491
|
*
|
|
@@ -494,7 +494,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
|
|
|
494
494
|
*
|
|
495
495
|
* @internal
|
|
496
496
|
*/
|
|
497
|
-
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;
|
|
497
|
+
type ResolveArgValues<A$1 extends Args, V extends Record<keyof A$1, unknown>> = { -readonly [Arg in keyof A$1]?: V[Arg] } & FilterArgs<A$1, V, 'default'> & FilterArgs<A$1, V, 'required'> & FilterPositionalArgs<A$1, V> extends infer P ? { [K in keyof P]: P[K] } : never;
|
|
498
498
|
/**
|
|
499
499
|
* Filters the arguments based on their default values.
|
|
500
500
|
*
|
|
@@ -504,7 +504,7 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
|
|
|
504
504
|
*
|
|
505
505
|
* @internal
|
|
506
506
|
*/
|
|
507
|
-
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] };
|
|
507
|
+
type FilterArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>, K$1 extends keyof ArgSchema> = { [Arg in keyof A$1 as A$1[Arg][K$1] extends {} ? Arg : never]: V[Arg] };
|
|
508
508
|
/**
|
|
509
509
|
* Filters positional arguments from the argument schema.
|
|
510
510
|
*
|
|
@@ -513,7 +513,7 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
513
513
|
*
|
|
514
514
|
* @internal
|
|
515
515
|
*/
|
|
516
|
-
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] };
|
|
516
|
+
type FilterPositionalArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>> = { [Arg in keyof A$1 as A$1[Arg]['type'] extends 'positional' ? Arg : never]: V[Arg] };
|
|
517
517
|
/**
|
|
518
518
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
519
519
|
*/
|
|
@@ -526,7 +526,7 @@ type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> =
|
|
|
526
526
|
*
|
|
527
527
|
* @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
|
|
528
528
|
*/
|
|
529
|
-
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
529
|
+
type ArgExplicitlyProvided<A$1 extends Args> = { [K in keyof A$1]: boolean };
|
|
530
530
|
/**
|
|
531
531
|
* Resolve command line arguments.
|
|
532
532
|
*
|
|
@@ -682,11 +682,11 @@ type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readon
|
|
|
682
682
|
*
|
|
683
683
|
* @since v0.27.0
|
|
684
684
|
*/
|
|
685
|
-
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
685
|
+
type Plugin<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
686
686
|
id: string;
|
|
687
687
|
name?: string;
|
|
688
688
|
dependencies?: (PluginDependency | string)[];
|
|
689
|
-
extension?: CommandContextExtension<E>;
|
|
689
|
+
extension?: CommandContextExtension<E$1>;
|
|
690
690
|
};
|
|
691
691
|
//#endregion
|
|
692
692
|
//#region ../gunshi/src/types.d.ts
|
|
@@ -717,7 +717,7 @@ type ExtendContext = Record<string, unknown>;
|
|
|
717
717
|
*
|
|
718
718
|
* @since v0.27.0
|
|
719
719
|
*/
|
|
720
|
-
interface GunshiParams<P extends {
|
|
720
|
+
interface GunshiParams<P$1 extends {
|
|
721
721
|
args?: Args;
|
|
722
722
|
extensions?: ExtendContext;
|
|
723
723
|
} = {
|
|
@@ -727,13 +727,13 @@ interface GunshiParams<P extends {
|
|
|
727
727
|
/**
|
|
728
728
|
* Command argument definitions.
|
|
729
729
|
*/
|
|
730
|
-
args: P extends {
|
|
730
|
+
args: P$1 extends {
|
|
731
731
|
args: infer A extends Args;
|
|
732
732
|
} ? A : Args;
|
|
733
733
|
/**
|
|
734
734
|
* Command context extensions.
|
|
735
735
|
*/
|
|
736
|
-
extensions: P extends {
|
|
736
|
+
extensions: P$1 extends {
|
|
737
737
|
extensions: infer E extends ExtendContext;
|
|
738
738
|
} ? E : {};
|
|
739
739
|
}
|
|
@@ -1110,7 +1110,7 @@ type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1110
1110
|
*
|
|
1111
1111
|
* @since v0.27.0
|
|
1112
1112
|
*/
|
|
1113
|
-
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1113
|
+
interface CommandContextExtension<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1114
1114
|
/**
|
|
1115
1115
|
* Plugin identifier
|
|
1116
1116
|
*/
|
|
@@ -1118,7 +1118,7 @@ interface CommandContextExtension<E extends GunshiParams['extensions'] = Default
|
|
|
1118
1118
|
/**
|
|
1119
1119
|
* Plugin extension factory
|
|
1120
1120
|
*/
|
|
1121
|
-
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E>;
|
|
1121
|
+
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E$1>;
|
|
1122
1122
|
/**
|
|
1123
1123
|
* Plugin extension factory after hook
|
|
1124
1124
|
*/
|
|
@@ -1320,8 +1320,8 @@ type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiP
|
|
|
1320
1320
|
* @param options - A {@link CliOptions | CLI options}
|
|
1321
1321
|
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
1322
1322
|
*/
|
|
1323
|
-
declare function cli<A extends Args = Args, G extends GunshiParams = {
|
|
1324
|
-
args: A;
|
|
1323
|
+
declare function cli<A$1 extends Args = Args, G extends GunshiParams = {
|
|
1324
|
+
args: A$1;
|
|
1325
1325
|
extensions: {};
|
|
1326
1326
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1327
1327
|
/**
|
|
@@ -1334,9 +1334,9 @@ declare function cli<A extends Args = Args, G extends GunshiParams = {
|
|
|
1334
1334
|
* @param options - A {@link CliOptions | CLI options}
|
|
1335
1335
|
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
1336
1336
|
*/
|
|
1337
|
-
declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiParams = {
|
|
1337
|
+
declare function cli<E$1 extends ExtendContext = ExtendContext, G extends GunshiParams = {
|
|
1338
1338
|
args: Args;
|
|
1339
|
-
extensions: E;
|
|
1339
|
+
extensions: E$1;
|
|
1340
1340
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1341
1341
|
/**
|
|
1342
1342
|
* Run the command.
|
package/lib/index.js
CHANGED
|
@@ -603,6 +603,21 @@ function deepFreeze(obj, ignores = []) {
|
|
|
603
603
|
//#endregion
|
|
604
604
|
//#region ../gunshi/src/context.ts
|
|
605
605
|
/**
|
|
606
|
+
* The entry for gunshi context.
|
|
607
|
+
* This module is exported for the purpose of testing the command.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```js
|
|
611
|
+
* import { createCommandContext } from 'gunshi/context'
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* @module
|
|
615
|
+
*/
|
|
616
|
+
/**
|
|
617
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
618
|
+
* @license MIT
|
|
619
|
+
*/
|
|
620
|
+
/**
|
|
606
621
|
* Create a command context.
|
|
607
622
|
*
|
|
608
623
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
@@ -675,7 +690,7 @@ function getCommandName(cmd) {
|
|
|
675
690
|
|
|
676
691
|
//#endregion
|
|
677
692
|
//#region ../gunshi/src/decorators.ts
|
|
678
|
-
const EMPTY_RENDERER =
|
|
693
|
+
const EMPTY_RENDERER = () => Promise.resolve("");
|
|
679
694
|
/**
|
|
680
695
|
* Factory function for creating a decorators manager.
|
|
681
696
|
*
|
|
@@ -834,6 +849,10 @@ function resolveDependencies(plugins) {
|
|
|
834
849
|
//#endregion
|
|
835
850
|
//#region ../gunshi/src/cli/core.ts
|
|
836
851
|
/**
|
|
852
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
853
|
+
* @license MIT
|
|
854
|
+
*/
|
|
855
|
+
/**
|
|
837
856
|
* Run the command.
|
|
838
857
|
*
|
|
839
858
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
@@ -851,7 +870,7 @@ async function cliCore(argv, entry, options, plugins) {
|
|
|
851
870
|
const cliOptions = normalizeCliOptions(options, decorators, pluginContext);
|
|
852
871
|
const tokens = parseArgs(argv);
|
|
853
872
|
const subCommand = getSubCommand(tokens);
|
|
854
|
-
const { commandName: name, command, callMode } =
|
|
873
|
+
const { commandName: name, command, callMode } = resolveCommand(subCommand, entry, cliOptions);
|
|
855
874
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
856
875
|
const args = resolveArguments(pluginContext, getCommandArgs(command));
|
|
857
876
|
const { explicit, values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
@@ -934,9 +953,9 @@ function getSubCommand(tokens) {
|
|
|
934
953
|
return firstToken && firstToken.kind === "positional" && firstToken.index === 0 && firstToken.value ? firstToken.value : "";
|
|
935
954
|
}
|
|
936
955
|
const CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
|
|
937
|
-
|
|
956
|
+
function resolveCommand(sub, entry, options) {
|
|
938
957
|
const omitted = !sub;
|
|
939
|
-
|
|
958
|
+
function doResolveCommand() {
|
|
940
959
|
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
|
|
941
960
|
commandName: entry.commandName,
|
|
942
961
|
command: entry,
|
|
@@ -1006,6 +1025,10 @@ async function executeCommand(cmd, ctx, decorators) {
|
|
|
1006
1025
|
//#endregion
|
|
1007
1026
|
//#region ../gunshi/src/cli/bone.ts
|
|
1008
1027
|
/**
|
|
1028
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
1029
|
+
* @license MIT
|
|
1030
|
+
*/
|
|
1031
|
+
/**
|
|
1009
1032
|
* Run the command.
|
|
1010
1033
|
*
|
|
1011
1034
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/bone",
|
|
3
3
|
"description": "gunshi minimum",
|
|
4
|
-
"version": "0.27.0-beta.
|
|
4
|
+
"version": "0.27.0-beta.4",
|
|
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.5.
|
|
54
|
+
"deno": "^2.5.6",
|
|
55
55
|
"jsr": "^0.13.5",
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
|
-
"publint": "^0.3.
|
|
58
|
-
"tsdown": "
|
|
59
|
-
"@gunshi/definition": "0.27.0-beta.
|
|
60
|
-
"@gunshi/plugin-
|
|
61
|
-
"gunshi": "0.27.0-beta.
|
|
62
|
-
"@gunshi/plugin-
|
|
57
|
+
"publint": "^0.3.15",
|
|
58
|
+
"tsdown": "0.15.12",
|
|
59
|
+
"@gunshi/definition": "0.27.0-beta.4",
|
|
60
|
+
"@gunshi/plugin-global": "0.27.0-beta.4",
|
|
61
|
+
"gunshi": "0.27.0-beta.4",
|
|
62
|
+
"@gunshi/plugin-renderer": "0.27.0-beta.4"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsdown",
|