@gunshi/definition 0.32.0 → 0.34.0
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 +86 -64
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
|
|
2
2
|
//#region src/parser.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Entry point of argument parser.
|
|
@@ -55,7 +55,7 @@ interface ArgToken {
|
|
|
55
55
|
* Parser Options.
|
|
56
56
|
*/
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
58
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/resolver.d.ts
|
|
59
59
|
//#region src/resolver.d.ts
|
|
60
60
|
/**
|
|
61
61
|
* An argument schema definition for command-line argument parsing.
|
|
@@ -172,7 +172,10 @@ interface ArgSchema {
|
|
|
172
172
|
* When `true`, the argument must be provided by the user.
|
|
173
173
|
* If missing, an `ArgResolveError` with type 'required' will be thrown.
|
|
174
174
|
*
|
|
175
|
-
*
|
|
175
|
+
* For single-value positional arguments, omitting `required` keeps the argument
|
|
176
|
+
* required for compatibility. Set `required: false` to make a positional argument
|
|
177
|
+
* optional. Optional positional arguments leave enough input values for later
|
|
178
|
+
* required positional arguments before consuming a value.
|
|
176
179
|
*
|
|
177
180
|
* @example
|
|
178
181
|
* Required arguments:
|
|
@@ -196,7 +199,8 @@ interface ArgSchema {
|
|
|
196
199
|
*
|
|
197
200
|
* When `true`, the resolved value becomes an array.
|
|
198
201
|
* For options: can be specified multiple times (--tag foo --tag bar)
|
|
199
|
-
* For positional: collects remaining positional arguments
|
|
202
|
+
* For positional: collects remaining positional arguments after preserving values for
|
|
203
|
+
* later required positional arguments.
|
|
200
204
|
*
|
|
201
205
|
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
202
206
|
*
|
|
@@ -276,7 +280,11 @@ interface ArgSchema {
|
|
|
276
280
|
* - `boolean` type: boolean default
|
|
277
281
|
* - `number` type: number default
|
|
278
282
|
* - `enum` type: must be one of the `choices` values
|
|
279
|
-
* - `positional`/`custom` type:
|
|
283
|
+
* - `positional`/`custom` type: string, boolean, or number default
|
|
284
|
+
*
|
|
285
|
+
* For single-value positional arguments, the default is used when the positional
|
|
286
|
+
* value is missing or when the value is preserved for later required positional
|
|
287
|
+
* arguments, unless `required: true` is set.
|
|
280
288
|
*
|
|
281
289
|
* @example
|
|
282
290
|
* Default values by type:
|
|
@@ -533,7 +541,8 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
533
541
|
*
|
|
534
542
|
* @internal
|
|
535
543
|
*/
|
|
536
|
-
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]
|
|
544
|
+
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as IsRequiredPositionalArg<A[Arg]> extends true ? Arg : never]: V[Arg] };
|
|
545
|
+
type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : A['required'] extends false ? A['default'] extends {} ? true : false : true : false;
|
|
537
546
|
/**
|
|
538
547
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
539
548
|
*/
|
|
@@ -581,15 +590,6 @@ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
|
581
590
|
*/
|
|
582
591
|
//#endregion
|
|
583
592
|
//#region ../gunshi/src/plugin/context.d.ts
|
|
584
|
-
/**
|
|
585
|
-
* Type helper to create GunshiParams from extracted args and extensions
|
|
586
|
-
*
|
|
587
|
-
* @internal
|
|
588
|
-
*/
|
|
589
|
-
type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string, unknown> = {}> = {
|
|
590
|
-
args: ExtractArgs<G>;
|
|
591
|
-
extensions: ExtractExtensions$1<G> & L;
|
|
592
|
-
};
|
|
593
593
|
/**
|
|
594
594
|
* Gunshi plugin context interface.
|
|
595
595
|
*
|
|
@@ -638,7 +638,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
638
638
|
*
|
|
639
639
|
* @param decorator - A decorator function that wraps the base header renderer.
|
|
640
640
|
*/
|
|
641
|
-
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
641
|
+
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
642
642
|
/**
|
|
643
643
|
* Decorate the usage renderer.
|
|
644
644
|
*
|
|
@@ -646,7 +646,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
646
646
|
*
|
|
647
647
|
* @param decorator - A decorator function that wraps the base usage renderer.
|
|
648
648
|
*/
|
|
649
|
-
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
649
|
+
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
650
650
|
/**
|
|
651
651
|
* Decorate the validation errors renderer.
|
|
652
652
|
*
|
|
@@ -654,7 +654,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
654
654
|
*
|
|
655
655
|
* @param decorator - A decorator function that wraps the base validation errors renderer.
|
|
656
656
|
*/
|
|
657
|
-
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
657
|
+
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>): void;
|
|
658
658
|
/**
|
|
659
659
|
* Decorate the command execution.
|
|
660
660
|
*
|
|
@@ -664,7 +664,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
664
664
|
*
|
|
665
665
|
* @param decorator - A decorator function that wraps the command runner
|
|
666
666
|
*/
|
|
667
|
-
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<
|
|
667
|
+
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>) => (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>): void;
|
|
668
668
|
}
|
|
669
669
|
//#endregion
|
|
670
670
|
//#region ../gunshi/src/plugin/core.d.ts
|
|
@@ -798,9 +798,46 @@ type ExtractArgExplicitlyProvided<G> = ArgExplicitlyProvided<ExtractArgs<G>>;
|
|
|
798
798
|
*
|
|
799
799
|
* @internal
|
|
800
800
|
*/
|
|
801
|
-
type ExtractExtensions
|
|
801
|
+
type ExtractExtensions<G> = G extends GunshiParams<any> ? G['extensions'] : G extends {
|
|
802
802
|
extensions: infer E;
|
|
803
803
|
} ? E : {};
|
|
804
|
+
/**
|
|
805
|
+
* Type helper to normalize G to GunshiParams
|
|
806
|
+
*
|
|
807
|
+
* @internal
|
|
808
|
+
*/
|
|
809
|
+
type NormalizeToGunshiParams<G> = G extends GunshiParams<any> ? G : G extends {
|
|
810
|
+
args: infer A extends Args;
|
|
811
|
+
extensions: infer E extends ExtendContext;
|
|
812
|
+
} ? GunshiParams<{
|
|
813
|
+
args: A;
|
|
814
|
+
extensions: E;
|
|
815
|
+
}> : G extends {
|
|
816
|
+
args: infer A extends Args;
|
|
817
|
+
} ? GunshiParams<{
|
|
818
|
+
args: A;
|
|
819
|
+
extensions: {};
|
|
820
|
+
}> : G extends {
|
|
821
|
+
extensions: infer E extends ExtendContext;
|
|
822
|
+
} ? GunshiParams<{
|
|
823
|
+
args: Args;
|
|
824
|
+
extensions: E;
|
|
825
|
+
}> : DefaultGunshiParams;
|
|
826
|
+
/**
|
|
827
|
+
* Type helper to merge command context extensions into G
|
|
828
|
+
*
|
|
829
|
+
* @internal
|
|
830
|
+
*/
|
|
831
|
+
type MergeGunshiExtensions<G extends GunshiParamsConstraint, E extends ExtendContext> = GunshiParams<{
|
|
832
|
+
/**
|
|
833
|
+
* Command argument definitions.
|
|
834
|
+
*/
|
|
835
|
+
args: ExtractArgs<G>;
|
|
836
|
+
/**
|
|
837
|
+
* Merged command context extensions.
|
|
838
|
+
*/
|
|
839
|
+
extensions: ExtractExtensions<G> & E;
|
|
840
|
+
}>;
|
|
804
841
|
/**
|
|
805
842
|
* Command environment.
|
|
806
843
|
*
|
|
@@ -1106,7 +1143,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1106
1143
|
*
|
|
1107
1144
|
* @since v0.27.0
|
|
1108
1145
|
*/
|
|
1109
|
-
extensions: keyof ExtractExtensions
|
|
1146
|
+
extensions: keyof ExtractExtensions<G> extends never ? any : ExtractExtensions<G>;
|
|
1110
1147
|
/**
|
|
1111
1148
|
* Validation error from argument parsing.
|
|
1112
1149
|
* This will be set if argument validation fails during CLI execution.
|
|
@@ -1114,7 +1151,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1114
1151
|
validationError?: AggregateError;
|
|
1115
1152
|
}
|
|
1116
1153
|
/**
|
|
1117
|
-
*
|
|
1154
|
+
* Readonly command context available to a command context extension factory.
|
|
1118
1155
|
*
|
|
1119
1156
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command context.
|
|
1120
1157
|
*
|
|
@@ -1355,7 +1392,16 @@ type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = ()
|
|
|
1355
1392
|
*
|
|
1356
1393
|
* @internal
|
|
1357
1394
|
*/
|
|
1358
|
-
type
|
|
1395
|
+
type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1396
|
+
/**
|
|
1397
|
+
* Return type of {@link createCommandContext}
|
|
1398
|
+
*
|
|
1399
|
+
* @internal
|
|
1400
|
+
*/
|
|
1401
|
+
type CommandContextResult<G extends GunshiParamsConstraint, E extends Record<string, CommandContextExtension>> = {} extends ExtractExtensionValues<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1402
|
+
args: ExtractArgs<G>;
|
|
1403
|
+
extensions: ExtractExtensionValues<E>;
|
|
1404
|
+
}>>>;
|
|
1359
1405
|
/**
|
|
1360
1406
|
* Parameters of {@link createCommandContext}
|
|
1361
1407
|
*/
|
|
@@ -1442,24 +1488,27 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
1442
1488
|
commandPath,
|
|
1443
1489
|
omitted,
|
|
1444
1490
|
validationError
|
|
1445
|
-
}: CommandContextParams<G, V, C, E>): Promise<
|
|
1446
|
-
args: ExtractArgs<G>;
|
|
1447
|
-
extensions: ExtractExtensions<E>;
|
|
1448
|
-
}>>>>;
|
|
1491
|
+
}: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
|
|
1449
1492
|
//#endregion
|
|
1450
1493
|
//#region ../gunshi/src/definition.d.ts
|
|
1451
1494
|
/**
|
|
1452
|
-
*
|
|
1495
|
+
* The result type of the {@link define} function
|
|
1453
1496
|
*
|
|
1454
1497
|
* @internal
|
|
1455
1498
|
*/
|
|
1456
|
-
type
|
|
1499
|
+
type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiParams, C = {}> = Prettify<Pick<C, keyof C> & Partial<Pick<Command<G>, Exclude<keyof Command<G>, keyof C>>>>;
|
|
1457
1500
|
/**
|
|
1458
|
-
* The
|
|
1501
|
+
* The command definition accepted by {@link define} helpers.
|
|
1459
1502
|
*
|
|
1460
1503
|
* @internal
|
|
1461
1504
|
*/
|
|
1462
|
-
type
|
|
1505
|
+
type CommandDefinition<A extends Args, E extends ExtendContext, C extends Partial<Command<{
|
|
1506
|
+
args: A;
|
|
1507
|
+
extensions: E;
|
|
1508
|
+
}>>> = C & Command<{
|
|
1509
|
+
args: A;
|
|
1510
|
+
extensions: E;
|
|
1511
|
+
}>;
|
|
1463
1512
|
/**
|
|
1464
1513
|
* Define a {@link Command | command}.
|
|
1465
1514
|
*
|
|
@@ -1490,10 +1539,10 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
1490
1539
|
* @param definition - A {@link Command | command} definition
|
|
1491
1540
|
* @returns A defined {@link Command | command}
|
|
1492
1541
|
*/
|
|
1493
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends
|
|
1542
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends Partial<Command<{
|
|
1494
1543
|
args: A;
|
|
1495
|
-
extensions: ExtractExtensions
|
|
1496
|
-
}>): CommandDefinitionResult<G, C>;
|
|
1544
|
+
extensions: ExtractExtensions<G>;
|
|
1545
|
+
}>> = {}>(definition: CommandDefinition<A, ExtractExtensions<G>, C>): CommandDefinitionResult<G, C>;
|
|
1497
1546
|
/**
|
|
1498
1547
|
* Return type for defineWithTypes
|
|
1499
1548
|
*
|
|
@@ -1504,10 +1553,7 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
1504
1553
|
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
1505
1554
|
args: A;
|
|
1506
1555
|
extensions: DefaultExtensions;
|
|
1507
|
-
}>> = {}>(definition: C
|
|
1508
|
-
args: A;
|
|
1509
|
-
extensions: DefaultExtensions;
|
|
1510
|
-
}>) => CommandDefinitionResult<{
|
|
1556
|
+
}>> = {}>(definition: CommandDefinition<A, DefaultExtensions, C>) => CommandDefinitionResult<{
|
|
1511
1557
|
args: A;
|
|
1512
1558
|
extensions: DefaultExtensions;
|
|
1513
1559
|
}, C>;
|
|
@@ -1540,7 +1586,7 @@ type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs
|
|
|
1540
1586
|
*
|
|
1541
1587
|
* @since v0.27.0
|
|
1542
1588
|
*/
|
|
1543
|
-
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions
|
|
1589
|
+
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions<G>, ExtractArgs<G>>;
|
|
1544
1590
|
/**
|
|
1545
1591
|
* Define a {@link LazyCommand | lazy command}.
|
|
1546
1592
|
*
|
|
@@ -1610,30 +1656,6 @@ declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A
|
|
|
1610
1656
|
args: A;
|
|
1611
1657
|
extensions: {};
|
|
1612
1658
|
}, D>;
|
|
1613
|
-
/**
|
|
1614
|
-
* Normalize G to a full GunshiParams type
|
|
1615
|
-
*
|
|
1616
|
-
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
1617
|
-
*
|
|
1618
|
-
* @internal
|
|
1619
|
-
*/
|
|
1620
|
-
type NormalizeGunshiParams<G extends GunshiParamsConstraint> = G extends GunshiParams<any> ? G : G extends {
|
|
1621
|
-
args: infer A;
|
|
1622
|
-
extensions: infer E;
|
|
1623
|
-
} ? {
|
|
1624
|
-
args: A;
|
|
1625
|
-
extensions: E;
|
|
1626
|
-
} : G extends {
|
|
1627
|
-
args: infer A;
|
|
1628
|
-
} ? {
|
|
1629
|
-
args: A;
|
|
1630
|
-
extensions: {};
|
|
1631
|
-
} : G extends {
|
|
1632
|
-
extensions: infer E;
|
|
1633
|
-
} ? {
|
|
1634
|
-
args: Args;
|
|
1635
|
-
extensions: E;
|
|
1636
|
-
} : DefaultGunshiParams;
|
|
1637
1659
|
/**
|
|
1638
1660
|
* Return type for lazyWithTypes
|
|
1639
1661
|
*
|
|
@@ -1676,7 +1698,7 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
1676
1698
|
*
|
|
1677
1699
|
* @since v0.27.0
|
|
1678
1700
|
*/
|
|
1679
|
-
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<
|
|
1701
|
+
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<NormalizeToGunshiParams<G>>;
|
|
1680
1702
|
//#endregion
|
|
1681
1703
|
//#region src/index.d.ts
|
|
1682
1704
|
/**
|
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.34.0",
|
|
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.2",
|
|
58
58
|
"publint": "^0.3.20",
|
|
59
59
|
"tsdown": "0.21.0",
|
|
60
|
-
"gunshi": "0.
|
|
60
|
+
"gunshi": "0.34.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|