gunshi 0.33.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/bone.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-CIPNDx1a.js";
2
- import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
2
+ import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
3
3
 
4
4
  //#region src/cli/bone.d.ts
5
5
  /**
package/lib/bone.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cliCore } from "./core-BKtZQ6dG.js";
1
+ import { t as cliCore } from "./core-C83Uo6wC.js";
2
2
  //#region src/cli/bone.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,6 +1,6 @@
1
1
  import { t as plugin } from "./core-D1daCTTE.js";
2
- import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-dTYUlEw_.js";
3
- import { t as cliCore } from "./core-BKtZQ6dG.js";
2
+ import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Cs21MA7o.js";
3
+ import { t as cliCore } from "./core-C83Uo6wC.js";
4
4
  //#region ../plugin-global/src/types.ts
5
5
  /**
6
6
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,6 +1,6 @@
1
- import { i as Args, n as ArgSchema } from "./resolver-CIPNDx1a.js";
1
+ import { i as Args, n as ArgSchema } from "./resolver-eOZBRWlR.js";
2
2
 
3
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/combinators.d.ts
3
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/combinators.d.ts
4
4
  /**
5
5
  * @author kazuya kawaguchi (a.k.a. kazupon)
6
6
  * @license MIT
@@ -242,6 +242,7 @@ type ArgSchemaPositionalType = {
242
242
  * const args = {
243
243
  * command: positional(), // resolves to string
244
244
  * port: positional(integer()), // resolves to number
245
+ * query: unrequired(positional()) // optional positional
245
246
  * }
246
247
  * ```
247
248
  *
@@ -262,6 +263,7 @@ declare function positional<T>(parser: CombinatorSchema<T>): CombinatorSchema<T>
262
263
  * const args = {
263
264
  * command: positional(), // resolves to string
264
265
  * port: positional(integer()), // resolves to number
266
+ * query: unrequired(positional()) // optional positional
265
267
  * }
266
268
  * ```
267
269
  *
@@ -511,10 +513,11 @@ type CombinatorUnrequired = {
511
513
  /**
512
514
  * Mark a combinator schema as not required.
513
515
  *
514
- * Useful for overriding a base combinator that was created with `required: true`.
516
+ * Useful for overriding a base combinator that was created with `required: true`,
517
+ * or for making a positional argument explicitly optional.
515
518
  * The original schema is not modified.
516
519
  *
517
- * @typeParam T - The schema's parsed type.
520
+ * @typeParam T - The schema type.
518
521
  *
519
522
  * @param schema - The base combinator schema.
520
523
  * @returns A new schema with `required: false`.
@@ -522,13 +525,14 @@ type CombinatorUnrequired = {
522
525
  * @example
523
526
  * ```ts
524
527
  * const args = {
525
- * name: unrequired(string({ required: true }))
528
+ * name: unrequired(string({ required: true })),
529
+ * query: unrequired(positional())
526
530
  * }
527
531
  * ```
528
532
  *
529
533
  * @experimental
530
534
  */
531
- declare function unrequired<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorUnrequired;
535
+ declare function unrequired<T extends ArgSchema>(schema: T): Omit<T, 'required'> & CombinatorUnrequired;
532
536
  /**
533
537
  * Recursively merge a tuple of {@link Args} types.
534
538
  * Later types override earlier ones on key conflicts.
@@ -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.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's parsed type.
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
  *
@@ -1,4 +1,4 @@
1
- import { m as DefaultGunshiParams, n as CliOptions } from "./types-CUdYQC8F.js";
1
+ import { m as DefaultGunshiParams, n as CliOptions } from "./types-DZ8CuO6z.js";
2
2
 
3
3
  //#region src/constants.d.ts
4
4
  /**
package/lib/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as Args, o as ArgToken, r as ArgValues } from "./resolver-CIPNDx1a.js";
2
- import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, m as DefaultGunshiParams, n as CliOptions, r as Command, s as CommandContextExtension, x as LazyCommand, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { i as Args, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
2
+ import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, m as DefaultGunshiParams, n as CliOptions, r as Command, s as CommandContextExtension, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
3
3
 
4
4
  //#region src/context.d.ts
5
5
 
package/lib/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as CLI_OPTIONS_DEFAULT, r as NOOP, t as ANONYMOUS_COMMAND_NAME } from "./constants-D_ixLD32.js";
2
- import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-jNy8sqR5.js";
2
+ import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-9CtzCGbg.js";
3
3
  //#region src/context.ts
4
4
  /**
5
5
  * The entry for gunshi context.
@@ -1,7 +1,7 @@
1
1
  import { n as CLI_OPTIONS_DEFAULT, r as NOOP } from "./constants-D_ixLD32.js";
2
- import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-jNy8sqR5.js";
2
+ import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-9CtzCGbg.js";
3
3
  import { createCommandContext } from "./context.js";
4
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/parser.js
4
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/parser.js
5
5
  /**
6
6
  * forked from `nodejs/node` (`pkgjs/parseargs`)
7
7
  * repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
@@ -206,7 +206,7 @@ function hasOptionValue(value) {
206
206
  return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
207
207
  }
208
208
  //#endregion
209
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/resolver.js
209
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/resolver.js
210
210
  /**
211
211
  * Entry point of argument options resolver.
212
212
  *
@@ -349,6 +349,8 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
349
349
  const errors = [];
350
350
  const explicit = Object.create(null);
351
351
  const actualInputNames = /* @__PURE__ */ new Map();
