@gunshi/combinators 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 +21 -9
- package/lib/index.js +8 -5
- 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/resolver.d.ts
|
|
2
2
|
|
|
3
3
|
//#region src/resolver.d.ts
|
|
4
4
|
/**
|
|
@@ -116,7 +116,10 @@ interface ArgSchema {
|
|
|
116
116
|
* When `true`, the argument must be provided by the user.
|
|
117
117
|
* If missing, an `ArgResolveError` with type 'required' will be thrown.
|
|
118
118
|
*
|
|
119
|
-
*
|
|
119
|
+
* For single-value positional arguments, omitting `required` keeps the argument
|
|
120
|
+
* required for compatibility. Set `required: false` to make a positional argument
|
|
121
|
+
* optional. Optional positional arguments leave enough input values for later
|
|
122
|
+
* required positional arguments before consuming a value.
|
|
120
123
|
*
|
|
121
124
|
* @example
|
|
122
125
|
* Required arguments:
|
|
@@ -140,7 +143,8 @@ interface ArgSchema {
|
|
|
140
143
|
*
|
|
141
144
|
* When `true`, the resolved value becomes an array.
|
|
142
145
|
* For options: can be specified multiple times (--tag foo --tag bar)
|
|
143
|
-
* For positional: collects remaining positional arguments
|
|
146
|
+
* For positional: collects remaining positional arguments after preserving values for
|
|
147
|
+
* later required positional arguments.
|
|
144
148
|
*
|
|
145
149
|
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
146
150
|
*
|
|
@@ -220,7 +224,11 @@ interface ArgSchema {
|
|
|
220
224
|
* - `boolean` type: boolean default
|
|
221
225
|
* - `number` type: number default
|
|
222
226
|
* - `enum` type: must be one of the `choices` values
|
|
223
|
-
* - `positional`/`custom` type:
|
|
227
|
+
* - `positional`/`custom` type: string, boolean, or number default
|
|
228
|
+
*
|
|
229
|
+
* For single-value positional arguments, the default is used when the positional
|
|
230
|
+
* value is missing or when the value is preserved for later required positional
|
|
231
|
+
* arguments, unless `required: true` is set.
|
|
224
232
|
*
|
|
225
233
|
* @example
|
|
226
234
|
* Default values by type:
|
|
@@ -439,7 +447,7 @@ interface Args {
|
|
|
439
447
|
* @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
|
|
440
448
|
*/
|
|
441
449
|
//#endregion
|
|
442
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
450
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/combinators.d.ts
|
|
443
451
|
//#region src/combinators.d.ts
|
|
444
452
|
/**
|
|
445
453
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -676,6 +684,7 @@ type ArgSchemaPositionalType = {
|
|
|
676
684
|
* const args = {
|
|
677
685
|
* command: positional(), // resolves to string
|
|
678
686
|
* port: positional(integer()), // resolves to number
|
|
687
|
+
* query: unrequired(positional()) // optional positional
|
|
679
688
|
* }
|
|
680
689
|
* ```
|
|
681
690
|
*
|
|
@@ -696,6 +705,7 @@ declare function positional<T>(parser: CombinatorSchema<T>): CombinatorSchema<T>
|
|
|
696
705
|
* const args = {
|
|
697
706
|
* command: positional(), // resolves to string
|
|
698
707
|
* port: positional(integer()), // resolves to number
|
|
708
|
+
* query: unrequired(positional()) // optional positional
|
|
699
709
|
* }
|
|
700
710
|
* ```
|
|
701
711
|
*
|
|
@@ -945,10 +955,11 @@ type CombinatorUnrequired = {
|
|
|
945
955
|
/**
|
|
946
956
|
* Mark a combinator schema as not required.
|
|
947
957
|
*
|
|
948
|
-
* Useful for overriding a base combinator that was created with `required: true
|
|
958
|
+
* Useful for overriding a base combinator that was created with `required: true`,
|
|
959
|
+
* or for making a positional argument explicitly optional.
|
|
949
960
|
* The original schema is not modified.
|
|
950
961
|
*
|
|
951
|
-
* @typeParam T - The schema
|
|
962
|
+
* @typeParam T - The schema type.
|
|
952
963
|
*
|
|
953
964
|
* @param schema - The base combinator schema.
|
|
954
965
|
* @returns A new schema with `required: false`.
|
|
@@ -956,13 +967,14 @@ type CombinatorUnrequired = {
|
|
|
956
967
|
* @example
|
|
957
968
|
* ```ts
|
|
958
969
|
* const args = {
|
|
959
|
-
* name: unrequired(string({ required: true }))
|
|
970
|
+
* name: unrequired(string({ required: true })),
|
|
971
|
+
* query: unrequired(positional())
|
|
960
972
|
* }
|
|
961
973
|
* ```
|
|
962
974
|
*
|
|
963
975
|
* @experimental
|
|
964
976
|
*/
|
|
965
|
-
declare function unrequired<T>(schema:
|
|
977
|
+
declare function unrequired<T extends ArgSchema>(schema: T): Omit<T, 'required'> & CombinatorUnrequired;
|
|
966
978
|
/**
|
|
967
979
|
* Recursively merge a tuple of {@link Args} types.
|
|
968
980
|
* Later types override earlier ones on key conflicts.
|
package/lib/index.js
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/combinators.js
|
|
2
2
|
/**
|
|
3
3
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
4
4
|
* @license MIT
|
|
@@ -179,7 +179,8 @@ function positional(parser) {
|
|
|
179
179
|
parse: parser.parse,
|
|
180
180
|
metavar: parser.metavar,
|
|
181
181
|
...parser.description != null ? { description: parser.description } : {},
|
|
182
|
-
...parser.required != null ? { required: parser.required } : {}
|
|
182
|
+
...parser.required != null ? { required: parser.required } : {},
|
|
183
|
+
...parser.default != null ? { default: parser.default } : {}
|
|
183
184
|
};
|
|
184
185
|
const opts = parser;
|
|
185
186
|
return {
|
|
@@ -437,10 +438,11 @@ function describe(schema, text) {
|
|
|
437
438
|
/**
|
|
438
439
|
* Mark a combinator schema as not required.
|
|
439
440
|
*
|
|
440
|
-
* Useful for overriding a base combinator that was created with `required: true
|
|
441
|
+
* Useful for overriding a base combinator that was created with `required: true`,
|
|
442
|
+
* or for making a positional argument explicitly optional.
|
|
441
443
|
* The original schema is not modified.
|
|
442
444
|
*
|
|
443
|
-
* @typeParam T - The schema
|
|
445
|
+
* @typeParam T - The schema type.
|
|
444
446
|
*
|
|
445
447
|
* @param schema - The base combinator schema.
|
|
446
448
|
* @returns A new schema with `required: false`.
|
|
@@ -448,7 +450,8 @@ function describe(schema, text) {
|
|
|
448
450
|
* @example
|
|
449
451
|
* ```ts
|
|
450
452
|
* const args = {
|
|
451
|
-
* name: unrequired(string({ required: true }))
|
|
453
|
+
* name: unrequired(string({ required: true })),
|
|
454
|
+
* query: unrequired(positional())
|
|
452
455
|
* }
|
|
453
456
|
* ```
|
|
454
457
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/combinators",
|
|
3
3
|
"description": "parser combinators for gunshi argument schema",
|
|
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",
|