gunshi 1.0.0-beta.0 → 1.0.0-beta.2

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/agent.d.ts CHANGED
@@ -1,16 +1,11 @@
1
1
  //#region ../../node_modules/.pnpm/std-env@4.1.0/node_modules/std-env/dist/index.d.mts
2
2
  //#region src/agents.d.ts
3
3
  /**
4
- * Represents the name of an AI coding agent.
5
- */
4
+ * Represents the name of an AI coding agent.
5
+ */
6
6
  type AgentName = (string & {}) | "cursor" | "claude" | "devin" | "replit" | "gemini" | "codex" | "auggie" | "opencode" | "kiro" | "goose" | "pi";
7
- /**
8
- * Provides information about an AI coding agent.
9
- */
10
-
11
7
  //#endregion
12
8
  //#region src/agent.d.ts
13
-
14
9
  /**
15
10
  * A profile that summarizes whether the current process is running on an
16
11
  * AI coding agent.
package/lib/bone.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-By5dj6NT.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-CVwpWSau.js";
3
-
1
+ import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-BezrTUr7.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-lD5uzpd5.js";
4
3
  //#region src/cli/bone.d.ts
5
- /**
6
- * @author kazuya kawaguchi (a.k.a. kazupon)
7
- * @license MIT
8
- */
9
-
10
4
  /**
11
5
  * Run the command.
12
6
  *
@@ -47,11 +41,4 @@ declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiPa
47
41
  */
48
42
  declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
49
43
  //#endregion
50
- //#region src/bone.d.ts
51
- /**
52
- * @author kazuya kawaguchi (a.k.a. kazupon)
53
- * @license MIT
54
- */
55
-
56
- //#endregion
57
- export { ArgSchema, ArgToken, ArgValues, Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, MergeGunshiExtensions, NormalizeToGunshiParams, Prettify, RendererDecorator, RenderingOptions, SubCommandable, ValidationErrorsDecorator, cli };
44
+ export { type ArgSchema, type ArgToken, type ArgValues, type Args, type Awaitable, type CliOptions, type Command, type CommandCallMode, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandDecorator, type CommandEnvironment, type CommandExamplesFetcher, type CommandLoader, type CommandRunner, type Commandable, type DefaultGunshiParams, type ExtendContext, type ExtractArgExplicitlyProvided, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, type MergeGunshiExtensions, type NormalizeToGunshiParams, type Prettify, type RendererDecorator, type RenderingOptions, type SubCommandable, type ValidationErrorsDecorator, cli };
package/lib/bone.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cliCore } from "./core-DARRFBGf.js";
1
+ import { t as cliCore } from "./core-D9EEP3Ac.js";
2
2
  //#region src/cli/bone.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,7 +1,7 @@
1
1
  import { a as hasPriorityValidationError } from "./error-wB83kWiv.js";
2
2
  import { t as plugin } from "./plugin-CG94VzCl.js";
3
- import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Cj5m08gX.js";
4
- import { t as cliCore } from "./core-DARRFBGf.js";
3
+ import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Dr9mmkFc.js";
4
+ import { t as cliCore } from "./core-D9EEP3Ac.js";
5
5
  //#region ../plugin-global/src/types.ts
6
6
  /**
7
7
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,7 +1,5 @@
1
- import { i as Args, n as ArgSchema } from "./resolver-By5dj6NT.js";
2
-
1
+ import { i as Args, n as ArgSchema } from "./resolver-BezrTUr7.js";
3
2
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/combinators.d.ts
4
-
5
3
  //#region src/combinators.d.ts
6
4
  /**
7
5
  * A combinator produced by combinator factory functions.
@@ -474,7 +472,7 @@ type PositionalParserKey = 'parse' | 'metavar' | 'description' | 'hidden' | 'req
474
472
  * As in {@link WithFlag}, it maps the properties of the parser itself, and reads `any` in a part of
475
473
  * its own, so that TypeScript still sees them for a parser typed by a type parameter.
476
474
  */
477
- type PositionalWithParser<S> = { [K in keyof S as K extends PositionalParserKey ? K : never]: S[K] } & ArgSchemaPositionalType & (0 extends 1 & S ? Pick<UntypedCombinatorSchema, PositionalParserKey> : unknown);
475
+ type PositionalWithParser<S> = { [K in keyof S as K extends PositionalParserKey ? K : never]: S[K]; } & ArgSchemaPositionalType & (0 extends 1 & S ? Pick<UntypedCombinatorSchema, PositionalParserKey> : unknown);
478
476
  /**
479
477
  * The positional argument schema that {@link positional} returns for a parser `S`:
480
478
  * {@link PositionalWithParser} for each schema of a union. For a parser typed by a type parameter,
@@ -1059,7 +1057,7 @@ type Modified<S, F> = S extends unknown ? WithFlag<S, F> : never;
1059
1057
  * For a type parameter, TypeScript does not take it for `Omit<S, K>`, so {@link hidden} and
1060
1058
  * {@link unrequired}, whose results were typed `Omit<S, K>` with their flag, return that type too.
1061
1059
  */
1062
- type Without<S, K> = { [P in keyof S as P extends K ? never : NamedKey<P>]: S[P] };
1060
+ type Without<S, K> = { [P in keyof S as P extends K ? never : NamedKey<P>]: S[P]; };
1063
1061
  /**
1064
1062
  * `K` for a property name, and `never` for the `string`, `number` or `symbol` key of an index
1065
1063
  * signature, such as those of `any`.
@@ -1333,11 +1331,5 @@ declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
1333
1331
  */
1334
1332
  declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
1335
1333
  //#endregion
1336
- //#region src/combinators.d.ts
1337
- /**
1338
- * @author kazuya kawaguchi (a.k.a. kazupon)
1339
- * @license MIT
1340
- */
1341
-
1342
1334
  //#endregion
