@gunshi/combinators 0.34.0 → 0.35.1
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 +54 -4
- package/lib/index.js +56 -20
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/resolver.d.ts
|
|
2
2
|
|
|
3
3
|
//#region src/resolver.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* An argument schema definition for command-line argument parsing.
|
|
6
6
|
*
|
|
7
7
|
* This schema is similar to the schema of Node.js `util.parseArgs` but with extended features:
|
|
8
|
-
* - Additional `required` and `
|
|
8
|
+
* - Additional `required`, `description`, and `hidden` properties
|
|
9
9
|
* - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom'
|
|
10
10
|
* - Simplified `default` property (single type, not union types)
|
|
11
11
|
*
|
|
@@ -110,6 +110,25 @@ interface ArgSchema {
|
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
112
|
description?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Hide the argument from generated help or usage output.
|
|
115
|
+
*
|
|
116
|
+
* This is metadata for renderers. It does not affect parsing, validation,
|
|
117
|
+
* required checks, defaults, conflicts, or resolved values.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* Hidden compatibility option:
|
|
121
|
+
* ```ts
|
|
122
|
+
* {
|
|
123
|
+
* legacy: {
|
|
124
|
+
* type: 'string',
|
|
125
|
+
* hidden: true,
|
|
126
|
+
* description: 'Deprecated compatibility option'
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
hidden?: boolean;
|
|
113
132
|
/**
|
|
114
133
|
* Marks the argument as required.
|
|
115
134
|
*
|
|
@@ -447,7 +466,7 @@ interface Args {
|
|
|
447
466
|
* @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
|
|
448
467
|
*/
|
|
449
468
|
//#endregion
|
|
450
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
469
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/combinators.d.ts
|
|
451
470
|
//#region src/combinators.d.ts
|
|
452
471
|
/**
|
|
453
472
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -488,6 +507,10 @@ interface BaseOptions {
|
|
|
488
507
|
* Human-readable description for help text generation.
|
|
489
508
|
*/
|
|
490
509
|
description?: string;
|
|
510
|
+
/**
|
|
511
|
+
* Hide from generated help or usage output.
|
|
512
|
+
*/
|
|
513
|
+
hidden?: boolean;
|
|
491
514
|
/**
|
|
492
515
|
* Single character short alias.
|
|
493
516
|
*/
|
|
@@ -946,6 +969,33 @@ type CombinatorDescribe<D extends string> = {
|
|
|
946
969
|
* @experimental
|
|
947
970
|
*/
|
|
948
971
|
declare function describe<T, D extends string>(schema: CombinatorSchema<T>, text: D): CombinatorSchema<T> & CombinatorDescribe<D>;
|
|
972
|
+
/**
|
|
973
|
+
* Options for the {@link hidden} combinator.
|
|
974
|
+
*/
|
|
975
|
+
type CombinatorHidden = {
|
|
976
|
+
hidden: true;
|
|
977
|
+
};
|
|
978
|
+
/**
|
|
979
|
+
* Hide a combinator schema from generated help or usage output.
|
|
980
|
+
*
|
|
981
|
+
* The original schema is not modified. This only marks renderer metadata and
|
|
982
|
+
* does not change parsing, validation, defaults, conflicts, or resolved values.
|
|
983
|
+
*
|
|
984
|
+
* @typeParam T - The schema type.
|
|
985
|
+
*
|
|
986
|
+
* @param schema - The base combinator schema.
|
|
987
|
+
* @returns A new schema with `hidden: true`.
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```ts
|
|
991
|
+
* const args = {
|
|
992
|
+
* legacy: hidden(string())
|
|
993
|
+
* }
|
|
994
|
+
* ```
|
|
995
|
+
*
|
|
996
|
+
* @experimental
|
|
997
|
+
*/
|
|
998
|
+
declare function hidden<T extends ArgSchema>(schema: T): Omit<T, 'hidden'> & CombinatorHidden;
|
|
949
999
|
/**
|
|
950
1000
|
* Options for the {@link unrequired} combinator.
|
|
951
1001
|
*/
|
|
@@ -1089,4 +1139,4 @@ declare function extend<T extends Args, U extends Args>(base: T, overrides: U):
|
|
|
1089
1139
|
*/
|
|
1090
1140
|
|
|
1091
1141
|
//#endregion
|
|
1092
|
-
export { BaseOptions, BooleanOptions, Combinator, CombinatorOptions, CombinatorSchema, FloatOptions, IntegerOptions, NumberOptions, StringOptions, args, boolean, choice, combinator, describe, extend, float, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
|
1142
|
+
export { BaseOptions, BooleanOptions, Combinator, CombinatorOptions, CombinatorSchema, FloatOptions, IntegerOptions, NumberOptions, StringOptions, args, boolean, choice, combinator, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
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.27.0/node_modules/args-tokens/lib/combinators.js
|
|
2
2
|
/**
|
|
3
3
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
4
4
|
* @license MIT
|
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
*
|
|
19
19
|
* @experimental
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
// @__NO_SIDE_EFFECTS__
|
|
22
22
|
function string(opts) {
|
|
23
23
|
return {
|
|
24
24
|
type: "string",
|
|
25
25
|
metavar: "string",
|
|
26
26
|
...opts?.description != null ? { description: opts.description } : {},
|
|
27
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
27
28
|
...opts?.short != null ? { short: opts.short } : {},
|
|
28
29
|
...opts?.required != null ? { required: opts.required } : {},
|
|
29
30
|
parse(value) {
|
|
@@ -51,12 +52,13 @@ function string(opts) {
|
|
|
51
52
|
*
|
|
52
53
|
* @experimental
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
+
// @__NO_SIDE_EFFECTS__
|
|
55
56
|
function number(opts) {
|
|
56
57
|
return {
|
|
57
58
|
type: "number",
|
|
58
59
|
metavar: "number",
|
|
59
60
|
...opts?.description != null ? { description: opts.description } : {},
|
|
61
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
60
62
|
...opts?.short != null ? { short: opts.short } : {},
|
|
61
63
|
...opts?.required != null ? { required: opts.required } : {},
|
|
62
64
|
parse(value) {
|
|
@@ -85,12 +87,13 @@ function number(opts) {
|
|
|
85
87
|
*
|
|
86
88
|
* @experimental
|
|
87
89
|
*/
|
|
88
|
-
|
|
90
|
+
// @__NO_SIDE_EFFECTS__
|
|
89
91
|
function integer(opts) {
|
|
90
92
|
return {
|
|
91
93
|
type: "custom",
|
|
92
94
|
metavar: "integer",
|
|
93
95
|
...opts?.description != null ? { description: opts.description } : {},
|
|
96
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
94
97
|
...opts?.short != null ? { short: opts.short } : {},
|
|
95
98
|
...opts?.required != null ? { required: opts.required } : {},
|
|
96
99
|
parse(value) {
|
|
@@ -120,12 +123,13 @@ function integer(opts) {
|
|
|
120
123
|
*
|
|
121
124
|
* @experimental
|
|
122
125
|
*/
|
|
123
|
-
|
|
126
|
+
// @__NO_SIDE_EFFECTS__
|
|
124
127
|
function float(opts) {
|
|
125
128
|
return {
|
|
126
129
|
type: "custom",
|
|
127
130
|
metavar: "float",
|
|
128
131
|
...opts?.description != null ? { description: opts.description } : {},
|
|
132
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
129
133
|
...opts?.short != null ? { short: opts.short } : {},
|
|
130
134
|
...opts?.required != null ? { required: opts.required } : {},
|
|
131
135
|
parse(value) {
|
|
@@ -158,13 +162,14 @@ function float(opts) {
|
|
|
158
162
|
*
|
|
159
163
|
* @experimental
|
|
160
164
|
*/
|
|
161
|
-
|
|
165
|
+
// @__NO_SIDE_EFFECTS__
|
|
162
166
|
function boolean(opts) {
|
|
163
167
|
return {
|
|
164
168
|
type: "boolean",
|
|
165
169
|
...opts?.negatable != null ? { negatable: opts.negatable } : {},
|
|
166
170
|
metavar: "boolean",
|
|
167
171
|
...opts?.description != null ? { description: opts.description } : {},
|
|
172
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
168
173
|
...opts?.short != null ? { short: opts.short } : {},
|
|
169
174
|
...opts?.required != null ? { required: opts.required } : {},
|
|
170
175
|
parse(value) {
|
|
@@ -172,13 +177,14 @@ function boolean(opts) {
|
|
|
172
177
|
}
|
|
173
178
|
};
|
|
174
179
|
}
|
|
175
|
-
|
|
180
|
+
// @__NO_SIDE_EFFECTS__
|
|
176
181
|
function positional(parser) {
|
|
177
182
|
if (parser && "parse" in parser) return {
|
|
178
183
|
type: "positional",
|
|
179
184
|
parse: parser.parse,
|
|
180
185
|
metavar: parser.metavar,
|
|
181
186
|
...parser.description != null ? { description: parser.description } : {},
|
|
187
|
+
...parser.hidden != null ? { hidden: parser.hidden } : {},
|
|
182
188
|
...parser.required != null ? { required: parser.required } : {},
|
|
183
189
|
...parser.default != null ? { default: parser.default } : {}
|
|
184
190
|
};
|
|
@@ -186,6 +192,7 @@ function positional(parser) {
|
|
|
186
192
|
return {
|
|
187
193
|
type: "positional",
|
|
188
194
|
...opts?.description != null ? { description: opts.description } : {},
|
|
195
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
189
196
|
...opts?.short != null ? { short: opts.short } : {},
|
|
190
197
|
...opts?.required != null ? { required: opts.required } : {}
|
|
191
198
|
};
|
|
@@ -211,13 +218,14 @@ function positional(parser) {
|
|
|
211
218
|
*
|
|
212
219
|
* @experimental
|
|
213
220
|
*/
|
|
214
|
-
|
|
221
|
+
// @__NO_SIDE_EFFECTS__
|
|
215
222
|
function choice(values, opts) {
|
|
216
223
|
return {
|
|
217
224
|
type: "enum",
|
|
218
225
|
metavar: values.join("|"),
|
|
219
226
|
choices: values,
|
|
220
227
|
...opts?.description != null ? { description: opts.description } : {},
|
|
228
|
+
...opts?.hidden != null ? { hidden: opts.hidden } : {},
|
|
221
229
|
...opts?.short != null ? { short: opts.short } : {},
|
|
222
230
|
...opts?.required != null ? { required: opts.required } : {},
|
|
223
231
|
parse(value) {
|
|
@@ -256,12 +264,13 @@ function choice(values, opts) {
|
|
|
256
264
|
*
|
|
257
265
|
* @experimental
|
|
258
266
|
*/
|
|
259
|
-
|
|
267
|
+
// @__NO_SIDE_EFFECTS__
|
|
260
268
|
function combinator(config) {
|
|
261
269
|
return {
|
|
262
270
|
type: "custom",
|
|
263
271
|
metavar: config.metavar ?? "custom",
|
|
264
272
|
...config.description != null ? { description: config.description } : {},
|
|
273
|
+
...config.hidden != null ? { hidden: config.hidden } : {},
|
|
265
274
|
...config.short != null ? { short: config.short } : {},
|
|
266
275
|
...config.required != null ? { required: config.required } : {},
|
|
267
276
|
parse: config.parse
|
|
@@ -289,7 +298,7 @@ function combinator(config) {
|
|
|
289
298
|
*
|
|
290
299
|
* @experimental
|
|
291
300
|
*/
|
|
292
|
-
|
|
301
|
+
// @__NO_SIDE_EFFECTS__
|
|
293
302
|
function map(schema, transform) {
|
|
294
303
|
const baseParse = schema.parse;
|
|
295
304
|
return {
|
|
@@ -319,7 +328,7 @@ function map(schema, transform) {
|
|
|
319
328
|
*
|
|
320
329
|
* @experimental
|
|
321
330
|
*/
|
|
322
|
-
|
|
331
|
+
// @__NO_SIDE_EFFECTS__
|
|
323
332
|
function withDefault(schema, defaultValue) {
|
|
324
333
|
return {
|
|
325
334
|
...schema,
|
|
@@ -345,7 +354,7 @@ function withDefault(schema, defaultValue) {
|
|
|
345
354
|
*
|
|
346
355
|
* @experimental
|
|
347
356
|
*/
|
|
348
|
-
|
|
357
|
+
// @__NO_SIDE_EFFECTS__
|
|
349
358
|
function multiple(schema) {
|
|
350
359
|
return {
|
|
351
360
|
...schema,
|
|
@@ -371,7 +380,7 @@ function multiple(schema) {
|
|
|
371
380
|
*
|
|
372
381
|
* @experimental
|
|
373
382
|
*/
|
|
374
|
-
|
|
383
|
+
// @__NO_SIDE_EFFECTS__
|
|
375
384
|
function required(schema) {
|
|
376
385
|
return {
|
|
377
386
|
...schema,
|
|
@@ -400,7 +409,7 @@ function required(schema) {
|
|
|
400
409
|
*
|
|
401
410
|
* @experimental
|
|
402
411
|
*/
|
|
403
|
-
|
|
412
|
+
// @__NO_SIDE_EFFECTS__
|
|
404
413
|
function short(schema, alias) {
|
|
405
414
|
return {
|
|
406
415
|
...schema,
|
|
@@ -428,7 +437,7 @@ function short(schema, alias) {
|
|
|
428
437
|
*
|
|
429
438
|
* @experimental
|
|
430
439
|
*/
|
|
431
|
-
|
|
440
|
+
// @__NO_SIDE_EFFECTS__
|
|
432
441
|
function describe(schema, text) {
|
|
433
442
|
return {
|
|
434
443
|
...schema,
|
|
@@ -436,6 +445,33 @@ function describe(schema, text) {
|
|
|
436
445
|
};
|
|
437
446
|
}
|
|
438
447
|
/**
|
|
448
|
+
* Hide a combinator schema from generated help or usage output.
|
|
449
|
+
*
|
|
450
|
+
* The original schema is not modified. This only marks renderer metadata and
|
|
451
|
+
* does not change parsing, validation, defaults, conflicts, or resolved values.
|
|
452
|
+
*
|
|
453
|
+
* @typeParam T - The schema type.
|
|
454
|
+
*
|
|
455
|
+
* @param schema - The base combinator schema.
|
|
456
|
+
* @returns A new schema with `hidden: true`.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* const args = {
|
|
461
|
+
* legacy: hidden(string())
|
|
462
|
+
* }
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* @experimental
|
|
466
|
+
*/
|
|
467
|
+
// @__NO_SIDE_EFFECTS__
|
|
468
|
+
function hidden(schema) {
|
|
469
|
+
return {
|
|
470
|
+
...schema,
|
|
471
|
+
hidden: true
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
439
475
|
* Mark a combinator schema as not required.
|
|
440
476
|
*
|
|
441
477
|
* Useful for overriding a base combinator that was created with `required: true`,
|
|
@@ -457,7 +493,7 @@ function describe(schema, text) {
|
|
|
457
493
|
*
|
|
458
494
|
* @experimental
|
|
459
495
|
*/
|
|
460
|
-
|
|
496
|
+
// @__NO_SIDE_EFFECTS__
|
|
461
497
|
function unrequired(schema) {
|
|
462
498
|
return {
|
|
463
499
|
...schema,
|
|
@@ -485,11 +521,11 @@ function unrequired(schema) {
|
|
|
485
521
|
*
|
|
486
522
|
* @experimental
|
|
487
523
|
*/
|
|
488
|
-
|
|
524
|
+
// @__NO_SIDE_EFFECTS__
|
|
489
525
|
function args(fields) {
|
|
490
526
|
return fields;
|
|
491
527
|
}
|
|
492
|
-
|
|
528
|
+
// @__NO_SIDE_EFFECTS__
|
|
493
529
|
function merge(...schemas) {
|
|
494
530
|
const result = Object.create(null);
|
|
495
531
|
for (const schema of schemas) for (const key of Object.keys(schema)) result[key] = schema[key];
|
|
@@ -516,7 +552,7 @@ function merge(...schemas) {
|
|
|
516
552
|
*
|
|
517
553
|
* @experimental
|
|
518
554
|
*/
|
|
519
|
-
|
|
555
|
+
// @__NO_SIDE_EFFECTS__
|
|
520
556
|
function extend(base, overrides) {
|
|
521
557
|
const result = Object.create(null);
|
|
522
558
|
for (const key of Object.keys(base)) result[key] = base[key];
|
|
@@ -530,4 +566,4 @@ function extend(base, overrides) {
|
|
|
530
566
|
* @license MIT
|
|
531
567
|
*/
|
|
532
568
|
//#endregion
|
|
533
|
-
export { args, boolean, choice, combinator, describe, extend, float, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
|
569
|
+
export { args, boolean, choice, combinator, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
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.35.1",
|
|
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.1"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|