gunshi 0.6.0 → 0.6.2
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.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, createCommandContext } from "./context-DmZAeiph.js";
|
|
2
2
|
import { create, log, resolveLazyCommand } from "./utils-NHs5DuHk.js";
|
|
3
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
3
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-v5Uq0km9.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
7
7
|
async function cli(args, entry, opts = {}) {
|
|
8
8
|
const tokens = parseArgs(args);
|
|
9
9
|
const subCommand = getSubCommand(tokens);
|
|
10
|
-
const resolvedCommandOptions = resolveCommandOptions(opts);
|
|
10
|
+
const resolvedCommandOptions = resolveCommandOptions(opts, entry);
|
|
11
11
|
const [name, command] = await resolveCommand(subCommand, entry, resolvedCommandOptions);
|
|
12
12
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
13
|
-
if (command.name && !resolvedCommandOptions.subCommands.has(command.name)) resolvedCommandOptions.subCommands.set(command.name, command);
|
|
14
13
|
const options = resolveArgOptions(command.options);
|
|
15
14
|
const { values, positionals, error } = resolveArgs(options, tokens);
|
|
16
15
|
const omitted = !subCommand;
|
|
@@ -20,7 +19,7 @@ async function cli(args, entry, opts = {}) {
|
|
|
20
19
|
positionals,
|
|
21
20
|
omitted,
|
|
22
21
|
command,
|
|
23
|
-
commandOptions:
|
|
22
|
+
commandOptions: resolvedCommandOptions
|
|
24
23
|
});
|
|
25
24
|
if (values.version) {
|
|
26
25
|
showVersion(ctx);
|
|
@@ -43,9 +42,10 @@ async function cli(args, entry, opts = {}) {
|
|
|
43
42
|
function resolveArgOptions(options) {
|
|
44
43
|
return Object.assign(create(), options, COMMON_OPTIONS);
|
|
45
44
|
}
|
|
46
|
-
function resolveCommandOptions(options) {
|
|
45
|
+
function resolveCommandOptions(options, entry) {
|
|
47
46
|
const subCommands = new Map(options.subCommands);
|
|
48
|
-
|
|
47
|
+
if (typeof entry === "object" && entry.name) subCommands.set(entry.name, entry);
|
|
48
|
+
return Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands });
|
|
49
49
|
}
|
|
50
50
|
function getSubCommand(tokens) {
|
|
51
51
|
const firstToken = tokens[0];
|
package/lib/renderer/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../utils-NHs5DuHk.js";
|
|
2
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-
|
|
2
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-v5Uq0km9.js";
|
|
3
3
|
|
|
4
4
|
export { renderHeader, renderUsage, renderValidationErrors };
|
|
@@ -10,7 +10,10 @@ function renderHeader(ctx) {
|
|
|
10
10
|
//#region src/renderer/usage.ts
|
|
11
11
|
async function renderUsage(ctx) {
|
|
12
12
|
const messages = [];
|
|
13
|
-
if (!ctx.omitted
|
|
13
|
+
if (!ctx.omitted) {
|
|
14
|
+
const description = resolveDescription(ctx);
|
|
15
|
+
if (description) messages.push(description, "");
|
|
16
|
+
}
|
|
14
17
|
messages.push(...await renderUsageSection(ctx), "");
|
|
15
18
|
if (ctx.omitted && await hasCommands(ctx)) messages.push(...await renderCommandsSection(ctx), "");
|
|
16
19
|
if (hasOptions(ctx)) messages.push(...await renderOptionsSection(ctx), "");
|
|
@@ -99,12 +102,12 @@ function resolveSubCommand(ctx) {
|
|
|
99
102
|
return ctx.name || ctx.translation("SUBCOMMAND");
|
|
100
103
|
}
|
|
101
104
|
/**
|
|
102
|
-
*
|
|
105
|
+
* Resolve the command description
|
|
103
106
|
* @param ctx A {@link CommandContext | command context}
|
|
104
|
-
* @returns
|
|
107
|
+
* @returns resolved command description
|
|
105
108
|
*/
|
|
106
|
-
function
|
|
107
|
-
return
|
|
109
|
+
function resolveDescription(ctx) {
|
|
110
|
+
return ctx.translation("description") || ctx.description || "";
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* Check if the command has sub commands
|