gunshi 0.16.0 → 0.18.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/{cli-B7eqtqBF.js → cli-8GpxrUOM.js} +10 -12
- package/lib/{context-BROXRnNP.js → context-DSuCy-i-.js} +5 -1
- package/lib/context.d.ts +54 -45
- package/lib/context.js +2 -2
- package/lib/definition-DZJeZYb2.js +28 -0
- package/lib/definition.d-DaKM6lt0.d.ts +21 -0
- package/lib/definition.d.ts +3 -4
- package/lib/definition.js +2 -2
- package/lib/generator.d.ts +2 -1
- package/lib/generator.js +4 -4
- package/lib/index.d.ts +10 -9
- package/lib/index.js +6 -6
- package/lib/locales/en-US.json +2 -0
- package/lib/locales/ja-JP.json +2 -0
- package/lib/{renderer-BNorS8VG.js → renderer-BgAkL9Re.js} +19 -3
- package/lib/renderer.d.ts +2 -1
- package/lib/renderer.js +2 -2
- package/lib/types.d-BqXvgR9J.d.ts +415 -0
- package/lib/{utils-BYPzZy9X.js → utils-6RnUrIMZ.js} +27 -4
- package/package.json +20 -20
- package/lib/definition-VzcnM0si.js +0 -12
- package/lib/definition.d-DllW_uD3.d.ts +0 -13
- package/lib/types.d-aDzUZTqM.d.ts +0 -403
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, create, resolveLazyCommand } from "./utils-
|
|
2
|
-
import { createCommandContext } from "./context-
|
|
3
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
1
|
+
import { COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, create, resolveLazyCommand } from "./utils-6RnUrIMZ.js";
|
|
2
|
+
import { createCommandContext } from "./context-DSuCy-i-.js";
|
|
3
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BgAkL9Re.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
@@ -15,13 +15,10 @@ async function cli(args, entry, opts = {}) {
|
|
|
15
15
|
const tokens = parseArgs(args);
|
|
16
16
|
const subCommand = getSubCommand(tokens);
|
|
17
17
|
const resolvedCommandOptions = resolveCommandOptions(opts, entry);
|
|
18
|
-
const [name, command] = await resolveCommand(subCommand, entry, resolvedCommandOptions);
|
|
18
|
+
const [name, command] = await resolveCommand(subCommand, entry, resolvedCommandOptions, true);
|
|
19
19
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
20
20
|
const options = resolveArgOptions(command.options);
|
|
21
|
-
const { values, positionals, rest, error } = resolveArgs(options, tokens, {
|
|
22
|
-
optionGrouping: true,
|
|
23
|
-
allowNegative: true
|
|
24
|
-
});
|
|
21
|
+
const { values, positionals, rest, error } = resolveArgs(options, tokens, { optionGrouping: true });
|
|
25
22
|
const omitted = !subCommand;
|
|
26
23
|
const ctx = await createCommandContext({
|
|
27
24
|
options,
|
|
@@ -50,6 +47,7 @@ async function cli(args, entry, opts = {}) {
|
|
|
50
47
|
await showValidationErrors(ctx, error);
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
50
|
+
if (!command.run) throw new Error(`'run' not found on Command \`${name || ""}\``);
|
|
53
51
|
await command.run(ctx);
|
|
54
52
|
}
|
|
55
53
|
function resolveArgOptions(options) {
|
|
@@ -90,15 +88,15 @@ async function showValidationErrors(ctx, error) {
|
|
|
90
88
|
const render = ctx.env.renderValidationErrors || renderValidationErrors;
|
|
91
89
|
ctx.log(await render(ctx, error));
|
|
92
90
|
}
|
|
93
|
-
async function resolveCommand(sub, entry, options) {
|
|
91
|
+
async function resolveCommand(sub, entry, options, needRunResolving = false) {
|
|
94
92
|
const omitted = !sub;
|
|
95
93
|
if (typeof entry === "function") return [void 0, { run: entry }];
|
|
96
|
-
else if (omitted) return typeof entry === "object" ? [resolveEntryName(entry), await resolveLazyCommand(entry)] : [void 0, void 0];
|
|
94
|
+
else if (omitted) return typeof entry === "object" ? [resolveEntryName(entry), await resolveLazyCommand(entry, "", needRunResolving)] : [void 0, void 0];
|
|
97
95
|
else {
|
|
98
|
-
if (options.subCommands == null || options.subCommands.size === 0) return [resolveEntryName(entry), await resolveLazyCommand(entry)];
|
|
96
|
+
if (options.subCommands == null || options.subCommands.size === 0) return [resolveEntryName(entry), await resolveLazyCommand(entry, "", needRunResolving)];
|
|
99
97
|
const cmd = options.subCommands?.get(sub);
|
|
100
98
|
if (cmd == null) return [sub, void 0];
|
|
101
|
-
return [sub, await resolveLazyCommand(cmd, sub)];
|
|
99
|
+
return [sub, await resolveLazyCommand(cmd, sub, needRunResolving)];
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
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, resolveLazyCommand, resolveOptionKey } from "./utils-
|
|
1
|
+
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveLazyCommand, resolveOptionKey } from "./utils-6RnUrIMZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/locales/en-US.json
|
|
4
4
|
var COMMAND = "COMMAND";
|
|
@@ -9,6 +9,8 @@ var OPTIONS = "OPTIONS";
|
|
|
9
9
|
var EXAMPLES = "EXAMPLES";
|
|
10
10
|
var FORMORE = "For more info, run any command with the `--help` flag:";
|
|
11
11
|
var NEGATABLE = "Negatable of";
|
|
12
|
+
var DEFAULT = "default";
|
|
13
|
+
var CHOICES = "choices";
|
|
12
14
|
var help = "Display this help message";
|
|
13
15
|
var version = "Display this version";
|
|
14
16
|
var en_US_default = {
|
|
@@ -20,6 +22,8 @@ var en_US_default = {
|
|
|
20
22
|
EXAMPLES,
|
|
21
23
|
FORMORE,
|
|
22
24
|
NEGATABLE,
|
|
25
|
+
DEFAULT,
|
|
26
|
+
CHOICES,
|
|
23
27
|
help,
|
|
24
28
|
version
|
|
25
29
|
};
|
package/lib/context.d.ts
CHANGED
|
@@ -1,54 +1,63 @@
|
|
|
1
|
-
import { Command, CommandContext, CommandOptions } from "./types.d-
|
|
1
|
+
import { Command, CommandContext, CommandOptions } from "./types.d-BqXvgR9J.js";
|
|
2
2
|
import { ArgOptions, ArgToken, ArgValues } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Parameters of {@link createCommandContext}
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
interface CommandContextParams<Options extends ArgOptions, Values> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
declare function createCommandContext<Options extends ArgOptions = ArgOptions, Values extends ArgValues<Options> = ArgValues<Options>>({ options, values, positionals, rest, args, tokens, command, commandOptions, omitted }: CommandContextParams<Options, Values>): Promise<Readonly<CommandContext<Options, Values>>>;
|
|
10
|
+
/**
|
|
11
|
+
* An options of target command
|
|
12
|
+
*/
|
|
13
|
+
options: Options;
|
|
14
|
+
/**
|
|
15
|
+
* A values of target command
|
|
16
|
+
*/
|
|
17
|
+
values: Values;
|
|
18
|
+
/**
|
|
19
|
+
* A positionals arguments, which passed to the target command
|
|
20
|
+
*/
|
|
21
|
+
positionals: string[];
|
|
22
|
+
/**
|
|
23
|
+
* A rest arguments, which passed to the target command
|
|
24
|
+
*/
|
|
25
|
+
rest: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Original command line arguments
|
|
28
|
+
*/
|
|
29
|
+
args: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Argument tokens that are parsed by the `parseArgs` function
|
|
32
|
+
*/
|
|
33
|
+
tokens: ArgToken[];
|
|
34
|
+
/**
|
|
35
|
+
* Whether the command is omitted
|
|
36
|
+
*/
|
|
37
|
+
omitted: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A target {@link Command | command}
|
|
40
|
+
*/
|
|
41
|
+
command: Command<Options>;
|
|
42
|
+
/**
|
|
43
|
+
* A command options, which is spicialized from `cli` function
|
|
44
|
+
*/
|
|
45
|
+
commandOptions: CommandOptions<Options>;
|
|
46
|
+
} /**
|
|
47
|
+
* Create a {@link CommandContext | command context}
|
|
48
|
+
* @param param A {@link CommandContextParams | parameters} to create a {@link CommandContext | command context}
|
|
49
|
+
* @returns A {@link CommandContext | command context}, which is readonly
|
|
50
|
+
*/
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
declare function createCommandContext<Options extends ArgOptions = ArgOptions, Values extends ArgValues<Options> = ArgValues<Options>>({
|
|
53
|
+
options,
|
|
54
|
+
values,
|
|
55
|
+
positionals,
|
|
56
|
+
rest,
|
|
57
|
+
args,
|
|
58
|
+
tokens,
|
|
59
|
+
command,
|
|
60
|
+
commandOptions,
|
|
61
|
+
omitted
|
|
62
|
+
}: CommandContextParams<Options, Values>): Promise<Readonly<CommandContext<Options, Values>>>; //#endregion
|
|
54
63
|
export { createCommandContext };
|
package/lib/context.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/definition.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define a {@link Command | command} with type inference
|
|
4
|
+
* @param definition A {@link Command | command} definition
|
|
5
|
+
* @returns A {@link Command | command} definition with type inference
|
|
6
|
+
*/
|
|
7
|
+
function define(definition) {
|
|
8
|
+
return definition;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Define a {@link LazyCommand | lazy command} with command loader, which is attached with command definition as usage metadata.
|
|
12
|
+
* @param loader A {@link CommandLoader | command loader}
|
|
13
|
+
* @param definition A {@link Command | command} definition
|
|
14
|
+
* @returns A {@link LazyCommand | lazy command} loader
|
|
15
|
+
*/
|
|
16
|
+
function lazy(loader, definition) {
|
|
17
|
+
if (definition != null) {
|
|
18
|
+
loader.commandName = definition.name;
|
|
19
|
+
loader.description = definition.description;
|
|
20
|
+
loader.options = definition.options;
|
|
21
|
+
loader.examples = definition.examples;
|
|
22
|
+
loader.resource = definition.resource;
|
|
23
|
+
}
|
|
24
|
+
return loader;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { define, lazy };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command, CommandLoader, LazyCommand } from "./types.d-BqXvgR9J.js";
|
|
2
|
+
import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues as ArgValues$1 } from "args-tokens";
|
|
3
|
+
|
|
4
|
+
//#region src/definition.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Define a {@link Command | command} with type inference
|
|
7
|
+
* @param definition A {@link Command | command} definition
|
|
8
|
+
* @returns A {@link Command | command} definition with type inference
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
declare function define<Options extends ArgOptions = ArgOptions>(definition: Command<Options>): Command<Options>; /**
|
|
12
|
+
* Define a {@link LazyCommand | lazy command} with command loader, which is attached with command definition as usage metadata.
|
|
13
|
+
* @param loader A {@link CommandLoader | command loader}
|
|
14
|
+
* @param definition A {@link Command | command} definition
|
|
15
|
+
* @returns A {@link LazyCommand | lazy command} loader
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare function lazy<Options extends ArgOptions = ArgOptions>(loader: CommandLoader<Options>, definition?: Command<Options>): LazyCommand<Options>;
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ArgOptionSchema, ArgOptions$1 as ArgOptions, ArgValues$1 as ArgValues, define as define$1, lazy as lazy$1 };
|
package/lib/definition.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./types.d-
|
|
2
|
-
import { ArgOptionSchema, ArgOptions, ArgValues, define$1 as define } from "./definition.d-
|
|
3
|
-
|
|
4
|
-
export { ArgOptionSchema, ArgOptions, ArgValues, define };
|
|
1
|
+
import "./types.d-BqXvgR9J.js";
|
|
2
|
+
import { ArgOptionSchema, ArgOptions, ArgValues, define$1 as define, lazy$1 as lazy } from "./definition.d-DaKM6lt0.js";
|
|
3
|
+
export { ArgOptionSchema, ArgOptions, ArgValues, define, lazy };
|
package/lib/definition.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { define } from "./definition-
|
|
1
|
+
import { define, lazy } from "./definition-DZJeZYb2.js";
|
|
2
2
|
|
|
3
|
-
export { define };
|
|
3
|
+
export { define, lazy };
|
package/lib/generator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandOptions } from "./types.d-
|
|
1
|
+
import { Command, CommandOptions } from "./types.d-BqXvgR9J.js";
|
|
2
2
|
import { ArgOptions } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/generator.d.ts
|
|
@@ -9,6 +9,7 @@ import { ArgOptions } from "args-tokens";
|
|
|
9
9
|
* @param opts - A {@link CommandOptions | command options}
|
|
10
10
|
* @returns A rendered usage.
|
|
11
11
|
*/
|
|
12
|
+
|
|
12
13
|
declare function generate<Options extends ArgOptions = ArgOptions>(command: string | null, entry: Command<Options>, opts?: CommandOptions<Options>): Promise<string>;
|
|
13
14
|
|
|
14
15
|
//#endregion
|
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-6RnUrIMZ.js";
|
|
2
|
+
import "./context-DSuCy-i-.js";
|
|
3
|
+
import "./renderer-BgAkL9Re.js";
|
|
4
|
+
import { cli } from "./cli-8GpxrUOM.js";
|
|
5
5
|
|
|
6
6
|
//#region src/generator.ts
|
|
7
7
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types.d-
|
|
2
|
-
import { define$1 as define } from "./definition.d-
|
|
1
|
+
import { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types.d-BqXvgR9J.js";
|
|
2
|
+
import { define$1 as define, lazy$1 as lazy } from "./definition.d-DaKM6lt0.js";
|
|
3
3
|
import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, parseArgs, resolveArgs } from "args-tokens";
|
|
4
4
|
|
|
5
5
|
//#region src/cli.d.ts
|
|
@@ -10,18 +10,19 @@ import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, par
|
|
|
10
10
|
* @param opts A {@link CommandOptions | command options}
|
|
11
11
|
* @returns A rendered usage or undefined. if you will use {@link CommandOptions.usageSilent} option, it will return rendered usage string.
|
|
12
12
|
*/
|
|
13
|
+
|
|
13
14
|
declare function cli<Options extends ArgOptions$1 = ArgOptions$1>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
|
|
14
15
|
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/translation.d.ts
|
|
17
18
|
declare class DefaultTranslation implements TranslationAdapter {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options: TranslationAdapterFactoryOptions);
|
|
21
|
+
getResource(locale: string): Record<string, string> | undefined;
|
|
22
|
+
setResource(locale: string, resource: Record<string, string>): void;
|
|
23
|
+
getMessage(locale: string, key: string): string | undefined;
|
|
24
|
+
translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
//#endregion
|
|
27
|
-
export { ArgOptionSchema, ArgOptions, ArgValues, Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, parseArgs, resolveArgs };
|
|
28
|
+
export { ArgOptionSchema, ArgOptions, ArgValues, Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgOptions, 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-
|
|
3
|
-
import { define } from "./definition-
|
|
4
|
-
import "./renderer-
|
|
5
|
-
import { cli } from "./cli-
|
|
1
|
+
import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-6RnUrIMZ.js";
|
|
2
|
+
import { DefaultTranslation } from "./context-DSuCy-i-.js";
|
|
3
|
+
import { define, lazy } from "./definition-DZJeZYb2.js";
|
|
4
|
+
import "./renderer-BgAkL9Re.js";
|
|
5
|
+
import { cli } from "./cli-8GpxrUOM.js";
|
|
6
6
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
7
7
|
|
|
8
|
-
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, parseArgs, resolveArgs };
|
|
8
|
+
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, lazy, parseArgs, resolveArgs };
|
package/lib/locales/en-US.json
CHANGED
package/lib/locales/ja-JP.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { create, resolveBuiltInKey, resolveOptionKey } from "./utils-
|
|
1
|
+
import { COMMON_OPTIONS, create, resolveBuiltInKey, resolveOptionKey } from "./utils-6RnUrIMZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/renderer/header.ts
|
|
4
4
|
/**
|
|
@@ -13,6 +13,7 @@ function renderHeader(ctx) {
|
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/renderer/usage.ts
|
|
16
|
+
const COMMON_OPTIONS_KEYS = Object.keys(COMMON_OPTIONS);
|
|
16
17
|
/**
|
|
17
18
|
* Render the usage.
|
|
18
19
|
* @param ctx A {@link CommandContext | command context}
|
|
@@ -181,7 +182,7 @@ function getOptionsPairs(ctx) {
|
|
|
181
182
|
let key = makeShortLongOptionPair(value, name);
|
|
182
183
|
if (value.type !== "boolean") key = value.default ? `${key} [${name}]` : `${key} <${name}>`;
|
|
183
184
|
acc[name] = key;
|
|
184
|
-
if (value.type === "boolean" && !(name
|
|
185
|
+
if (value.type === "boolean" && value.negatable && !COMMON_OPTIONS_KEYS.includes(name)) acc[`no-${name}`] = `--no-${name}`;
|
|
185
186
|
return acc;
|
|
186
187
|
}, create());
|
|
187
188
|
}
|
|
@@ -189,6 +190,20 @@ const resolveNegatableKey = (key) => key.split("no-")[1];
|
|
|
189
190
|
function resolveNegatableType(key, ctx) {
|
|
190
191
|
return ctx.options[key.startsWith("no-") ? resolveNegatableKey(key) : key].type;
|
|
191
192
|
}
|
|
193
|
+
function generateDefaultDisplayValue(ctx, schema) {
|
|
194
|
+
return `${ctx.translate(resolveBuiltInKey("DEFAULT"))}: ${schema.default}`;
|
|
195
|
+
}
|
|
196
|
+
function resolveDisplayValue(ctx, key) {
|
|
197
|
+
if (COMMON_OPTIONS_KEYS.includes(key)) return "";
|
|
198
|
+
const schema = ctx.options[key];
|
|
199
|
+
if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string") && schema.default !== void 0) return `(${generateDefaultDisplayValue(ctx, schema)})`;
|
|
200
|
+
if (schema.type === "enum") {
|
|
201
|
+
const _default = schema.default !== void 0 ? generateDefaultDisplayValue(ctx, schema) : "";
|
|
202
|
+
const choices = `${ctx.translate(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
|
|
203
|
+
return `(${_default ? `${_default}, ${choices}` : choices})`;
|
|
204
|
+
}
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
192
207
|
/**
|
|
193
208
|
* Generate options usage
|
|
194
209
|
* @param ctx A {@link CommandContext | command context}
|
|
@@ -207,8 +222,9 @@ async function generateOptionsUsage(ctx, optionsPairs) {
|
|
|
207
222
|
rawDesc = `${ctx.translate(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
|
|
208
223
|
}
|
|
209
224
|
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
|
|
225
|
+
const valueDesc = key.startsWith("no-") ? "" : resolveDisplayValue(ctx, key);
|
|
210
226
|
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
211
|
-
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}`;
|
|
227
|
+
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}${valueDesc ? ` ${valueDesc}` : ""}`;
|
|
212
228
|
return `${option.padStart(ctx.env.leftMargin + option.length)}`;
|
|
213
229
|
}));
|
|
214
230
|
return usages.join("\n");
|
package/lib/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandContext } from "./types.d-
|
|
1
|
+
import { CommandContext } from "./types.d-BqXvgR9J.js";
|
|
2
2
|
import { ArgOptions } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/renderer/header.d.ts
|
|
@@ -7,6 +7,7 @@ import { ArgOptions } from "args-tokens";
|
|
|
7
7
|
* @param ctx A {@link CommandContext | command context}
|
|
8
8
|
* @returns A rendered header.
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
declare function renderHeader<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
|
|
11
12
|
|
|
12
13
|
//#endregion
|
package/lib/renderer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./utils-
|
|
2
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
1
|
+
import "./utils-6RnUrIMZ.js";
|
|
2
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BgAkL9Re.js";
|
|
3
3
|
|
|
4
4
|
export { renderHeader, renderUsage, renderValidationErrors };
|