gunshi 0.13.0 → 0.14.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-D_4MqIMP.js → cli-DsMmOiVc.js} +5 -3
- package/lib/definition-by5EpPkZ.js +8 -0
- package/lib/definition.d-CFbYyc6i.d.ts +8 -0
- package/lib/definition.d.ts +4 -0
- package/lib/definition.js +3 -0
- package/lib/generator.d.ts +5 -10
- package/lib/generator.js +2 -2
- package/lib/index.d.ts +9 -13
- package/lib/index.js +4 -3
- package/lib/renderer/index.d.ts +9 -19
- package/lib/renderer/index.js +1 -1
- package/lib/{renderer-DAUAIZxV.js → renderer-B2JVfepJ.js} +6 -2
- package/lib/{types.d-DqtZy3HN.d.ts → types.d-CftFdhAF.d.ts} +19 -101
- package/package.json +8 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand } from "./renderer-
|
|
1
|
+
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey } from "./renderer-B2JVfepJ.js";
|
|
2
2
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/locales/en-US.json
|
|
@@ -60,7 +60,7 @@ var DefaultTranslation = class {
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/context.ts
|
|
62
62
|
const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
|
|
63
|
-
async function createCommandContext({ options, values, positionals, args, command, commandOptions, omitted = false }) {
|
|
63
|
+
async function createCommandContext({ options, values, positionals, args, tokens, command, commandOptions, omitted = false }) {
|
|
64
64
|
/**
|
|
65
65
|
* normailize the options schema and values, to avoid prototype pollution
|
|
66
66
|
*/
|
|
@@ -122,6 +122,7 @@ async function createCommandContext({ options, values, positionals, args, comman
|
|
|
122
122
|
values,
|
|
123
123
|
positionals,
|
|
124
124
|
_: args,
|
|
125
|
+
tokens,
|
|
125
126
|
log: commandOptions.usageSilent ? NOOP : log,
|
|
126
127
|
loadCommands,
|
|
127
128
|
translate
|
|
@@ -134,7 +135,7 @@ async function createCommandContext({ options, values, positionals, args, comman
|
|
|
134
135
|
return [key, description];
|
|
135
136
|
});
|
|
136
137
|
const defaultCommandResource = loadedOptionsResources.reduce((res, [key, value]) => {
|
|
137
|
-
res[key] = value;
|
|
138
|
+
res[resolveOptionKey(key)] = value;
|
|
138
139
|
return res;
|
|
139
140
|
}, create());
|
|
140
141
|
defaultCommandResource.description = command.description || "";
|
|
@@ -181,6 +182,7 @@ async function cli(args, entry, opts = {}) {
|
|
|
181
182
|
values,
|
|
182
183
|
positionals,
|
|
183
184
|
args,
|
|
185
|
+
tokens,
|
|
184
186
|
omitted,
|
|
185
187
|
command,
|
|
186
188
|
commandOptions: resolvedCommandOptions
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from "./types.d-CftFdhAF.js";
|
|
2
|
+
import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues as ArgValues$1 } from "args-tokens";
|
|
3
|
+
|
|
4
|
+
//#region lib/.tsdown-types-es/definition.d.ts
|
|
5
|
+
declare function define<Options extends ArgOptions = ArgOptions>(definition: Command<Options>): Command<Options>;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ArgOptionSchema, ArgOptions$1 as ArgOptions, ArgValues$1 as ArgValues, define };
|
package/lib/generator.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Command, CommandOptions } from "./types.d-CftFdhAF.js";
|
|
2
|
+
import { ArgOptions } from "args-tokens";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Generate the command usage.
|
|
6
|
-
* @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
|
|
7
|
-
* @param entry - A {@link Command | entry command}
|
|
8
|
-
* @param opts - A {@link CommandOptions | command options}
|
|
9
|
-
* @returns A rendered usage.
|
|
10
|
-
*/
|
|
4
|
+
//#region lib/.tsdown-types-es/generator.d.ts
|
|
11
5
|
declare function generate<Options extends ArgOptions = ArgOptions>(command: string | null, entry: Command<Options>, opts?: CommandOptions<Options>): Promise<string>;
|
|
12
6
|
|
|
13
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
export { generate };
|
package/lib/generator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { create } from "./renderer-
|
|
2
|
-
import { cli } from "./cli-
|
|
1
|
+
import { create } from "./renderer-B2JVfepJ.js";
|
|
2
|
+
import { cli } from "./cli-DsMmOiVc.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generator.ts
|
|
5
5
|
async function generate(command, entry, opts = {}) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
export { f as CommandBuiltinKeys, d as CommandBuiltinOptionsKeys, e as CommandBuiltinResourceKeys, h as CommandContext, g as CommandEnvironment, i as CommandResource, j as CommandResourceFetcher, l as Commandable, D as DEFAULT_LOCALE, G as GenerateNamespacedKey, L as LazyCommand, k as TranslationAdapterFactory } from './types.d-DqtZy3HN.js';
|
|
1
|
+
import { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types.d-CftFdhAF.js";
|
|
2
|
+
import { define } from "./definition.d-CFbYyc6i.js";
|
|
3
|
+
import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, parseArgs, resolveArgs } from "args-tokens";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @param args Command line arguments
|
|
9
|
-
* @param entry A {@link Command | entry command} or an {@link CommandRunner | inline command runner}
|
|
10
|
-
* @param opts A {@link CommandOptions | command options}
|
|
11
|
-
* @returns A rendered usage or undefined. if you will use {@link CommandOptions.usageSilent} option, it will return rendered usage string.
|
|
12
|
-
*/
|
|
13
|
-
declare function cli<Options extends ArgOptions = ArgOptions>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
|
|
5
|
+
//#region lib/.tsdown-types-es/cli.d.ts
|
|
6
|
+
declare function cli<Options extends ArgOptions$1 = ArgOptions$1>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
|
|
14
7
|
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region lib/.tsdown-types-es/translation.d.ts
|
|
15
10
|
declare class DefaultTranslation implements TranslationAdapter {
|
|
16
11
|
#private;
|
|
17
12
|
constructor(options: TranslationAdapterFactoryOptions);
|
|
@@ -21,4 +16,5 @@ declare class DefaultTranslation implements TranslationAdapter {
|
|
|
21
16
|
translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
|
|
22
17
|
}
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ArgOptionSchema, ArgOptions, ArgValues, Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, parseArgs, resolveArgs };
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { define } from "./definition-by5EpPkZ.js";
|
|
2
|
+
import { DEFAULT_LOCALE } from "./renderer-B2JVfepJ.js";
|
|
3
|
+
import { DefaultTranslation, cli } from "./cli-DsMmOiVc.js";
|
|
3
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
4
5
|
|
|
5
|
-
export { DEFAULT_LOCALE, DefaultTranslation, cli, parseArgs, resolveArgs };
|
|
6
|
+
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, parseArgs, resolveArgs };
|
package/lib/renderer/index.d.ts
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CommandContext } from "../types.d-CftFdhAF.js";
|
|
2
|
+
import { ArgOptions } from "args-tokens";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Render the header.
|
|
6
|
-
* @param ctx A {@link CommandContext | command context}
|
|
7
|
-
* @returns A rendered header.
|
|
8
|
-
*/
|
|
4
|
+
//#region lib/.tsdown-types-es/renderer/header.d.ts
|
|
9
5
|
declare function renderHeader<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @param ctx A {@link CommandContext | command context}
|
|
14
|
-
* @returns A rendered usage.
|
|
15
|
-
*/
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region lib/.tsdown-types-es/renderer/usage.d.ts
|
|
16
9
|
declare function renderUsage<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param ctx A {@link CommandContext | command context}
|
|
21
|
-
* @param error An {@link AggregateError} of option in `args-token` validation
|
|
22
|
-
* @returns A rendered validation error.
|
|
23
|
-
*/
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region lib/.tsdown-types-es/renderer/validation.d.ts
|
|
24
13
|
declare function renderValidationErrors<Options extends ArgOptions = ArgOptions>(_ctx: CommandContext<Options>, error: AggregateError): Promise<string>;
|
|
25
14
|
|
|
26
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
export { renderHeader, renderUsage, renderValidationErrors };
|
package/lib/renderer/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//#region src/constants.ts
|
|
3
3
|
const DEFAULT_LOCALE = "en-US";
|
|
4
4
|
const BUILT_IN_PREFIX = "_";
|
|
5
|
+
const OPTION_PREFIX = "Option";
|
|
5
6
|
const BUILT_IN_KEY_SEPARATOR = ":";
|
|
6
7
|
const NOOP = () => {};
|
|
7
8
|
const COMMON_OPTIONS = {
|
|
@@ -42,6 +43,9 @@ async function resolveLazyCommand(cmd, name) {
|
|
|
42
43
|
function resolveBuiltInKey(key) {
|
|
43
44
|
return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
44
45
|
}
|
|
46
|
+
function resolveOptionKey(key) {
|
|
47
|
+
return `${OPTION_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
|
|
48
|
+
}
|
|
45
49
|
function mapResourceWithBuiltinKey(resource) {
|
|
46
50
|
return Object.entries(resource).reduce((acc, [key, value]) => {
|
|
47
51
|
acc[resolveBuiltInKey(key)] = value;
|
|
@@ -244,7 +248,7 @@ async function generateOptionsUsage(ctx, optionsPairs) {
|
|
|
244
248
|
const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
|
|
245
249
|
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key, _]) => ctx.options[key].type.length)) : 0;
|
|
246
250
|
const usages = await Promise.all(Object.entries(optionsPairs).map(([key, value]) => {
|
|
247
|
-
const rawDesc = ctx.translate(key);
|
|
251
|
+
const rawDesc = ctx.translate(resolveOptionKey(key));
|
|
248
252
|
const optionsSchema = ctx.env.usageOptionType ? `[${ctx.options[key].type}] ` : "";
|
|
249
253
|
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
250
254
|
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}`;
|
|
@@ -262,4 +266,4 @@ function renderValidationErrors(_ctx, error) {
|
|
|
262
266
|
}
|
|
263
267
|
|
|
264
268
|
//#endregion
|
|
265
|
-
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand };
|
|
269
|
+
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey };
|
|
@@ -1,71 +1,24 @@
|
|
|
1
|
-
import { ArgOptions, ArgValues } from
|
|
1
|
+
import { ArgOptions, ArgToken, ArgValues } from "args-tokens";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* The default locale string, which format is BCP 47 language tag.
|
|
5
|
-
*/
|
|
3
|
+
//#region lib/.tsdown-types-es/constants.d.ts
|
|
6
4
|
declare const DEFAULT_LOCALE = "en-US";
|
|
7
5
|
declare const BUILT_IN_PREFIX = "_";
|
|
6
|
+
declare const OPTION_PREFIX = "Option";
|
|
8
7
|
declare const BUILT_IN_KEY_SEPARATOR = ":";
|
|
9
|
-
declare const NOOP: () => void;
|
|
10
|
-
type CommonOptionType = {
|
|
11
|
-
readonly help: {
|
|
12
|
-
readonly type: "boolean"
|
|
13
|
-
readonly short: "h"
|
|
14
|
-
readonly description: string
|
|
15
|
-
}
|
|
16
|
-
readonly version: {
|
|
17
|
-
readonly type: "boolean"
|
|
18
|
-
readonly short: "v"
|
|
19
|
-
readonly description: string
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
declare const COMMON_OPTIONS: CommonOptionType;
|
|
23
|
-
declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<ArgOptions>;
|
|
24
|
-
declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE"];
|
|
25
|
-
|
|
26
|
-
declare const __constants_ts_BUILT_IN_KEY_SEPARATOR: typeof BUILT_IN_KEY_SEPARATOR;
|
|
27
|
-
declare const __constants_ts_BUILT_IN_PREFIX: typeof BUILT_IN_PREFIX;
|
|
28
|
-
declare const __constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS: typeof COMMAND_BUILTIN_RESOURCE_KEYS;
|
|
29
|
-
declare const __constants_ts_COMMAND_OPTIONS_DEFAULT: typeof COMMAND_OPTIONS_DEFAULT;
|
|
30
|
-
declare const __constants_ts_COMMON_OPTIONS: typeof COMMON_OPTIONS;
|
|
31
|
-
declare const __constants_ts_DEFAULT_LOCALE: typeof DEFAULT_LOCALE;
|
|
32
|
-
declare const __constants_ts_NOOP: typeof NOOP;
|
|
33
|
-
declare namespace __constants_ts {
|
|
34
|
-
export {
|
|
35
|
-
__constants_ts_BUILT_IN_KEY_SEPARATOR as BUILT_IN_KEY_SEPARATOR,
|
|
36
|
-
__constants_ts_BUILT_IN_PREFIX as BUILT_IN_PREFIX,
|
|
37
|
-
__constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS as COMMAND_BUILTIN_RESOURCE_KEYS,
|
|
38
|
-
__constants_ts_COMMAND_OPTIONS_DEFAULT as COMMAND_OPTIONS_DEFAULT,
|
|
39
|
-
__constants_ts_COMMON_OPTIONS as COMMON_OPTIONS,
|
|
40
|
-
__constants_ts_DEFAULT_LOCALE as DEFAULT_LOCALE,
|
|
41
|
-
__constants_ts_NOOP as NOOP,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
8
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*/
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region lib/.tsdown-types-es/types.d.ts
|
|
48
11
|
type Awaitable<T> = T | Promise<T>;
|
|
12
|
+
type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K] : T[K] };
|
|
13
|
+
type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T] : T[K] }>;
|
|
49
14
|
type GenerateNamespacedKey<
|
|
50
15
|
Key extends string,
|
|
51
16
|
Prefixed extends string = typeof BUILT_IN_PREFIX
|
|
52
17
|
> = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
type CommandBuiltinOptionsKeys = keyof (typeof __constants_ts)["COMMON_OPTIONS"];
|
|
57
|
-
/**
|
|
58
|
-
* Command i18n built-in resource keys.
|
|
59
|
-
*/
|
|
60
|
-
type CommandBuiltinResourceKeys = (typeof __constants_ts)["COMMAND_BUILTIN_RESOURCE_KEYS"][number];
|
|
61
|
-
/**
|
|
62
|
-
* Command i18n built-in keys.
|
|
63
|
-
* The command i18n built-in keys are used to {@link CommandContext.translate | translate} function.
|
|
64
|
-
*/
|
|
18
|
+
type CommandBuiltinOptionsKeys = keyof (typeof import("./constants.ts"))["COMMON_OPTIONS"];
|
|
19
|
+
type CommandBuiltinResourceKeys = (typeof import("./constants.ts"))["COMMAND_BUILTIN_RESOURCE_KEYS"][number];
|
|
65
20
|
type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinOptionsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | "description" | "examples";
|
|
66
|
-
|
|
67
|
-
* Command environment.
|
|
68
|
-
*/
|
|
21
|
+
type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>;
|
|
69
22
|
interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
|
|
70
23
|
/**
|
|
71
24
|
* Current working directory.
|
|
@@ -130,9 +83,6 @@ interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
|
|
|
130
83
|
*/
|
|
131
84
|
renderValidationErrors: ((ctx: CommandContext<Options>, error: AggregateError) => Promise<string>) | null | undefined;
|
|
132
85
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Command options.
|
|
135
|
-
*/
|
|
136
86
|
interface CommandOptions<Options extends ArgOptions = ArgOptions> {
|
|
137
87
|
/**
|
|
138
88
|
* Current working directory.
|
|
@@ -192,10 +142,6 @@ interface CommandOptions<Options extends ArgOptions = ArgOptions> {
|
|
|
192
142
|
*/
|
|
193
143
|
translationAdapterFactory?: TranslationAdapterFactory;
|
|
194
144
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Command context.
|
|
197
|
-
* Command context is the context of the command execution.
|
|
198
|
-
*/
|
|
199
145
|
interface CommandContext<
|
|
200
146
|
Options extends ArgOptions = ArgOptions,
|
|
201
147
|
Values = ArgValues<Options>
|
|
@@ -240,6 +186,10 @@ interface CommandContext<
|
|
|
240
186
|
*/
|
|
241
187
|
_: string[];
|
|
242
188
|
/**
|
|
189
|
+
* Argument tokens, that is parsed by `parseArgs` function.
|
|
190
|
+
*/
|
|
191
|
+
tokens: ArgToken[];
|
|
192
|
+
/**
|
|
243
193
|
* Whether the currently executing command has been executed with the sub-command name omitted.
|
|
244
194
|
*/
|
|
245
195
|
omitted: boolean;
|
|
@@ -264,12 +214,10 @@ interface CommandContext<
|
|
|
264
214
|
*/
|
|
265
215
|
translate: <
|
|
266
216
|
T extends string = CommandBuiltinKeys,
|
|
267
|
-
|
|
217
|
+
O = CommandOptionKeys<Options>,
|
|
218
|
+
Key = CommandBuiltinKeys | O | T
|
|
268
219
|
>(key: Key, values?: Record<string, unknown>) => string;
|
|
269
220
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Command interface.
|
|
272
|
-
*/
|
|
273
221
|
interface Command<Options extends ArgOptions = ArgOptions> {
|
|
274
222
|
/**
|
|
275
223
|
* Command name.
|
|
@@ -300,9 +248,6 @@ interface Command<Options extends ArgOptions = ArgOptions> {
|
|
|
300
248
|
*/
|
|
301
249
|
resource?: CommandResourceFetcher<Options>;
|
|
302
250
|
}
|
|
303
|
-
/**
|
|
304
|
-
* Command resource.
|
|
305
|
-
*/
|
|
306
251
|
type CommandResource<Options extends ArgOptions = ArgOptions> = {
|
|
307
252
|
/**
|
|
308
253
|
* Command description.
|
|
@@ -312,25 +257,14 @@ type CommandResource<Options extends ArgOptions = ArgOptions> = {
|
|
|
312
257
|
* Examples usage.
|
|
313
258
|
*/
|
|
314
259
|
examples: string
|
|
315
|
-
} & { [Option in keyof Options] : string } & {
|
|
260
|
+
} & { [Option in GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>] : string } & {
|
|
316
261
|
[key: string]: string
|
|
317
262
|
};
|
|
318
|
-
/**
|
|
319
|
-
* Command resource fetcher.
|
|
320
|
-
* @param ctx A {@link CommandContext | command context}
|
|
321
|
-
* @returns A fetched {@link CommandResource | command resource}.
|
|
322
|
-
*/
|
|
323
263
|
type CommandResourceFetcher<
|
|
324
264
|
Options extends ArgOptions = ArgOptions,
|
|
325
265
|
Values = ArgValues<Options>
|
|
326
266
|
> = (ctx: Readonly<CommandContext<Options, Values>>) => Promise<CommandResource<Options>>;
|
|
327
|
-
/**
|
|
328
|
-
* Translation adapter factory.
|
|
329
|
-
*/
|
|
330
267
|
type TranslationAdapterFactory = (options: TranslationAdapterFactoryOptions) => TranslationAdapter;
|
|
331
|
-
/**
|
|
332
|
-
* Translation adapter factory options.
|
|
333
|
-
*/
|
|
334
268
|
interface TranslationAdapterFactoryOptions {
|
|
335
269
|
/**
|
|
336
270
|
* A locale.
|
|
@@ -341,11 +275,6 @@ interface TranslationAdapterFactoryOptions {
|
|
|
341
275
|
*/
|
|
342
276
|
fallbackLocale: string;
|
|
343
277
|
}
|
|
344
|
-
/**
|
|
345
|
-
* Translation adapter.
|
|
346
|
-
* This adapter is used to custom message formatter like {@link https://github.com/intlify/vue-i18n/blob/master/spec/syntax.ebnf | Intlify message format}, {@link https://github.com/tc39/proposal-intl-messageformat | `Intl.MessageFormat` (MF2)}, and etc.
|
|
347
|
-
* This adapter will support localization with your preferred message format.
|
|
348
|
-
*/
|
|
349
278
|
interface TranslationAdapter<MessageResource = string> {
|
|
350
279
|
/**
|
|
351
280
|
* Get a resource of locale.
|
|
@@ -375,20 +304,9 @@ interface TranslationAdapter<MessageResource = string> {
|
|
|
375
304
|
*/
|
|
376
305
|
translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
|
|
377
306
|
}
|
|
378
|
-
/**
|
|
379
|
-
* Command runner.
|
|
380
|
-
* @param ctx A {@link CommandContext | command context}
|
|
381
|
-
*/
|
|
382
307
|
type CommandRunner<Options extends ArgOptions = ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Awaitable<void>;
|
|
383
|
-
/**
|
|
384
|
-
* Lazy command interface.
|
|
385
|
-
* Lazy command that's not loaded until it is executed.
|
|
386
|
-
*/
|
|
387
308
|
type LazyCommand<Options extends ArgOptions = ArgOptions> = () => Awaitable<Command<Options>>;
|
|
388
|
-
/**
|
|
389
|
-
* Define a command type.
|
|
390
|
-
*/
|
|
391
309
|
type Commandable<Options extends ArgOptions> = Command<Options> | LazyCommand<Options>;
|
|
392
310
|
|
|
393
|
-
|
|
394
|
-
export
|
|
311
|
+
//#endregion
|
|
312
|
+
export { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
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.14.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -41,6 +41,12 @@
|
|
|
41
41
|
"require": "./lib/index.js",
|
|
42
42
|
"default": "./lib/index.js"
|
|
43
43
|
},
|
|
44
|
+
"./definition": {
|
|
45
|
+
"types": "./lib/definition.d.ts",
|
|
46
|
+
"import": "./lib/definition.js",
|
|
47
|
+
"require": "./lib/definition.js",
|
|
48
|
+
"default": "./lib/definition.js"
|
|
49
|
+
},
|
|
44
50
|
"./renderer": {
|
|
45
51
|
"types": "./lib/renderer/index.d.ts",
|
|
46
52
|
"import": "./lib/renderer/index.js",
|
|
@@ -97,7 +103,7 @@
|
|
|
97
103
|
"messageformat": "4.0.0-10",
|
|
98
104
|
"pkg-pr-new": "^0.0.42",
|
|
99
105
|
"prettier": "^3.5.3",
|
|
100
|
-
"tsdown": "^0.
|
|
106
|
+
"tsdown": "^0.7.0",
|
|
101
107
|
"typedoc": "^0.28.1",
|
|
102
108
|
"typedoc-plugin-markdown": "^4.6.0",
|
|
103
109
|
"typedoc-vitepress-theme": "^1.1.2",
|