gunshi 0.29.3 → 0.29.5
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 +2 -4
- package/lib/{cli-Dq9-F-ZP.js → cli-COx8zjEj.js} +9 -13
- package/lib/combinators.d.ts +1 -1
- package/lib/combinators.js +1 -2
- package/lib/{constants-QPaYzi6d.d.ts → constants-BKVrvh3H.d.ts} +1 -1
- package/lib/{constants-WviiKqbt.js → constants-Bum1xzqZ.js} +1 -2
- package/lib/context.d.ts +2 -2
- package/lib/context.js +91 -3
- package/lib/{core-BabkHGNU.js → core-CDWBHGHv.js} +6 -13
- package/lib/{core-eN5xmB3s.js → core-x8spYr6g.js} +1 -2
- package/lib/definition.d.ts +2 -2
- package/lib/definition.js +2 -4
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +3 -7
- package/lib/index.d.ts +3 -3
- package/lib/index.js +9 -20
- package/lib/plugin.d.ts +3 -3
- package/lib/plugin.js +4 -5
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +2 -3
- package/lib/{src-CLiit_Bx.js → src-D_ZSzQUF.js} +18 -38
- package/lib/{types-CcuJzRjy.d.ts → types-FFgtdrno.d.ts} +1 -1
- package/lib/{utils-DZGPApAe.js → utils-1JDAM4DH.js} +1 -3
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +2 -3
- package/package.json +8 -8
- package/lib/context-BSv3I5Ip.js +0 -93
- /package/lib/{resolver-D4JorBDf.d.ts → resolver-DGtVt298.d.ts} +0 -0
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 Prettify, D as ValidationErrorsDecorator, E as SubCommandable, S as NormalizeToGunshiParams, T as RenderingOptions, _ 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 RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-
|
|
1
|
+
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-DGtVt298.js";
|
|
2
|
+
import { C as Prettify, D as ValidationErrorsDecorator, E as SubCommandable, S as NormalizeToGunshiParams, T as RenderingOptions, _ 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 RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-FFgtdrno.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/bone.d.ts
|
|
5
5
|
/**
|
package/lib/bone.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as cliCore } from "./core-
|
|
2
|
-
|
|
1
|
+
import { t as cliCore } from "./core-CDWBHGHv.js";
|
|
3
2
|
//#region src/cli/bone.ts
|
|
4
3
|
/**
|
|
5
4
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -18,6 +17,5 @@ import { t as cliCore } from "./core-BabkHGNU.js";
|
|
|
18
17
|
async function cli(args, entry, options = {}) {
|
|
19
18
|
return cliCore(args, entry, options, []);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
//#endregion
|
|
23
|
-
export { cli };
|
|
21
|
+
export { cli };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as cliCore } from "./core-
|
|
2
|
-
import { t as plugin } from "./core-
|
|
3
|
-
import { a as namespacedId,
|
|
4
|
-
|
|
1
|
+
import { t as cliCore } from "./core-CDWBHGHv.js";
|
|
2
|
+
import { t as plugin } from "./core-x8spYr6g.js";
|
|
3
|
+
import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-D_ZSzQUF.js";
|
|
5
4
|
//#region ../plugin-global/src/types.ts
|
|
6
5
|
/**
|
|
7
6
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
@@ -11,7 +10,6 @@ import { a as namespacedId, s as COMMON_ARGS, t as renderer } from "./src-CLiit_
|
|
|
11
10
|
* The unique identifier for the global options plugin.
|
|
12
11
|
*/
|
|
13
12
|
const pluginId = namespacedId("global");
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region ../plugin-global/src/decorator.ts
|
|
17
15
|
/**
|
|
@@ -38,11 +36,12 @@ const decorator = (baseRunner) => async (ctx) => {
|
|
|
38
36
|
}
|
|
39
37
|
return;
|
|
40
38
|
}
|
|
41
|
-
if (validationError)
|
|
39
|
+
if (validationError) {
|
|
40
|
+
await showValidationErrors(validationError);
|
|
41
|
+
throw validationError;
|
|
42
|
+
}
|
|
42
43
|
return baseRunner(ctx);
|
|
43
44
|
};
|
|
44
|
-
var decorator_default = decorator;
|
|
45
|
-
|
|
46
45
|
//#endregion
|
|
47
46
|
//#region ../plugin-global/src/extension.ts
|
|
48
47
|
/**
|
|
@@ -88,7 +87,6 @@ function extension(ctx) {
|
|
|
88
87
|
}
|
|
89
88
|
};
|
|
90
89
|
}
|
|
91
|
-
|
|
92
90
|
//#endregion
|
|
93
91
|
//#region ../plugin-global/src/index.ts
|
|
94
92
|
/**
|
|
@@ -132,11 +130,10 @@ function global() {
|
|
|
132
130
|
extension,
|
|
133
131
|
setup(ctx) {
|
|
134
132
|
for (const [name, schema] of Object.entries(COMMON_ARGS)) ctx.addGlobalOption(name, schema);
|
|
135
|
-
ctx.decorateCommand(
|
|
133
|
+
ctx.decorateCommand(decorator);
|
|
136
134
|
}
|
|
137
135
|
});
|
|
138
136
|
}
|
|
139
|
-
|
|
140
137
|
//#endregion
|
|
141
138
|
//#region src/cli/builtin.ts
|
|
142
139
|
/**
|
|
@@ -156,6 +153,5 @@ function global() {
|
|
|
156
153
|
async function cli(args, entry, options = {}) {
|
|
157
154
|
return cliCore(args, entry, options, [global(), renderer()]);
|
|
158
155
|
}
|
|
159
|
-
|
|
160
156
|
//#endregion
|
|
161
|
-
export { cli as t };
|
|
157
|
+
export { cli as t };
|
package/lib/combinators.d.ts
CHANGED
package/lib/combinators.js
CHANGED
|
@@ -516,6 +516,5 @@ function extend(base, overrides) {
|
|
|
516
516
|
for (const key of Object.keys(overrides)) result[key] = overrides[key];
|
|
517
517
|
return result;
|
|
518
518
|
}
|
|
519
|
-
|
|
520
519
|
//#endregion
|
|
521
|
-
export { args, boolean, choice, combinator, describe, extend, float, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
|
520
|
+
export { args, boolean, choice, combinator, describe, extend, float, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
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-DGtVt298.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-FFgtdrno.js";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
5
5
|
|
package/lib/context.js
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-1JDAM4DH.js";
|
|
2
|
+
import { n as CLI_OPTIONS_DEFAULT, r as NOOP, t as ANONYMOUS_COMMAND_NAME } from "./constants-Bum1xzqZ.js";
|
|
3
|
+
//#region src/context.ts
|
|
4
|
+
/**
|
|
5
|
+
* The entry for gunshi context.
|
|
6
|
+
* This module is exported for the purpose of testing the command.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* import { createCommandContext } from 'gunshi/context'
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Create a command context.
|
|
21
|
+
*
|
|
22
|
+
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
23
|
+
* @returns A {@link CommandContext | command context}, which is readonly.
|
|
24
|
+
*/
|
|
25
|
+
async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", commandPath = [], omitted = false, validationError = void 0 }) {
|
|
26
|
+
/**
|
|
27
|
+
* normailize the options schema and values, to avoid prototype pollution
|
|
28
|
+
*/
|
|
29
|
+
const _args = Object.entries(args).reduce((acc, [key, value]) => {
|
|
30
|
+
acc[key] = Object.assign(create(), value);
|
|
31
|
+
return acc;
|
|
32
|
+
}, create());
|
|
33
|
+
/**
|
|
34
|
+
* setup the environment
|
|
35
|
+
*/
|
|
36
|
+
const env = Object.assign(create(), CLI_OPTIONS_DEFAULT, cliOptions);
|
|
37
|
+
/**
|
|
38
|
+
* apply Command definition's rendering option with highest priority
|
|
39
|
+
*/
|
|
40
|
+
if (command.rendering) {
|
|
41
|
+
const { header, usage, validationErrors } = command.rendering;
|
|
42
|
+
if (header !== void 0) env.renderHeader = header;
|
|
43
|
+
if (usage !== void 0) env.renderUsage = usage;
|
|
44
|
+
if (validationErrors !== void 0) env.renderValidationErrors = validationErrors;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* create the command context
|
|
48
|
+
*/
|
|
49
|
+
const core = Object.assign(create(), {
|
|
50
|
+
name: getCommandName(command),
|
|
51
|
+
description: command.description,
|
|
52
|
+
omitted,
|
|
53
|
+
callMode,
|
|
54
|
+
commandPath,
|
|
55
|
+
env,
|
|
56
|
+
args: _args,
|
|
57
|
+
explicit,
|
|
58
|
+
values,
|
|
59
|
+
positionals,
|
|
60
|
+
rest,
|
|
61
|
+
_: argv,
|
|
62
|
+
tokens,
|
|
63
|
+
toKebab: command.toKebab,
|
|
64
|
+
log: cliOptions.usageSilent ? NOOP : log,
|
|
65
|
+
validationError
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* extend the command context with extensions
|
|
69
|
+
*/
|
|
70
|
+
if (Object.keys(extensions).length > 0) {
|
|
71
|
+
const ext = create(null);
|
|
72
|
+
Object.defineProperty(core, "extensions", {
|
|
73
|
+
value: ext,
|
|
74
|
+
writable: false,
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
for (const [key, extension] of Object.entries(extensions)) {
|
|
79
|
+
ext[key] = await extension.factory(core, command);
|
|
80
|
+
if (extension.onFactory) await extension.onFactory(core, command);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return deepFreeze(core, ["extensions"]);
|
|
84
|
+
}
|
|
85
|
+
function getCommandName(cmd) {
|
|
86
|
+
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || "(anonymous)";
|
|
87
|
+
else if (typeof cmd === "object") return cmd.name || "(anonymous)";
|
|
88
|
+
else return ANONYMOUS_COMMAND_NAME;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { createCommandContext };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-
|
|
2
|
-
import { n as CLI_OPTIONS_DEFAULT, r as NOOP
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { i as isLazyCommand, o as resolveLazyCommand, r as getCommandSubCommands, s as kebabnize, t as create } from "./utils-1JDAM4DH.js";
|
|
2
|
+
import { n as CLI_OPTIONS_DEFAULT, r as NOOP } from "./constants-Bum1xzqZ.js";
|
|
3
|
+
import { createCommandContext } from "./context.js";
|
|
5
4
|
//#region ../../node_modules/.pnpm/args-tokens@0.24.3/node_modules/args-tokens/lib/parser.js
|
|
6
5
|
const HYPHEN_CHAR = "-";
|
|
7
6
|
const HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
|
|
@@ -198,7 +197,6 @@ function hasLongOptionPrefix(arg) {
|
|
|
198
197
|
function hasOptionValue(value) {
|
|
199
198
|
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
200
199
|
}
|
|
201
|
-
|
|
202
200
|
//#endregion
|
|
203
201
|
//#region ../../node_modules/.pnpm/args-tokens@0.24.3/node_modules/args-tokens/lib/resolver.js
|
|
204
202
|
/**
|
|
@@ -499,7 +497,6 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
|
499
497
|
}
|
|
500
498
|
return [];
|
|
501
499
|
}
|
|
502
|
-
|
|
503
500
|
//#endregion
|
|
504
501
|
//#region src/decorators.ts
|
|
505
502
|
const EMPTY_RENDERER = () => Promise.resolve("");
|
|
@@ -564,7 +561,6 @@ function createDecorators() {
|
|
|
564
561
|
}
|
|
565
562
|
});
|
|
566
563
|
}
|
|
567
|
-
|
|
568
564
|
//#endregion
|
|
569
565
|
//#region src/plugin/context.ts
|
|
570
566
|
/**
|
|
@@ -619,7 +615,6 @@ function createPluginContext(decorators, initialSubCommands) {
|
|
|
619
615
|
}
|
|
620
616
|
});
|
|
621
617
|
}
|
|
622
|
-
|
|
623
618
|
//#endregion
|
|
624
619
|
//#region src/plugin/dependency.ts
|
|
625
620
|
/**
|
|
@@ -657,7 +652,6 @@ function resolveDependencies(plugins) {
|
|
|
657
652
|
for (const plugin of plugins) visit(plugin);
|
|
658
653
|
return sorted;
|
|
659
654
|
}
|
|
660
|
-
|
|
661
655
|
//#endregion
|
|
662
656
|
//#region src/cli/core.ts
|
|
663
657
|
/**
|
|
@@ -748,7 +742,7 @@ function createInitialSubCommands(options, entryCmd) {
|
|
|
748
742
|
const entryCopy = Object.assign(create(), entryCmd, { entry: true });
|
|
749
743
|
subCommands.set(resolveEntryName(entryCopy), entryCopy);
|
|
750
744
|
} else if (typeof entryCmd === "function") {
|
|
751
|
-
const name = entryCmd.name ||
|
|
745
|
+
const name = entryCmd.name || "(anonymous)";
|
|
752
746
|
subCommands.set(name, {
|
|
753
747
|
run: entryCmd,
|
|
754
748
|
name,
|
|
@@ -865,7 +859,7 @@ function resolveCommandTree(tokens, entry, options) {
|
|
|
865
859
|
};
|
|
866
860
|
}
|
|
867
861
|
function resolveEntryName(entry) {
|
|
868
|
-
return isLazyCommand(entry) ? entry.commandName ||
|
|
862
|
+
return isLazyCommand(entry) ? entry.commandName || "(anonymous)" : entry.name || "(anonymous)";
|
|
869
863
|
}
|
|
870
864
|
function getPluginExtensions(plugins) {
|
|
871
865
|
const extensions = create();
|
|
@@ -893,6 +887,5 @@ async function executeCommand(cmd, ctx, decorators) {
|
|
|
893
887
|
throw error;
|
|
894
888
|
}
|
|
895
889
|
}
|
|
896
|
-
|
|
897
890
|
//#endregion
|
|
898
|
-
export { resolveArgs as n, parseArgs as r, cliCore as t };
|
|
891
|
+
export { resolveArgs as n, parseArgs as r, cliCore as t };
|
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 Prettify, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, x as LazyCommand, y as GunshiParams } from "./types-
|
|
1
|
+
import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-DGtVt298.js";
|
|
2
|
+
import { C as Prettify, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, x as LazyCommand, y as GunshiParams } from "./types-FFgtdrno.js";
|
|
3
3
|
import { CommandContextParams, createCommandContext } from "./context.js";
|
|
4
4
|
|
|
5
5
|
//#region src/definition.d.ts
|
package/lib/definition.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createCommandContext } from "./context.js";
|
|
3
2
|
//#region src/definition.ts
|
|
4
3
|
/**
|
|
5
4
|
* Define a {@link Command | command}.
|
|
@@ -107,6 +106,5 @@ function lazyWithTypes() {
|
|
|
107
106
|
return lazy(loader, definition);
|
|
108
107
|
};
|
|
109
108
|
}
|
|
110
|
-
|
|
111
109
|
//#endregion
|
|
112
|
-
export { createCommandContext, define, defineWithTypes, lazy, lazyWithTypes };
|
|
110
|
+
export { 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-FFgtdrno.js";
|
|
2
2
|
|
|
3
3
|
//#region src/generator.d.ts
|
|
4
4
|
|
package/lib/generator.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { t as
|
|
3
|
-
import "./src-CLiit_Bx.js";
|
|
4
|
-
import { t as cli } from "./cli-Dq9-F-ZP.js";
|
|
5
|
-
|
|
1
|
+
import { t as create } from "./utils-1JDAM4DH.js";
|
|
2
|
+
import { t as cli } from "./cli-COx8zjEj.js";
|
|
6
3
|
//#region src/generator.ts
|
|
7
4
|
/**
|
|
8
5
|
* The entry for usage generator.
|
|
@@ -40,6 +37,5 @@ async function generate(command, entry, options = {}) {
|
|
|
40
37
|
usageSilent: true
|
|
41
38
|
}) || "";
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
//#endregion
|
|
45
|
-
export { generate };
|
|
41
|
+
export { generate };
|
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 PluginDependency, C as Prettify, D as ValidationErrorsDecorator, E as SubCommandable, F as PluginWithoutExtension, I as plugin, L as PluginContext, M as PluginFunction, N as PluginOptions, O as OnPluginExtension, P as PluginWithExtension, S as NormalizeToGunshiParams, T as RenderingOptions, _ 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 PluginExtension, k as Plugin, 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 RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-
|
|
1
|
+
import { a as resolveArgs, i as Args, n as ArgSchema, o as ArgToken, r as ArgValues, s as parseArgs } from "./resolver-DGtVt298.js";
|
|
2
|
+
import { A as PluginDependency, C as Prettify, D as ValidationErrorsDecorator, E as SubCommandable, F as PluginWithoutExtension, I as plugin, L as PluginContext, M as PluginFunction, N as PluginOptions, O as OnPluginExtension, P as PluginWithExtension, S as NormalizeToGunshiParams, T as RenderingOptions, _ 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 PluginExtension, k as Plugin, 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 RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-FFgtdrno.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-BKVrvh3H.js";
|
|
6
6
|
|
|
7
7
|
//#region ../plugin-i18n/src/types.d.ts
|
|
8
8
|
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { n as resolveArgs, r as parseArgs } from "./core-
|
|
2
|
-
import { t as ANONYMOUS_COMMAND_NAME } from "./constants-
|
|
3
|
-
import {
|
|
1
|
+
import { n as resolveArgs, r as parseArgs } from "./core-CDWBHGHv.js";
|
|
2
|
+
import { t as ANONYMOUS_COMMAND_NAME } from "./constants-Bum1xzqZ.js";
|
|
3
|
+
import { createCommandContext } from "./context.js";
|
|
4
4
|
import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
|
|
5
|
-
import { t as plugin } from "./core-
|
|
6
|
-
import { a as namespacedId
|
|
7
|
-
import { t as cli } from "./cli-
|
|
8
|
-
|
|
5
|
+
import { t as plugin } from "./core-x8spYr6g.js";
|
|
6
|
+
import { a as namespacedId } from "./src-D_ZSzQUF.js";
|
|
7
|
+
import { t as cli } from "./cli-COx8zjEj.js";
|
|
9
8
|
//#region ../plugin-i18n/src/translation.ts
|
|
10
9
|
/**
|
|
11
10
|
* Default implementation of {@linkcode TranslationAdapter}.
|
|
@@ -69,17 +68,7 @@ var DefaultTranslation = class {
|
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
};
|
|
72
|
-
|
|
71
|
+
namespacedId("i18n");
|
|
72
|
+
"_".codePointAt(0);
|
|
73
73
|
//#endregion
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The unique identifier for the i18n plugin.
|
|
77
|
-
*/
|
|
78
|
-
const pluginId = namespacedId("i18n");
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region ../plugin-i18n/src/index.ts
|
|
82
|
-
const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
export { ANONYMOUS_COMMAND_NAME, DefaultTranslation, cli, createCommandContext, define, defineWithTypes, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
|
|
74
|
+
export { ANONYMOUS_COMMAND_NAME, DefaultTranslation, cli, createCommandContext, define, defineWithTypes, lazy, lazyWithTypes, parseArgs, plugin, resolveArgs };
|
package/lib/plugin.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 { A as PluginDependency, C as Prettify, D as ValidationErrorsDecorator, F as PluginWithoutExtension, I as plugin, L as PluginContext, M as PluginFunction, N as PluginOptions, O as OnPluginExtension, P as PluginWithExtension, S as NormalizeToGunshiParams, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginExtension, k as Plugin, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-
|
|
1
|
+
import { i as Args, n as ArgSchema, o as ArgToken, r as ArgValues } from "./resolver-DGtVt298.js";
|
|
2
|
+
import { A as PluginDependency, C as Prettify, D as ValidationErrorsDecorator, F as PluginWithoutExtension, I as plugin, L as PluginContext, M as PluginFunction, N as PluginOptions, O as OnPluginExtension, P as PluginWithExtension, S as NormalizeToGunshiParams, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginExtension, k as Plugin, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as RendererDecorator, x as LazyCommand, y as GunshiParams } from "./types-FFgtdrno.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-BKVrvh3H.js";
|
|
5
5
|
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 };
|
package/lib/plugin.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-
|
|
2
|
-
import {
|
|
3
|
-
import { t as plugin } from "./core-
|
|
4
|
-
|
|
5
|
-
export { ANONYMOUS_COMMAND_NAME, CLI_OPTIONS_DEFAULT, createCommandContext, plugin };
|
|
1
|
+
import { n as CLI_OPTIONS_DEFAULT, t as ANONYMOUS_COMMAND_NAME } from "./constants-Bum1xzqZ.js";
|
|
2
|
+
import { createCommandContext } from "./context.js";
|
|
3
|
+
import { t as plugin } from "./core-x8spYr6g.js";
|
|
4
|
+
export { ANONYMOUS_COMMAND_NAME, CLI_OPTIONS_DEFAULT, createCommandContext, plugin };
|
package/lib/renderer.d.ts
CHANGED
package/lib/renderer.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-
|
|
2
|
-
|
|
3
|
-
export { renderHeader, renderUsage, renderValidationErrors };
|
|
1
|
+
import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-D_ZSzQUF.js";
|
|
2
|
+
export { renderHeader, renderUsage, renderValidationErrors };
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import { o as resolveLazyCommand, s as kebabnize } from "./utils-
|
|
2
|
-
import
|
|
3
|
-
import { t as plugin } from "./core-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
8
|
-
* @license MIT
|
|
9
|
-
*/
|
|
10
|
-
const BUILT_IN_PREFIX = "_";
|
|
11
|
-
const PLUGIN_PREFIX = "g";
|
|
12
|
-
const ARG_PREFIX = "arg";
|
|
13
|
-
const BUILT_IN_KEY_SEPARATOR = ":";
|
|
14
|
-
const BUILD_IN_PREFIX_AND_KEY_SEPARATOR = `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
15
|
-
const ARG_PREFIX_AND_KEY_SEPARATOR = `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}`;
|
|
16
|
-
const ARG_NEGATABLE_PREFIX = "no-";
|
|
1
|
+
import { o as resolveLazyCommand, s as kebabnize } from "./utils-1JDAM4DH.js";
|
|
2
|
+
import "./constants-Bum1xzqZ.js";
|
|
3
|
+
import { t as plugin } from "./core-x8spYr6g.js";
|
|
4
|
+
const BUILD_IN_PREFIX_AND_KEY_SEPARATOR = `_:`;
|
|
5
|
+
const ARG_PREFIX_AND_KEY_SEPARATOR = `arg:`;
|
|
17
6
|
const COMMON_ARGS = {
|
|
18
7
|
help: {
|
|
19
8
|
type: "boolean",
|
|
@@ -26,7 +15,6 @@ const COMMON_ARGS = {
|
|
|
26
15
|
description: "Display this version"
|
|
27
16
|
}
|
|
28
17
|
};
|
|
29
|
-
|
|
30
18
|
//#endregion
|
|
31
19
|
//#region ../resources/locales/en-US.json
|
|
32
20
|
var NEGATABLE = "Negatable of";
|
|
@@ -45,7 +33,6 @@ var en_US_default = {
|
|
|
45
33
|
help: "Display this help message",
|
|
46
34
|
version: "Display this version"
|
|
47
35
|
};
|
|
48
|
-
|
|
49
36
|
//#endregion
|
|
50
37
|
//#region ../shared/src/utils.ts
|
|
51
38
|
/**
|
|
@@ -63,7 +50,7 @@ var en_US_default = {
|
|
|
63
50
|
* @returns Prefixed built-in key.
|
|
64
51
|
*/
|
|
65
52
|
function resolveBuiltInKey(key) {
|
|
66
|
-
return
|
|
53
|
+
return `_:${key}`;
|
|
67
54
|
}
|
|
68
55
|
/**
|
|
69
56
|
* Resolve a namespaced key for argument resources.
|
|
@@ -78,7 +65,7 @@ function resolveBuiltInKey(key) {
|
|
|
78
65
|
* @returns Prefixed argument key.
|
|
79
66
|
*/
|
|
80
67
|
function resolveArgKey(key, name) {
|
|
81
|
-
return `${name ? `${name}
|
|
68
|
+
return `${name ? `${name}:` : ""}arg:${key}`;
|
|
82
69
|
}
|
|
83
70
|
/**
|
|
84
71
|
* Resolve a namespaced key for non-built-in resources.
|
|
@@ -92,7 +79,7 @@ function resolveArgKey(key, name) {
|
|
|
92
79
|
* @returns Prefixed non-built-in key.
|
|
93
80
|
*/
|
|
94
81
|
function resolveKey(key, name) {
|
|
95
|
-
return `${name ? `${name}
|
|
82
|
+
return `${name ? `${name}:` : ""}${key}`;
|
|
96
83
|
}
|
|
97
84
|
/**
|
|
98
85
|
* Resolve command examples.
|
|
@@ -115,7 +102,7 @@ async function resolveExamples$1(ctx, examples) {
|
|
|
115
102
|
* @returns A namespaced key for the plugin.
|
|
116
103
|
*/
|
|
117
104
|
function namespacedId(id) {
|
|
118
|
-
return
|
|
105
|
+
return `g:${id}`;
|
|
119
106
|
}
|
|
120
107
|
/**
|
|
121
108
|
* Generate a short and long option pair for command arguments.
|
|
@@ -130,7 +117,6 @@ function makeShortLongOptionPair(schema, name, toKebab) {
|
|
|
130
117
|
if (schema.short) key = `-${schema.short}, ${key}`;
|
|
131
118
|
return key;
|
|
132
119
|
}
|
|
133
|
-
|
|
134
120
|
//#endregion
|
|
135
121
|
//#region ../shared/src/localization.ts
|
|
136
122
|
/**
|
|
@@ -159,8 +145,8 @@ function localizable(ctx, cmd, translate) {
|
|
|
159
145
|
if (key.startsWith(namaspacedArgKey)) {
|
|
160
146
|
let argKey = key.slice(namaspacedArgKey.length);
|
|
161
147
|
let negatable = false;
|
|
162
|
-
if (argKey.startsWith(
|
|
163
|
-
argKey = argKey.slice(
|
|
148
|
+
if (argKey.startsWith("no-")) {
|
|
149
|
+
argKey = argKey.slice(3);
|
|
164
150
|
negatable = true;
|
|
165
151
|
}
|
|
166
152
|
const schema = ctx.args[argKey];
|
|
@@ -173,7 +159,6 @@ function localizable(ctx, cmd, translate) {
|
|
|
173
159
|
}
|
|
174
160
|
return localize;
|
|
175
161
|
}
|
|
176
|
-
|
|
177
162
|
//#endregion
|
|
178
163
|
//#region ../plugin-renderer/src/header.ts
|
|
179
164
|
/**
|
|
@@ -186,7 +171,6 @@ function renderHeader(ctx) {
|
|
|
186
171
|
const title = ctx.env.description || ctx.env.name || "";
|
|
187
172
|
return Promise.resolve(title ? `${title} (${ctx.env.name || ""}${ctx.env.version ? ` v${ctx.env.version}` : ""})` : title);
|
|
188
173
|
}
|
|
189
|
-
|
|
190
174
|
//#endregion
|
|
191
175
|
//#region ../plugin-renderer/src/types.ts
|
|
192
176
|
/**
|
|
@@ -197,7 +181,6 @@ function renderHeader(ctx) {
|
|
|
197
181
|
* The unique identifier for usage renderer plugin.
|
|
198
182
|
*/
|
|
199
183
|
const pluginId = namespacedId("renderer");
|
|
200
|
-
|
|
201
184
|
//#endregion
|
|
202
185
|
//#region ../plugin-renderer/src/usage.ts
|
|
203
186
|
/**
|
|
@@ -319,7 +302,7 @@ async function renderCommandsSection(ctx) {
|
|
|
319
302
|
async function makeCommandSymbol(ctx, cmd) {
|
|
320
303
|
const optionSymbol = await generateOptionsSymbols(ctx, ctx.args);
|
|
321
304
|
const positionalSymbol = generatePositionalSymbols(ctx.args);
|
|
322
|
-
let commandStr = cmd.entry ? cmd.name === void 0 || cmd.name ===
|
|
305
|
+
let commandStr = cmd.entry ? cmd.name === void 0 || cmd.name === "(anonymous)" ? "" : `[${cmd.name}]` : cmd.name || "";
|
|
323
306
|
if (optionSymbol) {
|
|
324
307
|
if (commandStr) commandStr += " ";
|
|
325
308
|
commandStr += `${optionSymbol}`;
|
|
@@ -433,14 +416,14 @@ function getOptionalArgsPairs(ctx) {
|
|
|
433
416
|
acc[name] = key;
|
|
434
417
|
if (schema.type === "boolean" && schema.negatable && !COMMON_ARGS_KEYS.includes(name)) {
|
|
435
418
|
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
436
|
-
acc[
|
|
419
|
+
acc[`no-${name}`] = `--no-${displayName}`;
|
|
437
420
|
}
|
|
438
421
|
return acc;
|
|
439
422
|
}, Object.create(null));
|
|
440
423
|
}
|
|
441
|
-
const resolveNegatableKey = (key) => key.split(
|
|
424
|
+
const resolveNegatableKey = (key) => key.split("no-")[1];
|
|
442
425
|
function resolveNegatableType(key, ctx) {
|
|
443
|
-
return ctx.args[key.startsWith(
|
|
426
|
+
return ctx.args[key.startsWith("no-") ? resolveNegatableKey(key) : key].type;
|
|
444
427
|
}
|
|
445
428
|
async function generateDefaultDisplayValue(ctx, schema) {
|
|
446
429
|
return `${await ctx.extensions[pluginId].text(resolveBuiltInKey("DEFAULT"))}: ${schema.default}`;
|
|
@@ -468,14 +451,14 @@ async function generateOptionalArgsUsage(ctx, optionsPairs) {
|
|
|
468
451
|
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
|
|
469
452
|
return (await Promise.all(Object.entries(optionsPairs).map(async ([key, value]) => {
|
|
470
453
|
let rawDesc = await ctx.extensions[pluginId].text(resolveArgKey(key, ctx.name));
|
|
471
|
-
if (!rawDesc && key.startsWith(
|
|
454
|
+
if (!rawDesc && key.startsWith("no-")) {
|
|
472
455
|
const name = resolveNegatableKey(key);
|
|
473
456
|
const schema = ctx.args[name];
|
|
474
457
|
const optionKey = makeShortLongOptionPair(schema, name, ctx.toKebab);
|
|
475
458
|
rawDesc = `${await ctx.extensions[pluginId].text(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
|
|
476
459
|
}
|
|
477
460
|
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
|
|
478
|
-
const valueDesc = key.startsWith(
|
|
461
|
+
const valueDesc = key.startsWith("no-") ? "" : await resolveDisplayValue(ctx, key);
|
|
479
462
|
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
480
463
|
const descLength = desc.length + valueDesc.length;
|
|
481
464
|
const option = `${value.padEnd((descLength > 0 ? optionsMaxLength : 0) + ctx.env.middleMargin)}${desc}${valueDesc ? ` ${valueDesc}` : ""}`;
|
|
@@ -502,7 +485,6 @@ function generatePositionalSymbols(args) {
|
|
|
502
485
|
return elements.join(" ");
|
|
503
486
|
}).join(" ") : "";
|
|
504
487
|
}
|
|
505
|
-
|
|
506
488
|
//#endregion
|
|
507
489
|
//#region ../plugin-renderer/src/validation.ts
|
|
508
490
|
/**
|
|
@@ -517,7 +499,6 @@ function renderValidationErrors(_ctx, error) {
|
|
|
517
499
|
for (const err of error.errors) messages.push(err.message);
|
|
518
500
|
return Promise.resolve(messages.join("\n"));
|
|
519
501
|
}
|
|
520
|
-
|
|
521
502
|
//#endregion
|
|
522
503
|
//#region ../plugin-renderer/src/index.ts
|
|
523
504
|
/**
|
|
@@ -593,6 +574,5 @@ function renderer() {
|
|
|
593
574
|
}
|
|
594
575
|
});
|
|
595
576
|
}
|
|
596
|
-
|
|
597
577
|
//#endregion
|
|
598
|
-
export { namespacedId as a, renderHeader as i, renderValidationErrors as n,
|
|
578
|
+
export { namespacedId as a, renderHeader as i, renderValidationErrors as n, COMMON_ARGS as o, renderUsage as r, renderer as t };
|
|
@@ -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-DGtVt298.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin/context.d.ts
|
|
4
4
|
/**
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
function kebabnize(str) {
|
|
20
20
|
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
//#endregion
|
|
24
23
|
//#region src/utils.ts
|
|
25
24
|
/**
|
|
@@ -124,6 +123,5 @@ function deepFreeze(obj, ignores = []) {
|
|
|
124
123
|
}
|
|
125
124
|
return Object.freeze(obj);
|
|
126
125
|
}
|
|
127
|
-
|
|
128
126
|
//#endregion
|
|
129
|
-
export { log as a, isLazyCommand as i, deepFreeze as n, resolveLazyCommand as o, getCommandSubCommands as r, kebabnize as s, create as t };
|
|
127
|
+
export { log as a, isLazyCommand as i, deepFreeze as n, resolveLazyCommand as o, getCommandSubCommands as r, kebabnize as s, create as t };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-FFgtdrno.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../node_modules/.pnpm/args-tokens@0.24.3/node_modules/args-tokens/lib/utils.d.ts
|
|
4
4
|
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +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-
|
|
2
|
-
|
|
3
|
-
export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveLazyCommand };
|
|
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-1JDAM4DH.js";
|
|
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.29.
|
|
4
|
+
"version": "0.29.5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -103,17 +103,17 @@
|
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"args-tokens": "^0.24.3",
|
|
106
|
-
"deno": "^2.7.
|
|
107
|
-
"jsr": "^0.
|
|
106
|
+
"deno": "^2.7.11",
|
|
107
|
+
"jsr": "^0.14.3",
|
|
108
108
|
"jsr-exports-lint": "^0.4.2",
|
|
109
109
|
"publint": "^0.3.18",
|
|
110
110
|
"tsdown": "0.15.12",
|
|
111
111
|
"zod": "^4.3.6",
|
|
112
|
-
"@gunshi/plugin-
|
|
113
|
-
"@gunshi/plugin-
|
|
114
|
-
"@gunshi/plugin-
|
|
115
|
-
"@gunshi/
|
|
116
|
-
"@gunshi/
|
|
112
|
+
"@gunshi/plugin-global": "0.29.5",
|
|
113
|
+
"@gunshi/plugin-renderer": "0.29.5",
|
|
114
|
+
"@gunshi/plugin-i18n": "0.29.5",
|
|
115
|
+
"@gunshi/shared": "0.29.5",
|
|
116
|
+
"@gunshi/resources": "0.29.5"
|
|
117
117
|
},
|
|
118
118
|
"scripts": {
|
|
119
119
|
"build": "tsdown",
|
package/lib/context-BSv3I5Ip.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { a as log, i as isLazyCommand, n as deepFreeze, t as create } from "./utils-DZGPApAe.js";
|
|
2
|
-
import { n as CLI_OPTIONS_DEFAULT, r as NOOP, t as ANONYMOUS_COMMAND_NAME } from "./constants-WviiKqbt.js";
|
|
3
|
-
|
|
4
|
-
//#region src/context.ts
|
|
5
|
-
/**
|
|
6
|
-
* The entry for gunshi context.
|
|
7
|
-
* This module is exported for the purpose of testing the command.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```js
|
|
11
|
-
* import { createCommandContext } from 'gunshi/context'
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @module
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
18
|
-
* @license MIT
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Create a command context.
|
|
22
|
-
*
|
|
23
|
-
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
24
|
-
* @returns A {@link CommandContext | command context}, which is readonly.
|
|
25
|
-
*/
|
|
26
|
-
async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", commandPath = [], omitted = false, validationError = void 0 }) {
|
|
27
|
-
/**
|
|
28
|
-
* normailize the options schema and values, to avoid prototype pollution
|
|
29
|
-
*/
|
|
30
|
-
const _args = Object.entries(args).reduce((acc, [key, value]) => {
|
|
31
|
-
acc[key] = Object.assign(create(), value);
|
|
32
|
-
return acc;
|
|
33
|
-
}, create());
|
|
34
|
-
/**
|
|
35
|
-
* setup the environment
|
|
36
|
-
*/
|
|
37
|
-
const env = Object.assign(create(), CLI_OPTIONS_DEFAULT, cliOptions);
|
|
38
|
-
/**
|
|
39
|
-
* apply Command definition's rendering option with highest priority
|
|
40
|
-
*/
|
|
41
|
-
if (command.rendering) {
|
|
42
|
-
const { header, usage, validationErrors } = command.rendering;
|
|
43
|
-
if (header !== void 0) env.renderHeader = header;
|
|
44
|
-
if (usage !== void 0) env.renderUsage = usage;
|
|
45
|
-
if (validationErrors !== void 0) env.renderValidationErrors = validationErrors;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* create the command context
|
|
49
|
-
*/
|
|
50
|
-
const core = Object.assign(create(), {
|
|
51
|
-
name: getCommandName(command),
|
|
52
|
-
description: command.description,
|
|
53
|
-
omitted,
|
|
54
|
-
callMode,
|
|
55
|
-
commandPath,
|
|
56
|
-
env,
|
|
57
|
-
args: _args,
|
|
58
|
-
explicit,
|
|
59
|
-
values,
|
|
60
|
-
positionals,
|
|
61
|
-
rest,
|
|
62
|
-
_: argv,
|
|
63
|
-
tokens,
|
|
64
|
-
toKebab: command.toKebab,
|
|
65
|
-
log: cliOptions.usageSilent ? NOOP : log,
|
|
66
|
-
validationError
|
|
67
|
-
});
|
|
68
|
-
/**
|
|
69
|
-
* extend the command context with extensions
|
|
70
|
-
*/
|
|
71
|
-
if (Object.keys(extensions).length > 0) {
|
|
72
|
-
const ext = create(null);
|
|
73
|
-
Object.defineProperty(core, "extensions", {
|
|
74
|
-
value: ext,
|
|
75
|
-
writable: false,
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true
|
|
78
|
-
});
|
|
79
|
-
for (const [key, extension] of Object.entries(extensions)) {
|
|
80
|
-
ext[key] = await extension.factory(core, command);
|
|
81
|
-
if (extension.onFactory) await extension.onFactory(core, command);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return deepFreeze(core, ["extensions"]);
|
|
85
|
-
}
|
|
86
|
-
function getCommandName(cmd) {
|
|
87
|
-
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
88
|
-
else if (typeof cmd === "object") return cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
89
|
-
else return ANONYMOUS_COMMAND_NAME;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
export { createCommandContext as t };
|
|
File without changes
|