gunshi 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bone.d.ts +3 -3
- package/lib/bone.js +1 -1
- package/lib/{cli-DfaFk6tk.js → cli-CS4q7S8l.js} +2 -2
- package/lib/combinators.d.ts +10 -6
- package/lib/combinators.js +8 -5
- package/lib/{constants-CPTXtFxe.d.ts → constants-Dmeogxy-.d.ts} +1 -1
- package/lib/context.d.ts +14 -8
- package/lib/context.js +1 -1
- package/lib/{core-BKtZQ6dG.js → core-C83Uo6wC.js} +43 -9
- package/lib/definition.d.ts +16 -37
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/index.js +3 -3
- package/lib/plugin.d.ts +4 -4
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +1 -1
- package/lib/{resolver-CIPNDx1a.d.ts → resolver-eOZBRWlR.d.ts} +15 -6
- package/lib/{src-dTYUlEw_.js → src-Cs21MA7o.js} +10 -3
- package/lib/{types-CyyzAaDx.d.ts → types-DZ8CuO6z.d.ts} +70 -47
- package/lib/{utils-jNy8sqR5.js → utils-9CtzCGbg.js} +1 -1
- package/lib/utils.d.ts +2 -2
- package/lib/utils.js +1 -1
- package/package.json +7 -7
package/lib/bone.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-
|
|
2
|
-
import { C as
|
|
1
|
+
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
|
|
2
|
+
import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/bone.d.ts
|
|
5
5
|
/**
|
|
@@ -54,4 +54,4 @@ declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[
|
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
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, NormalizeToGunshiParams, Prettify, RendererDecorator, RenderingOptions, SubCommandable, ValidationErrorsDecorator, cli };
|
|
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 };
|
package/lib/bone.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as plugin } from "./core-D1daCTTE.js";
|
|
2
|
-
import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-
|
|
3
|
-
import { t as cliCore } from "./core-
|
|
2
|
+
import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Cs21MA7o.js";
|
|
3
|
+
import { t as cliCore } from "./core-C83Uo6wC.js";
|
|
4
4
|
//#region ../plugin-global/src/types.ts
|
|
5
5
|
/**
|
|
6
6
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
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-eOZBRWlR.js";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/combinators.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
6
6
|
* @license MIT
|
|
@@ -242,6 +242,7 @@ type ArgSchemaPositionalType = {
|
|
|
242
242
|
* const args = {
|
|
243
243
|
* command: positional(), // resolves to string
|
|
244
244
|
* port: positional(integer()), // resolves to number
|
|
245
|
+
* query: unrequired(positional()) // optional positional
|
|
245
246
|
* }
|
|
246
247
|
* ```
|
|
247
248
|
*
|
|
@@ -262,6 +263,7 @@ declare function positional<T>(parser: CombinatorSchema<T>): CombinatorSchema<T>
|
|
|
262
263
|
* const args = {
|
|
263
264
|
* command: positional(), // resolves to string
|
|
264
265
|
* port: positional(integer()), // resolves to number
|
|
266
|
+
* query: unrequired(positional()) // optional positional
|
|
265
267
|
* }
|
|
266
268
|
* ```
|
|
267
269
|
*
|
|
@@ -511,10 +513,11 @@ type CombinatorUnrequired = {
|
|
|
511
513
|
/**
|
|
512
514
|
* Mark a combinator schema as not required.
|
|
513
515
|
*
|
|
514
|
-
* Useful for overriding a base combinator that was created with `required: true
|
|
516
|
+
* Useful for overriding a base combinator that was created with `required: true`,
|
|
517
|
+
* or for making a positional argument explicitly optional.
|
|
515
518
|
* The original schema is not modified.
|
|
516
519
|
*
|
|
517
|
-
* @typeParam T - The schema
|
|
520
|
+
* @typeParam T - The schema type.
|
|
518
521
|
*
|
|
519
522
|
* @param schema - The base combinator schema.
|
|
520
523
|
* @returns A new schema with `required: false`.
|
|
@@ -522,13 +525,14 @@ type CombinatorUnrequired = {
|
|
|
522
525
|
* @example
|
|
523
526
|
* ```ts
|
|
524
527
|
* const args = {
|
|
525
|
-
* name: unrequired(string({ required: true }))
|
|
528
|
+
* name: unrequired(string({ required: true })),
|
|
529
|
+
* query: unrequired(positional())
|
|
526
530
|
* }
|
|
527
531
|
* ```
|
|
528
532
|
*
|
|
529
533
|
* @experimental
|
|
530
534
|
*/
|
|
531
|
-
declare function unrequired<T>(schema:
|
|
535
|
+
declare function unrequired<T extends ArgSchema>(schema: T): Omit<T, 'required'> & CombinatorUnrequired;
|
|
532
536
|
/**
|
|
533
537
|
* Recursively merge a tuple of {@link Args} types.
|
|
534
538
|
* Later types override earlier ones on key conflicts.
|
package/lib/combinators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/combinators.js
|
|
2
2
|
/**
|
|
3
3
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
4
4
|
* @license MIT
|
|
@@ -179,7 +179,8 @@ function positional(parser) {
|
|
|
179
179
|
parse: parser.parse,
|
|
180
180
|
metavar: parser.metavar,
|
|
181
181
|
...parser.description != null ? { description: parser.description } : {},
|
|
182
|
-
...parser.required != null ? { required: parser.required } : {}
|
|
182
|
+
...parser.required != null ? { required: parser.required } : {},
|
|
183
|
+
...parser.default != null ? { default: parser.default } : {}
|
|
183
184
|
};
|
|
184
185
|
const opts = parser;
|
|
185
186
|
return {
|
|
@@ -437,10 +438,11 @@ function describe(schema, text) {
|
|
|
437
438
|
/**
|
|
438
439
|
* Mark a combinator schema as not required.
|
|
439
440
|
*
|
|
440
|
-
* Useful for overriding a base combinator that was created with `required: true
|
|
441
|
+
* Useful for overriding a base combinator that was created with `required: true`,
|
|
442
|
+
* or for making a positional argument explicitly optional.
|
|
441
443
|
* The original schema is not modified.
|
|
442
444
|
*
|
|
443
|
-
* @typeParam T - The schema
|
|
445
|
+
* @typeParam T - The schema type.
|
|
444
446
|
*
|
|
445
447
|
* @param schema - The base combinator schema.
|
|
446
448
|
* @returns A new schema with `required: false`.
|
|
@@ -448,7 +450,8 @@ function describe(schema, text) {
|
|
|
448
450
|
* @example
|
|
449
451
|
* ```ts
|
|
450
452
|
* const args = {
|
|
451
|
-
* name: unrequired(string({ required: true }))
|
|
453
|
+
* name: unrequired(string({ required: true })),
|
|
454
|
+
* query: unrequired(positional())
|
|
452
455
|
* }
|
|
453
456
|
* ```
|
|
454
457
|
*
|
package/lib/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Args, o as ArgToken, r as ArgValues } from "./resolver-
|
|
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, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
|
|
2
|
+
import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, m as DefaultGunshiParams, n as CliOptions, r as Command, s as CommandContextExtension, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
5
5
|
|
|
@@ -8,7 +8,16 @@ import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g a
|
|
|
8
8
|
*
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
type
|
|
11
|
+
type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
12
|
+
/**
|
|
13
|
+
* Return type of {@link createCommandContext}
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
type CommandContextResult<G extends GunshiParamsConstraint, E extends Record<string, CommandContextExtension>> = {} extends ExtractExtensionValues<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
18
|
+
args: ExtractArgs<G>;
|
|
19
|
+
extensions: ExtractExtensionValues<E>;
|
|
20
|
+
}>>>;
|
|
12
21
|
/**
|
|
13
22
|
* Parameters of {@link createCommandContext}
|
|
14
23
|
*/
|
|
@@ -95,9 +104,6 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
95
104
|
commandPath,
|
|
96
105
|
omitted,
|
|
97
106
|
validationError
|
|
98
|
-
}: CommandContextParams<G, V, C, E>): Promise<
|
|
99
|
-
args: ExtractArgs<G>;
|
|
100
|
-
extensions: ExtractExtensions<E>;
|
|
101
|
-
}>>>>;
|
|
107
|
+
}: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
|
|
102
108
|
//#endregion
|
|
103
|
-
export { CommandContextParams,
|
|
109
|
+
export { CommandContextParams, ExtractExtensionValues, createCommandContext };
|
package/lib/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as CLI_OPTIONS_DEFAULT, r as NOOP, t as ANONYMOUS_COMMAND_NAME } from "./constants-D_ixLD32.js";
|
|
2
|
-
import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-
|
|
2
|
+
import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-9CtzCGbg.js";
|
|
3
3
|
//#region src/context.ts
|
|
4
4
|
/**
|
|
5
5
|
* The entry for gunshi context.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as CLI_OPTIONS_DEFAULT, r as NOOP } from "./constants-D_ixLD32.js";
|
|
2
|
-
import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-
|
|
2
|
+
import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-9CtzCGbg.js";
|
|
3
3
|
import { createCommandContext } from "./context.js";
|
|
4
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
4
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/parser.js
|
|
5
5
|
/**
|
|
6
6
|
* forked from `nodejs/node` (`pkgjs/parseargs`)
|
|
7
7
|
* repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
|
|
@@ -206,7 +206,7 @@ function hasOptionValue(value) {
|
|
|
206
206
|
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
207
207
|
}
|
|
208
208
|
//#endregion
|
|
209
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
209
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/resolver.js
|
|
210
210
|
/**
|
|
211
211
|
* Entry point of argument options resolver.
|
|
212
212
|
*
|
|
@@ -349,6 +349,8 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
349
349
|
const errors = [];
|
|
350
350
|
const explicit = Object.create(null);
|
|
351
351
|
const actualInputNames = /* @__PURE__ */ new Map();
|
|
352
|
+
const argEntries = Object.entries(args);
|
|
353
|
+
let requiredPositionalsAfter;
|
|
352
354
|
function checkTokenName(option, schema, token) {
|
|
353
355
|
return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
|
|
354
356
|
}
|
|
@@ -356,14 +358,21 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
356
358
|
function getPositionalSkipIndex() {
|
|
357
359
|
return Math.min(skipPositionalIndex, positionalItemCount);
|
|
358
360
|
}
|
|
361
|
+
function getRequiredPositionalsAfter(rawArg) {
|
|
362
|
+
requiredPositionalsAfter ??= createRequiredPositionalsAfter(argEntries);
|
|
363
|
+
return requiredPositionalsAfter[rawArg] ?? 0;
|
|
364
|
+
}
|
|
359
365
|
let positionalsCount = 0;
|
|
360
|
-
for (const [rawArg, schema] of
|
|
366
|
+
for (const [rawArg, schema] of argEntries) {
|
|
361
367
|
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
362
368
|
explicit[rawArg] = false;
|
|
363
369
|
if (schema.type === "positional") {
|
|
364
370
|
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
371
|
+
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
372
|
+
const availablePositionals = Math.max(positionalTokens.length - positionalsCount, 0);
|
|
365
373
|
if (schema.multiple) {
|
|
366
|
-
const
|
|
374
|
+
const positionalsToConsume = Math.max(availablePositionals - requiredPositionals, 0);
|
|
375
|
+
const remainingPositionals = positionalTokens.slice(positionalsCount, positionalsCount + positionalsToConsume);
|
|
367
376
|
if (remainingPositionals.length > 0) {
|
|
368
377
|
if (typeof schema.parse === "function") {
|
|
369
378
|
const parsed = [];
|
|
@@ -379,7 +388,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
379
388
|
} else if (schema.required) errors.push(createRequireError(arg, schema));
|
|
380
389
|
} else {
|
|
381
390
|
const positional = positionalTokens[positionalsCount];
|
|
382
|
-
if (positional != null) {
|
|
391
|
+
if (positional != null && (shouldRequireMissingSinglePositional(schema) || availablePositionals > requiredPositionals)) {
|
|
383
392
|
if (typeof schema.parse === "function") try {
|
|
384
393
|
values[rawArg] = schema.parse(positional.value);
|
|
385
394
|
} catch (error) {
|
|
@@ -387,8 +396,9 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
387
396
|
}
|
|
388
397
|
else values[rawArg] = positional.value;
|
|
389
398
|
explicit[rawArg] = true;
|
|
390
|
-
|
|
391
|
-
|
|
399
|
+
positionalsCount++;
|
|
400
|
+
} else if (shouldRequireMissingSinglePositional(schema)) errors.push(createRequireError(arg, schema));
|
|
401
|
+
else if (hasDefault(schema)) values[rawArg] = schema.default;
|
|
392
402
|
}
|
|
393
403
|
continue;
|
|
394
404
|
}
|
|
@@ -457,6 +467,30 @@ function parse(token, option, schema) {
|
|
|
457
467
|
function createRequireError(option, schema) {
|
|
458
468
|
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
|
|
459
469
|
}
|
|
470
|
+
function hasDefault(schema) {
|
|
471
|
+
return schema.default != null;
|
|
472
|
+
}
|
|
473
|
+
function shouldRequireMissingSinglePositional(schema) {
|
|
474
|
+
if (schema.required === true) return true;
|
|
475
|
+
if (schema.required === false) return false;
|
|
476
|
+
return !hasDefault(schema);
|
|
477
|
+
}
|
|
478
|
+
function getRequiredPositionalInputCount(schema) {
|
|
479
|
+
if (schema.type !== "positional") return 0;
|
|
480
|
+
if (schema.multiple) return schema.required === true ? 1 : 0;
|
|
481
|
+
return shouldRequireMissingSinglePositional(schema) ? 1 : 0;
|
|
482
|
+
}
|
|
483
|
+
function createRequiredPositionalsAfter(argEntries) {
|
|
484
|
+
const requiredPositionalsAfter = Object.create(null);
|
|
485
|
+
let minimumRequiredPositionals = 0;
|
|
486
|
+
for (let i = argEntries.length - 1; i >= 0; i--) {
|
|
487
|
+
const [rawArg, schema] = argEntries[i];
|
|
488
|
+
if (schema.type !== "positional") continue;
|
|
489
|
+
requiredPositionalsAfter[rawArg] = minimumRequiredPositionals;
|
|
490
|
+
minimumRequiredPositionals += getRequiredPositionalInputCount(schema);
|
|
491
|
+
}
|
|
492
|
+
return requiredPositionalsAfter;
|
|
493
|
+
}
|
|
460
494
|
/**
|
|
461
495
|
* An error that occurs when resolving arguments.
|
|
462
496
|
* This error is thrown when the argument is not valid.
|
|
@@ -506,7 +540,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
|
506
540
|
return [];
|
|
507
541
|
}
|
|
508
542
|
//#endregion
|
|
509
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
543
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/index.js
|
|
510
544
|
/**
|
|
511
545
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
512
546
|
* @license MIT
|
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
|
|
1
|
+
import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-eOZBRWlR.js";
|
|
2
|
+
import { C as NormalizeToGunshiParams, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
4
|
|
|
5
5
|
//#region src/definition.d.ts
|
|
@@ -9,17 +9,23 @@ import { CommandContextParams, createCommandContext } from "./context.js";
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The result type of the {@link define} function
|
|
13
13
|
*
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
|
-
type
|
|
16
|
+
type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiParams, C = {}> = Prettify<Pick<C, keyof C> & Partial<Pick<Command<G>, Exclude<keyof Command<G>, keyof C>>>>;
|
|
17
17
|
/**
|
|
18
|
-
* The
|
|
18
|
+
* The command definition accepted by {@link define} helpers.
|
|
19
19
|
*
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
type
|
|
22
|
+
type CommandDefinition<A extends Args, E extends ExtendContext, C extends Partial<Command<{
|
|
23
|
+
args: A;
|
|
24
|
+
extensions: E;
|
|
25
|
+
}>>> = C & Command<{
|
|
26
|
+
args: A;
|
|
27
|
+
extensions: E;
|
|
28
|
+
}>;
|
|
23
29
|
/**
|
|
24
30
|
* Define a {@link Command | command}.
|
|
25
31
|
*
|
|
@@ -50,10 +56,10 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
50
56
|
* @param definition - A {@link Command | command} definition
|
|
51
57
|
* @returns A defined {@link Command | command}
|
|
52
58
|
*/
|
|
53
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends
|
|
59
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends Partial<Command<{
|
|
54
60
|
args: A;
|
|
55
61
|
extensions: ExtractExtensions<G>;
|
|
56
|
-
}>): CommandDefinitionResult<G, C>;
|
|
62
|
+
}>> = {}>(definition: CommandDefinition<A, ExtractExtensions<G>, C>): CommandDefinitionResult<G, C>;
|
|
57
63
|
/**
|
|
58
64
|
* Return type for defineWithTypes
|
|
59
65
|
*
|
|
@@ -64,10 +70,7 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
64
70
|
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
65
71
|
args: A;
|
|
66
72
|
extensions: DefaultExtensions;
|
|
67
|
-
}>> = {}>(definition: C
|
|
68
|
-
args: A;
|
|
69
|
-
extensions: DefaultExtensions;
|
|
70
|
-
}>) => CommandDefinitionResult<{
|
|
73
|
+
}>> = {}>(definition: CommandDefinition<A, DefaultExtensions, C>) => CommandDefinitionResult<{
|
|
71
74
|
args: A;
|
|
72
75
|
extensions: DefaultExtensions;
|
|
73
76
|
}, C>;
|
|
@@ -170,30 +173,6 @@ declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A
|
|
|
170
173
|
args: A;
|
|
171
174
|
extensions: {};
|
|
172
175
|
}, D>;
|
|
173
|
-
/**
|
|
174
|
-
* Normalize G to a full GunshiParams type
|
|
175
|
-
*
|
|
176
|
-
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
177
|
-
*
|
|
178
|
-
* @internal
|
|
179
|
-
*/
|
|
180
|
-
type NormalizeGunshiParams<G extends GunshiParamsConstraint> = G extends GunshiParams<any> ? G : G extends {
|
|
181
|
-
args: infer A;
|
|
182
|
-
extensions: infer E;
|
|
183
|
-
} ? {
|
|
184
|
-
args: A;
|
|
185
|
-
extensions: E;
|
|
186
|
-
} : G extends {
|
|
187
|
-
args: infer A;
|
|
188
|
-
} ? {
|
|
189
|
-
args: A;
|
|
190
|
-
extensions: {};
|
|
191
|
-
} : G extends {
|
|
192
|
-
extensions: infer E;
|
|
193
|
-
} ? {
|
|
194
|
-
args: Args;
|
|
195
|
-
extensions: E;
|
|
196
|
-
} : DefaultGunshiParams;
|
|
197
176
|
/**
|
|
198
177
|
* Return type for lazyWithTypes
|
|
199
178
|
*
|
|
@@ -236,6 +215,6 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
236
215
|
*
|
|
237
216
|
* @since v0.27.0
|
|
238
217
|
*/
|
|
239
|
-
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<
|
|
218
|
+
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<NormalizeToGunshiParams<G>>;
|
|
240
219
|
//#endregion
|
|
241
220
|
export { type ArgSchema, type ArgValues, type Args, type Command, type CommandContextParams, type CommandLoader, type CommandRunner, type DefaultGunshiParams, type ExtendContext, type GunshiParams, type LazyCommand, createCommandContext, define, defineWithTypes, lazy, lazyWithTypes };
|
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-DZ8CuO6z.js";
|
|
2
2
|
|
|
3
3
|
//#region src/generator.d.ts
|
|
4
4
|
|
package/lib/generator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as create } from "./utils-
|
|
2
|
-
import { t as cli } from "./cli-
|
|
1
|
+
import { t as create } from "./utils-9CtzCGbg.js";
|
|
2
|
+
import { t as cli } from "./cli-CS4q7S8l.js";
|
|
3
3
|
//#region src/generator.ts
|
|
4
4
|
/**
|
|
5
5
|
* The entry for usage generator.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as resolveArgs, i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, s as parseArgs } from "./resolver-
|
|
2
|
-
import { A as
|
|
1
|
+
import { a as resolveArgs, i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, s as parseArgs } from "./resolver-eOZBRWlR.js";
|
|
2
|
+
import { A as Plugin, C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, j as PluginDependency, k as OnPluginExtension, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
4
|
import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
|
|
5
|
-
import { t as ANONYMOUS_COMMAND_NAME } from "./constants-
|
|
5
|
+
import { t as ANONYMOUS_COMMAND_NAME } from "./constants-Dmeogxy-.js";
|
|
6
6
|
|
|
7
7
|
//#region ../plugin-i18n/src/types.d.ts
|
|
8
8
|
/**
|
|
@@ -186,4 +186,4 @@ declare function cli(args: string[], entry: SubCommandable, options?: CliOptions
|
|
|
186
186
|
*/
|
|
187
187
|
|
|
188
188
|
//#endregion
|
|
189
|
-
export { ANONYMOUS_COMMAND_NAME, ArgSchema, ArgToken, ArgValues, Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, type CommandContextParams, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, DefaultTranslation, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, 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, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
|
|
189
|
+
export { ANONYMOUS_COMMAND_NAME, ArgSchema, ArgToken, ArgValues, Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, type CommandContextParams, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, 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, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as ANONYMOUS_COMMAND_NAME } from "./constants-D_ixLD32.js";
|
|
2
2
|
import { createCommandContext } from "./context.js";
|
|
3
3
|
import { t as plugin } from "./core-D1daCTTE.js";
|
|
4
|
-
import { a as namespacedId } from "./src-
|
|
5
|
-
import { n as resolveArgs, r as parseArgs } from "./core-
|
|
6
|
-
import { t as cli } from "./cli-
|
|
4
|
+
import { a as namespacedId } from "./src-Cs21MA7o.js";
|
|
5
|
+
import { n as resolveArgs, r as parseArgs } from "./core-C83Uo6wC.js";
|
|
6
|
+
import { t as cli } from "./cli-CS4q7S8l.js";
|
|
7
7
|
import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
|
|
8
8
|
//#region ../plugin-i18n/src/translation.ts
|
|
9
9
|
/**
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-
|
|
2
|
-
import { A as
|
|
1
|
+
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-eOZBRWlR.js";
|
|
2
|
+
import { A as Plugin, C as NormalizeToGunshiParams, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginDependency, k as OnPluginExtension, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-DZ8CuO6z.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
|
-
import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-
|
|
4
|
+
import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-Dmeogxy-.js";
|
|
5
5
|
|
|
6
6
|
//#region src/plugin.d.ts
|
|
7
7
|
/**
|
|
@@ -10,4 +10,4 @@ import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constan
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
|
-
export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, type Awaitable, CLI_OPTIONS_DEFAULT, type Command, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandContextParams, type CommandDecorator, type CommandExamplesFetcher, type CommandRunner, type DefaultGunshiParams, type ExtendContext, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, 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, plugin };
|
|
13
|
+
export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, type Awaitable, CLI_OPTIONS_DEFAULT, type Command, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandContextParams, type CommandDecorator, type CommandExamplesFetcher, 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, 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-Cs21MA7o.js";
|
|
2
2
|
//#region src/renderer.ts
|
|
3
3
|
/**
|
|
4
4
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
|
|
2
2
|
//#region src/parser.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Entry point of argument parser.
|
|
@@ -88,7 +88,7 @@ declare function parseArgs(args: string[], options?: ParserOptions): ArgToken[];
|
|
|
88
88
|
* @returns Whether `arg` is a short option.
|
|
89
89
|
*/
|
|
90
90
|
//#endregion
|
|
91
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
91
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/resolver.d.ts
|
|
92
92
|
//#region src/resolver.d.ts
|
|
93
93
|
/**
|
|
94
94
|
* An argument schema definition for command-line argument parsing.
|
|
@@ -205,7 +205,10 @@ interface ArgSchema {
|
|
|
205
205
|
* When `true`, the argument must be provided by the user.
|
|
206
206
|
* If missing, an `ArgResolveError` with type 'required' will be thrown.
|
|
207
207
|
*
|
|
208
|
-
*
|
|
208
|
+
* For single-value positional arguments, omitting `required` keeps the argument
|
|
209
|
+
* required for compatibility. Set `required: false` to make a positional argument
|
|
210
|
+
* optional. Optional positional arguments leave enough input values for later
|
|
211
|
+
* required positional arguments before consuming a value.
|
|
209
212
|
*
|
|
210
213
|
* @example
|
|
211
214
|
* Required arguments:
|
|
@@ -229,7 +232,8 @@ interface ArgSchema {
|
|
|
229
232
|
*
|
|
230
233
|
* When `true`, the resolved value becomes an array.
|
|
231
234
|
* For options: can be specified multiple times (--tag foo --tag bar)
|
|
232
|
-
* For positional: collects remaining positional arguments
|
|
235
|
+
* For positional: collects remaining positional arguments after preserving values for
|
|
236
|
+
* later required positional arguments.
|
|
233
237
|
*
|
|
234
238
|
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
235
239
|
*
|
|
@@ -309,7 +313,11 @@ interface ArgSchema {
|
|
|
309
313
|
* - `boolean` type: boolean default
|
|
310
314
|
* - `number` type: number default
|
|
311
315
|
* - `enum` type: must be one of the `choices` values
|
|
312
|
-
* - `positional`/`custom` type:
|
|
316
|
+
* - `positional`/`custom` type: string, boolean, or number default
|
|
317
|
+
*
|
|
318
|
+
* For single-value positional arguments, the default is used when the positional
|
|
319
|
+
* value is missing or when the value is preserved for later required positional
|
|
320
|
+
* arguments, unless `required: true` is set.
|
|
313
321
|
*
|
|
314
322
|
* @example
|
|
315
323
|
* Default values by type:
|
|
@@ -566,7 +574,8 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
566
574
|
*
|
|
567
575
|
* @internal
|
|
568
576
|
*/
|
|
569
|
-
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]
|
|
577
|
+
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as IsRequiredPositionalArg<A[Arg]> extends true ? Arg : never]: V[Arg] };
|
|
578
|
+
type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : A['required'] extends false ? A['default'] extends {} ? true : false : true : false;
|
|
570
579
|
/**
|
|
571
580
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
572
581
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./constants-D_ixLD32.js";
|
|
2
|
-
import { o as resolveLazyCommand, s as kebabnize } from "./utils-
|
|
2
|
+
import { o as resolveLazyCommand, s as kebabnize } from "./utils-9CtzCGbg.js";
|
|
3
3
|
import { t as plugin } from "./core-D1daCTTE.js";
|
|
4
4
|
/**
|
|
5
5
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -494,11 +494,18 @@ async function generatePositionalArgsUsage(ctx) {
|
|
|
494
494
|
function generatePositionalSymbols(args) {
|
|
495
495
|
return hasPositionalArgs(args) ? getPositionalArgs(args).map(([name, arg]) => {
|
|
496
496
|
const elements = [];
|
|
497
|
-
if (
|
|
498
|
-
|
|
497
|
+
if (arg.multiple) {
|
|
498
|
+
if (arg.required) elements.push(`<${name}>`);
|
|
499
|
+
elements.push(`[<${name}> ...]`);
|
|
500
|
+
} else elements.push(isRequiredSinglePositionalArg(arg) ? `<${name}>` : `[<${name}>]`);
|
|
499
501
|
return elements.join(" ");
|
|
500
502
|
}).join(" ") : "";
|
|
501
503
|
}
|
|
504
|
+
function isRequiredSinglePositionalArg(arg) {
|
|
505
|
+
if (arg.required === true) return true;
|
|
506
|
+
if (arg.required === false) return false;
|
|
507
|
+
return arg.default == null;
|
|
508
|
+
}
|
|
502
509
|
//#endregion
|
|
503
510
|
//#region ../plugin-renderer/src/validation.ts
|
|
504
511
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-
|
|
1
|
+
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-eOZBRWlR.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin/context.d.ts
|
|
4
4
|
/**
|
|
@@ -6,15 +6,6 @@ import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, t as ArgExpli
|
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Type helper to create GunshiParams from extracted args and extensions
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string, unknown> = {}> = {
|
|
15
|
-
args: ExtractArgs<G>;
|
|
16
|
-
extensions: ExtractExtensions<G> & L;
|
|
17
|
-
};
|
|
18
9
|
/**
|
|
19
10
|
* Gunshi plugin context interface.
|
|
20
11
|
*
|
|
@@ -63,7 +54,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
63
54
|
*
|
|
64
55
|
* @param decorator - A decorator function that wraps the base header renderer.
|
|
65
56
|
*/
|
|
66
|
-
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
57
|
+
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
67
58
|
/**
|
|
68
59
|
* Decorate the usage renderer.
|
|
69
60
|
*
|
|
@@ -71,7 +62,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
71
62
|
*
|
|
72
63
|
* @param decorator - A decorator function that wraps the base usage renderer.
|
|
73
64
|
*/
|
|
74
|
-
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
65
|
+
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
75
66
|
/**
|
|
76
67
|
* Decorate the validation errors renderer.
|
|
77
68
|
*
|
|
@@ -79,7 +70,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
79
70
|
*
|
|
80
71
|
* @param decorator - A decorator function that wraps the base validation errors renderer.
|
|
81
72
|
*/
|
|
82
|
-
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
73
|
+
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>): void;
|
|
83
74
|
/**
|
|
84
75
|
* Decorate the command execution.
|
|
85
76
|
*
|
|
@@ -89,7 +80,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
89
80
|
*
|
|
90
81
|
* @param decorator - A decorator function that wraps the command runner
|
|
91
82
|
*/
|
|
92
|
-
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<
|
|
83
|
+
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>) => (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>): void;
|
|
93
84
|
}
|
|
94
85
|
//#endregion
|
|
95
86
|
//#region src/plugin/core.d.ts
|
|
@@ -155,6 +146,36 @@ type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = Defau
|
|
|
155
146
|
type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => Awaitable<void>;
|
|
156
147
|
type IsStringLiteral<S extends string> = string extends S ? false : true;
|
|
157
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;
|
|
149
|
+
/**
|
|
150
|
+
* Extensions resolved from the declared plugin dependencies.
|
|
151
|
+
*
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
type DependencyExtensions<Deps extends ReadonlyArray<PluginDependency | string>, Context extends ExtendContext> = InferDependencyExtensions<Deps, Context>;
|
|
155
|
+
/**
|
|
156
|
+
* Gunshi params available while a plugin extension resolves its dependencies.
|
|
157
|
+
*
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
type DependencyParams<Deps extends ReadonlyArray<PluginDependency | string>, Context extends ExtendContext> = GunshiParams<{
|
|
161
|
+
args: Args;
|
|
162
|
+
extensions: DependencyExtensions<Deps, Context>;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Extensions available after applying the current plugin extension.
|
|
166
|
+
*
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
type MergedPluginExtensions<Id extends string, Deps extends ReadonlyArray<PluginDependency | string>, Context extends ExtendContext, Ext extends ExtendContext> = MergeExtension<Id, DependencyExtensions<Deps, Context>, Ext>;
|
|
170
|
+
/**
|
|
171
|
+
* Gunshi params available after applying the current plugin extension.
|
|
172
|
+
*
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
type MergedPluginParams<Id extends string, Deps extends ReadonlyArray<PluginDependency | string>, Context extends ExtendContext, Ext extends ExtendContext> = GunshiParams<{
|
|
176
|
+
args: Args;
|
|
177
|
+
extensions: MergedPluginExtensions<Id, Deps, Context, Ext>;
|
|
178
|
+
}>;
|
|
158
179
|
/**
|
|
159
180
|
* Plugin definition options
|
|
160
181
|
*
|
|
@@ -168,13 +189,7 @@ Deps extends ReadonlyArray<PluginDependency | string> = (PluginDependency | stri
|
|
|
168
189
|
// for plugin dependencies
|
|
169
190
|
Ext extends Record<string, unknown> = {},
|
|
170
191
|
// for plugin extension type
|
|
171
|
-
ResolvedDepExt extends GunshiParams = GunshiParams<{
|
|
172
|
-
args: Args;
|
|
173
|
-
extensions: InferDependencyExtensions<Deps, DepExt>;
|
|
174
|
-
}>, PluginExt extends PluginExtension<Ext, ResolvedDepExt> = PluginExtension<Ext, ResolvedDepExt>, MergedExt extends GunshiParams = GunshiParams<{
|
|
175
|
-
args: Args;
|
|
176
|
-
extensions: MergeExtension<Id, InferDependencyExtensions<Deps, DepExt>, Awaited<ReturnType<PluginExt>>>;
|
|
177
|
-
}>> {
|
|
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
193
|
/**
|
|
179
194
|
* Plugin unique identifier
|
|
180
195
|
*/
|
|
@@ -283,20 +298,11 @@ Deps extends ReadonlyArray<PluginDependency | string> = [],
|
|
|
283
298
|
// for plugin dependencies
|
|
284
299
|
Extension extends {} = {},
|
|
285
300
|
// for plugin extension type
|
|
286
|
-
ResolvedDepExtensions extends GunshiParams = GunshiParams<{
|
|
287
|
-
args: Args;
|
|
288
|
-
extensions: InferDependencyExtensions<Deps, Context>;
|
|
289
|
-
}>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = GunshiParams<{
|
|
290
|
-
args: Args;
|
|
291
|
-
extensions: MergeExtension<Id, InferDependencyExtensions<Deps, Context>, Awaited<ReturnType<PluginExt>>>;
|
|
292
|
-
}>>(options: {
|
|
301
|
+
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: {
|
|
293
302
|
id: Id;
|
|
294
303
|
name?: string;
|
|
295
304
|
dependencies?: Deps;
|
|
296
|
-
setup?: (ctx: Readonly<PluginContext<
|
|
297
|
-
args: Args;
|
|
298
|
-
extensions: MergeExtension<Id, InferDependencyExtensions<Deps, Context>, Awaited<ReturnType<PluginExt>>>;
|
|
299
|
-
}>>>) => Awaitable<void>;
|
|
305
|
+
setup?: (ctx: Readonly<PluginContext<MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>>) => Awaitable<void>;
|
|
300
306
|
extension: PluginExt;
|
|
301
307
|
onExtension?: OnPluginExtension<MergedExtensions>;
|
|
302
308
|
}): PluginWithExtension<Awaited<ReturnType<PluginExt>>>;
|
|
@@ -321,20 +327,11 @@ Deps extends ReadonlyArray<PluginDependency | string> = [],
|
|
|
321
327
|
// for plugin dependencies
|
|
322
328
|
Extension extends Record<string, unknown> = {},
|
|
323
329
|
// for plugin extension type
|
|
324
|
-
ResolvedDepExtensions extends GunshiParams = GunshiParams<{
|
|
325
|
-
args: Args;
|
|
326
|
-
extensions: InferDependencyExtensions<Deps, Context>;
|
|
327
|
-
}>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = GunshiParams<{
|
|
328
|
-
args: Args;
|
|
329
|
-
extensions: MergeExtension<Id, InferDependencyExtensions<Deps, Context>, Awaited<ReturnType<PluginExt>>>;
|
|
330
|
-
}>>(options: {
|
|
330
|
+
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: {
|
|
331
331
|
id: Id;
|
|
332
332
|
name?: string;
|
|
333
333
|
dependencies?: Deps;
|
|
334
|
-
setup?: (ctx: Readonly<PluginContext<
|
|
335
|
-
args: Args;
|
|
336
|
-
extensions: MergeExtension<Id, InferDependencyExtensions<Deps, Context>, Awaited<ReturnType<PluginExt>>>;
|
|
337
|
-
}>>>) => Awaitable<void>;
|
|
334
|
+
setup?: (ctx: Readonly<PluginContext<MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>>) => Awaitable<void>;
|
|
338
335
|
onExtension?: OnPluginExtension<MergedExtensions>;
|
|
339
336
|
}): PluginWithoutExtension<DefaultGunshiParams['extensions']>;
|
|
340
337
|
//#endregion
|
|
@@ -436,11 +433,37 @@ type ExtractExtensions<G> = G extends GunshiParams<any> ? G['extensions'] : G ex
|
|
|
436
433
|
* @internal
|
|
437
434
|
*/
|
|
438
435
|
type NormalizeToGunshiParams<G> = G extends GunshiParams<any> ? G : G extends {
|
|
439
|
-
|
|
436
|
+
args: infer A extends Args;
|
|
437
|
+
extensions: infer E extends ExtendContext;
|
|
438
|
+
} ? GunshiParams<{
|
|
439
|
+
args: A;
|
|
440
|
+
extensions: E;
|
|
441
|
+
}> : G extends {
|
|
442
|
+
args: infer A extends Args;
|
|
443
|
+
} ? GunshiParams<{
|
|
444
|
+
args: A;
|
|
445
|
+
extensions: {};
|
|
446
|
+
}> : G extends {
|
|
447
|
+
extensions: infer E extends ExtendContext;
|
|
440
448
|
} ? GunshiParams<{
|
|
441
449
|
args: Args;
|
|
442
|
-
extensions:
|
|
450
|
+
extensions: E;
|
|
443
451
|
}> : DefaultGunshiParams;
|
|
452
|
+
/**
|
|
453
|
+
* Type helper to merge command context extensions into G
|
|
454
|
+
*
|
|
455
|
+
* @internal
|
|
456
|
+
*/
|
|
457
|
+
type MergeGunshiExtensions<G extends GunshiParamsConstraint, E extends ExtendContext> = GunshiParams<{
|
|
458
|
+
/**
|
|
459
|
+
* Command argument definitions.
|
|
460
|
+
*/
|
|
461
|
+
args: ExtractArgs<G>;
|
|
462
|
+
/**
|
|
463
|
+
* Merged command context extensions.
|
|
464
|
+
*/
|
|
465
|
+
extensions: ExtractExtensions<G> & E;
|
|
466
|
+
}>;
|
|
444
467
|
/**
|
|
445
468
|
* Command environment.
|
|
446
469
|
*
|
|
@@ -754,7 +777,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
754
777
|
validationError?: AggregateError;
|
|
755
778
|
}
|
|
756
779
|
/**
|
|
757
|
-
*
|
|
780
|
+
* Readonly command context available to a command context extension factory.
|
|
758
781
|
*
|
|
759
782
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command context.
|
|
760
783
|
*
|
|
@@ -1037,4 +1060,4 @@ type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams
|
|
|
1037
1060
|
*/
|
|
1038
1061
|
type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>;
|
|
1039
1062
|
//#endregion
|
|
1040
|
-
export {
|
|
1063
|
+
export { Plugin as A, NormalizeToGunshiParams as C, SubCommandable as D, RenderingOptions as E, PluginWithExtension as F, PluginWithoutExtension as I, plugin as L, PluginExtension as M, PluginFunction as N, ValidationErrorsDecorator as O, PluginOptions as P, PluginContext as R, MergeGunshiExtensions as S, RendererDecorator as T, ExtractArgs as _, CommandContext as a, GunshiParamsConstraint as b, CommandDecorator as c, CommandLoader as d, CommandRunner as f, ExtractArgExplicitlyProvided as g, ExtendContext as h, CommandCallMode as i, PluginDependency as j, OnPluginExtension as k, CommandEnvironment as l, DefaultGunshiParams as m, CliOptions as n, CommandContextCore as o, Commandable as p, Command as r, CommandContextExtension as s, Awaitable as t, CommandExamplesFetcher as u, ExtractExtensions as v, Prettify as w, LazyCommand as x, GunshiParams as y };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-
|
|
1
|
+
import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-DZ8CuO6z.js";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/utils.d.ts
|
|
4
4
|
|
|
5
5
|
//#region src/utils.d.ts
|
|
6
6
|
/**
|
package/lib/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as log, i as isLazyCommand, n as deepFreeze, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-
|
|
1
|
+
import { a as log, i as isLazyCommand, n as deepFreeze, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-9CtzCGbg.js";
|
|
2
2
|
export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveLazyCommand };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gunshi",
|
|
3
3
|
"description": "Modern javascript command-line library",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.34.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
-
"args-tokens": "^0.
|
|
111
|
+
"args-tokens": "^0.26.1",
|
|
112
112
|
"deno": "^2.7.14",
|
|
113
113
|
"jsr": "^0.14.3",
|
|
114
114
|
"jsr-exports-lint": "^0.4.2",
|
|
@@ -116,11 +116,11 @@
|
|
|
116
116
|
"std-env": "^4.1.0",
|
|
117
117
|
"tsdown": "0.21.0",
|
|
118
118
|
"zod": "^4.4.3",
|
|
119
|
-
"@gunshi/
|
|
120
|
-
"@gunshi/plugin-i18n": "0.
|
|
121
|
-
"@gunshi/
|
|
122
|
-
"@gunshi/
|
|
123
|
-
"@gunshi/plugin-renderer": "0.
|
|
119
|
+
"@gunshi/plugin-global": "0.34.0",
|
|
120
|
+
"@gunshi/plugin-i18n": "0.34.0",
|
|
121
|
+
"@gunshi/resources": "0.34.0",
|
|
122
|
+
"@gunshi/shared": "0.34.0",
|
|
123
|
+
"@gunshi/plugin-renderer": "0.34.0"
|
|
124
124
|
},
|
|
125
125
|
"scripts": {
|
|
126
126
|
"build": "tsdown",
|