@gunshi/definition 0.33.0 → 0.35.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 +59 -22
- package/lib/index.js +4 -4
- 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.27.0/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,13 +55,13 @@ 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.27.0/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.
|
|
62
62
|
*
|
|
63
63
|
* This schema is similar to the schema of Node.js `util.parseArgs` but with extended features:
|
|
64
|
-
* - Additional `required` and `
|
|
64
|
+
* - Additional `required`, `description`, and `hidden` properties
|
|
65
65
|
* - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom'
|
|
66
66
|
* - Simplified `default` property (single type, not union types)
|
|
67
67
|
*
|
|
@@ -166,13 +166,35 @@ interface ArgSchema {
|
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
168
|
description?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Hide the argument from generated help or usage output.
|
|
171
|
+
*
|
|
172
|
+
* This is metadata for renderers. It does not affect parsing, validation,
|
|
173
|
+
* required checks, defaults, conflicts, or resolved values.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* Hidden compatibility option:
|
|
177
|
+
* ```ts
|
|
178
|
+
* {
|
|
179
|
+
* legacy: {
|
|
180
|
+
* type: 'string',
|
|
181
|
+
* hidden: true,
|
|
182
|
+
* description: 'Deprecated compatibility option'
|
|
183
|
+
* }
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
hidden?: boolean;
|
|
169
188
|
/**
|
|
170
189
|
* Marks the argument as required.
|
|
171
190
|
*
|
|
172
191
|
* When `true`, the argument must be provided by the user.
|
|
173
192
|
* If missing, an `ArgResolveError` with type 'required' will be thrown.
|
|
174
193
|
*
|
|
175
|
-
*
|
|
194
|
+
* For single-value positional arguments, omitting `required` keeps the argument
|
|
195
|
+
* required for compatibility. Set `required: false` to make a positional argument
|
|
196
|
+
* optional. Optional positional arguments leave enough input values for later
|
|
197
|
+
* required positional arguments before consuming a value.
|
|
176
198
|
*
|
|
177
199
|
* @example
|
|
178
200
|
* Required arguments:
|
|
@@ -196,7 +218,8 @@ interface ArgSchema {
|
|
|
196
218
|
*
|
|
197
219
|
* When `true`, the resolved value becomes an array.
|
|
198
220
|
* For options: can be specified multiple times (--tag foo --tag bar)
|
|
199
|
-
* For positional: collects remaining positional arguments
|
|
221
|
+
* For positional: collects remaining positional arguments after preserving values for
|
|
222
|
+
* later required positional arguments.
|
|
200
223
|
*
|
|
201
224
|
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
202
225
|
*
|
|
@@ -276,7 +299,11 @@ interface ArgSchema {
|
|
|
276
299
|
* - `boolean` type: boolean default
|
|
277
300
|
* - `number` type: number default
|
|
278
301
|
* - `enum` type: must be one of the `choices` values
|
|
279
|
-
* - `positional`/`custom` type:
|
|
302
|
+
* - `positional`/`custom` type: string, boolean, or number default
|
|
303
|
+
*
|
|
304
|
+
* For single-value positional arguments, the default is used when the positional
|
|
305
|
+
* value is missing or when the value is preserved for later required positional
|
|
306
|
+
* arguments, unless `required: true` is set.
|
|
280
307
|
*
|
|
281
308
|
* @example
|
|
282
309
|
* Default values by type:
|
|
@@ -533,7 +560,8 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
533
560
|
*
|
|
534
561
|
* @internal
|
|
535
562
|
*/
|
|
536
|
-
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]
|
|
563
|
+
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] };
|
|
564
|
+
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
565
|
/**
|
|
538
566
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
539
567
|
*/
|
|
@@ -1551,7 +1579,7 @@ type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs
|
|
|
1551
1579
|
/**
|
|
1552
1580
|
* Define a {@link Command | command} with types
|
|
1553
1581
|
*
|
|
1554
|
-
* This helper function allows specifying the type parameter of {@link
|
|
1582
|
+
* This helper function allows specifying the type parameter of {@link GunshiParamsConstraint}
|
|
1555
1583
|
* while inferring the {@link Args} type, {@link ExtendContext} type from the definition.
|
|
1556
1584
|
*
|
|
1557
1585
|
* @example
|
|
@@ -1571,7 +1599,7 @@ type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs
|
|
|
1571
1599
|
* })
|
|
1572
1600
|
* ```
|
|
1573
1601
|
*
|
|
1574
|
-
* @typeParam G - A {@link
|
|
1602
|
+
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
1575
1603
|
*
|
|
1576
1604
|
* @returns A function that takes a command definition via {@link define}
|
|
1577
1605
|
*
|
|
@@ -1627,30 +1655,39 @@ declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
|
1627
1655
|
* }, testDefinition)
|
|
1628
1656
|
* ```
|
|
1629
1657
|
*
|
|
1630
|
-
* @typeParam
|
|
1631
|
-
* @typeParam D - A partial {@link Command} definition type
|
|
1658
|
+
* @typeParam D - A partial {@link Command} definition type with required `args`
|
|
1632
1659
|
*
|
|
1633
1660
|
* @param loader - A {@link CommandLoader | command loader} function that returns a command definition
|
|
1634
|
-
* @param definition -
|
|
1661
|
+
* @param definition - A {@link Command | command} definition
|
|
1635
1662
|
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
1636
1663
|
*/
|
|
1637
|
-
declare function lazy<
|
|
1638
|
-
args:
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
args: A;
|
|
1664
|
+
declare function lazy<D extends {
|
|
1665
|
+
args: Args;
|
|
1666
|
+
} & Partial<Command<{
|
|
1667
|
+
args: D['args'];
|
|
1642
1668
|
extensions: {};
|
|
1643
1669
|
}>>>(loader: CommandLoader<{
|
|
1644
|
-
args:
|
|
1670
|
+
args: D['args'];
|
|
1645
1671
|
extensions: {};
|
|
1646
1672
|
}>, definition: D): LazyCommand<{
|
|
1647
|
-
args:
|
|
1673
|
+
args: D['args'];
|
|
1648
1674
|
extensions: {};
|
|
1649
1675
|
}, D>;
|
|
1676
|
+
/**
|
|
1677
|
+
* Define a {@link LazyCommand | lazy command} with explicit Gunshi parameters and optional definition.
|
|
1678
|
+
*
|
|
1679
|
+
* @typeParam G - A {@link GunshiParamsConstraint}
|
|
1680
|
+
* @typeParam D - A partial {@link Command} definition type
|
|
1681
|
+
*
|
|
1682
|
+
* @param loader - A {@link CommandLoader | command loader} function that returns a command definition
|
|
1683
|
+
* @param definition - An optional {@link Command | command} definition
|
|
1684
|
+
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
1685
|
+
*/
|
|
1686
|
+
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, D extends Partial<Command<G>> = Partial<Command<G>>>(loader: CommandLoader<G>, definition?: D): LazyCommand<G, D>;
|
|
1650
1687
|
/**
|
|
1651
1688
|
* Return type for lazyWithTypes
|
|
1652
1689
|
*
|
|
1653
|
-
* @typeParam FullG - The normalized {@link
|
|
1690
|
+
* @typeParam FullG - The normalized {@link GunshiParamsConstraint} type
|
|
1654
1691
|
*
|
|
1655
1692
|
* @internal
|
|
1656
1693
|
*/
|
|
@@ -1658,7 +1695,7 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
1658
1695
|
/**
|
|
1659
1696
|
* Define a {@link LazyCommand | lazy command} with specific type parameters.
|
|
1660
1697
|
*
|
|
1661
|
-
* This helper function allows specifying the type parameter of {@link
|
|
1698
|
+
* This helper function allows specifying the type parameter of {@link GunshiParamsConstraint}
|
|
1662
1699
|
* while inferring the {@link Args} type, {@link ExtendContext} type from the definition.
|
|
1663
1700
|
*
|
|
1664
1701
|
* @example
|
|
@@ -1683,7 +1720,7 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
1683
1720
|
* )
|
|
1684
1721
|
* ```
|
|
1685
1722
|
*
|
|
1686
|
-
* @typeParam G - A {@link
|
|
1723
|
+
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
1687
1724
|
*
|
|
1688
1725
|
* @returns A function that takes a lazy command definition via {@link lazy}
|
|
1689
1726
|
*
|
package/lib/index.js
CHANGED
|
@@ -181,7 +181,7 @@ function define(definition) {
|
|
|
181
181
|
/**
|
|
182
182
|
* Define a {@link Command | command} with types
|
|
183
183
|
*
|
|
184
|
-
* This helper function allows specifying the type parameter of {@link
|
|
184
|
+
* This helper function allows specifying the type parameter of {@link GunshiParamsConstraint}
|
|
185
185
|
* while inferring the {@link Args} type, {@link ExtendContext} type from the definition.
|
|
186
186
|
*
|
|
187
187
|
* @example
|
|
@@ -201,7 +201,7 @@ function define(definition) {
|
|
|
201
201
|
* })
|
|
202
202
|
* ```
|
|
203
203
|
*
|
|
204
|
-
* @typeParam G - A {@link
|
|
204
|
+
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
205
205
|
*
|
|
206
206
|
* @returns A function that takes a command definition via {@link define}
|
|
207
207
|
*
|
|
@@ -237,7 +237,7 @@ function lazy(loader, definition) {
|
|
|
237
237
|
/**
|
|
238
238
|
* Define a {@link LazyCommand | lazy command} with specific type parameters.
|
|
239
239
|
*
|
|
240
|
-
* This helper function allows specifying the type parameter of {@link
|
|
240
|
+
* This helper function allows specifying the type parameter of {@link GunshiParamsConstraint}
|
|
241
241
|
* while inferring the {@link Args} type, {@link ExtendContext} type from the definition.
|
|
242
242
|
*
|
|
243
243
|
* @example
|
|
@@ -262,7 +262,7 @@ function lazy(loader, definition) {
|
|
|
262
262
|
* )
|
|
263
263
|
* ```
|
|
264
264
|
*
|
|
265
|
-
* @typeParam G - A {@link
|
|
265
|
+
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
266
266
|
*
|
|
267
267
|
* @returns A function that takes a lazy command definition via {@link lazy}
|
|
268
268
|
*
|
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.35.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.35.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|