@gunshi/plugin-renderer 0.27.5 → 0.28.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/index.d.ts +3 -3
- package/lib/index.js +14 -10
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -67,9 +67,9 @@ type CommandBuiltinKeys = GenerateNamespacedKey<BuiltinResourceKeys>;
|
|
|
67
67
|
* Command i18n option keys.
|
|
68
68
|
* The command i18n option keys are used by the i18n plugin for translation.
|
|
69
69
|
*/
|
|
70
|
-
type CommandArgKeys<A extends Args$1, C = {}, K
|
|
70
|
+
type CommandArgKeys<A extends Args$1, C = {}, K extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A>>, string>, typeof ARG_PREFIX>> = C extends {
|
|
71
71
|
name: infer N;
|
|
72
|
-
} ? (N extends string ? GenerateNamespacedKey<K
|
|
72
|
+
} ? (N extends string ? GenerateNamespacedKey<K, N> : K) : K;
|
|
73
73
|
/**
|
|
74
74
|
* Resolve translation keys for command context.
|
|
75
75
|
*/
|
|
@@ -112,7 +112,7 @@ interface UsageRendererExtension<G extends GunshiParams<any> = DefaultGunshiPara
|
|
|
112
112
|
// for CommandContext
|
|
113
113
|
E extends Record<string, string> = {},
|
|
114
114
|
// for extended resources
|
|
115
|
-
K
|
|
115
|
+
K = ResolveTranslationKeys<A, C, E>>(key: K, values?: Record<string, unknown>) => Promise<string>;
|
|
116
116
|
/**
|
|
117
117
|
* Load commands
|
|
118
118
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ANONYMOUS_COMMAND_NAME, plugin } from "@gunshi/plugin";
|
|
2
2
|
|
|
3
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.23.
|
|
3
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.23.1/node_modules/args-tokens/lib/utils-CxvkckUD.js
|
|
4
4
|
/**
|
|
5
5
|
* Entry point of utils.
|
|
6
6
|
*
|
|
@@ -50,7 +50,8 @@ async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
|
50
50
|
args: cmd.args,
|
|
51
51
|
examples: cmd.examples,
|
|
52
52
|
internal: cmd.internal,
|
|
53
|
-
entry: cmd.entry
|
|
53
|
+
entry: cmd.entry,
|
|
54
|
+
subCommands: cmd.subCommands
|
|
54
55
|
};
|
|
55
56
|
if ("resource" in cmd && cmd.resource) baseCommand.resource = cmd.resource;
|
|
56
57
|
command = Object.assign(create(), baseCommand);
|
|
@@ -66,6 +67,7 @@ async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
|
66
67
|
command.examples = loaded.examples;
|
|
67
68
|
command.internal = loaded.internal;
|
|
68
69
|
command.entry = loaded.entry;
|
|
70
|
+
command.subCommands = loaded.subCommands || cmd.subCommands;
|
|
69
71
|
if ("resource" in loaded && loaded.resource) command.resource = loaded.resource;
|
|
70
72
|
} else throw new TypeError(`Cannot resolve command: ${cmd.name || name}`);
|
|
71
73
|
}
|
|
@@ -201,7 +203,7 @@ function resolveKey(key, name) {
|
|
|
201
203
|
* @param examples - The examples to resolve, which can be a string or a {@linkcode CommandExamplesFetcher | function} that returns a string.
|
|
202
204
|
* @returns A resolved string of examples.
|
|
203
205
|
*/
|
|
204
|
-
async function resolveExamples(ctx, examples) {
|
|
206
|
+
async function resolveExamples$1(ctx, examples) {
|
|
205
207
|
return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
|
|
206
208
|
}
|
|
207
209
|
/**
|
|
@@ -266,7 +268,7 @@ function localizable(ctx, cmd, translate) {
|
|
|
266
268
|
return negatable && schema.type === "boolean" && schema.negatable ? `${NEGATABLE} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
|
|
267
269
|
}
|
|
268
270
|
if (key === resolveKey("description", ctx.name)) return "";
|
|
269
|
-
else if (key === resolveKey("examples", ctx.name)) return await resolveExamples(ctx, cmd.examples);
|
|
271
|
+
else if (key === resolveKey("examples", ctx.name)) return await resolveExamples$1(ctx, cmd.examples);
|
|
270
272
|
else return key;
|
|
271
273
|
}
|
|
272
274
|
return localize;
|
|
@@ -311,7 +313,7 @@ const COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
|
|
|
311
313
|
*/
|
|
312
314
|
async function renderUsage(ctx) {
|
|
313
315
|
const messages = [];
|
|
314
|
-
if (
|
|
316
|
+
if (ctx.callMode === "subCommand") {
|
|
315
317
|
const description = await resolveDescription(ctx);
|
|
316
318
|
if (description) messages.push(description, "");
|
|
317
319
|
}
|
|
@@ -355,7 +357,7 @@ async function renderOptionalArgsSection(ctx) {
|
|
|
355
357
|
*/
|
|
356
358
|
async function renderExamplesSection(ctx) {
|
|
357
359
|
const messages = [];
|
|
358
|
-
const resolvedExamples = await resolveExamples
|
|
360
|
+
const resolvedExamples = await resolveExamples(ctx);
|
|
359
361
|
if (resolvedExamples) {
|
|
360
362
|
const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
|
|
361
363
|
messages.push(`${await ctx.extensions[pluginId].text(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
|
|
@@ -405,10 +407,11 @@ async function renderCommandsSection(ctx) {
|
|
|
405
407
|
return `${command.padStart(ctx.env.leftMargin + command.length)}`;
|
|
406
408
|
}));
|
|
407
409
|
messages.push(...commandsStr, "", `${await ctx.extensions[pluginId].text(resolveBuiltInKey("FORMORE"))}:`);
|
|
410
|
+
const basePath = ctx.commandPath && ctx.commandPath.length > 0 ? `${ctx.env.name} ${ctx.commandPath.join(" ")}` : ctx.env.name;
|
|
408
411
|
messages.push(...loadedCommands.map((cmd) => {
|
|
409
412
|
let commandStr = cmd.entry ? "" : cmd.name || "";
|
|
410
413
|
if (commandStr) commandStr += " ";
|
|
411
|
-
const commandHelp = `${
|
|
414
|
+
const commandHelp = `${basePath} ${commandStr}--help`;
|
|
412
415
|
return `${commandHelp.padStart(ctx.env.leftMargin + commandHelp.length)}`;
|
|
413
416
|
}));
|
|
414
417
|
return messages;
|
|
@@ -443,6 +446,7 @@ async function resolveEntry(ctx) {
|
|
|
443
446
|
* @returns The sub command name
|
|
444
447
|
*/
|
|
445
448
|
async function resolveSubCommand(ctx) {
|
|
449
|
+
if (ctx.commandPath && ctx.commandPath.length > 0) return ctx.commandPath.join(" ");
|
|
446
450
|
return ctx.name || await ctx.extensions[pluginId].text(resolveBuiltInKey("SUBCOMMAND"));
|
|
447
451
|
}
|
|
448
452
|
/**
|
|
@@ -460,11 +464,11 @@ async function resolveDescription(ctx) {
|
|
|
460
464
|
* @param ctx - A {@link CommandContext | command context}
|
|
461
465
|
* @returns resolved command examples, if not resolved, return empty string
|
|
462
466
|
*/
|
|
463
|
-
async function resolveExamples
|
|
467
|
+
async function resolveExamples(ctx) {
|
|
464
468
|
const ret = await ctx.extensions[pluginId].text(resolveKey("examples", ctx.name));
|
|
465
469
|
if (ret) return ret;
|
|
466
470
|
const command = ctx.env.subCommands?.get(ctx.name || "");
|
|
467
|
-
return await resolveExamples(ctx, command?.examples);
|
|
471
|
+
return await resolveExamples$1(ctx, command?.examples);
|
|
468
472
|
}
|
|
469
473
|
/**
|
|
470
474
|
* Check if the command has sub commands
|
|
@@ -666,7 +670,7 @@ function renderer() {
|
|
|
666
670
|
async function loadCommands() {
|
|
667
671
|
if (cachedCommands) return cachedCommands;
|
|
668
672
|
const subCommands = [...ctx.env.subCommands || []];
|
|
669
|
-
cachedCommands = (await Promise.all(subCommands.map(async ([name, cmd
|
|
673
|
+
cachedCommands = (await Promise.all(subCommands.map(async ([name, cmd]) => await resolveLazyCommand(cmd, name)))).filter((cmd) => !cmd.internal).filter(Boolean);
|
|
670
674
|
cachedCommands.sort((a, b) => {
|
|
671
675
|
if (a.entry && !b.entry) return -1;
|
|
672
676
|
if (!a.entry && b.entry) return 1;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/plugin-renderer",
|
|
3
3
|
"description": "usage renderer plugin for gunshi",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@gunshi/plugin": "0.
|
|
56
|
+
"@gunshi/plugin": "0.28.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@gunshi/plugin-i18n": "0.
|
|
59
|
+
"@gunshi/plugin-i18n": "0.28.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"deno": "^2.6.3",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"tsdown": "0.15.12",
|
|
67
67
|
"typedoc": "^0.28.15",
|
|
68
68
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
69
|
-
"@gunshi/shared": "0.
|
|
69
|
+
"@gunshi/shared": "0.28.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsdown",
|