@gunshi/definition 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.
Files changed (2) hide show
  1. package/lib/index.d.ts +38 -6
  2. package/package.json +2 -2
package/lib/index.d.ts CHANGED
@@ -473,10 +473,10 @@ interface Args {
473
473
  *
474
474
  * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
475
475
  */
476
- type ArgValues<T$1> = T$1 extends Args ? ResolveArgValues<T$1, { [Arg in keyof T$1]: ExtractOptionValue<T$1[Arg]> }> : {
476
+ type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
477
477
  [option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
478
478
  };
479
- type IsFunction<T$1> = T$1 extends ((...args: any[]) => any) ? true : false;
479
+ type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
480
480
  /**
481
481
  * Extracts the value type from the argument schema.
482
482
  *
@@ -485,7 +485,7 @@ type IsFunction<T$1> = T$1 extends ((...args: any[]) => any) ? true : false;
485
485
  * @internal
486
486
  */
487
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$1> = A$1['multiple'] extends true ? T$1[] : T$1;
488
+ type ResolveOptionValue<A$1 extends ArgSchema, T> = A$1['multiple'] extends true ? T[] : T;
489
489
  /**
490
490
  * Resolved argument values.
491
491
  *
@@ -695,13 +695,13 @@ type Plugin<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extens
695
695
  *
696
696
  * @typeParam T - The type of the value that can be awaited.
697
697
  */
698
- type Awaitable<T$1> = T$1 | Promise<T$1>;
698
+ type Awaitable<T> = T | Promise<T>;
699
699
  /**
700
700
  * Prettify a type by flattening its structure.
701
701
  *
702
702
  * @typeParam T - The type to be prettified.
703
703
  */
704
- type Prettify<T$1> = { [K in keyof T$1]: T$1[K] } & {};
704
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
705
705
  /**
706
706
  * Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
707
707
  *
@@ -912,7 +912,7 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
912
912
  /**
913
913
  * Sub commands.
914
914
  */
915
- subCommands?: Record<string, Command<any> | LazyCommand<any>> | Map<string, Command<any> | LazyCommand<any>>;
915
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
916
916
  /**
917
917
  * Left margin of the command output.
918
918
  */
@@ -1220,6 +1220,38 @@ type LazyCommand<G extends GunshiParamsConstraint = DefaultGunshiParams, D exten
1220
1220
  } : {
1221
1221
  commandName?: string;
1222
1222
  }) & Omit<D, 'name' | 'run'> & Partial<Omit<Command<G>, keyof D | 'run' | 'name'>>;
1223
+ /**
1224
+ * Sub-command entry type for use in subCommands.
1225
+ *
1226
+ * This type uses a loose structural match to bypass TypeScript's contravariance issues
1227
+ * with function parameters, allowing any Command or LazyCommand to be used as a sub-command.
1228
+ *
1229
+ * @since v0.27.1
1230
+ */
1231
+ interface SubCommandable {
1232
+ /** Command name */
1233
+ name?: string;
1234
+ /** Command description */
1235
+ description?: string;
1236
+ /** Command arguments - accepts any args structure */
1237
+ args?: Args | Record<string, any>;
1238
+ /** Command examples */
1239
+ examples?: string | ((...args: any[]) => any);
1240
+ /** Command runner */
1241
+ run?: (...args: any[]) => any;
1242
+ /** Whether to convert camelCase to kebab-case */
1243
+ toKebab?: boolean;
1244
+ /** Whether this is an internal command */
1245
+ internal?: boolean;
1246
+ /** Whether this is an entry command */
1247
+ entry?: boolean;
1248
+ /** Rendering options */
1249
+ rendering?: any;
1250
+ /** Command name for lazy commands */
1251
+ commandName?: string;
1252
+ /** Index signature to allow additional properties */
1253
+ [key: string]: any;
1254
+ }
1223
1255
  /**
1224
1256
  * Command examples fetcher.
1225
1257
  *
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.27.0",
4
+ "version": "0.27.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -57,7 +57,7 @@
57
57
  "jsr-exports-lint": "^0.4.1",
58
58
  "publint": "^0.3.16",
59
59
  "tsdown": "0.15.12",
60
- "gunshi": "0.27.0"
60
+ "gunshi": "0.27.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsdown",