gunshi 0.19.0 → 0.21.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/README.md +1 -0
- package/lib/{cli-m93bHwFR.js → cli-PK_LzdQr.js} +34 -9
- package/lib/{context-CBDAvGDh.js → context-BefYjlE-.js} +5 -7
- package/lib/context.d.ts +6 -1
- package/lib/context.js +2 -2
- package/lib/{definition-Bdw7cMea.d.ts → definition-DUNcKGVg.d.ts} +1 -1
- package/lib/definition.d.ts +2 -2
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +4 -4
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -4
- package/lib/{renderer-BDs5T_Z4.js → renderer-BpwhGYRZ.js} +6 -6
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +2 -2
- package/lib/{types-BVZKXMbJ.d.ts → types-BbgfNBFM.d.ts} +25 -3
- package/lib/{utils-DWRmOGGa.js → utils-STQBqMtf.js} +4 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ About more details and usage, see [documentations](https://gunshi.dev)
|
|
|
99
99
|
## 💁♀️ Showcases
|
|
100
100
|
|
|
101
101
|
- [pnpmc](https://github.com/kazupon/pnpmc): PNPM Catalogs Tooling
|
|
102
|
+
- [sourcemap-publisher](https://github.com/es-tooling/sourcemap-publisher): A tool to publish sourcemaps externally and rewrite sourcemap URLs at pre-publish time
|
|
102
103
|
|
|
103
104
|
## 🙌 Contributing guidelines
|
|
104
105
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, resolveLazyCommand } from "./utils-
|
|
2
|
-
import { createCommandContext } from "./context-
|
|
3
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
1
|
+
import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, resolveLazyCommand } from "./utils-STQBqMtf.js";
|
|
2
|
+
import { createCommandContext } from "./context-BefYjlE-.js";
|
|
3
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
@@ -15,7 +15,7 @@ async function cli(argv, entry, opts = {}) {
|
|
|
15
15
|
const tokens = parseArgs(argv);
|
|
16
16
|
const subCommand = getSubCommand(tokens);
|
|
17
17
|
const resolvedCommandOptions = resolveCommandOptions(opts, entry);
|
|
18
|
-
const [name, command] = await resolveCommand(subCommand, entry, resolvedCommandOptions, true);
|
|
18
|
+
const [name, command, callMode] = await resolveCommand(subCommand, entry, resolvedCommandOptions, true);
|
|
19
19
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
20
20
|
const args = resolveArguments(command.args);
|
|
21
21
|
const { values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
@@ -31,6 +31,7 @@ async function cli(argv, entry, opts = {}) {
|
|
|
31
31
|
argv,
|
|
32
32
|
tokens,
|
|
33
33
|
omitted,
|
|
34
|
+
callMode,
|
|
34
35
|
command,
|
|
35
36
|
commandOptions: resolvedCommandOptions
|
|
36
37
|
});
|
|
@@ -93,13 +94,37 @@ async function showValidationErrors(ctx, error) {
|
|
|
93
94
|
}
|
|
94
95
|
async function resolveCommand(sub, entry, options, needRunResolving = false) {
|
|
95
96
|
const omitted = !sub;
|
|
96
|
-
if (typeof entry === "function") return [
|
|
97
|
-
|
|
97
|
+
if (typeof entry === "function") return [
|
|
98
|
+
void 0,
|
|
99
|
+
{ run: entry },
|
|
100
|
+
"entry"
|
|
101
|
+
];
|
|
102
|
+
else if (omitted) return typeof entry === "object" ? [
|
|
103
|
+
resolveEntryName(entry),
|
|
104
|
+
await resolveLazyCommand(entry, "", needRunResolving),
|
|
105
|
+
"entry"
|
|
106
|
+
] : [
|
|
107
|
+
void 0,
|
|
108
|
+
void 0,
|
|
109
|
+
"unexpected"
|
|
110
|
+
];
|
|
98
111
|
else {
|
|
99
|
-
if (options.subCommands == null || options.subCommands.size === 0) return [
|
|
112
|
+
if (options.subCommands == null || options.subCommands.size === 0) return [
|
|
113
|
+
resolveEntryName(entry),
|
|
114
|
+
await resolveLazyCommand(entry, "", needRunResolving),
|
|
115
|
+
"entry"
|
|
116
|
+
];
|
|
100
117
|
const cmd = options.subCommands?.get(sub);
|
|
101
|
-
if (cmd == null) return [
|
|
102
|
-
|
|
118
|
+
if (cmd == null) return [
|
|
119
|
+
sub,
|
|
120
|
+
void 0,
|
|
121
|
+
"unexpected"
|
|
122
|
+
];
|
|
123
|
+
return [
|
|
124
|
+
sub,
|
|
125
|
+
await resolveLazyCommand(cmd, sub, needRunResolving),
|
|
126
|
+
"subCommand"
|
|
127
|
+
];
|
|
103
128
|
}
|
|
104
129
|
}
|
|
105
130
|
function resolveEntryName(entry) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveLazyCommand } from "./utils-
|
|
1
|
+
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-STQBqMtf.js";
|
|
2
2
|
|
|
3
3
|
//#region src/locales/en-US.json
|
|
4
4
|
var COMMAND = "COMMAND";
|
|
@@ -72,7 +72,7 @@ const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
|
|
|
72
72
|
* @param param A {@link CommandContextParams | parameters} to create a {@link CommandContext | command context}
|
|
73
73
|
* @returns A {@link CommandContext | command context}, which is readonly
|
|
74
74
|
*/
|
|
75
|
-
async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, commandOptions, omitted = false }) {
|
|
75
|
+
async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, commandOptions, callMode = "entry", omitted = false }) {
|
|
76
76
|
/**
|
|
77
77
|
* normailize the options schema and values, to avoid prototype pollution
|
|
78
78
|
*/
|
|
@@ -128,6 +128,7 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
128
128
|
name: command.name,
|
|
129
129
|
description: command.description,
|
|
130
130
|
omitted,
|
|
131
|
+
callMode,
|
|
131
132
|
locale,
|
|
132
133
|
env,
|
|
133
134
|
args: _args,
|
|
@@ -152,14 +153,11 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
152
153
|
return res;
|
|
153
154
|
}, create());
|
|
154
155
|
defaultCommandResource.description = command.description || "";
|
|
155
|
-
defaultCommandResource.examples = command.examples
|
|
156
|
+
defaultCommandResource.examples = await resolveExamples(ctx, command.examples);
|
|
156
157
|
adapter.setResource(DEFAULT_LOCALE, defaultCommandResource);
|
|
157
158
|
const originalResource = await loadCommandResource(ctx, command);
|
|
158
159
|
if (originalResource) {
|
|
159
|
-
const resource = Object.assign(create(), {
|
|
160
|
-
description: originalResource.description,
|
|
161
|
-
examples: originalResource.examples
|
|
162
|
-
}, originalResource);
|
|
160
|
+
const resource = Object.assign(create(), originalResource, { examples: await resolveExamples(ctx, originalResource.examples) });
|
|
163
161
|
if (builtInLoadedResources) {
|
|
164
162
|
resource.help = builtInLoadedResources.help;
|
|
165
163
|
resource.version = builtInLoadedResources.version;
|
package/lib/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandContext, CommandOptions } from "./types-
|
|
1
|
+
import { Command, CommandCallMode, CommandContext, CommandOptions } from "./types-BbgfNBFM.js";
|
|
2
2
|
import { ArgToken, ArgValues, Args } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
@@ -38,6 +38,10 @@ interface CommandContextParams<A extends Args, V> {
|
|
|
38
38
|
* Whether the command is omitted
|
|
39
39
|
*/
|
|
40
40
|
omitted: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Command call mode.
|
|
43
|
+
*/
|
|
44
|
+
callMode: CommandCallMode;
|
|
41
45
|
/**
|
|
42
46
|
* A target {@link Command | command}
|
|
43
47
|
*/
|
|
@@ -61,6 +65,7 @@ declare function createCommandContext<A extends Args = Args, V extends ArgValues
|
|
|
61
65
|
tokens,
|
|
62
66
|
command,
|
|
63
67
|
commandOptions,
|
|
68
|
+
callMode,
|
|
64
69
|
omitted
|
|
65
70
|
}: CommandContextParams<A, V>): Promise<Readonly<CommandContext<A, V>>>; //#endregion
|
|
66
71
|
export { createCommandContext };
|
package/lib/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandLoader, LazyCommand } from "./types-
|
|
1
|
+
import { Command, CommandLoader, LazyCommand } from "./types-BbgfNBFM.js";
|
|
2
2
|
import { ArgSchema, ArgValues as ArgValues$1, Args, Args as Args$1 } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/definition.d.ts
|
package/lib/definition.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-
|
|
1
|
+
import "./types-BbgfNBFM.js";
|
|
2
|
+
import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-DUNcKGVg.js";
|
|
3
3
|
export { ArgSchema, ArgValues, Args, define, lazy };
|
package/lib/generator.d.ts
CHANGED
package/lib/generator.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { create } from "./utils-
|
|
2
|
-
import "./context-
|
|
3
|
-
import "./renderer-
|
|
4
|
-
import { cli } from "./cli-
|
|
1
|
+
import { create } from "./utils-STQBqMtf.js";
|
|
2
|
+
import "./context-BefYjlE-.js";
|
|
3
|
+
import "./renderer-BpwhGYRZ.js";
|
|
4
|
+
import { cli } from "./cli-PK_LzdQr.js";
|
|
5
5
|
|
|
6
6
|
//#region src/generator.ts
|
|
7
7
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-
|
|
2
|
-
import { define$1 as define, lazy$1 as lazy } from "./definition-
|
|
1
|
+
import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-BbgfNBFM.js";
|
|
2
|
+
import { define$1 as define, lazy$1 as lazy } from "./definition-DUNcKGVg.js";
|
|
3
3
|
import { ArgSchema, ArgValues, Args, Args as Args$1, parseArgs, resolveArgs } from "args-tokens";
|
|
4
4
|
|
|
5
5
|
//#region src/cli.d.ts
|
|
@@ -32,4 +32,4 @@ declare class DefaultTranslation implements TranslationAdapter {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
|
-
export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
|
|
35
|
+
export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-
|
|
2
|
-
import { DefaultTranslation } from "./context-
|
|
1
|
+
import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-STQBqMtf.js";
|
|
2
|
+
import { DefaultTranslation } from "./context-BefYjlE-.js";
|
|
3
3
|
import { define, lazy } from "./definition-DyVBFqB7.js";
|
|
4
|
-
import "./renderer-
|
|
5
|
-
import { cli } from "./cli-
|
|
4
|
+
import "./renderer-BpwhGYRZ.js";
|
|
5
|
+
import { cli } from "./cli-PK_LzdQr.js";
|
|
6
6
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
7
7
|
|
|
8
8
|
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, lazy, parseArgs, resolveArgs };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey } from "./utils-
|
|
1
|
+
import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey, resolveExamples } from "./utils-STQBqMtf.js";
|
|
2
2
|
|
|
3
3
|
//#region src/renderer/header.ts
|
|
4
4
|
/**
|
|
@@ -29,7 +29,7 @@ async function renderUsage(ctx) {
|
|
|
29
29
|
if (ctx.omitted && await hasCommands(ctx)) messages.push(...await renderCommandsSection(ctx), "");
|
|
30
30
|
if (hasPositionalArgs(ctx)) messages.push(...await renderPositionalArgsSection(ctx), "");
|
|
31
31
|
if (hasOptionalArgs(ctx)) messages.push(...await renderOptionalArgsSection(ctx), "");
|
|
32
|
-
const examples = renderExamplesSection(ctx);
|
|
32
|
+
const examples = await renderExamplesSection(ctx);
|
|
33
33
|
if (examples.length > 0) messages.push(...examples, "");
|
|
34
34
|
return messages.join("\n");
|
|
35
35
|
}
|
|
@@ -60,9 +60,9 @@ async function renderOptionalArgsSection(ctx) {
|
|
|
60
60
|
* @param ctx A {@link CommandContext | command context}
|
|
61
61
|
* @returns A rendered examples section
|
|
62
62
|
*/
|
|
63
|
-
function renderExamplesSection(ctx) {
|
|
63
|
+
async function renderExamplesSection(ctx) {
|
|
64
64
|
const messages = [];
|
|
65
|
-
const resolvedExamples = resolveExamples(ctx);
|
|
65
|
+
const resolvedExamples = await resolveExamples$1(ctx);
|
|
66
66
|
if (resolvedExamples) {
|
|
67
67
|
const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
|
|
68
68
|
messages.push(`${ctx.translate(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
|
|
@@ -140,11 +140,11 @@ function resolveDescription(ctx) {
|
|
|
140
140
|
* @param ctx A {@link CommandContext | command context}
|
|
141
141
|
* @returns resolved command examples, if not resolved, return empty string
|
|
142
142
|
*/
|
|
143
|
-
function resolveExamples(ctx) {
|
|
143
|
+
async function resolveExamples$1(ctx) {
|
|
144
144
|
const ret = ctx.translate("examples");
|
|
145
145
|
if (ret) return ret;
|
|
146
146
|
const command = ctx.env.subCommands?.get(ctx.name || "");
|
|
147
|
-
return command?.examples
|
|
147
|
+
return await resolveExamples(ctx, command?.examples);
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Check if the command has sub commands
|
package/lib/renderer.d.ts
CHANGED
package/lib/renderer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./utils-
|
|
2
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
1
|
+
import "./utils-STQBqMtf.js";
|
|
2
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
|
|
3
3
|
|
|
4
4
|
export { renderHeader, renderUsage, renderValidationErrors };
|
|
@@ -34,29 +34,36 @@ type Awaitable<T> = T | Promise<T>;
|
|
|
34
34
|
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
|
|
35
35
|
/**
|
|
36
36
|
* Remove index signature from object or record type.
|
|
37
|
+
* @internal
|
|
37
38
|
*/
|
|
38
39
|
type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
|
|
40
|
+
/** @internal */
|
|
39
41
|
type KeyOfArgs<A extends Args> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A];
|
|
40
42
|
/**
|
|
41
43
|
* Generate a namespaced key.
|
|
44
|
+
* @internal
|
|
42
45
|
*/
|
|
43
46
|
type GenerateNamespacedKey<Key extends string, Prefixed extends string = typeof BUILT_IN_PREFIX> = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
|
|
44
47
|
/**
|
|
45
48
|
* Command i18n built-in arguments keys.
|
|
49
|
+
* @internal
|
|
46
50
|
*/
|
|
47
51
|
type CommandBuiltinArgsKeys = keyof (typeof constants_d_exports)['COMMON_ARGS'];
|
|
48
52
|
/**
|
|
49
53
|
* Command i18n built-in resource keys.
|
|
54
|
+
* @internal
|
|
50
55
|
*/
|
|
51
56
|
type CommandBuiltinResourceKeys = (typeof constants_d_exports)['COMMAND_BUILTIN_RESOURCE_KEYS'][number];
|
|
52
57
|
/**
|
|
53
58
|
* Command i18n built-in keys.
|
|
54
59
|
* The command i18n built-in keys are used to {@link CommandContext.translate | translate} function.
|
|
60
|
+
* @internal
|
|
55
61
|
*/
|
|
56
62
|
type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinArgsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | 'description' | 'examples';
|
|
57
63
|
/**
|
|
58
64
|
* Command i18n option keys.
|
|
59
65
|
* The command i18n option keys are used to {@link CommandContext.translate | translate} function.
|
|
66
|
+
* @internal
|
|
60
67
|
*/
|
|
61
68
|
type CommandArgKeys<A extends Args> = GenerateNamespacedKey<KeyOfArgs<RemovedIndex<A>>, typeof ARG_PREFIX>;
|
|
62
69
|
/**
|
|
@@ -198,6 +205,10 @@ interface CommandOptions<A extends Args = Args> {
|
|
|
198
205
|
*/
|
|
199
206
|
translationAdapterFactory?: TranslationAdapterFactory;
|
|
200
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Command call mode.
|
|
210
|
+
*/
|
|
211
|
+
type CommandCallMode = 'entry' | 'subCommand' | 'unexpected';
|
|
201
212
|
/**
|
|
202
213
|
* Command context.
|
|
203
214
|
* Command context is the context of the command execution.
|
|
@@ -254,6 +265,11 @@ interface CommandContext<A extends Args = Args, V = ArgValues<A>> {
|
|
|
254
265
|
* Whether the currently executing command has been executed with the sub-command name omitted.
|
|
255
266
|
*/
|
|
256
267
|
omitted: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Command call mode.
|
|
270
|
+
* The command call mode is `entry` when the command is executed as an entry command, and `subCommand` when the command is executed as a sub-command.
|
|
271
|
+
*/
|
|
272
|
+
callMode: CommandCallMode;
|
|
257
273
|
/**
|
|
258
274
|
* Output a message.
|
|
259
275
|
* If {@link CommandEnvironment.usageSilent} is true, the message is not output.
|
|
@@ -298,7 +314,7 @@ interface Command<A extends Args = Args> {
|
|
|
298
314
|
* Command examples.
|
|
299
315
|
* examples of how to use the command.
|
|
300
316
|
*/
|
|
301
|
-
examples?: string
|
|
317
|
+
examples?: string | CommandExamplesFetcher<A>;
|
|
302
318
|
/**
|
|
303
319
|
* Command runner. it's the command to be executed
|
|
304
320
|
*/
|
|
@@ -319,10 +335,16 @@ type CommandResource<A extends Args = Args> = {
|
|
|
319
335
|
/**
|
|
320
336
|
* Examples usage.
|
|
321
337
|
*/
|
|
322
|
-
examples: string
|
|
338
|
+
examples: string | CommandExamplesFetcher<A>;
|
|
323
339
|
} & { [Arg in GenerateNamespacedKey<KeyOfArgs<RemovedIndex<A>>, typeof ARG_PREFIX>]: string } & {
|
|
324
340
|
[key: string]: string;
|
|
325
341
|
};
|
|
342
|
+
/**
|
|
343
|
+
* Command examples fetcher.
|
|
344
|
+
* @param ctx A {@link CommandContext | command context}
|
|
345
|
+
* @returns A fetched command examples.
|
|
346
|
+
*/
|
|
347
|
+
type CommandExamplesFetcher<A extends Args = Args, V = ArgValues<A>> = (ctx: Readonly<CommandContext<A, V>>) => Promise<string>;
|
|
326
348
|
/**
|
|
327
349
|
* Command resource fetcher.
|
|
328
350
|
* @param ctx A {@link CommandContext | command context}
|
|
@@ -404,4 +426,4 @@ type LazyCommand<A extends Args = Args> = {
|
|
|
404
426
|
* Define a command type.
|
|
405
427
|
*/
|
|
406
428
|
type Commandable<A extends Args> = Command<A> | LazyCommand<A>; //#endregion
|
|
407
|
-
export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
|
429
|
+
export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
|
@@ -71,6 +71,9 @@ function resolveBuiltInKey(key) {
|
|
|
71
71
|
function resolveArgKey(key) {
|
|
72
72
|
return `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
73
73
|
}
|
|
74
|
+
async function resolveExamples(ctx, examples) {
|
|
75
|
+
return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
|
|
76
|
+
}
|
|
74
77
|
function mapResourceWithBuiltinKey(resource) {
|
|
75
78
|
return Object.entries(resource).reduce((acc, [key, value]) => {
|
|
76
79
|
acc[resolveBuiltInKey(key)] = value;
|
|
@@ -93,4 +96,4 @@ function deepFreeze(obj) {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
//#endregion
|
|
96
|
-
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveLazyCommand };
|
|
99
|
+
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveExamples, 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.21.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -103,11 +103,13 @@
|
|
|
103
103
|
"eslint-plugin-vue-composable": "^1.0.0",
|
|
104
104
|
"eslint-plugin-yml": "^1.18.0",
|
|
105
105
|
"gh-changelogen": "^0.2.8",
|
|
106
|
+
"gunshi019": "npm:gunshi@0.19.0",
|
|
106
107
|
"jsr": "^0.13.4",
|
|
107
108
|
"jsr-exports-lint": "^0.2.0",
|
|
108
109
|
"knip": "^5.53.0",
|
|
109
110
|
"lint-staged": "^15.5.1",
|
|
110
111
|
"messageformat": "4.0.0-10",
|
|
112
|
+
"mitata": "^1.0.34",
|
|
111
113
|
"pkg-pr-new": "^0.0.43",
|
|
112
114
|
"prettier": "^3.5.3",
|
|
113
115
|
"publint": "^0.3.12",
|
|
@@ -138,6 +140,8 @@
|
|
|
138
140
|
]
|
|
139
141
|
},
|
|
140
142
|
"scripts": {
|
|
143
|
+
"bench:mitata": "node --expose-gc bench/mitata.js",
|
|
144
|
+
"bench:vitest": "vitest bench --run",
|
|
141
145
|
"build": "tsdown",
|
|
142
146
|
"changelog": "gh-changelogen --repo=kazupon/gunshi",
|
|
143
147
|
"clean": "git clean -df",
|
|
@@ -145,7 +149,7 @@
|
|
|
145
149
|
"dev:eslint": "pnpx @eslint/config-inspector --config eslint.config.ts",
|
|
146
150
|
"dev:typedoc": "typedoc --watch --preserveWatchOutput",
|
|
147
151
|
"docs:build": "pnpm run docs:build:typedoc && pnpm docs:build:vitepress",
|
|
148
|
-
"docs:build:typedoc": "typedoc",
|
|
152
|
+
"docs:build:typedoc": "typedoc --excludeInternal",
|
|
149
153
|
"docs:build:vitepress": "vitepress build docs",
|
|
150
154
|
"docs:dev": "pnpm run docs:build:typedoc && pnpm docs:dev:vitepress",
|
|
151
155
|
"docs:dev:vitepress": "vitepress dev docs",
|