1343
1335
  export { type BaseOptions, type BooleanOptions, type Combinator, type CombinatorOptions, type CombinatorSchema, type FloatOptions, type IntegerOptions, type NumberOptions, type StringOptions, args, boolean, choice, combinator, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
package/lib/context.d.ts CHANGED
@@ -1,14 +1,12 @@
1
- import { i as Args, l as ArgToken, r as ArgValues } from "./resolver-By5dj6NT.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-CVwpWSau.js";
3
-
1
+ import { i as Args, l as ArgToken, r as ArgValues } from "./resolver-BezrTUr7.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-lD5uzpd5.js";
4
3
  //#region src/context.d.ts
5
-
6
4
  /**
7
5
  * Extract extension return types from extensions record
8
6
  *
9
7
  * @internal
10
8
  */
11
- type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
9
+ type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never; };
12
10
  /**
13
11
  * Return type of {@link createCommandContext}
14
12
  *
@@ -89,21 +87,6 @@ interface CommandContextParams<G extends GunshiParams | {
89
87
  * @param param - A {@link CommandContextParams | parameters} to create a command context.
90
88
  * @returns A {@link CommandContext | command context}, which is readonly.
91
89
  */
92
- declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = {}>({
93
- args,
94
- explicit,
95
- values,
96
- positionals,
97
- rest,
98
- argv,
99
- tokens,
100
- command,
101
- extensions,
102
- cliOptions,
103
- callMode,
104
- commandPath,
105
- omitted,
106
- validationError
107
- }: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
90
+ declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = {}>({ args, explicit, values, positionals, rest, argv, tokens, command, extensions, cliOptions, callMode, commandPath, omitted, validationError }: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
108
91
  //#endregion
109
92
  export { CommandContextParams, ExtractExtensionValues, createCommandContext };
@@ -1,6 +1,6 @@
1
1
  import { i as NOOP, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CSecf6R5.js";
2
2
  import { n as kebabnize } from "./utils-CJLgPw25.js";
3
- import { create, getCommandSubCommands, isLazyCommand, resolveCommandArgs, resolveLazyCommand } from "./utils.js";
3
+ import { create, getCommandSubCommands, isLazyCommand, resolveLazyCommand } from "./utils.js";
4
4
  import { a as resolveArgs, n as ArgsValidationErrorKeys, o as parseArgs, t as ArgsValidationError } from "./resolver-CAlgxe_R-y4BytVTg.js";
5
5
  import { a as hasPriorityValidationError, i as CommandResolutionErrorKeys, n as CommandNotFoundErrorKeys, r as CommandResolutionError, t as CommandNotFoundError } from "./error-wB83kWiv.js";
6
6
  //#region src/decorators.ts
@@ -197,6 +197,47 @@ function resolveDependencies(plugins) {
197
197
  return sorted;
198
198
  }
199
199
  //#endregion
200
+ //#region src/cli/args.ts
201
+ /**
202
+ * @author kazuya kawaguchi (a.k.a. kazupon)
203
+ * @license MIT
204
+ */
205
+ /**
206
+ * Resolve the arguments of a command, the way gunshi parses and renders them.
207
+ *
208
+ * The global options belong to no command definition, so they are merged into the arguments of the
209
+ * command that runs. An argument of the command shadows the global option of the same name, and it
210
+ * shadows the same way by short name: a global option gives up its short name to an argument of the
211
+ * command that claims the same letter, and keeps its long name.
212
+ *
213
+ * NOTE(kazupon): this is not exported from the entry points. `@gunshi/plugin-completion` completes
214
+ * the arguments the same way with the copy in `@gunshi/shared`, and the tests of that copy pin it
215
+ * to the results of this one, so a change here has to be made there too.
216
+ *
217
+ * @param globalOptions - The global options that plugins registered with `addGlobalOption`
218
+ * @param args - The arguments that the command declares
219
+ * @returns The merged arguments
220
+ */
221
+ function resolveCommandArgs(globalOptions, args) {
222
+ return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
223
+ }
224
+ function resolveGlobalOptions(globalOptions, args) {
225
+ if (!globalOptions) return;
226
+ const shortNames = /* @__PURE__ */ new Set();
227
+ for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
228
+ const resolved = create();
229
+ for (const [name, schema] of globalOptions)
230
+ /**
231
+ * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
232
+ * command of the CLI shares. Only this command gives up the short name.
233
+ */
234
+ resolved[name] = schema.short && shortNames.has(schema.short) ? {
235
+ ...schema,
236
+ short: void 0
237
+ } : schema;
238
+ return resolved;
239
+ }
240
+ //#endregion
200
241
  //#region src/cli/core.ts
201
242
  /**
202
243
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -269,7 +310,7 @@ async function cliCore(argv, entry, options, plugins, usageOnly = false) {
269
310
  * the merge, so the core says which ones are in effect for this command (#745).
270
311
  */
271
312
  cliOptions.globalOptions = resolveEffectiveGlobalOptions(pluginContext.globalOptions, commandArgs, args);
272
- const skipPositional = targetDepth > 0 ? targetDepth - 1 : -1;
313
+ const skipPositional = resolveSkipPositional(tokens, pluginContext.globalOptions, resolvedCommand, targetDepth);
273
314
  const diagnostic = selection.diagnostic === true;
274
315
  const { explicit, values, positionals, rest, error } = diagnostic ? {
275
316
  explicit: create(),
@@ -690,6 +731,25 @@ function getEntryRoutingCommand(entry, options) {
690
731
  return entry;
691
732
  }
692
733
  function getRoutingPositionals(tokens, globalOptions, command) {
734
+ /**
735
+ * NOTE(kazupon): an empty argument is never a command name. `getPositionalTokens()` skips it when it
736
+ * collects the candidates, and the routing of each candidate must skip it too; otherwise the routing
737
+ * looks for a sub-command named `''`, and fails with `inconsistent-options` (#781).
738
+ */
739
+ return readPositionals(tokens, globalOptions, command).filter((value) => value !== "");
740
+ }
741
+ /**
742
+ * Read the positional arguments as `resolveArgs()` reads them for a command, empty ones included.
743
+ *
744
+ * The schemas are projected down to the metadata that classifies the tokens, so no code of the user,
745
+ * such as `parse`, runs.
746
+ *
747
+ * @param tokens - Tokenized command-line arguments
748
+ * @param globalOptions - Global option schemas
749
+ * @param command - The command whose arguments classify the tokens
750
+ * @returns The positional arguments, in the order that `skipPositional` of args-tokens counts them
751
+ */
752
+ function readPositionals(tokens, globalOptions, command) {
693
753
  const effective = resolveCommandArgs(globalOptions, getCommandArgs(command));
694
754
  const routingArgs = create();
695
755
  for (const [name, schema] of Object.entries(effective)) {
@@ -701,15 +761,36 @@ function getRoutingPositionals(tokens, globalOptions, command) {
701
761
  toKebab: schema.toKebab
702
762
  };
703
763
  }
704
- /**
705
- * NOTE(kazupon): an empty argument is never a command name. `getPositionalTokens()` skips it when it
706
- * collects the candidates, and the routing of each candidate must skip it too; otherwise the routing
707
- * looks for a sub-command named `''`, and fails with `inconsistent-options` (#781).
708
- */
709
764
  return resolveArgs(routingArgs, tokens, {
710
765
  shortGrouping: true,
711
766
  toKebab: command.toKebab
712
- }).positionals.filter((value) => value !== "");
767
+ }).positionals;
768
+ }
769
+ /**
770
+ * Resolve `skipPositional` of args-tokens: the index of the last positional argument to skip.
771
+ *
772
+ * NOTE(kazupon): the command names are the first positional arguments that are not empty, and the
773
+ * last one is at `depth - 1` only when no empty argument comes before it. `skipPositional` counts every
774
+ * positional argument, the empty ones too, so `app '' build x` gave `build` to the first positional
775
+ * argument of `build` (#793). The index is found in the reading of `resolveArgs()`, in which the values
776
+ * of the options are already taken out, so that an empty value of an option is not counted.
777
+ *
778
+ * @param tokens - Tokenized command-line arguments
779
+ * @param globalOptions - Global option schemas
780
+ * @param command - The command whose arguments are resolved
781
+ * @param depth - The number of command names
782
+ * @returns The index of the last command name among the positional arguments, or `-1` for the entry
783
+ */
784
+ function resolveSkipPositional(tokens, globalOptions, command, depth) {
785
+ if (depth === 0) return -1;
786
+ if (!tokens.some((token) => token.kind === "positional" && token.value === "")) return depth - 1;
787
+ let names = 0;
788
+ for (const [index, value] of readPositionals(tokens, globalOptions, command).entries()) {
789
+ if (value === "") continue;
790
+ names++;
791
+ if (names === depth) return index;
792
+ }
793
+ return depth - 1;
713
794
  }
714
795
  function sameCommandPath(left, right) {
715
796
  return left.length === right.length && left.every((name, index) => name === right[index]);
@@ -1,13 +1,7 @@
1
- import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-By5dj6NT.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-CVwpWSau.js";
1
+ import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-BezrTUr7.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-lD5uzpd5.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
-
5
4
  //#region src/definition.d.ts
6
- /**
7
- * @author kazuya kawaguchi (a.k.a. kazupon)
8
- * @license MIT
9
- */
10
-
11
5
  /**
12
6
  * The result type of the {@link define} function
13
7
  *
@@ -1,11 +1,6 @@
1
- import { a as ArgsValidationError } from "./resolver-By5dj6NT.js";
2
- import { m as DefaultGunshiParams, n as CliOptions } from "./types-CVwpWSau.js";
3
-
1
+ import { a as ArgsValidationError } from "./resolver-BezrTUr7.js";
2
+ import { m as DefaultGunshiParams, n as CliOptions } from "./types-lD5uzpd5.js";
4
3
  //#region src/constants.d.ts
5
- /**
6
- * @author kazuya kawaguchi (a.k.a. kazupon)
7
- * @license MIT
8
- */
9
4
  declare const ANONYMOUS_COMMAND_NAME = "(anonymous)";
10
5
  declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
11
6
  //#endregion
@@ -1,7 +1,5 @@
1
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-CVwpWSau.js";
2
-
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-lD5uzpd5.js";
3
2
  //#region src/generator.d.ts
4
-
5
3
  /**
6
4
  * generate options of `generate` function.
7
5
  *
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { create } from "./utils.js";
2
- import { n as cliUsage } from "./builtin-DpTuEkZb.js";
2
+ import { n as cliUsage } from "./builtin-ClJbNR1q.js";
3
3
  //#region src/generator.ts
4
4
  /**
5
5
  * The entry for usage generator.
package/lib/index.d.ts CHANGED
@@ -1,15 +1,9 @@
1
- import { a as ArgsValidationError, c as resolveArgs, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys, u as parseArgs } from "./resolver-By5dj6NT.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-CVwpWSau.js";
1
+ import { a as ArgsValidationError, c as resolveArgs, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys, u as parseArgs } from "./resolver-BezrTUr7.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-lD5uzpd5.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
4
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
5
- import { a as CommandResolutionError, c as CommandResolutionErrorOptions, d as isCommandNotFoundError, f as isCommandResolutionError, i as CommandNotFoundErrorOptions, l as hasPriorityValidationError, n as CommandNotFoundErrorCode, o as CommandResolutionErrorCode, p as ANONYMOUS_COMMAND_NAME, r as CommandNotFoundErrorKeys, s as CommandResolutionErrorKeys, t as CommandNotFoundError, u as isArgsValidationError } from "./error-BWBKYs9E.js";
6
-
5
+ import { a as CommandResolutionError, c as CommandResolutionErrorOptions, d as isCommandNotFoundError, f as isCommandResolutionError, i as CommandNotFoundErrorOptions, l as hasPriorityValidationError, n as CommandNotFoundErrorCode, o as CommandResolutionErrorCode, p as ANONYMOUS_COMMAND_NAME, r as CommandNotFoundErrorKeys, s as CommandResolutionErrorKeys, t as CommandNotFoundError, u as isArgsValidationError } from "./error-e_--t4mB.js";
7
6
  //#region ../plugin-i18n/src/types.d.ts
8
- /**
9
- * @author kazuya kawaguchi (a.k.a. kazupon)
10
- * @license MIT
11
- */
12
-
13
7
  /**
14
8
  * Translation adapter factory options.
15
9
  */
@@ -179,11 +173,4 @@ declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[
179
173
  */
180
174
  declare function cli(args: string[], entry: SubCommandable, options?: CliOptions): Promise<string | undefined>;
181
175
  //#endregion
182
- //#region src/index.d.ts
183
- /**
184
- * @author kazuya kawaguchi (a.k.a. kazupon)
185
- * @license MIT
186
- */
187
-
188
- //#endregion
189
- export { ANONYMOUS_COMMAND_NAME, ArgSchema, ArgToken, ArgValues, Args, ArgsValidationError, type ArgsValidationErrorCode, ArgsValidationErrorKeys, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, type CommandContextParams, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandNotFoundError, type CommandNotFoundErrorCode, CommandNotFoundErrorKeys, type CommandNotFoundErrorOptions, CommandResolutionError, type CommandResolutionErrorCode, CommandResolutionErrorKeys, type CommandResolutionErrorOptions, CommandRunner, Commandable, DefaultGunshiParams, DefaultTranslation, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, MergeGunshiExtensions, NormalizeToGunshiParams, type OnPluginExtension, type Plugin, type PluginContext, type PluginDependency, type PluginExtension, type PluginFunction, type PluginOptions, type PluginWithExtension, type PluginWithoutExtension, Prettify, RendererDecorator, RenderingOptions, SubCommandable, ValidationErrorsDecorator, cli, createCommandContext, define, defineWithTypes, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, isCommandResolutionError, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
176
+ export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, ArgsValidationError, type ArgsValidationErrorCode, ArgsValidationErrorKeys, type Awaitable, type CliOptions, type Command, type CommandCallMode, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandContextParams, type CommandDecorator, type CommandEnvironment, type CommandExamplesFetcher, type CommandLoader, CommandNotFoundError, type CommandNotFoundErrorCode, CommandNotFoundErrorKeys, type CommandNotFoundErrorOptions, CommandResolutionError, type CommandResolutionErrorCode, CommandResolutionErrorKeys, type CommandResolutionErrorOptions, type CommandRunner, type Commandable, type DefaultGunshiParams, DefaultTranslation, type ExtendContext, type ExtractArgExplicitlyProvided, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, type MergeGunshiExtensions, type NormalizeToGunshiParams, type OnPluginExtension, type Plugin, type PluginContext, type PluginDependency, type PluginExtension, type PluginFunction, type PluginOptions, type PluginWithExtension, type PluginWithoutExtension, type Prettify, type RendererDecorator, type RenderingOptions, type SubCommandable, type ValidationErrorsDecorator, cli, createCommandContext, define, defineWithTypes, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, isCommandResolutionError, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
package/lib/index.js CHANGED
@@ -2,8 +2,8 @@ import { n as ANONYMOUS_COMMAND_NAME, t as createCommandContext } from "./contex
2
2
  import { a as resolveArgs, n as ArgsValidationErrorKeys, o as parseArgs, t as ArgsValidationError } from "./resolver-CAlgxe_R-y4BytVTg.js";
3
3
  import { a as hasPriorityValidationError, c as isCommandResolutionError, i as CommandResolutionErrorKeys, n as CommandNotFoundErrorKeys, o as isArgsValidationError, r as CommandResolutionError, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-wB83kWiv.js";
4
4
  import { t as plugin } from "./plugin-CG94VzCl.js";
5
- import { a as namespacedId } from "./src-Cj5m08gX.js";
6
- import { t as cli } from "./builtin-DpTuEkZb.js";
5
+ import { a as namespacedId } from "./src-Dr9mmkFc.js";
6
+ import { t as cli } from "./builtin-ClJbNR1q.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,13 +1,5 @@
1
- import { a as ArgsValidationError, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys } from "./resolver-By5dj6NT.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-CVwpWSau.js";
1
+ import { a as ArgsValidationError, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys } from "./resolver-BezrTUr7.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-lD5uzpd5.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
- import { a as CommandResolutionError, c as CommandResolutionErrorOptions, d as isCommandNotFoundError, f as isCommandResolutionError, i as CommandNotFoundErrorOptions, l as hasPriorityValidationError, m as CLI_OPTIONS_DEFAULT, n as CommandNotFoundErrorCode, o as CommandResolutionErrorCode, p as ANONYMOUS_COMMAND_NAME, r as CommandNotFoundErrorKeys, s as CommandResolutionErrorKeys, t as CommandNotFoundError, u as isArgsValidationError } from "./error-BWBKYs9E.js";
5
-
6
- //#region src/plugin.d.ts
7
- /**
8
- * @author kazuya kawaguchi (a.k.a. kazupon)
9
- * @license MIT
10
- */
11
-
12
- //#endregion
4
+ import { a as CommandResolutionError, c as CommandResolutionErrorOptions, d as isCommandNotFoundError, f as isCommandResolutionError, i as CommandNotFoundErrorOptions, l as hasPriorityValidationError, m as CLI_OPTIONS_DEFAULT, n as CommandNotFoundErrorCode, o as CommandResolutionErrorCode, p as ANONYMOUS_COMMAND_NAME, r as CommandNotFoundErrorKeys, s as CommandResolutionErrorKeys, t as CommandNotFoundError, u as isArgsValidationError } from "./error-e_--t4mB.js";
13
5
  export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, ArgsValidationError, type ArgsValidationErrorCode, ArgsValidationErrorKeys, type Awaitable, CLI_OPTIONS_DEFAULT, type Command, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandContextParams, type CommandDecorator, type CommandExamplesFetcher, CommandNotFoundError, type CommandNotFoundErrorCode, CommandNotFoundErrorKeys, type CommandNotFoundErrorOptions, CommandResolutionError, type CommandResolutionErrorCode, CommandResolutionErrorKeys, type CommandResolutionErrorOptions, type CommandRunner, type DefaultGunshiParams, type ExtendContext, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, type MergeGunshiExtensions, type NormalizeToGunshiParams, type OnPluginExtension, type Plugin, type PluginContext, type PluginDependency, type PluginExtension, type PluginFunction, type PluginOptions, type PluginWithExtension, type PluginWithoutExtension, type Prettify, type RendererDecorator, type ValidationErrorsDecorator, createCommandContext, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, isCommandResolutionError, plugin };
package/lib/renderer.d.ts CHANGED
@@ -1,11 +1,5 @@
1
- import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-CVwpWSau.js";
2
-
1
+ import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-lD5uzpd5.js";
3
2
  //#region ../plugin-renderer/src/header.d.ts
4
- /**
5
- * @author kazuya kawaguchi (a.k.a. kazupon)
6
- * @license MIT
7
- */
8
-
9
3
  /**
10
4
  * Render the header.
11
5
  *
@@ -32,12 +26,5 @@ declare function renderUsage<G extends GunshiParams = DefaultGunshiParams>(ctx:
32
26
  * @returns A rendered validation error.
33
27
  */
34
28
  declare function renderValidationErrors<G extends GunshiParams = DefaultGunshiParams>(ctx: CommandContext<G>, error: AggregateError): Promise<string>;
35
- //#endregion
36
- //#region src/renderer.d.ts
37
- /**
38
- * @author kazuya kawaguchi (a.k.a. kazupon)
39
- * @license MIT
40
- */
41
-
42
29
  //#endregion
43
30
  export { renderHeader, renderUsage, renderValidationErrors };
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-Cj5m08gX.js";
1
+ import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-Dr9mmkFc.js";
2
2
  //#region src/renderer.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -85,12 +85,6 @@ interface ParserOptions {
85
85
  * ```
86
86
  */
87
87
  declare function parseArgs(args: string[], options?: ParserOptions): ArgToken[];
88
- /**
89
- * Check if `arg` is a short option (e.g. `-f`).
90
- *
91
- * @param arg - An argument to check
92
- * @returns Whether `arg` is a short option.
93
- */
94
88
  //#endregion
95
89
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/resolver.d.ts
96
90
  //#region src/resolver.d.ts
@@ -734,7 +728,7 @@ interface Args {
734
728
  *
735
729
  * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
736
730
  */
737
- type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
731
+ type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]>; }> : {
738
732
  [option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
739
733
  };
740
734
  /**
@@ -766,7 +760,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
766
760
  *
767
761
  * @internal
768
762
  */
769
- type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg] } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg] } extends (infer P) ? { [K in keyof P]: P[K] } : never;
763
+ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg]; } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg]; } extends (infer P) ? { [K in keyof P]: P[K]; } : never;
770
764
  /**
771
765
  * Whether an argument with the schema `S` has a value: with a default, with `required: true` or as
772
766
  * a required positional argument. For a union of schemas, only when each schema of the union has
@@ -774,16 +768,6 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
774
768
  * value, as {@link FilterArgs} does.
775
769
  */
776
770
  type IsPresentArg<S extends ArgSchema> = S extends ArgSchema ? true extends (S['default'] extends {} ? true : S['required'] extends true ? true : false) ? true : IsRequiredPositionalArg<S> : never;
777
- /**
778
- * Filters the arguments based on their default values.
779
- *
780
- * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
781
- * @typeParam V - Resolvable argument values.
782
- * @typeParam K - Key of the {@link ArgSchema | argument schema} to filter by.
783
- *
784
- * @internal
785
- */
786
-
787
771
  type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : MayBeUnrequired<A> extends true ? A['default'] extends {} ? true : false : true : false;
788
772
  /**
789
773
  * Whether the `required` of `A` may be `false`. An optional `required` of type `boolean`, as in
@@ -837,7 +821,7 @@ interface ResolveArgs {
837
821
  *
838
822
  * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
839
823
  */
840
- type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
824
+ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean; };
841
825
  /**
842
826
  * Resolve command line arguments.
843
827
  *
@@ -870,11 +854,7 @@ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
870
854
  * explicit.host // false (not provided, fallback to default)
871
855
  * ```
872
856
  */
873
- declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
874
- shortGrouping,
875
- skipPositional,
876
- toKebab
877
- }?: ResolveArgs): {
857
+ declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], { shortGrouping, skipPositional, toKebab }?: ResolveArgs): {
878
858
  values: ArgValues<A>;
879
859
  positionals: string[];
880
860
  rest: string[];
@@ -44,13 +44,14 @@ var en_US_default = {
44
44
  help: "Display this help message",
45
45
  version: "Display this version",
46
46
  "err:arg:required-option": "Optional argument {$displayName} is required",
47
- "err:arg:required-positional": "Positional argument {$name} is required",
47
+ "err:arg:required-positional": "Positional argument {$displayName} is required",
48
48
  "err:arg:invalid-type": "Invalid value for {$displayName}: expected {$expected}",
49
49
  "err:arg:invalid-choice": "Invalid value for {$displayName}: expected one of {$choices}",
50
50
  "err:arg:custom-parse": "Invalid value for {$displayName}: {$reason}",
51
51
  "err:arg:unknown-option": "Unknown option: {$rawName}",
52
52
  "err:arg:unexpected-value": "Optional argument {$displayName} does not take a value",
53
53
  "err:arg:missing-value": "Optional argument {$displayName} requires a value",
54
+ "err:arg:missing-value:hint": "(to pass '{$next}' as its value, write '{$suggestion}')",
54
55
  "err:arg:conflict": "{$displayName} conflicts with {$conflictDisplayName}",
55
56
  "err:arg:invalid-default": "Invalid default for {$displayName}: {$actual} is not one of {$choices}",
56
57
  "err:cmd:not-found": "Command not found: {$commandName}",
@@ -333,10 +334,10 @@ function isHiddenArg(schema) {
333
334
  return schema.hidden === true;
334
335
  }
335
336
  function getVisibleOptionalArgs(args) {
336
- return Object.entries(args).filter(([_, schema]) => schema.type !== "positional" && !isHiddenArg(schema));
337
+ return Object.entries(args).filter(([, schema]) => schema.type !== "positional" && !isHiddenArg(schema));
337
338
  }
338
339
  function getVisiblePositionalArgs(args) {
339
- return Object.entries(args).filter(([_, schema]) => schema.type === "positional" && !isHiddenArg(schema));
340
+ return Object.entries(args).filter(([, schema]) => schema.type === "positional" && !isHiddenArg(schema));
340
341
  }
341
342
  /**
342
343
  * Render the usage.
@@ -552,7 +553,7 @@ function hasAllDefaultOptions(args) {
552
553
  * NOTE(kazupon): an argument has a default when one is declared, whatever its value. `0`, `''` and
553
554
  * `false` are defaults like any other, and an option that has one is not required (#750).
554
555
  */
555
- return visibleOptionalArgs.length > 0 && visibleOptionalArgs.every(([_, arg]) => arg.default !== void 0);
556
+ return visibleOptionalArgs.length > 0 && visibleOptionalArgs.every(([, arg]) => arg.default !== void 0);
556
557
  }
557
558
  /**
558
559
  * Generate options symbols for usage
@@ -607,6 +608,11 @@ async function resolveDisplayValue(ctx, key) {
607
608
  if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${await generateDefaultDisplayValue(ctx, schema)})`;
608
609
  if (schema.type === "enum") {
609
610
  const _default = schema.default === void 0 ? "" : await generateDefaultDisplayValue(ctx, schema);
611
+ /**
612
+ * NOTE(kazupon): an `enum` argument that has a `parse` function needs no `choices`, as args-tokens
613
+ * resolves its value with the function. There is no list to show then (#800).
614
+ */
615
+ if (!Array.isArray(schema.choices)) return _default ? `(${_default})` : "";
610
616
  const choices = `${await ctx.extensions[pluginId].text(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
611
617
  return `(${_default ? `${_default}, ${choices}` : choices})`;
612
618
  }
@@ -622,7 +628,7 @@ async function resolveDisplayValue(ctx, key) {
622
628
  async function generateOptionalArgsUsage(ctx, optionsPairs) {
623
629
  const optionsPairsEntries = Object.entries(optionsPairs);
624
630
  if (optionsPairsEntries.length === 0) return "";
625
- const optionsMaxLength = Math.max(...optionsPairsEntries.map(([_, value]) => displayWidth(value)));
631
+ const optionsMaxLength = Math.max(...optionsPairsEntries.map(([, value]) => displayWidth(value)));
626
632
  const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...optionsPairsEntries.map(([key]) => displayWidth(resolveNegatableType(key, ctx)))) : 0;
627
633
  return (await Promise.all(optionsPairsEntries.map(async ([key, value]) => {
628
634
  let rawDesc = await ctx.extensions[pluginId].text(resolveArgKey(key, ctx.name));
@@ -681,6 +687,7 @@ function isRequiredSinglePositionalArg(arg) {
681
687
  * @license MIT
682
688
  */
683
689
  const i18nPluginId$1 = namespacedId("i18n");
690
+ const missingValueHintKey = "err:arg:missing-value:hint";
684
691
  /**
685
692
  * Render the validation errors.
686
693
  *
@@ -705,10 +712,31 @@ async function renderValidationError(ctx, error) {
705
712
  if (isArgsValidationError(error) && error.code) {
706
713
  const values = await resolveValidationValues(ctx, error);
707
714
  const message = await localize(ctx, error.code, values);
708
- if (message && message !== error.code) return message;
715
+ if (message && message !== error.code) {
716
+ const hint = await localizeHint(ctx, error, values);
717
+ return hint ? `${message} ${hint}` : message;
718
+ }
709
719
  }
710
720
  return error.message;
711
721
  }
722
+ /**
723
+ * Localize the hint that args-tokens adds to the message of an error.
724
+ *
725
+ * A translation replaces the whole message, hint included, so the hint is translated by a key of
726
+ * its own and follows the translated error. args-tokens gives one today: for an option given without
727
+ * a value, when the argument after it may be the value, the long form with `=` (`--port=-5` for
728
+ * `--port -5`), in `values.next` and `values.suggestion`.
729
+ *
730
+ * @param ctx - A {@link CommandContext | command context}
731
+ * @param error - An args validation error
732
+ * @param values - The values of the error, as given to its translation
733
+ * @returns The localized hint, or `undefined` when the error has none.
734
+ */
735
+ async function localizeHint(ctx, error, values) {
736
+ if (error.code !== ArgsValidationErrorKeys.missingValue || typeof values.next !== "string" || typeof values.suggestion !== "string") return;
737
+ const hint = await localize(ctx, missingValueHintKey, values);
738
+ return hint && hint !== missingValueHintKey ? hint : void 0;
739
+ }
712
740
  async function resolveValidationValues(ctx, error) {
713
741
  if (error.code !== ArgsValidationErrorKeys.customParse) return error.values;
714
742
  const { reasonKey, reasonValues } = error.values;
@@ -1,11 +1,5 @@
1
- import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-By5dj6NT.js";
2
-
1
+ import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-BezrTUr7.js";
3
2
  //#region src/plugin/context.d.ts
4
- /**
5
- * @author kazuya kawaguchi (a.k.a. kazupon)
6
- * @license MIT
7
- */
8
-
9
3
  /**
10
4
  * Gunshi plugin context interface.
11
5
  *
@@ -84,12 +78,12 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
84
78
  }
85
79
  //#endregion
86
80
  //#region src/plugin/core.d.ts
87
- type ProcessDependency<D, A extends ExtendContext> = D extends string ? D extends keyof A ? { [K in D]: A[K] } : {} : D extends {
81
+ type ProcessDependency<D, A extends ExtendContext> = D extends string ? D extends keyof A ? { [K in D]: A[K]; } : {} : D extends {
88
82
  id: infer ID;
89
83
  optional?: any;
90
84
  } ? ID extends string ? ID extends keyof A ? D extends {
91
85
  optional: true;
92
- } ? { [K in ID]: A[K] | undefined } : { [K in ID]: A[K] } : {} : never : never;
86
+ } ? { [K in ID]: A[K] | undefined; } : { [K in ID]: A[K]; } : {} : never : never;
93
87
  /**
94
88
  * Helper type to infer dependency extensions with optional support
95
89
  *
@@ -145,7 +139,7 @@ type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = Defau
145
139
  */
146
140
  type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => Awaitable<void>;
147
141
  type IsStringLiteral<S extends string> = string extends S ? false : true;
148
- type MergeExtension<Id, ResolvedDepExt extends ExtendContext, PluginExt extends ExtendContext> = Id extends infer I ? I extends string ? IsStringLiteral<I> extends true ? ResolvedDepExt & { [K in I]: PluginExt } : ResolvedDepExt : ResolvedDepExt : ResolvedDepExt;
142
+ type MergeExtension<Id, ResolvedDepExt extends ExtendContext, PluginExt extends ExtendContext> = Id extends (infer I) ? I extends string ? IsStringLiteral<I> extends true ? ResolvedDepExt & { [K in I]: PluginExt; } : ResolvedDepExt : ResolvedDepExt : ResolvedDepExt;
149
143
  /**
150
144
  * Extensions resolved from the declared plugin dependencies.
151
145
  *
@@ -181,15 +175,11 @@ type MergedPluginParams<Id extends string, Deps extends ReadonlyArray<PluginDepe
181
175
  *
182
176
  * @since v0.27.0
183
177
  */
184
- interface PluginOptions<DepExt extends ExtendContext = DefaultGunshiParams['extensions'],
185
- // for plugin dependency extensions
186
- Id extends string = string,
187
- // for plugin id
188
- Deps extends ReadonlyArray<PluginDependency | string> = (PluginDependency | string)[],
189
- // for plugin dependencies
190
- Ext extends Record<string, unknown> = {},
191
- // for plugin extension type
192
- ResolvedDepExt extends GunshiParams = DependencyParams<Deps, DepExt>, PluginExt extends PluginExtension<Ext, ResolvedDepExt> = PluginExtension<Ext, ResolvedDepExt>, MergedExt extends GunshiParams = MergedPluginParams<Id, Deps, DepExt, Awaited<ReturnType<PluginExt>>>> {
178
+ interface PluginOptions<DepExt extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
179
+ , Id extends string = string // for plugin id
180
+ , Deps extends ReadonlyArray<PluginDependency | string> = (PluginDependency | string)[] // for plugin dependencies
181
+ , Ext extends Record<string, unknown> = {} // for plugin extension type
182
+ , ResolvedDepExt extends GunshiParams = DependencyParams<Deps, DepExt>, PluginExt extends PluginExtension<Ext, ResolvedDepExt> = PluginExtension<Ext, ResolvedDepExt>, MergedExt extends GunshiParams = MergedPluginParams<Id, Deps, DepExt, Awaited<ReturnType<PluginExt>>>> {
193
183
  /**
194
184
  * Plugin unique identifier.
195
185
  *
@@ -292,15 +282,11 @@ interface PluginWithoutExtension<E extends GunshiParams['extensions'] = DefaultG
292
282
  *
293
283
  * @since v0.27.0
294
284
  */
295
- declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'],
296
- // for plugin dependency extensions
297
- Id extends string = string,
298
- // for plugin id
299
- Deps extends ReadonlyArray<PluginDependency | string> = [],
300
- // for plugin dependencies
301
- Extension extends {} = {},
302
- // for plugin extension type
303
- ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
285
+ declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
286
+ , Id extends string = string // for plugin id
287
+ , Deps extends ReadonlyArray<PluginDependency | string> = [] // for plugin dependencies
288
+ , Extension extends {} = {} // for plugin extension type
289
+ , ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
304
290
  id: Id;
305
291
  name?: string;
306
292
  dependencies?: Deps;
@@ -321,15 +307,11 @@ ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, Pl
321
307
  *
322
308
  * @since v0.27.0
323
309
  */
324
- declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'],
325
- // for plugin dependency extensions
326
- Id extends string = string,
327
- // for plugin id
328
- Deps extends ReadonlyArray<PluginDependency | string> = [],
329
- // for plugin dependencies
330
- Extension extends Record<string, unknown> = {},
331
- // for plugin extension type
332
- ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
310
+ declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
311
+ , Id extends string = string // for plugin id
312
+ , Deps extends ReadonlyArray<PluginDependency | string> = [] // for plugin dependencies
313
+ , Extension extends Record<string, unknown> = {} // for plugin extension type
314
+ , ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
333
315
  id: Id;
334
316
  name?: string;
335
317
  dependencies?: Deps;
@@ -349,7 +331,7 @@ type Awaitable<T> = T | Promise<T>;
349
331
  *
350
332
  * @typeParam T - The type to be prettified.
351
333
  */
352
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
334
+ type Prettify<T> = { [K in keyof T]: T[K]; } & {};
353
335
  /**
354
336
  * Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
355
337
  *
package/lib/utils.d.ts CHANGED
@@ -1,12 +1,5 @@
1
- import { i as Args, n as ArgSchema } from "./resolver-By5dj6NT.js";
2
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-CVwpWSau.js";
3
-
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-lD5uzpd5.js";
4
2
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/utils.d.ts
5
- /**
6
- * @author kazuya kawaguchi (a.k.a. kazupon)
7
- * @license MIT
8
- */
9
-
10
3
  //#region src/utils.d.ts
11
4
  /**
12
5
  * Entry point of utils.
@@ -57,19 +50,6 @@ declare function resolveLazyCommand<G extends GunshiParamsConstraint = DefaultGu
57
50
  * @returns A new object with the specified prototype
58
51
  */
59
52
  declare function create<T>(obj?: object | null): T;
60
- /**
61
- * Resolve the arguments of a command, the way gunshi parses and renders them.
62
- *
63
- * The global options belong to no command definition, so they are merged into the arguments of the
64
- * command that runs. An argument of the command shadows the global option of the same name, and it
65
- * shadows the same way by short name: a global option gives up its short name to an argument of the
66
- * command that claims the same letter, and keeps its long name.
67
- *
68
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
69
- * @param args - The arguments that the command declares
70
- * @returns The merged arguments
71
- */
72
- declare function resolveCommandArgs<A extends Args = Args>(globalOptions?: ReadonlyMap<string, ArgSchema>, args?: A): A;
73
53
  /**
74
54
  * Log a message to the console.
75
55
  *
@@ -92,4 +72,4 @@ declare function getCommandSubCommands<G extends GunshiParamsConstraint = Defaul
92
72
  */
93
73
  declare function deepFreeze<T extends Record<string, any>>(obj: T, ignores?: string[]): Readonly<T>;
94
74
  //#endregion
95
- export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveCommandArgs, resolveLazyCommand };
75
+ export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveLazyCommand };
package/lib/utils.js CHANGED
@@ -80,37 +80,6 @@ function create(obj = null) {
80
80
  return Object.create(obj);
81
81
  }
82
82
  /**
83
- * Resolve the arguments of a command, the way gunshi parses and renders them.
84
- *
85
- * The global options belong to no command definition, so they are merged into the arguments of the
86
- * command that runs. An argument of the command shadows the global option of the same name, and it
87
- * shadows the same way by short name: a global option gives up its short name to an argument of the
88
- * command that claims the same letter, and keeps its long name.
89
- *
90
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
91
- * @param args - The arguments that the command declares
92
- * @returns The merged arguments
93
- */
94
- function resolveCommandArgs(globalOptions, args) {
95
- return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
96
- }
97
- function resolveGlobalOptions(globalOptions, args) {
98
- if (!globalOptions) return;
99
- const shortNames = /* @__PURE__ */ new Set();
100
- for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
101
- const resolved = create();
102
- for (const [name, schema] of globalOptions)
103
- /**
104
- * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
105
- * command of the CLI shares. Only this command gives up the short name.
106
- */
107
- resolved[name] = schema.short && shortNames.has(schema.short) ? {
108
- ...schema,
109
- short: void 0
110
- } : schema;
111
- return resolved;
112
- }
113
- /**
114
83
  * Log a message to the console.
115
84
  *
116
85
  * @param args - Arguments to log
@@ -153,4 +122,4 @@ function deepFreeze(obj, ignores = []) {
153
122
  return Object.freeze(obj);
154
123
  }
155
124
  //#endregion
156
- export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveCommandArgs, resolveLazyCommand };
125
+ 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": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -108,6 +108,11 @@
108
108
  }
109
109
  },
110
110
  "devDependencies": {
111
+ "@gunshi/plugin-global": "1.0.0-beta.2",
112
+ "@gunshi/plugin-i18n": "1.0.0-beta.2",
113
+ "@gunshi/plugin-renderer": "1.0.0-beta.2",
114
+ "@gunshi/resources": "1.0.0-beta.2",
115
+ "@gunshi/shared": "1.0.0-beta.2",
111
116
  "@types/node": "^25.6.2",
112
117
  "args-tokens": "1.0.0-beta.1",
113
118
  "deno": "^2.7.14",
@@ -115,13 +120,8 @@
115
120
  "jsr-exports-lint": "^0.4.2",
116
121
  "publint": "^0.3.20",
117
122
  "std-env": "^4.1.0",
118
- "tsdown": "0.21.0",
119
- "zod": "^4.4.3",
120
- "@gunshi/plugin-global": "1.0.0-beta.0",
121
- "@gunshi/plugin-renderer": "1.0.0-beta.0",
122
- "@gunshi/plugin-i18n": "1.0.0-beta.0",
123
- "@gunshi/resources": "1.0.0-beta.0",
124
- "@gunshi/shared": "1.0.0-beta.0"
123
+ "tsdown": "0.22.14",
124
+ "zod": "^4.4.3"
125
125
  },
126
126
  "scripts": {
127
127
  "build": "tsdown",