352
+ const argEntries = Object.entries(args);
353
+ let requiredPositionalsAfter;
352
354
  function checkTokenName(option, schema, token) {
353
355
  return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
354
356
  }
@@ -356,14 +358,21 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
356
358
  function getPositionalSkipIndex() {
357
359
  return Math.min(skipPositionalIndex, positionalItemCount);
358
360
  }
361
+ function getRequiredPositionalsAfter(rawArg) {
362
+ requiredPositionalsAfter ??= createRequiredPositionalsAfter(argEntries);
363
+ return requiredPositionalsAfter[rawArg] ?? 0;
364
+ }
359
365
  let positionalsCount = 0;
360
- for (const [rawArg, schema] of Object.entries(args)) {
366
+ for (const [rawArg, schema] of argEntries) {
361
367
  const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
362
368
  explicit[rawArg] = false;
363
369
  if (schema.type === "positional") {
364
370
  if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
371
+ const requiredPositionals = getRequiredPositionalsAfter(rawArg);
372
+ const availablePositionals = Math.max(positionalTokens.length - positionalsCount, 0);
365
373
  if (schema.multiple) {
366
- const remainingPositionals = positionalTokens.slice(positionalsCount);
374
+ const positionalsToConsume = Math.max(availablePositionals - requiredPositionals, 0);
375
+ const remainingPositionals = positionalTokens.slice(positionalsCount, positionalsCount + positionalsToConsume);
367
376
  if (remainingPositionals.length > 0) {
368
377
  if (typeof schema.parse === "function") {
369
378
  const parsed = [];
@@ -379,7 +388,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
379
388
  } else if (schema.required) errors.push(createRequireError(arg, schema));
380
389
  } else {
381
390
  const positional = positionalTokens[positionalsCount];
382
- if (positional != null) {
391
+ if (positional != null && (shouldRequireMissingSinglePositional(schema) || availablePositionals > requiredPositionals)) {
383
392
  if (typeof schema.parse === "function") try {
384
393
  values[rawArg] = schema.parse(positional.value);
385
394
  } catch (error) {
@@ -387,8 +396,9 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
387
396
  }
388
397
  else values[rawArg] = positional.value;
389
398
  explicit[rawArg] = true;
390
- } else errors.push(createRequireError(arg, schema));
391
- positionalsCount++;
399
+ positionalsCount++;
400
+ } else if (shouldRequireMissingSinglePositional(schema)) errors.push(createRequireError(arg, schema));
401
+ else if (hasDefault(schema)) values[rawArg] = schema.default;
392
402
  }
393
403
  continue;
394
404
  }
@@ -457,6 +467,30 @@ function parse(token, option, schema) {
457
467
  function createRequireError(option, schema) {
458
468
  return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
459
469
  }
470
+ function hasDefault(schema) {
471
+ return schema.default != null;
472
+ }
473
+ function shouldRequireMissingSinglePositional(schema) {
474
+ if (schema.required === true) return true;
475
+ if (schema.required === false) return false;
476
+ return !hasDefault(schema);
477
+ }
478
+ function getRequiredPositionalInputCount(schema) {
479
+ if (schema.type !== "positional") return 0;
480
+ if (schema.multiple) return schema.required === true ? 1 : 0;
481
+ return shouldRequireMissingSinglePositional(schema) ? 1 : 0;
482
+ }
483
+ function createRequiredPositionalsAfter(argEntries) {
484
+ const requiredPositionalsAfter = Object.create(null);
485
+ let minimumRequiredPositionals = 0;
486
+ for (let i = argEntries.length - 1; i >= 0; i--) {
487
+ const [rawArg, schema] = argEntries[i];
488
+ if (schema.type !== "positional") continue;
489
+ requiredPositionalsAfter[rawArg] = minimumRequiredPositionals;
490
+ minimumRequiredPositionals += getRequiredPositionalInputCount(schema);
491
+ }
492
+ return requiredPositionalsAfter;
493
+ }
460
494
  /**
461
495
  * An error that occurs when resolving arguments.
462
496
  * This error is thrown when the argument is not valid.
@@ -506,7 +540,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
506
540
  return [];
507
541
  }
508
542
  //#endregion
509
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/index.js
543
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/index.js
510
544
  /**
511
545
  * @author kazuya kawaguchi (a.k.a. kazupon)
512
546
  * @license MIT
@@ -1,5 +1,5 @@
1
- import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-CIPNDx1a.js";
2
- import { C as NormalizeToGunshiParams, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-eOZBRWlR.js";
2
+ import { C as NormalizeToGunshiParams, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
4
 
5
5
  //#region src/definition.d.ts
@@ -1,4 +1,4 @@
1
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-CUdYQC8F.js";
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-DZ8CuO6z.js";
2
2
 
3
3
  //#region src/generator.d.ts
4
4
 
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as create } from "./utils-jNy8sqR5.js";
2
- import { t as cli } from "./cli-DfaFk6tk.js";
1
+ import { t as create } from "./utils-9CtzCGbg.js";
2
+ import { t as cli } from "./cli-CS4q7S8l.js";
3
3
  //#region src/generator.ts
4
4
  /**
5
5
  * The entry for usage generator.
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { a as resolveArgs, i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, s as parseArgs } from "./resolver-CIPNDx1a.js";
2
- import { A as Plugin, C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, j as PluginDependency, k as OnPluginExtension, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { a as resolveArgs, i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, s as parseArgs } from "./resolver-eOZBRWlR.js";
2
+ import { A as Plugin, C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, j as PluginDependency, k as OnPluginExtension, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
4
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
5
- import { t as ANONYMOUS_COMMAND_NAME } from "./constants-XndHBbIz.js";
5
+ import { t as ANONYMOUS_COMMAND_NAME } from "./constants-Dmeogxy-.js";
6
6
 
7
7
  //#region ../plugin-i18n/src/types.d.ts
8
8
  /**
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { t as ANONYMOUS_COMMAND_NAME } from "./constants-D_ixLD32.js";
2
2
  import { createCommandContext } from "./context.js";
3
3
  import { t as plugin } from "./core-D1daCTTE.js";
4
- import { a as namespacedId } from "./src-dTYUlEw_.js";
5
- import { n as resolveArgs, r as parseArgs } from "./core-BKtZQ6dG.js";
6
- import { t as cli } from "./cli-DfaFk6tk.js";
4
+ import { a as namespacedId } from "./src-Cs21MA7o.js";
5
+ import { n as resolveArgs, r as parseArgs } from "./core-C83Uo6wC.js";
6
+ import { t as cli } from "./cli-CS4q7S8l.js";
7
7
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
8
8
  //#region ../plugin-i18n/src/translation.ts
9
9
  /**
package/lib/plugin.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-CIPNDx1a.js";
2
- import { A as Plugin, C as NormalizeToGunshiParams, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginDependency, k as OnPluginExtension, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
2
+ import { A as Plugin, C as NormalizeToGunshiParams, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginDependency, k as OnPluginExtension, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
- import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-XndHBbIz.js";
4
+ import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-Dmeogxy-.js";
5
5
 
6
6
  //#region src/plugin.d.ts
7
7
  /**
package/lib/renderer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-CUdYQC8F.js";
1
+ import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-DZ8CuO6z.js";
2
2
 
3
3
  //#region ../plugin-renderer/src/header.d.ts
4
4
  /**
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-dTYUlEw_.js";
1
+ import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-Cs21MA7o.js";
2
2
  //#region src/renderer.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/parser-D95CJBHr.d.ts
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.
@@ -88,7 +88,7 @@ declare function parseArgs(args: string[], options?: ParserOptions): ArgToken[];
88
88
  * @returns Whether `arg` is a short option.
89
89
  */
90
90
  //#endregion
91
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/resolver.d.ts
91
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/resolver.d.ts
92
92
  //#region src/resolver.d.ts
93
93
  /**
94
94
  * An argument schema definition for command-line argument parsing.
@@ -205,7 +205,10 @@ interface ArgSchema {
205
205
  * When `true`, the argument must be provided by the user.
206
206
  * If missing, an `ArgResolveError` with type 'required' will be thrown.
207
207
  *
208
- * Note: Only `true` is allowed (not `false`) to make intent explicit.
208
+ * For single-value positional arguments, omitting `required` keeps the argument
209
+ * required for compatibility. Set `required: false` to make a positional argument
210
+ * optional. Optional positional arguments leave enough input values for later
211
+ * required positional arguments before consuming a value.
209
212
  *
210
213
  * @example
211
214
  * Required arguments:
@@ -229,7 +232,8 @@ interface ArgSchema {
229
232
  *
230
233
  * When `true`, the resolved value becomes an array.
231
234
  * For options: can be specified multiple times (--tag foo --tag bar)
232
- * For positional: collects remaining positional arguments
235
+ * For positional: collects remaining positional arguments after preserving values for
236
+ * later required positional arguments.
233
237
  *
234
238
  * Note: Only `true` is allowed (not `false`) to make intent explicit.
235
239
  *
@@ -309,7 +313,11 @@ interface ArgSchema {
309
313
  * - `boolean` type: boolean default
310
314
  * - `number` type: number default
311
315
  * - `enum` type: must be one of the `choices` values
312
- * - `positional`/`custom` type: any appropriate default
316
+ * - `positional`/`custom` type: string, boolean, or number default
317
+ *
318
+ * For single-value positional arguments, the default is used when the positional
319
+ * value is missing or when the value is preserved for later required positional
320
+ * arguments, unless `required: true` is set.
313
321
  *
314
322
  * @example
315
323
  * Default values by type:
@@ -566,7 +574,8 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
566
574
  *
567
575
  * @internal
568
576
  */
569
- type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]['type'] extends 'positional' ? Arg : never]: V[Arg] };
577
+ 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] };
578
+ 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;
570
579
  /**
571
580
  * An arguments for {@link resolveArgs | resolve arguments}.
572
581
  */
