@gunshi/combinators 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 CHANGED
@@ -1,11 +1,11 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/resolver.d.ts
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 `description` properties
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,13 +110,35 @@ 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
  *
116
135
  * When `true`, the argument must be provided by the user.
117
136
  * If missing, an `ArgResolveError` with type 'required' will be thrown.
118
137
  *
119
- * Note: Only `true` is allowed (not `false`) to make intent explicit.
138
+ * For single-value positional arguments, omitting `required` keeps the argument
139
+ * required for compatibility. Set `required: false` to make a positional argument
140
+ * optional. Optional positional arguments leave enough input values for later
141
+ * required positional arguments before consuming a value.
120
142
  *
121
143
  * @example
122
144
  * Required arguments:
@@ -140,7 +162,8 @@ interface ArgSchema {
140
162
  *
141
163
  * When `true`, the resolved value becomes an array.
142
164
  * For options: can be specified multiple times (--tag foo --tag bar)
143
- * For positional: collects remaining positional arguments
165
+ * For positional: collects remaining positional arguments after preserving values for
166
+ * later required positional arguments.
144
167
  *
145
168
  * Note: Only `true` is allowed (not `false`) to make intent explicit.
146
169
  *
@@ -220,7 +243,11 @@ interface ArgSchema {
220
243
  * - `boolean` type: boolean default
221
244
  * - `number` type: number default
222
245
  * - `enum` type: must be one of the `choices` values
223
- * - `positional`/`custom` type: any appropriate default
246
+ * - `positional`/`custom` type: string, boolean, or number default
247
+ *
248
+ * For single-value positional arguments, the default is used when the positional
249
+ * value is missing or when the value is preserved for later required positional
250
+ * arguments, unless `required: true` is set.
224
251
  *
225
252
  * @example
226
253
  * Default values by type:
@@ -439,7 +466,7 @@ interface Args {
439
466
  * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
440
467
  */
441
468
  //#endregion
442
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/combinators.d.ts
469
+ //#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/combinators.d.ts
443
470
  //#region src/combinators.d.ts
444
471
  /**
445
472
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -480,6 +507,10 @@ interface BaseOptions {
480
507
  * Human-readable description for help text generation.
481
508
  */
482
509
  description?: string;
510
+ /**
511
+ * Hide from generated help or usage output.
512
+ */
513
+ hidden?: boolean;
483
514
  /**
484
515
  * Single character short alias.
485
516
  */
@@ -676,6 +707,7 @@ type ArgSchemaPositionalType = {
676
707
  * const args = {
677
708
  * command: positional(), // resolves to string
678
709
  * port: positional(integer()), // resolves to number
710
+ * query: unrequired(positional()) // optional positional
679
711
  * }
680
712
  * ```
681
713
  *
@@ -696,6 +728,7 @@ declare function positional<T>(parser: CombinatorSchema<T>): CombinatorSchema<T>
696
728
  * const args = {
697
729
  * command: positional(), // resolves to string
698
730
  * port: positional(integer()), // resolves to number
731
+ * query: unrequired(positional()) // optional positional
699
732
  * }
700
733
  * ```
701
734
  *
@@ -936,6 +969,33 @@ type CombinatorDescribe<D extends string> = {
936
969
  * @experimental
937
970
  */
938
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;
939
999
  /**
940
1000
  * Options for the {@link unrequired} combinator.
941
1001
  */
@@ -945,10 +1005,11 @@ type CombinatorUnrequired = {
945
1005
  /**
946
1006
  * Mark a combinator schema as not required.
947
1007
  *
948
- * Useful for overriding a base combinator that was created with `required: true`.
1008
+ * Useful for overriding a base combinator that was created with `required: true`,
1009
+ * or for making a positional argument explicitly optional.
949
1010
  * The original schema is not modified.
950
1011
  *
951
- * @typeParam T - The schema's parsed type.
1012
+ * @typeParam T - The schema type.
952
1013
  *
953
1014
  * @param schema - The base combinator schema.
954
1015
  * @returns A new schema with `required: false`.
@@ -956,13 +1017,14 @@ type CombinatorUnrequired = {
956
1017
  * @example
957
1018
  * ```ts
958
1019
  * const args = {
959
- * name: unrequired(string({ required: true }))
1020
+ * name: unrequired(string({ required: true })),
1021
+ * query: unrequired(positional())
960
1022
  * }
961
1023
  * ```
962
1024
  *
963
1025
  * @experimental
964
1026
  */
965
- declare function unrequired<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorUnrequired;
1027
+ declare function unrequired<T extends ArgSchema>(schema: T): Omit<T, 'required'> & CombinatorUnrequired;
966
1028
  /**
967
1029
  * Recursively merge a tuple of {@link Args} types.
968
1030
  * Later types override earlier ones on key conflicts.
@@ -1077,4 +1139,4 @@ declare function extend<T extends Args, U extends Args>(base: T, overrides: U):
1077
1139
  */
1078
1140
 
1079
1141
  //#endregion
1080
- 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.25.0/node_modules/args-tokens/lib/combinators.js
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
- /* @__NO_SIDE_EFFECTS__ */
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
- /* @__NO_SIDE_EFFECTS__ */
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
- /* @__NO_SIDE_EFFECTS__ */
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
- /* @__NO_SIDE_EFFECTS__ */
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
- /* @__NO_SIDE_EFFECTS__ */
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,19 +177,22 @@ function boolean(opts) {
172
177
  }
173
178
  };
174
179
  }
175
- /* @__NO_SIDE_EFFECTS__ */
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 } : {},
182
- ...parser.required != null ? { required: parser.required } : {}
187
+ ...parser.hidden != null ? { hidden: parser.hidden } : {},
188
+ ...parser.required != null ? { required: parser.required } : {},
189
+ ...parser.default != null ? { default: parser.default } : {}
183
190
  };
184
191
  const opts = parser;
185
192
  return {
186
193
  type: "positional",
187
194
  ...opts?.description != null ? { description: opts.description } : {},
195
+ ...opts?.hidden != null ? { hidden: opts.hidden } : {},
188
196
  ...opts?.short != null ? { short: opts.short } : {},
189
197
  ...opts?.required != null ? { required: opts.required } : {}
190
198
  };
@@ -210,13 +218,14 @@ function positional(parser) {
210
218
  *
211
219
  * @experimental
212
220
  */
213
- /* @__NO_SIDE_EFFECTS__ */
221
+ // @__NO_SIDE_EFFECTS__
214
222
  function choice(values, opts) {
215
223
  return {
216
224
  type: "enum",
217
225
  metavar: values.join("|"),
218
226
  choices: values,
219
227
  ...opts?.description != null ? { description: opts.description } : {},
228
+ ...opts?.hidden != null ? { hidden: opts.hidden } : {},
220
229
  ...opts?.short != null ? { short: opts.short } : {},
221
230
  ...opts?.required != null ? { required: opts.required } : {},
222
231
  parse(value) {
@@ -255,12 +264,13 @@ function choice(values, opts) {
255
264
  *
256
265
  * @experimental
257
266
  */
258
- /* @__NO_SIDE_EFFECTS__ */
267
+ // @__NO_SIDE_EFFECTS__
259
268
  function combinator(config) {
260
269
  return {
261
270
  type: "custom",
262
271
  metavar: config.metavar ?? "custom",
263
272
  ...config.description != null ? { description: config.description } : {},
273
+ ...config.hidden != null ? { hidden: config.hidden } : {},
264
274
  ...config.short != null ? { short: config.short } : {},
265
275
  ...config.required != null ? { required: config.required } : {},
266
276
  parse: config.parse
@@ -288,7 +298,7 @@ function combinator(config) {
288
298
  *
289
299
  * @experimental
290
300
  */
291
- /* @__NO_SIDE_EFFECTS__ */
301
+ // @__NO_SIDE_EFFECTS__
292
302
  function map(schema, transform) {
293
303
  const baseParse = schema.parse;
294
304
  return {
@@ -318,7 +328,7 @@ function map(schema, transform) {
318
328
  *
319
329
  * @experimental
320
330
  */
321
- /* @__NO_SIDE_EFFECTS__ */
331
+ // @__NO_SIDE_EFFECTS__
322
332
  function withDefault(schema, defaultValue) {
323
333
  return {
324
334
  ...schema,
@@ -344,7 +354,7 @@ function withDefault(schema, defaultValue) {
344
354
  *
345
355
  * @experimental
346
356
  */
347
- /* @__NO_SIDE_EFFECTS__ */
357
+ // @__NO_SIDE_EFFECTS__
348
358
  function multiple(schema) {
349
359
  return {
350
360
  ...schema,
@@ -370,7 +380,7 @@ function multiple(schema) {
370
380
  *
371
381
  * @experimental
372
382
  */
373
- /* @__NO_SIDE_EFFECTS__ */
383
+ // @__NO_SIDE_EFFECTS__
374
384
  function required(schema) {
375
385
  return {
376
386
  ...schema,
@@ -399,7 +409,7 @@ function required(schema) {
399
409
  *
400
410
  * @experimental
401
411
  */
402
- /* @__NO_SIDE_EFFECTS__ */
412
+ // @__NO_SIDE_EFFECTS__
403
413
  function short(schema, alias) {
404
414
  return {
405
415
  ...schema,
@@ -427,7 +437,7 @@ function short(schema, alias) {
427
437
  *
428
438
  * @experimental
429
439
  */
430
- /* @__NO_SIDE_EFFECTS__ */
440
+ // @__NO_SIDE_EFFECTS__
431
441
  function describe(schema, text) {
432
442
  return {
433
443
  ...schema,
@@ -435,12 +445,40 @@ function describe(schema, text) {
435
445
  };
436
446
  }
437
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
+ /**
438
475
  * Mark a combinator schema as not required.
439
476
  *
440
- * Useful for overriding a base combinator that was created with `required: true`.
477
+ * Useful for overriding a base combinator that was created with `required: true`,
478
+ * or for making a positional argument explicitly optional.
441
479
  * The original schema is not modified.
442
480
  *
443
- * @typeParam T - The schema's parsed type.
481
+ * @typeParam T - The schema type.
444
482
  *
445
483
  * @param schema - The base combinator schema.
446
484
  * @returns A new schema with `required: false`.
@@ -448,13 +486,14 @@ function describe(schema, text) {
448
486
  * @example
449
487
  * ```ts
450
488
  * const args = {
451
- * name: unrequired(string({ required: true }))
489
+ * name: unrequired(string({ required: true })),
490
+ * query: unrequired(positional())
452
491
  * }
453
492
  * ```
454
493
  *
455
494
  * @experimental
456
495
  */
457
- /* @__NO_SIDE_EFFECTS__ */
496
+ // @__NO_SIDE_EFFECTS__
458
497
  function unrequired(schema) {
459
498
  return {
460
499
  ...schema,
@@ -482,11 +521,11 @@ function unrequired(schema) {
482
521
  *
483
522
  * @experimental
484
523
  */
485
- /* @__NO_SIDE_EFFECTS__ */
524
+ // @__NO_SIDE_EFFECTS__
486
525
  function args(fields) {
487
526
  return fields;
488
527
  }
489
- /* @__NO_SIDE_EFFECTS__ */
528
+ // @__NO_SIDE_EFFECTS__
490
529
  function merge(...schemas) {
491
530
  const result = Object.create(null);
492
531
  for (const schema of schemas) for (const key of Object.keys(schema)) result[key] = schema[key];
@@ -513,7 +552,7 @@ function merge(...schemas) {
513
552
  *
514
553
  * @experimental
515
554
  */
516
- /* @__NO_SIDE_EFFECTS__ */
555
+ // @__NO_SIDE_EFFECTS__
517
556
  function extend(base, overrides) {
518
557
  const result = Object.create(null);
519
558
  for (const key of Object.keys(base)) result[key] = base[key];
@@ -527,4 +566,4 @@ function extend(base, overrides) {
527
566
  * @license MIT
528
567
  */
529
568
  //#endregion
530
- 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.33.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.33.0"
60
+ "gunshi": "0.35.0"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsdown",