@gunshi/bone 0.27.0 → 0.27.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 +48 -16
- package/package.json +5 -5
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
|
|
488
|
-
type ResolveOptionValue<A
|
|
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;
|
|
489
489
|
/**
|
|
490
490
|
* Resolved argument values.
|
|
491
491
|
*
|
|
@@ -494,7 +494,7 @@ type ResolveOptionValue<A$1 extends ArgSchema, T> = A$1['multiple'] extends true
|
|
|
494
494
|
*
|
|
495
495
|
* @internal
|
|
496
496
|
*/
|
|
497
|
-
type ResolveArgValues<A
|
|
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;
|
|
498
498
|
/**
|
|
499
499
|
* Filters the arguments based on their default values.
|
|
500
500
|
*
|
|
@@ -504,7 +504,7 @@ type ResolveArgValues<A$1 extends Args, V extends Record<keyof A$1, unknown>> =
|
|
|
504
504
|
*
|
|
505
505
|
* @internal
|
|
506
506
|
*/
|
|
507
|
-
type FilterArgs<A
|
|
507
|
+
type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K$1 extends keyof ArgSchema> = { [Arg in keyof A as A[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$1 extends Args, V extends Record<keyof A$1, unknown>, K$1 exte
|
|
|
513
513
|
*
|
|
514
514
|
* @internal
|
|
515
515
|
*/
|
|
516
|
-
type FilterPositionalArgs<A
|
|
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] };
|
|
517
517
|
/**
|
|
518
518
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
519
519
|
*/
|
|
@@ -526,7 +526,7 @@ type FilterPositionalArgs<A$1 extends Args, V extends Record<keyof A$1, 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
|
|
529
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: 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
|
|
685
|
+
type Plugin<E 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>;
|
|
690
690
|
};
|
|
691
691
|
//#endregion
|
|
692
692
|
//#region ../gunshi/src/types.d.ts
|
|
@@ -923,7 +923,7 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
923
923
|
/**
|
|
924
924
|
* Sub commands.
|
|
925
925
|
*/
|
|
926
|
-
subCommands?: Record<string,
|
|
926
|
+
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
|
|
927
927
|
/**
|
|
928
928
|
* Left margin of the command output.
|
|
929
929
|
*/
|
|
@@ -1110,7 +1110,7 @@ type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1110
1110
|
*
|
|
1111
1111
|
* @since v0.27.0
|
|
1112
1112
|
*/
|
|
1113
|
-
interface CommandContextExtension<E
|
|
1113
|
+
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1114
1114
|
/**
|
|
1115
1115
|
* Plugin identifier
|
|
1116
1116
|
*/
|
|
@@ -1118,7 +1118,7 @@ interface CommandContextExtension<E$1 extends GunshiParams['extensions'] = Defau
|
|
|
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>;
|
|
1122
1122
|
/**
|
|
1123
1123
|
* Plugin extension factory after hook
|
|
1124
1124
|
*/
|
|
@@ -1237,6 +1237,38 @@ type LazyCommand<G extends GunshiParamsConstraint = DefaultGunshiParams, D exten
|
|
|
1237
1237
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command.
|
|
1238
1238
|
*/
|
|
1239
1239
|
type Commandable<G extends GunshiParamsConstraint = DefaultGunshiParams> = Command<G> | LazyCommand<G, {}>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Sub-command entry type for use in subCommands.
|
|
1242
|
+
*
|
|
1243
|
+
* This type uses a loose structural match to bypass TypeScript's contravariance issues
|
|
1244
|
+
* with function parameters, allowing any Command or LazyCommand to be used as a sub-command.
|
|
1245
|
+
*
|
|
1246
|
+
* @since v0.27.1
|
|
1247
|
+
*/
|
|
1248
|
+
interface SubCommandable {
|
|
1249
|
+
/** Command name */
|
|
1250
|
+
name?: string;
|
|
1251
|
+
/** Command description */
|
|
1252
|
+
description?: string;
|
|
1253
|
+
/** Command arguments - accepts any args structure */
|
|
1254
|
+
args?: Args | Record<string, any>;
|
|
1255
|
+
/** Command examples */
|
|
1256
|
+
examples?: string | ((...args: any[]) => any);
|
|
1257
|
+
/** Command runner */
|
|
1258
|
+
run?: (...args: any[]) => any;
|
|
1259
|
+
/** Whether to convert camelCase to kebab-case */
|
|
1260
|
+
toKebab?: boolean;
|
|
1261
|
+
/** Whether this is an internal command */
|
|
1262
|
+
internal?: boolean;
|
|
1263
|
+
/** Whether this is an entry command */
|
|
1264
|
+
entry?: boolean;
|
|
1265
|
+
/** Rendering options */
|
|
1266
|
+
rendering?: any;
|
|
1267
|
+
/** Command name for lazy commands */
|
|
1268
|
+
commandName?: string;
|
|
1269
|
+
/** Index signature to allow additional properties */
|
|
1270
|
+
[key: string]: any;
|
|
1271
|
+
}
|
|
1240
1272
|
/**
|
|
1241
1273
|
* Command examples fetcher.
|
|
1242
1274
|
*
|
|
@@ -1320,8 +1352,8 @@ type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiP
|
|
|
1320
1352
|
* @param options - A {@link CliOptions | CLI options}
|
|
1321
1353
|
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
1322
1354
|
*/
|
|
1323
|
-
declare function cli<A
|
|
1324
|
-
args: A
|
|
1355
|
+
declare function cli<A extends Args = Args, G extends GunshiParams = {
|
|
1356
|
+
args: A;
|
|
1325
1357
|
extensions: {};
|
|
1326
1358
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1327
1359
|
/**
|
|
@@ -1334,9 +1366,9 @@ declare function cli<A$1 extends Args = Args, G extends GunshiParams = {
|
|
|
1334
1366
|
* @param options - A {@link CliOptions | CLI options}
|
|
1335
1367
|
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
1336
1368
|
*/
|
|
1337
|
-
declare function cli<E
|
|
1369
|
+
declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiParams = {
|
|
1338
1370
|
args: Args;
|
|
1339
|
-
extensions: E
|
|
1371
|
+
extensions: E;
|
|
1340
1372
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1341
1373
|
/**
|
|
1342
1374
|
* Run the command.
|
|
@@ -1350,4 +1382,4 @@ declare function cli<E$1 extends ExtendContext = ExtendContext, G extends Gunshi
|
|
|
1350
1382
|
*/
|
|
1351
1383
|
declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1352
1384
|
//#endregion
|
|
1353
|
-
export { type ArgSchema, type ArgToken, type ArgValues, type Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, Prettify, RendererDecorator, RenderingOptions, ValidationErrorsDecorator, cli };
|
|
1385
|
+
export { type ArgSchema, type ArgToken, type ArgValues, type Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, Prettify, RendererDecorator, RenderingOptions, SubCommandable, 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.27.
|
|
4
|
+
"version": "0.27.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
57
|
"publint": "^0.3.16",
|
|
58
58
|
"tsdown": "0.15.12",
|
|
59
|
-
"@gunshi/
|
|
60
|
-
"@gunshi/
|
|
61
|
-
"gunshi": "0.27.
|
|
62
|
-
"
|
|
59
|
+
"@gunshi/plugin-global": "0.27.2",
|
|
60
|
+
"@gunshi/definition": "0.27.2",
|
|
61
|
+
"@gunshi/plugin-renderer": "0.27.2",
|
|
62
|
+
"gunshi": "0.27.2"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsdown",
|