gunshi 0.37.1 → 0.37.3
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 +2 -2
- package/lib/bone.js +1 -1
- package/lib/{cli-8lpU57Wl.js → cli-BnmSo-DW.js} +6 -5
- package/lib/combinators.d.ts +17 -9
- package/lib/combinators.js +9 -7
- package/lib/context.d.ts +2 -2
- package/lib/{core-vmpEqkpT.js → core-CLzX86kY.js} +25 -24
- package/lib/definition.d.ts +2 -2
- package/lib/error-B5QxSzk9.js +139 -0
- package/lib/{error-DdRv50OI.d.ts → error-DHF6LJCG.d.ts} +31 -6
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +5 -5
- package/lib/{plugin-BY44BdcY.js → plugin-DneW3Toi.js} +1 -1
- package/lib/plugin.d.ts +3 -3
- package/lib/plugin.js +3 -3
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +1 -1
- package/lib/{resolver-CKLHkuQa.d.ts → resolver-CbDvcwY3.d.ts} +14 -20
- package/lib/{resolver-UjEQwV-U.js → resolver-D5skgYcF.js} +98 -42
- package/lib/{src-a-JpaUM5.js → src-80_afJQM.js} +8 -7
- package/lib/{types-8Qh1S2q6.d.ts → types-H9nag_2Z.d.ts} +1 -1
- package/lib/{utils-CfOBA5zn.js → utils-DbRhwNIU.js} +1 -1
- package/lib/utils.d.ts +6 -8
- package/lib/utils.js +1 -1
- package/package.json +8 -7
- package/lib/error-BxeGn0JU.js +0 -65
package/lib/bone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Args,
|
|
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-
|
|
1
|
+
import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-CbDvcwY3.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-H9nag_2Z.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/bone.d.ts
|
|
5
5
|
/**
|
package/lib/bone.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as hasPriorityValidationError } from "./error-
|
|
2
|
-
import { t as plugin } from "./plugin-
|
|
3
|
-
import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-
|
|
4
|
-
import { t as cliCore } from "./core-
|
|
1
|
+
import { r as hasPriorityValidationError } from "./error-B5QxSzk9.js";
|
|
2
|
+
import { t as plugin } from "./plugin-DneW3Toi.js";
|
|
3
|
+
import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-80_afJQM.js";
|
|
4
|
+
import { t as cliCore } from "./core-CLzX86kY.js";
|
|
5
5
|
//#region ../plugin-global/src/types.ts
|
|
6
6
|
/**
|
|
7
7
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -160,7 +160,8 @@ function global() {
|
|
|
160
160
|
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
161
161
|
*/
|
|
162
162
|
async function cli(args, entry, options = {}) {
|
|
163
|
-
|
|
163
|
+
const builtInPlugins = [global(), renderer()];
|
|
164
|
+
return cliCore(args, entry, options, builtInPlugins);
|
|
164
165
|
}
|
|
165
166
|
//#endregion
|
|
166
167
|
//#region src/cli.ts
|
package/lib/combinators.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema } from "./resolver-
|
|
1
|
+
import { i as Args, n as ArgSchema } from "./resolver-CbDvcwY3.js";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.d.ts
|
|
4
4
|
|
|
5
5
|
//#region src/combinators.d.ts
|
|
6
6
|
/**
|
|
@@ -391,6 +391,13 @@ type CombinatorWithDefault<T> = {
|
|
|
391
391
|
* @experimental
|
|
392
392
|
*/
|
|
393
393
|
declare function withDefault<T extends string | boolean | number>(schema: CombinatorSchema<T>, defaultValue: T): CombinatorSchema<T> & CombinatorWithDefault<T>;
|
|
394
|
+
/**
|
|
395
|
+
* Overlay a flag onto a combinator schema without dropping other modifiers.
|
|
396
|
+
*
|
|
397
|
+
* Omits the flag keys from `S` first so optional `ArgSchema` fields
|
|
398
|
+
* (`multiple?: true`, `required?: boolean`) cannot stay as unions.
|
|
399
|
+
*/
|
|
400
|
+
type WithFlag<S, F> = Omit<S, keyof F> & F;
|
|
394
401
|
/**
|
|
395
402
|
* Options for the {@link multiple} combinator.
|
|
396
403
|
*/
|
|
@@ -401,10 +408,11 @@ type CombinatorMultiple = {
|
|
|
401
408
|
* Mark a combinator schema as accepting multiple values.
|
|
402
409
|
*
|
|
403
410
|
* The resolved value becomes an array. The original schema is not modified.
|
|
411
|
+
* Other modifiers on `schema` (for example {@link required}) are kept.
|
|
404
412
|
*
|
|
405
|
-
* @typeParam
|
|
413
|
+
* @typeParam S - The input combinator schema.
|
|
406
414
|
* @param schema - The base combinator schema.
|
|
407
|
-
* @returns A
|
|
415
|
+
* @returns A copy of `schema` with `multiple: true`.
|
|
408
416
|
*
|
|
409
417
|
* @example
|
|
410
418
|
* ```ts
|
|
@@ -416,7 +424,7 @@ type CombinatorMultiple = {
|
|
|
416
424
|
*
|
|
417
425
|
* @experimental
|
|
418
426
|
*/
|
|
419
|
-
declare function multiple<
|
|
427
|
+
declare function multiple<S extends CombinatorSchema<unknown>>(schema: S): WithFlag<S, CombinatorMultiple>;
|
|
420
428
|
/**
|
|
421
429
|
* Options for the {@link required} combinator.
|
|
422
430
|
*/
|
|
@@ -427,11 +435,12 @@ type CombinatorRequired = {
|
|
|
427
435
|
* Mark a combinator schema as required.
|
|
428
436
|
*
|
|
429
437
|
* The original schema is not modified.
|
|
438
|
+
* Other modifiers on `schema` (for example {@link multiple}) are kept.
|
|
430
439
|
*
|
|
431
|
-
* @typeParam
|
|
440
|
+
* @typeParam S - The input combinator schema.
|
|
432
441
|
*
|
|
433
442
|
* @param schema - The base combinator schema.
|
|
434
|
-
* @returns A
|
|
443
|
+
* @returns A copy of `schema` with `required: true`.
|
|
435
444
|
*
|
|
436
445
|
* @example
|
|
437
446
|
* ```ts
|
|
@@ -442,7 +451,7 @@ type CombinatorRequired = {
|
|
|
442
451
|
*
|
|
443
452
|
* @experimental
|
|
444
453
|
*/
|
|
445
|
-
declare function required<
|
|
454
|
+
declare function required<S extends CombinatorSchema<unknown>>(schema: S): WithFlag<S, CombinatorRequired>;
|
|
446
455
|
/**
|
|
447
456
|
* Options for the {@link short} combinator.
|
|
448
457
|
*/
|
|
@@ -662,7 +671,6 @@ declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
|
|
|
662
671
|
*/
|
|
663
672
|
declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
|
|
664
673
|
//#endregion
|
|
665
|
-
//#endregion
|
|
666
674
|
//#region src/combinators.d.ts
|
|
667
675
|
/**
|
|
668
676
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
package/lib/combinators.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as formatChoices } from "./utils-
|
|
2
|
-
import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
import { t as formatChoices } from "./utils-DbRhwNIU.js";
|
|
2
|
+
import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.js
|
|
4
4
|
/**
|
|
5
5
|
* Parser combinator factory functions for composable argument schema construction.
|
|
6
6
|
*
|
|
@@ -412,10 +412,11 @@ function withDefault(schema, defaultValue) {
|
|
|
412
412
|
* Mark a combinator schema as accepting multiple values.
|
|
413
413
|
*
|
|
414
414
|
* The resolved value becomes an array. The original schema is not modified.
|
|
415
|
+
* Other modifiers on `schema` (for example {@link required}) are kept.
|
|
415
416
|
*
|
|
416
|
-
* @typeParam
|
|
417
|
+
* @typeParam S - The input combinator schema.
|
|
417
418
|
* @param schema - The base combinator schema.
|
|
418
|
-
* @returns A
|
|
419
|
+
* @returns A copy of `schema` with `multiple: true`.
|
|
419
420
|
*
|
|
420
421
|
* @example
|
|
421
422
|
* ```ts
|
|
@@ -438,11 +439,12 @@ function multiple(schema) {
|
|
|
438
439
|
* Mark a combinator schema as required.
|
|
439
440
|
*
|
|
440
441
|
* The original schema is not modified.
|
|
442
|
+
* Other modifiers on `schema` (for example {@link multiple}) are kept.
|
|
441
443
|
*
|
|
442
|
-
* @typeParam
|
|
444
|
+
* @typeParam S - The input combinator schema.
|
|
443
445
|
*
|
|
444
446
|
* @param schema - The base combinator schema.
|
|
445
|
-
* @returns A
|
|
447
|
+
* @returns A copy of `schema` with `required: true`.
|
|
446
448
|
*
|
|
447
449
|
* @example
|
|
448
450
|
* ```ts
|
package/lib/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Args,
|
|
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-
|
|
1
|
+
import { i as Args, l as ArgToken, r as ArgValues } from "./resolver-CbDvcwY3.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-H9nag_2Z.js";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
5
5
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as NOOP, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CAPhwgJJ.js";
|
|
2
|
-
import { n as kebabnize } from "./utils-
|
|
2
|
+
import { n as kebabnize } from "./utils-DbRhwNIU.js";
|
|
3
3
|
import { create, getCommandSubCommands, isLazyCommand, resolveLazyCommand } from "./utils.js";
|
|
4
|
-
import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-
|
|
5
|
-
import { n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-
|
|
4
|
+
import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
|
|
5
|
+
import { n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
|
|
6
6
|
//#region src/decorators.ts
|
|
7
7
|
/**
|
|
8
8
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -361,27 +361,28 @@ function getPositionalTokens(tokens) {
|
|
|
361
361
|
function resolveCommandTree(tokens, entry, options) {
|
|
362
362
|
const positionals = getPositionalTokens(tokens);
|
|
363
363
|
function resolveAsEntry() {
|
|
364
|
-
if (typeof entry === "function")
|
|
365
|
-
commandName
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
364
|
+
if (typeof entry === "function") {
|
|
365
|
+
if ("commandName" in entry && entry.commandName) return {
|
|
366
|
+
commandName: entry.commandName,
|
|
367
|
+
command: entry,
|
|
368
|
+
callMode: "entry",
|
|
369
|
+
commandPath: [],
|
|
370
|
+
depth: 0,
|
|
371
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
372
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
|
|
373
|
+
};
|
|
374
|
+
else return {
|
|
375
|
+
command: {
|
|
376
|
+
run: entry,
|
|
377
|
+
entry: true
|
|
378
|
+
},
|
|
379
|
+
callMode: "entry",
|
|
380
|
+
commandPath: [],
|
|
381
|
+
depth: 0,
|
|
382
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
383
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
|
|
384
|
+
};
|
|
385
|
+
} else if (typeof entry === "object") return {
|
|
385
386
|
commandName: resolveEntryName(entry),
|
|
386
387
|
command: entry,
|
|
387
388
|
callMode: "entry",
|
package/lib/definition.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-
|
|
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-
|
|
1
|
+
import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-CbDvcwY3.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-H9nag_2Z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
4
|
|
|
5
5
|
//#region src/definition.d.ts
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { n as ArgsValidationErrorKeys, r as isArgsValidationError$1, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/index.js
|
|
3
|
+
/**
|
|
4
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/error.ts
|
|
13
|
+
/**
|
|
14
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
15
|
+
* @license MIT
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Command not found error resource keys.
|
|
19
|
+
*/
|
|
20
|
+
const CommandNotFoundErrorKeys = { notFound: "err:cmd:not-found" };
|
|
21
|
+
/**
|
|
22
|
+
* Brand that marks {@link CommandNotFoundError} instances.
|
|
23
|
+
*
|
|
24
|
+
* The brand is looked up in the global symbol registry with `Symbol.for`, so it stays
|
|
25
|
+
* identical across bundled copies of gunshi (`gunshi`, `@gunshi/plugin`, `@gunshi/bone`)
|
|
26
|
+
* and across realms. It lets {@link isCommandNotFoundError} recognize errors created by
|
|
27
|
+
* another copy, where `instanceof` cannot match.
|
|
28
|
+
*/
|
|
29
|
+
const COMMAND_NOT_FOUND_ERROR_BRAND = Symbol.for("gunshi.CommandNotFoundError");
|
|
30
|
+
/**
|
|
31
|
+
* Error raised when a command cannot be resolved.
|
|
32
|
+
*
|
|
33
|
+
* Each instance carries a non-enumerable brand keyed by
|
|
34
|
+
* `Symbol.for('gunshi.CommandNotFoundError')`, so that {@link isCommandNotFoundError}
|
|
35
|
+
* recognizes it even when it was created by another bundled copy of gunshi.
|
|
36
|
+
*/
|
|
37
|
+
var CommandNotFoundError = class extends Error {
|
|
38
|
+
code;
|
|
39
|
+
values;
|
|
40
|
+
commandName;
|
|
41
|
+
candidates;
|
|
42
|
+
commandPath;
|
|
43
|
+
/**
|
|
44
|
+
* Create a command-not-found error.
|
|
45
|
+
*
|
|
46
|
+
* @param message - Fallback error message
|
|
47
|
+
* @param options - Command-not-found metadata
|
|
48
|
+
*/
|
|
49
|
+
constructor(message, options) {
|
|
50
|
+
super(message, { cause: options.cause });
|
|
51
|
+
this.name = "CommandNotFoundError";
|
|
52
|
+
this.code = options.code;
|
|
53
|
+
this.values = options.values || {};
|
|
54
|
+
this.commandName = options.commandName;
|
|
55
|
+
this.candidates = options.candidates || [];
|
|
56
|
+
this.commandPath = options.commandPath || [];
|
|
57
|
+
Object.defineProperty(this, COMMAND_NOT_FOUND_ERROR_BRAND, {
|
|
58
|
+
value: true,
|
|
59
|
+
enumerable: false,
|
|
60
|
+
writable: false,
|
|
61
|
+
configurable: false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Check whether an error is a {@link CommandNotFoundError}.
|
|
67
|
+
*
|
|
68
|
+
* `instanceof` alone is not enough: `@gunshi/plugin` is bundled with its own copy of this
|
|
69
|
+
* class (`noExternal: ['gunshi/plugin']`), so an error thrown by `gunshi` is never an instance
|
|
70
|
+
* of the class a plugin imports. Errors from another copy are recognized through the
|
|
71
|
+
* `Symbol.for('gunshi.CommandNotFoundError')` brand, which does not depend on `error.name`.
|
|
72
|
+
*
|
|
73
|
+
* @param error - An unknown error
|
|
74
|
+
* @returns `true` if the error is a {@link CommandNotFoundError}
|
|
75
|
+
*/
|
|
76
|
+
function isCommandNotFoundError(error) {
|
|
77
|
+
if (error instanceof CommandNotFoundError) return true;
|
|
78
|
+
if (!isRecord(error) || !hasCommandNotFoundErrorShape(error)) return false;
|
|
79
|
+
if (Object.hasOwn(error, COMMAND_NOT_FOUND_ERROR_BRAND) && error[COMMAND_NOT_FOUND_ERROR_BRAND] === true) return true;
|
|
80
|
+
return error instanceof Error && error.name === "CommandNotFoundError";
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check whether an error is an {@link ArgsValidationError}.
|
|
84
|
+
*
|
|
85
|
+
* Prefer this over the `args-tokens` guard of the same name. Both recognize errors from another
|
|
86
|
+
* bundled copy through the `Symbol.for('args-tokens.ArgsValidationError')` brand that
|
|
87
|
+
* `args-tokens` 0.29.0 or later sets, including subclasses such as `ArgResolveError` that
|
|
88
|
+
* override `name` with the argument name. This guard additionally:
|
|
89
|
+
*
|
|
90
|
+
* - recognizes direct `ArgsValidationError` instances from copies bundling `args-tokens`
|
|
91
|
+
* older than 0.29.0, which do not set the brand
|
|
92
|
+
* - checks that `code` and `values` of an error from another copy have the expected types
|
|
93
|
+
*
|
|
94
|
+
* The guard narrows only to {@link ArgsValidationError}: across copies,
|
|
95
|
+
* `instanceof ArgResolveError` still fails, so do not rely on `type` or `schema` for such errors.
|
|
96
|
+
*
|
|
97
|
+
* @param error - An unknown error
|
|
98
|
+
* @returns `true` if the error is an {@link ArgsValidationError}
|
|
99
|
+
*/
|
|
100
|
+
function isArgsValidationError(error) {
|
|
101
|
+
if (error instanceof ArgsValidationError) return true;
|
|
102
|
+
if (!isRecord(error) || !hasArgsValidationErrorShape(error)) return false;
|
|
103
|
+
if (isArgsValidationError$1(error)) return true;
|
|
104
|
+
return error instanceof Error && error.name === "ArgsValidationError";
|
|
105
|
+
}
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return typeof value === "object" && value !== null;
|
|
108
|
+
}
|
|
109
|
+
function isStringArray(value) {
|
|
110
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check whether `code` is an own or inherited property that is a string or `undefined`.
|
|
114
|
+
*
|
|
115
|
+
* Constructors always assign `code`, even when the option is omitted.
|
|
116
|
+
*
|
|
117
|
+
* @param error - An error from another copy
|
|
118
|
+
* @returns `true` if `code` has the expected type
|
|
119
|
+
*/
|
|
120
|
+
function hasOptionalStringCode(error) {
|
|
121
|
+
return "code" in error && (error.code === void 0 || typeof error.code === "string");
|
|
122
|
+
}
|
|
123
|
+
function hasCommandNotFoundErrorShape(error) {
|
|
124
|
+
return hasOptionalStringCode(error) && isRecord(error.values) && typeof error.commandName === "string" && isStringArray(error.candidates) && isStringArray(error.commandPath);
|
|
125
|
+
}
|
|
126
|
+
function hasArgsValidationErrorShape(error) {
|
|
127
|
+
return hasOptionalStringCode(error) && isRecord(error.values);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check whether validation errors should be handled before version, help, or command execution.
|
|
131
|
+
*
|
|
132
|
+
* @param error - An aggregate validation error
|
|
133
|
+
* @returns `true` if the validation error must be handled with priority
|
|
134
|
+
*/
|
|
135
|
+
function hasPriorityValidationError(error) {
|
|
136
|
+
return error?.errors.some((error) => isCommandNotFoundError(error) || isArgsValidationError(error) && error.code === ArgsValidationErrorKeys.unknownOption) ?? false;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { isCommandNotFoundError as a, isArgsValidationError as i, CommandNotFoundErrorKeys as n, hasPriorityValidationError as r, CommandNotFoundError as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as ArgsValidationError } from "./resolver-CbDvcwY3.js";
|
|
2
|
+
import { m as DefaultGunshiParams, n as CliOptions } from "./types-H9nag_2Z.js";
|
|
2
3
|
|
|
3
4
|
//#region src/constants.d.ts
|
|
4
5
|
/**
|
|
@@ -9,10 +10,6 @@ declare const ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
|
9
10
|
declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
|
|
10
11
|
//#endregion
|
|
11
12
|
//#region src/error.d.ts
|
|
12
|
-
/**
|
|
13
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
14
|
-
* @license MIT
|
|
15
|
-
*/
|
|
16
13
|
/**
|
|
17
14
|
* Command not found error resource keys.
|
|
18
15
|
*/
|
|
@@ -54,6 +51,10 @@ type CommandNotFoundErrorOptions = {
|
|
|
54
51
|
};
|
|
55
52
|
/**
|
|
56
53
|
* Error raised when a command cannot be resolved.
|
|
54
|
+
*
|
|
55
|
+
* Each instance carries a non-enumerable brand keyed by
|
|
56
|
+
* `Symbol.for('gunshi.CommandNotFoundError')`, so that {@link isCommandNotFoundError}
|
|
57
|
+
* recognizes it even when it was created by another bundled copy of gunshi.
|
|
57
58
|
*/
|
|
58
59
|
declare class CommandNotFoundError extends Error {
|
|
59
60
|
readonly code?: CommandNotFoundErrorCode;
|
|
@@ -72,10 +73,34 @@ declare class CommandNotFoundError extends Error {
|
|
|
72
73
|
/**
|
|
73
74
|
* Check whether an error is a {@link CommandNotFoundError}.
|
|
74
75
|
*
|
|
76
|
+
* `instanceof` alone is not enough: `@gunshi/plugin` is bundled with its own copy of this
|
|
77
|
+
* class (`noExternal: ['gunshi/plugin']`), so an error thrown by `gunshi` is never an instance
|
|
78
|
+
* of the class a plugin imports. Errors from another copy are recognized through the
|
|
79
|
+
* `Symbol.for('gunshi.CommandNotFoundError')` brand, which does not depend on `error.name`.
|
|
80
|
+
*
|
|
75
81
|
* @param error - An unknown error
|
|
76
82
|
* @returns `true` if the error is a {@link CommandNotFoundError}
|
|
77
83
|
*/
|
|
78
84
|
declare function isCommandNotFoundError(error: unknown): error is CommandNotFoundError;
|
|
85
|
+
/**
|
|
86
|
+
* Check whether an error is an {@link ArgsValidationError}.
|
|
87
|
+
*
|
|
88
|
+
* Prefer this over the `args-tokens` guard of the same name. Both recognize errors from another
|
|
89
|
+
* bundled copy through the `Symbol.for('args-tokens.ArgsValidationError')` brand that
|
|
90
|
+
* `args-tokens` 0.29.0 or later sets, including subclasses such as `ArgResolveError` that
|
|
91
|
+
* override `name` with the argument name. This guard additionally:
|
|
92
|
+
*
|
|
93
|
+
* - recognizes direct `ArgsValidationError` instances from copies bundling `args-tokens`
|
|
94
|
+
* older than 0.29.0, which do not set the brand
|
|
95
|
+
* - checks that `code` and `values` of an error from another copy have the expected types
|
|
96
|
+
*
|
|
97
|
+
* The guard narrows only to {@link ArgsValidationError}: across copies,
|
|
98
|
+
* `instanceof ArgResolveError` still fails, so do not rely on `type` or `schema` for such errors.
|
|
99
|
+
*
|
|
100
|
+
* @param error - An unknown error
|
|
101
|
+
* @returns `true` if the error is an {@link ArgsValidationError}
|
|
102
|
+
*/
|
|
103
|
+
declare function isArgsValidationError(error: unknown): error is ArgsValidationError;
|
|
79
104
|
/**
|
|
80
105
|
* Check whether validation errors should be handled before version, help, or command execution.
|
|
81
106
|
*
|
|
@@ -84,4 +109,4 @@ declare function isCommandNotFoundError(error: unknown): error is CommandNotFoun
|
|
|
84
109
|
*/
|
|
85
110
|
declare function hasPriorityValidationError(error: AggregateError | undefined): boolean;
|
|
86
111
|
//#endregion
|
|
87
|
-
export { hasPriorityValidationError as a,
|
|
112
|
+
export { hasPriorityValidationError as a, ANONYMOUS_COMMAND_NAME as c, CommandNotFoundErrorOptions as i, CLI_OPTIONS_DEFAULT as l, CommandNotFoundErrorCode as n, isArgsValidationError as o, CommandNotFoundErrorKeys as r, isCommandNotFoundError as s, CommandNotFoundError as t };
|
package/lib/generator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-
|
|
1
|
+
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-H9nag_2Z.js";
|
|
2
2
|
|
|
3
3
|
//#region src/generator.d.ts
|
|
4
4
|
|
package/lib/generator.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as ArgsValidationError, c as
|
|
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-
|
|
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-CbDvcwY3.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-H9nag_2Z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
4
|
import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
|
|
5
|
-
import { a as hasPriorityValidationError, i as CommandNotFoundErrorOptions, n as CommandNotFoundErrorCode, o as
|
|
5
|
+
import { a as hasPriorityValidationError, c as ANONYMOUS_COMMAND_NAME, i as CommandNotFoundErrorOptions, n as CommandNotFoundErrorCode, o as isArgsValidationError, r as CommandNotFoundErrorKeys, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-DHF6LJCG.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 { n as ANONYMOUS_COMMAND_NAME, t as createCommandContext } from "./context-CAPhwgJJ.js";
|
|
2
|
-
import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys,
|
|
3
|
-
import {
|
|
4
|
-
import { t as plugin } from "./plugin-
|
|
5
|
-
import { a as namespacedId } from "./src-
|
|
6
|
-
import { t as cli } from "./cli-
|
|
2
|
+
import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
|
|
3
|
+
import { a as isCommandNotFoundError, i as isArgsValidationError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
|
|
4
|
+
import { t as plugin } from "./plugin-DneW3Toi.js";
|
|
5
|
+
import { a as namespacedId } from "./src-80_afJQM.js";
|
|
6
|
+
import { t as cli } from "./cli-BnmSo-DW.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 { a as ArgsValidationError,
|
|
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-
|
|
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-CbDvcwY3.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-H9nag_2Z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
|
-
import { a as hasPriorityValidationError, c as
|
|
4
|
+
import { a as hasPriorityValidationError, c as ANONYMOUS_COMMAND_NAME, i as CommandNotFoundErrorOptions, l as CLI_OPTIONS_DEFAULT, n as CommandNotFoundErrorCode, o as isArgsValidationError, r as CommandNotFoundErrorKeys, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-DHF6LJCG.js";
|
|
5
5
|
|
|
6
6
|
//#region src/plugin.d.ts
|
|
7
7
|
/**
|
package/lib/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as ANONYMOUS_COMMAND_NAME, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CAPhwgJJ.js";
|
|
2
|
-
import { n as ArgsValidationErrorKeys,
|
|
3
|
-
import {
|
|
4
|
-
import { t as plugin } from "./plugin-
|
|
2
|
+
import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
|
|
3
|
+
import { a as isCommandNotFoundError, i as isArgsValidationError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
|
|
4
|
+
import { t as plugin } from "./plugin-DneW3Toi.js";
|
|
5
5
|
export { ANONYMOUS_COMMAND_NAME, ArgsValidationError, ArgsValidationErrorKeys, CLI_OPTIONS_DEFAULT, CommandNotFoundError, CommandNotFoundErrorKeys, createCommandContext, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, plugin };
|
package/lib/renderer.d.ts
CHANGED
package/lib/renderer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-
|
|
1
|
+
import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-80_afJQM.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.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/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.
|
|
91
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/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.
|
|
@@ -548,12 +548,12 @@ interface ArgSchema {
|
|
|
548
548
|
* i18n resource key for localized rendering.
|
|
549
549
|
*/
|
|
550
550
|
declare const ArgsValidationErrorKeys: {
|
|
551
|
-
readonly requiredOption:
|
|
552
|
-
readonly requiredPositional:
|
|
553
|
-
readonly invalidType:
|
|
554
|
-
readonly invalidChoice:
|
|
555
|
-
readonly customParse:
|
|
556
|
-
readonly unknownOption:
|
|
551
|
+
readonly requiredOption: 'err:arg:required-option';
|
|
552
|
+
readonly requiredPositional: 'err:arg:required-positional';
|
|
553
|
+
readonly invalidType: 'err:arg:invalid-type';
|
|
554
|
+
readonly invalidChoice: 'err:arg:invalid-choice';
|
|
555
|
+
readonly customParse: 'err:arg:custom-parse';
|
|
556
|
+
readonly unknownOption: 'err:arg:unknown-option';
|
|
557
557
|
};
|
|
558
558
|
/**
|
|
559
559
|
* A machine-readable argument validation error code.
|
|
@@ -568,6 +568,10 @@ type ArgsValidationErrorCode = (typeof ArgsValidationErrorKeys)[keyof typeof Arg
|
|
|
568
568
|
* The `message` remains the English fallback message. Renderers can use `code`
|
|
569
569
|
* and `values` to localize the error, falling back to `message` when localization
|
|
570
570
|
* is unavailable.
|
|
571
|
+
*
|
|
572
|
+
* Each instance carries a non-enumerable brand keyed by
|
|
573
|
+
* `Symbol.for('args-tokens.ArgsValidationError')`, which {@link isArgsValidationError}
|
|
574
|
+
* uses to recognize instances created by another bundled copy of `args-tokens`.
|
|
571
575
|
*/
|
|
572
576
|
declare class ArgsValidationError extends Error {
|
|
573
577
|
/**
|
|
@@ -592,13 +596,6 @@ declare class ArgsValidationError extends Error {
|
|
|
592
596
|
cause?: unknown;
|
|
593
597
|
});
|
|
594
598
|
}
|
|
595
|
-
/**
|
|
596
|
-
* Check whether the given value is an {@link ArgsValidationError}.
|
|
597
|
-
*
|
|
598
|
-
* @param error - value to check
|
|
599
|
-
* @returns `true` when the value is an `ArgsValidationError`
|
|
600
|
-
*/
|
|
601
|
-
declare function isArgsValidationError(error: unknown): error is ArgsValidationError;
|
|
602
599
|
/**
|
|
603
600
|
* An object that contains {@link ArgSchema | argument schema}.
|
|
604
601
|
*
|
|
@@ -632,7 +629,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
|
|
|
632
629
|
*
|
|
633
630
|
* @internal
|
|
634
631
|
*/
|
|
635
|
-
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends infer P ? { [K in keyof P]: P[K] } : never;
|
|
632
|
+
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends (infer P) ? { [K in keyof P]: P[K] } : never;
|
|
636
633
|
/**
|
|
637
634
|
* Filters the arguments based on their default values.
|
|
638
635
|
*
|
|
@@ -730,8 +727,5 @@ declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
|
|
|
730
727
|
error: AggregateError | undefined;
|
|
731
728
|
explicit: ArgExplicitlyProvided<A>;
|
|
732
729
|
};
|
|
733
|
-
/**
|
|
734
|
-
* An error type for {@link ArgResolveError}.
|
|
735
|
-
*/
|
|
736
730
|
//#endregion
|
|
737
|
-
export { ArgsValidationError as a,
|
|
731
|
+
export { ArgsValidationError as a, resolveArgs as c, Args as i, ArgToken as l, ArgSchema as n, ArgsValidationErrorCode as o, ArgValues as r, ArgsValidationErrorKeys as s, ArgExplicitlyProvided as t, parseArgs as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as kebabnize, t as formatChoices } from "./utils-
|
|
2
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
import { n as kebabnize, t as formatChoices } from "./utils-DbRhwNIU.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/parser.js
|
|
3
3
|
/**
|
|
4
4
|
* forked from `nodejs/node` (`pkgjs/parseargs`)
|
|
5
5
|
* repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
|
|
@@ -204,7 +204,7 @@ function hasOptionValue(value) {
|
|
|
204
204
|
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
205
205
|
}
|
|
206
206
|
//#endregion
|
|
207
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
207
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.js
|
|
208
208
|
/**
|
|
209
209
|
* Entry point of argument options resolver.
|
|
210
210
|
*
|
|
@@ -229,11 +229,24 @@ const ArgsValidationErrorKeys = {
|
|
|
229
229
|
unknownOption: "err:arg:unknown-option"
|
|
230
230
|
};
|
|
231
231
|
/**
|
|
232
|
+
* Brand that marks {@link ArgsValidationError} instances.
|
|
233
|
+
*
|
|
234
|
+
* The brand is looked up in the global symbol registry with `Symbol.for`, so it stays
|
|
235
|
+
* identical across bundled copies of this module and across realms. It lets
|
|
236
|
+
* {@link isArgsValidationError} recognize errors created by another copy of `args-tokens`,
|
|
237
|
+
* where `instanceof` cannot match.
|
|
238
|
+
*/
|
|
239
|
+
const ARGS_VALIDATION_ERROR_BRAND = Symbol.for("args-tokens.ArgsValidationError");
|
|
240
|
+
/**
|
|
232
241
|
* An error that contains structured metadata for argument validation failures.
|
|
233
242
|
*
|
|
234
243
|
* The `message` remains the English fallback message. Renderers can use `code`
|
|
235
244
|
* and `values` to localize the error, falling back to `message` when localization
|
|
236
245
|
* is unavailable.
|
|
246
|
+
*
|
|
247
|
+
* Each instance carries a non-enumerable brand keyed by
|
|
248
|
+
* `Symbol.for('args-tokens.ArgsValidationError')`, which {@link isArgsValidationError}
|
|
249
|
+
* uses to recognize instances created by another bundled copy of `args-tokens`.
|
|
237
250
|
*/
|
|
238
251
|
var ArgsValidationError = class extends Error {
|
|
239
252
|
/**
|
|
@@ -257,16 +270,35 @@ var ArgsValidationError = class extends Error {
|
|
|
257
270
|
this.name = "ArgsValidationError";
|
|
258
271
|
this.code = options.code;
|
|
259
272
|
this.values = options.values ?? {};
|
|
273
|
+
Object.defineProperty(this, ARGS_VALIDATION_ERROR_BRAND, {
|
|
274
|
+
value: true,
|
|
275
|
+
enumerable: false,
|
|
276
|
+
writable: false,
|
|
277
|
+
configurable: false
|
|
278
|
+
});
|
|
260
279
|
}
|
|
261
280
|
};
|
|
262
281
|
/**
|
|
263
282
|
* Check whether the given value is an {@link ArgsValidationError}.
|
|
264
283
|
*
|
|
284
|
+
* This guard also recognizes errors created by another bundled copy of `args-tokens`
|
|
285
|
+
* (0.29.0 or later), where `instanceof` does not match. Such an error must have an own brand
|
|
286
|
+
* keyed by `Symbol.for('args-tokens.ArgsValidationError')` set to `true`, and a `values` object.
|
|
287
|
+
* The guard does not rely on `error.name`, so subclasses such as {@link ArgResolveError} that
|
|
288
|
+
* override `name` are still recognized.
|
|
289
|
+
*
|
|
290
|
+
* The guard narrows to `ArgsValidationError` only. Across bundled copies,
|
|
291
|
+
* `instanceof ArgResolveError` still does not match.
|
|
292
|
+
*
|
|
265
293
|
* @param error - value to check
|
|
266
294
|
* @returns `true` when the value is an `ArgsValidationError`
|
|
267
295
|
*/
|
|
268
296
|
function isArgsValidationError(error) {
|
|
269
|
-
|
|
297
|
+
if (error instanceof ArgsValidationError) return true;
|
|
298
|
+
if (typeof error !== "object" || error === null) return false;
|
|
299
|
+
if (!Object.hasOwn(error, ARGS_VALIDATION_ERROR_BRAND) || error[ARGS_VALIDATION_ERROR_BRAND] !== true) return false;
|
|
300
|
+
const values = error.values;
|
|
301
|
+
return typeof values === "object" && values !== null;
|
|
270
302
|
}
|
|
271
303
|
const SKIP_POSITIONAL_DEFAULT = -1;
|
|
272
304
|
/**
|
|
@@ -359,46 +391,52 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
359
391
|
rest.push(token.value);
|
|
360
392
|
continue;
|
|
361
393
|
}
|
|
362
|
-
if (currentShortOption)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
394
|
+
if (currentShortOption) {
|
|
395
|
+
if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) {
|
|
396
|
+
positionalTokens.push({ ...token });
|
|
397
|
+
applyShortOptionValue();
|
|
398
|
+
} else applyShortOptionValue(token.value);
|
|
399
|
+
} else if (currentLongOption) {
|
|
400
|
+
if (booleanLongOptionNames.has(currentLongOption.name)) {
|
|
401
|
+
positionalTokens.push({ ...token });
|
|
402
|
+
applyLongOptionValue();
|
|
403
|
+
} else applyLongOptionValue(token.value);
|
|
404
|
+
} else positionalTokens.push({ ...token });
|
|
405
|
+
} else if (token.kind === "option") {
|
|
406
|
+
if (token.rawName) {
|
|
407
|
+
if (hasLongOptionPrefix(token.rawName)) {
|
|
408
|
+
applyLongOptionValue();
|
|
409
|
+
if (token.inlineValue) optionTokens.push({ ...token });
|
|
410
|
+
else currentLongOption = { ...token };
|
|
411
|
+
applyShortOptionValue();
|
|
412
|
+
} else if (isShortOption(token.rawName)) {
|
|
413
|
+
if (currentShortOption) {
|
|
414
|
+
if (currentShortOption.index === token.index) {
|
|
415
|
+
if (shortGrouping) {
|
|
416
|
+
currentShortOption.value = token.value;
|
|
417
|
+
optionTokens.push({ ...currentShortOption });
|
|
418
|
+
currentShortOption = { ...token };
|
|
419
|
+
} else expandableShortOptions.push({ ...token });
|
|
420
|
+
} else {
|
|
421
|
+
currentShortOption.value = toShortValue();
|
|
422
|
+
optionTokens.push({ ...currentShortOption });
|
|
423
|
+
currentShortOption = { ...token };
|
|
424
|
+
}
|
|
425
|
+
applyLongOptionValue();
|
|
426
|
+
} else {
|
|
427
|
+
currentShortOption = { ...token };
|
|
428
|
+
applyLongOptionValue();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
} else {
|
|
432
|
+
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
|
|
379
433
|
currentShortOption.value = token.value;
|
|
380
434
|
optionTokens.push({ ...currentShortOption });
|
|
381
|
-
currentShortOption =
|
|
382
|
-
} else expandableShortOptions.push({ ...token });
|
|
383
|
-
else {
|
|
384
|
-
currentShortOption.value = toShortValue();
|
|
385
|
-
optionTokens.push({ ...currentShortOption });
|
|
386
|
-
currentShortOption = { ...token };
|
|
435
|
+
currentShortOption = void 0;
|
|
387
436
|
}
|
|
388
437
|
applyLongOptionValue();
|
|
389
|
-
} else {
|
|
390
|
-
currentShortOption = { ...token };
|
|
391
|
-
applyLongOptionValue();
|
|
392
438
|
}
|
|
393
439
|
} else {
|
|
394
|
-
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
|
|
395
|
-
currentShortOption.value = token.value;
|
|
396
|
-
optionTokens.push({ ...currentShortOption });
|
|
397
|
-
currentShortOption = void 0;
|
|
398
|
-
}
|
|
399
|
-
applyLongOptionValue();
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
440
|
if (token.kind === "option-terminator") terminated = true;
|
|
403
441
|
applyLongOptionValue();
|
|
404
442
|
applyShortOptionValue();
|
|
@@ -643,10 +681,8 @@ function createChoiceError(rawArg, option, schema, actual) {
|
|
|
643
681
|
});
|
|
644
682
|
}
|
|
645
683
|
function createCustomParseError(error, rawArg, option, schema, value) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
return error;
|
|
649
|
-
}
|
|
684
|
+
const reused = reuseValidationError(error, rawArg, option, schema, value);
|
|
685
|
+
if (reused) return reused;
|
|
650
686
|
const reason = getErrorReason(error);
|
|
651
687
|
return new ArgsValidationError(reason, {
|
|
652
688
|
code: ArgsValidationErrorKeys.customParse,
|
|
@@ -658,6 +694,26 @@ function createCustomParseError(error, rawArg, option, schema, value) {
|
|
|
658
694
|
cause: error
|
|
659
695
|
});
|
|
660
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Reuse an {@link ArgsValidationError} thrown from a custom `parse` function, filling in missing values.
|
|
699
|
+
*
|
|
700
|
+
* @param error - The value thrown from `parse`
|
|
701
|
+
* @param rawArg - The argument key in the schema
|
|
702
|
+
* @param option - The option name used on the command line
|
|
703
|
+
* @param schema - The argument schema
|
|
704
|
+
* @param value - The raw input value
|
|
705
|
+
* @returns The same error when it can be reused, otherwise `undefined` so the caller wraps it.
|
|
706
|
+
* Inspecting or updating the thrown value can throw, for example when its `values` object is frozen
|
|
707
|
+
* or an accessor throws; such values are not reused, so a custom `parse` cannot make `resolveArgs` throw this way.
|
|
708
|
+
*/
|
|
709
|
+
function reuseValidationError(error, rawArg, option, schema, value) {
|
|
710
|
+
try {
|
|
711
|
+
if (isArgsValidationError(error)) {
|
|
712
|
+
augmentValidationError(error, rawArg, option, schema, value);
|
|
713
|
+
return error;
|
|
714
|
+
}
|
|
715
|
+
} catch {}
|
|
716
|
+
}
|
|
661
717
|
function augmentValidationError(error, rawArg, option, schema, value) {
|
|
662
718
|
const values = error.values;
|
|
663
719
|
values.name ??= rawArg;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./context-CAPhwgJJ.js";
|
|
2
|
-
import { n as kebabnize } from "./utils-
|
|
2
|
+
import { n as kebabnize } from "./utils-DbRhwNIU.js";
|
|
3
3
|
import { resolveLazyCommand } from "./utils.js";
|
|
4
|
-
import { n as ArgsValidationErrorKeys
|
|
5
|
-
import {
|
|
6
|
-
import { t as plugin } from "./plugin-
|
|
4
|
+
import { n as ArgsValidationErrorKeys } from "./resolver-D5skgYcF.js";
|
|
5
|
+
import { a as isCommandNotFoundError, i as isArgsValidationError } from "./error-B5QxSzk9.js";
|
|
6
|
+
import { t as plugin } from "./plugin-DneW3Toi.js";
|
|
7
7
|
/**
|
|
8
8
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
9
9
|
* @license MIT
|
|
@@ -315,9 +315,10 @@ async function renderUsageSection(ctx) {
|
|
|
315
315
|
}
|
|
316
316
|
async function makeUsageSymbols(ctx) {
|
|
317
317
|
const messages = [await resolveEntry(ctx)];
|
|
318
|
-
if (ctx.omitted)
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
if (ctx.omitted) {
|
|
319
|
+
if (await hasCommands(ctx)) messages.push(` [${await ctx.extensions[pluginId].text(resolveBuiltInKey("COMMANDS"))}]`);
|
|
320
|
+
else messages.push(`${ctx.callMode === "subCommand" ? ` ${await resolveSubCommand(ctx)}` : ""}`);
|
|
321
|
+
} else messages.push(`${ctx.callMode === "subCommand" ? ` ${await resolveSubCommand(ctx)}` : ""}`);
|
|
321
322
|
const optionsSymbols = await generateOptionsSymbols(ctx, ctx.args);
|
|
322
323
|
if (optionsSymbols) messages.push(" ", optionsSymbols);
|
|
323
324
|
const positionalSymbols = generatePositionalSymbols(ctx.args);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided
|
|
1
|
+
import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-CbDvcwY3.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin/context.d.ts
|
|
4
4
|
/**
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-
|
|
1
|
+
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-H9nag_2Z.js";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/utils.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
4
8
|
|
|
5
9
|
//#region src/utils.d.ts
|
|
6
10
|
/**
|
|
@@ -21,12 +25,6 @@ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable
|
|
|
21
25
|
* @returns Converted string into kebab-case.
|
|
22
26
|
*/
|
|
23
27
|
declare function kebabnize(str: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* Format allowed argument choices for validation error values and fallback messages.
|
|
26
|
-
*
|
|
27
|
-
* @param choices - Choice values to format
|
|
28
|
-
* @returns JSON-quoted choices joined with `, `.
|
|
29
|
-
*/
|
|
30
28
|
//#endregion
|
|
31
29
|
//#region src/utils.d.ts
|
|
32
30
|
/**
|
package/lib/utils.js
CHANGED
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.37.
|
|
4
|
+
"version": "0.37.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -108,7 +108,8 @@
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"
|
|
111
|
+
"@types/node": "^25.6.2",
|
|
112
|
+
"args-tokens": "^0.29.0",
|
|
112
113
|
"deno": "^2.7.14",
|
|
113
114
|
"jsr": "^0.14.3",
|
|
114
115
|
"jsr-exports-lint": "^0.4.2",
|
|
@@ -116,11 +117,11 @@
|
|
|
116
117
|
"std-env": "^4.1.0",
|
|
117
118
|
"tsdown": "0.21.0",
|
|
118
119
|
"zod": "^4.4.3",
|
|
119
|
-
"@gunshi/plugin-
|
|
120
|
-
"@gunshi/plugin-
|
|
121
|
-
"@gunshi/
|
|
122
|
-
"@gunshi/shared": "0.37.
|
|
123
|
-
"@gunshi/
|
|
120
|
+
"@gunshi/plugin-global": "0.37.3",
|
|
121
|
+
"@gunshi/plugin-i18n": "0.37.3",
|
|
122
|
+
"@gunshi/resources": "0.37.3",
|
|
123
|
+
"@gunshi/shared": "0.37.3",
|
|
124
|
+
"@gunshi/plugin-renderer": "0.37.3"
|
|
124
125
|
},
|
|
125
126
|
"scripts": {
|
|
126
127
|
"build": "tsdown",
|
package/lib/error-BxeGn0JU.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { n as ArgsValidationErrorKeys, r as isArgsValidationError } from "./resolver-UjEQwV-U.js";
|
|
2
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/index.js
|
|
3
|
-
/**
|
|
4
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/error.ts
|
|
13
|
-
/**
|
|
14
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
15
|
-
* @license MIT
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Command not found error resource keys.
|
|
19
|
-
*/
|
|
20
|
-
const CommandNotFoundErrorKeys = { notFound: "err:cmd:not-found" };
|
|
21
|
-
/**
|
|
22
|
-
* Error raised when a command cannot be resolved.
|
|
23
|
-
*/
|
|
24
|
-
var CommandNotFoundError = class extends Error {
|
|
25
|
-
code;
|
|
26
|
-
values;
|
|
27
|
-
commandName;
|
|
28
|
-
candidates;
|
|
29
|
-
commandPath;
|
|
30
|
-
/**
|
|
31
|
-
* Create a command-not-found error.
|
|
32
|
-
*
|
|
33
|
-
* @param message - Fallback error message
|
|
34
|
-
* @param options - Command-not-found metadata
|
|
35
|
-
*/
|
|
36
|
-
constructor(message, options) {
|
|
37
|
-
super(message, { cause: options.cause });
|
|
38
|
-
this.name = "CommandNotFoundError";
|
|
39
|
-
this.code = options.code;
|
|
40
|
-
this.values = options.values || {};
|
|
41
|
-
this.commandName = options.commandName;
|
|
42
|
-
this.candidates = options.candidates || [];
|
|
43
|
-
this.commandPath = options.commandPath || [];
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Check whether an error is a {@link CommandNotFoundError}.
|
|
48
|
-
*
|
|
49
|
-
* @param error - An unknown error
|
|
50
|
-
* @returns `true` if the error is a {@link CommandNotFoundError}
|
|
51
|
-
*/
|
|
52
|
-
function isCommandNotFoundError(error) {
|
|
53
|
-
return error instanceof CommandNotFoundError;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Check whether validation errors should be handled before version, help, or command execution.
|
|
57
|
-
*
|
|
58
|
-
* @param error - An aggregate validation error
|
|
59
|
-
* @returns `true` if the validation error must be handled with priority
|
|
60
|
-
*/
|
|
61
|
-
function hasPriorityValidationError(error) {
|
|
62
|
-
return error?.errors.some((error) => isCommandNotFoundError(error) || isArgsValidationError(error) && error.code === ArgsValidationErrorKeys.unknownOption) ?? false;
|
|
63
|
-
}
|
|
64
|
-
//#endregion
|
|
65
|
-
export { isCommandNotFoundError as i, CommandNotFoundErrorKeys as n, hasPriorityValidationError as r, CommandNotFoundError as t };
|