@@ -1,5 +1,5 @@
1
1
  import "./constants-D_ixLD32.js";
2
- import { o as resolveLazyCommand, s as kebabnize } from "./utils-jNy8sqR5.js";
2
+ import { o as resolveLazyCommand, s as kebabnize } from "./utils-9CtzCGbg.js";
3
3
  import { t as plugin } from "./core-D1daCTTE.js";
4
4
  /**
5
5
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -494,11 +494,18 @@ async function generatePositionalArgsUsage(ctx) {
494
494
  function generatePositionalSymbols(args) {
495
495
  return hasPositionalArgs(args) ? getPositionalArgs(args).map(([name, arg]) => {
496
496
  const elements = [];
497
- if (!arg.multiple || arg.required) elements.push(`<${name}>`);
498
- if (arg.multiple) elements.push(`[<${name}> ...]`);
497
+ if (arg.multiple) {
498
+ if (arg.required) elements.push(`<${name}>`);
499
+ elements.push(`[<${name}> ...]`);
500
+ } else elements.push(isRequiredSinglePositionalArg(arg) ? `<${name}>` : `[<${name}>]`);
499
501
  return elements.join(" ");
500
502
  }).join(" ") : "";
501
503
  }
504
+ function isRequiredSinglePositionalArg(arg) {
505
+ if (arg.required === true) return true;
506
+ if (arg.required === false) return false;
507
+ return arg.default == null;
508
+ }
502
509
  //#endregion
503
510
  //#region ../plugin-renderer/src/validation.ts
504
511
  /**
@@ -1,4 +1,4 @@
1
- import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-CIPNDx1a.js";
1
+ import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-eOZBRWlR.js";
2
2
 
3
3
  //#region src/plugin/context.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/utils.js
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/utils.js
2
2
  /**
3
3
  * Entry point of utils.
4
4
  *
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-CUdYQC8F.js";
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-DZ8CuO6z.js";
2
2
 
3
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/utils.d.ts
3
+ //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/utils.d.ts
4
4
 
5
5
  //#region src/utils.d.ts
6
6
  /**
package/lib/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as log, i as isLazyCommand, n as deepFreeze, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-jNy8sqR5.js";
1
+ import { a as log, i as isLazyCommand, n as deepFreeze, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-9CtzCGbg.js";
2
2
  export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveLazyCommand };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gunshi",
3
3
  "description": "Modern javascript command-line library",
4
- "version": "0.33.0",
4
+ "version": "0.34.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -108,7 +108,7 @@
108
108
  }
109
109
  },
110
110
  "devDependencies": {
111
- "args-tokens": "^0.25.0",
111
+ "args-tokens": "^0.26.1",
112
112
  "deno": "^2.7.14",
113
113
  "jsr": "^0.14.3",
114
114
  "jsr-exports-lint": "^0.4.2",
@@ -116,11 +116,11 @@
116
116
  "std-env": "^4.1.0",
117
117
  "tsdown": "0.21.0",
118
118
  "zod": "^4.4.3",
119
- "@gunshi/plugin-global": "0.33.0",
120
- "@gunshi/plugin-renderer": "0.33.0",
121
- "@gunshi/shared": "0.33.0",
122
- "@gunshi/resources": "0.33.0",
123
- "@gunshi/plugin-i18n": "0.33.0"
119
+ "@gunshi/plugin-global": "0.34.0",
120
+ "@gunshi/plugin-i18n": "0.34.0",
121
+ "@gunshi/resources": "0.34.0",
122
+ "@gunshi/shared": "0.34.0",
123
+ "@gunshi/plugin-renderer": "0.34.0"
124
124
  },
125
125
  "scripts": {
126
126
  "build": "tsdown",