gunshi 0.22.0 → 0.23.1
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-DEuAxEk9.js → cli-BVD3QITm.js} +59 -47
- package/lib/{context-BefYjlE-.js → context-COFfMm-R.js} +13 -8
- package/lib/context.d.ts +5 -5
- package/lib/context.js +2 -2
- package/lib/{definition-DUNcKGVg.d.ts → definition-zTfMFgKw.d.ts} +1 -1
- package/lib/definition.d.ts +2 -2
- package/lib/generator.d.ts +9 -9
- package/lib/generator.js +11 -10
- package/lib/index.d.ts +18 -4
- package/lib/index.js +4 -4
- package/lib/{renderer-BpwhGYRZ.js → renderer-kzo45gaB.js} +1 -1
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +2 -2
- package/lib/{types-BbgfNBFM.d.ts → types-BDWiiycu.d.ts} +16 -15
- package/lib/{utils-STQBqMtf.js → utils-D41C8Abf.js} +6 -2
- package/package.json +3 -3
|
@@ -1,19 +1,26 @@
|
|
|
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 { ANONYMOUS_COMMAND_NAME, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, isLazyCommand, resolveLazyCommand } from "./utils-D41C8Abf.js";
|
|
2
|
+
import { createCommandContext } from "./context-COFfMm-R.js";
|
|
3
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-kzo45gaB.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Run the command.
|
|
9
|
+
* @param args Command line arguments
|
|
10
|
+
* @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
11
|
+
* @param options A {@link CliOptions | CLI options}
|
|
12
|
+
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
13
|
+
*/
|
|
14
|
+
async function cli(argv, entry, options = {}) {
|
|
15
|
+
const cliOptions = resolveCliOptions(options, entry);
|
|
8
16
|
const tokens = parseArgs(argv);
|
|
9
17
|
const subCommand = getSubCommand(tokens);
|
|
10
|
-
const
|
|
11
|
-
const [name, command, callMode] = await resolveCommand(subCommand, entry, resolvedCommandOptions, true);
|
|
18
|
+
const { commandName: name, command, callMode } = await resolveCommand(subCommand, entry, cliOptions);
|
|
12
19
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
13
|
-
const args = resolveArguments(command
|
|
20
|
+
const args = resolveArguments(getCommandArgs(command));
|
|
14
21
|
const { values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
15
22
|
optionGrouping: true,
|
|
16
|
-
skipPositional:
|
|
23
|
+
skipPositional: cliOptions.subCommands.size > 0 ? 0 : -1
|
|
17
24
|
});
|
|
18
25
|
const omitted = !subCommand;
|
|
19
26
|
const ctx = await createCommandContext({
|
|
@@ -26,7 +33,7 @@ async function cli(argv, entry, opts = {}) {
|
|
|
26
33
|
omitted,
|
|
27
34
|
callMode,
|
|
28
35
|
command,
|
|
29
|
-
|
|
36
|
+
cliOptions
|
|
30
37
|
});
|
|
31
38
|
if (values.version) {
|
|
32
39
|
showVersion(ctx);
|
|
@@ -44,16 +51,20 @@ async function cli(argv, entry, opts = {}) {
|
|
|
44
51
|
await showValidationErrors(ctx, error);
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
|
-
|
|
48
|
-
await command.run(ctx);
|
|
54
|
+
await executeCommand(command, ctx, name || "");
|
|
49
55
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
56
|
+
function getCommandArgs(cmd) {
|
|
57
|
+
if (isLazyCommand(cmd)) return cmd.args || create();
|
|
58
|
+
else if (typeof cmd === "object") return cmd.args || create();
|
|
59
|
+
else return create();
|
|
52
60
|
}
|
|
53
|
-
function
|
|
61
|
+
function resolveArguments(args) {
|
|
62
|
+
return Object.assign(create(), args, COMMON_ARGS);
|
|
63
|
+
}
|
|
64
|
+
function resolveCliOptions(options, entry) {
|
|
54
65
|
const subCommands = new Map(options.subCommands);
|
|
55
66
|
if (options.subCommands) {
|
|
56
|
-
if (
|
|
67
|
+
if (isLazyCommand(entry)) subCommands.set(entry.commandName, entry);
|
|
57
68
|
else if (typeof entry === "object" && entry.name) subCommands.set(entry.name, entry);
|
|
58
69
|
}
|
|
59
70
|
const resolvedOptions = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands });
|
|
@@ -88,46 +99,47 @@ async function showValidationErrors(ctx, error) {
|
|
|
88
99
|
const render = ctx.env.renderValidationErrors || renderValidationErrors;
|
|
89
100
|
ctx.log(await render(ctx, error));
|
|
90
101
|
}
|
|
91
|
-
const CANNOT_RESOLVE_COMMAND =
|
|
92
|
-
|
|
93
|
-
void 0,
|
|
94
|
-
"unexpected"
|
|
95
|
-
];
|
|
96
|
-
async function resolveCommand(sub, entry, options, needRunResolving = false) {
|
|
102
|
+
const CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
|
|
103
|
+
async function resolveCommand(sub, entry, options) {
|
|
97
104
|
const omitted = !sub;
|
|
98
105
|
async function doResolveCommand() {
|
|
99
|
-
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return
|
|
100
|
-
entry.commandName,
|
|
101
|
-
|
|
102
|
-
"entry"
|
|
103
|
-
|
|
104
|
-
else return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
];
|
|
106
|
+
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
|
|
107
|
+
commandName: entry.commandName,
|
|
108
|
+
command: entry,
|
|
109
|
+
callMode: "entry"
|
|
110
|
+
};
|
|
111
|
+
else return {
|
|
112
|
+
command: { run: entry },
|
|
113
|
+
callMode: "entry"
|
|
114
|
+
};
|
|
115
|
+
else if (typeof entry === "object") return {
|
|
116
|
+
commandName: resolveEntryName(entry),
|
|
117
|
+
command: entry,
|
|
118
|
+
callMode: "entry"
|
|
119
|
+
};
|
|
114
120
|
else return CANNOT_RESOLVE_COMMAND;
|
|
115
121
|
}
|
|
116
122
|
if (omitted || options.subCommands?.size === 0) return doResolveCommand();
|
|
117
123
|
const cmd = options.subCommands?.get(sub);
|
|
118
|
-
if (cmd == null) return
|
|
119
|
-
sub,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
if (cmd == null) return {
|
|
125
|
+
commandName: sub,
|
|
126
|
+
callMode: "unexpected"
|
|
127
|
+
};
|
|
128
|
+
if (isLazyCommand(cmd) && cmd.commandName == null) cmd.commandName = sub;
|
|
129
|
+
else if (typeof cmd === "object" && cmd.name == null) cmd.name = sub;
|
|
130
|
+
return {
|
|
131
|
+
commandName: sub,
|
|
132
|
+
command: cmd,
|
|
133
|
+
callMode: "subCommand"
|
|
134
|
+
};
|
|
128
135
|
}
|
|
129
136
|
function resolveEntryName(entry) {
|
|
130
|
-
return entry.name ||
|
|
137
|
+
return entry.name || ANONYMOUS_COMMAND_NAME;
|
|
138
|
+
}
|
|
139
|
+
async function executeCommand(cmd, ctx, name) {
|
|
140
|
+
const resolved = isLazyCommand(cmd) ? await resolveLazyCommand(cmd, name, true) : cmd;
|
|
141
|
+
if (resolved.run == null) throw new Error(`'run' not found on Command \`${name}\``);
|
|
142
|
+
await resolved.run(ctx);
|
|
131
143
|
}
|
|
132
144
|
|
|
133
145
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-
|
|
1
|
+
import { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, isLazyCommand, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-D41C8Abf.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,
|
|
75
|
+
async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, cliOptions, callMode = "entry", omitted = false }) {
|
|
76
76
|
/**
|
|
77
77
|
* normailize the options schema and values, to avoid prototype pollution
|
|
78
78
|
*/
|
|
@@ -83,10 +83,10 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
83
83
|
/**
|
|
84
84
|
* setup the environment
|
|
85
85
|
*/
|
|
86
|
-
const env = Object.assign(create(), COMMAND_OPTIONS_DEFAULT,
|
|
87
|
-
const locale = resolveLocale(
|
|
86
|
+
const env = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, cliOptions);
|
|
87
|
+
const locale = resolveLocale(cliOptions.locale);
|
|
88
88
|
const localeStr = locale.toString();
|
|
89
|
-
const translationAdapterFactory =
|
|
89
|
+
const translationAdapterFactory = cliOptions.translationAdapterFactory || createTranslationAdapter;
|
|
90
90
|
const adapter = translationAdapterFactory({
|
|
91
91
|
locale: localeStr,
|
|
92
92
|
fallbackLocale: DEFAULT_LOCALE
|
|
@@ -118,14 +118,14 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
118
118
|
let cachedCommands;
|
|
119
119
|
async function loadCommands() {
|
|
120
120
|
if (cachedCommands) return cachedCommands;
|
|
121
|
-
const subCommands = [...
|
|
121
|
+
const subCommands = [...cliOptions.subCommands || []];
|
|
122
122
|
return cachedCommands = await Promise.all(subCommands.map(async ([name, cmd]) => await resolveLazyCommand(cmd, name)));
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* create the context
|
|
126
126
|
*/
|
|
127
127
|
const ctx = deepFreeze(Object.assign(create(), {
|
|
128
|
-
name: command
|
|
128
|
+
name: getCommandName(command),
|
|
129
129
|
description: command.description,
|
|
130
130
|
omitted,
|
|
131
131
|
callMode,
|
|
@@ -137,7 +137,7 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
137
137
|
rest,
|
|
138
138
|
_: argv,
|
|
139
139
|
tokens,
|
|
140
|
-
log:
|
|
140
|
+
log: cliOptions.usageSilent ? NOOP : log,
|
|
141
141
|
loadCommands,
|
|
142
142
|
translate
|
|
143
143
|
}));
|
|
@@ -166,6 +166,11 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
|
|
|
166
166
|
}
|
|
167
167
|
return ctx;
|
|
168
168
|
}
|
|
169
|
+
function getCommandName(cmd) {
|
|
170
|
+
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
171
|
+
else if (typeof cmd === "object") return cmd.name || ANONYMOUS_COMMAND_NAME;
|
|
172
|
+
else return ANONYMOUS_COMMAND_NAME;
|
|
173
|
+
}
|
|
169
174
|
function resolveLocale(locale) {
|
|
170
175
|
return locale instanceof Intl.Locale ? locale : typeof locale === "string" ? new Intl.Locale(locale) : new Intl.Locale(DEFAULT_LOCALE);
|
|
171
176
|
}
|
package/lib/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandCallMode, CommandContext,
|
|
1
|
+
import { CliOptions, Command, CommandCallMode, CommandContext, LazyCommand } from "./types-BDWiiycu.js";
|
|
2
2
|
import { ArgToken, ArgValues, Args } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/context.d.ts
|
|
@@ -43,13 +43,13 @@ interface CommandContextParams<A extends Args, V> {
|
|
|
43
43
|
*/
|
|
44
44
|
callMode: CommandCallMode;
|
|
45
45
|
/**
|
|
46
|
-
* A target
|
|
46
|
+
* A target command
|
|
47
47
|
*/
|
|
48
|
-
command: Command<A>;
|
|
48
|
+
command: Command<A> | LazyCommand<A>;
|
|
49
49
|
/**
|
|
50
50
|
* A command options, which is spicialized from `cli` function
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
cliOptions: CliOptions<A>;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Create a {@link CommandContext | command context}
|
|
@@ -64,7 +64,7 @@ declare function createCommandContext<A extends Args = Args, V extends ArgValues
|
|
|
64
64
|
argv,
|
|
65
65
|
tokens,
|
|
66
66
|
command,
|
|
67
|
-
|
|
67
|
+
cliOptions,
|
|
68
68
|
callMode,
|
|
69
69
|
omitted
|
|
70
70
|
}: CommandContextParams<A, V>): Promise<Readonly<CommandContext<A, V>>>; //#endregion
|
package/lib/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandLoader, LazyCommand } from "./types-
|
|
1
|
+
import { Command, CommandLoader, LazyCommand } from "./types-BDWiiycu.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-BDWiiycu.js";
|
|
2
|
+
import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-zTfMFgKw.js";
|
|
3
3
|
export { ArgSchema, ArgValues, Args, define, lazy };
|
package/lib/generator.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Command,
|
|
1
|
+
import { CliOptions, Command, LazyCommand } from "./types-BDWiiycu.js";
|
|
2
2
|
import { Args } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/generator.d.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @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`.
|
|
8
|
-
* @param entry - A {@link Command | entry command}
|
|
9
|
-
* @param opts - A {@link CommandOptions | command options}
|
|
10
|
-
* @returns A rendered usage.
|
|
6
|
+
* generate options of `generate` function.
|
|
11
7
|
*/
|
|
12
8
|
|
|
9
|
+
/**
|
|
10
|
+
* generate options of `generate` function.
|
|
11
|
+
*/
|
|
12
|
+
type GenerateOptions<A extends Args = Args> = CliOptions<A>;
|
|
13
13
|
/**
|
|
14
14
|
* Generate the command usage.
|
|
15
15
|
* @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`.
|
|
16
16
|
* @param entry - A {@link Command | entry command}
|
|
17
|
-
* @param
|
|
17
|
+
* @param options - A {@link CliOptions | cli options}
|
|
18
18
|
* @returns A rendered usage.
|
|
19
19
|
*/
|
|
20
|
-
declare function generate<A extends Args = Args>(command: string | null, entry: Command<A>,
|
|
20
|
+
declare function generate<A extends Args = Args>(command: string | null, entry: Command<A> | LazyCommand<A>, options?: GenerateOptions<A>): Promise<string>;
|
|
21
21
|
|
|
22
22
|
//#endregion
|
|
23
|
-
export { generate };
|
|
23
|
+
export { GenerateOptions, generate };
|
package/lib/generator.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { create } from "./utils-
|
|
2
|
-
import "./context-
|
|
3
|
-
import "./renderer-
|
|
4
|
-
import { cli } from "./cli-
|
|
1
|
+
import { create } from "./utils-D41C8Abf.js";
|
|
2
|
+
import "./context-COFfMm-R.js";
|
|
3
|
+
import "./renderer-kzo45gaB.js";
|
|
4
|
+
import { cli } from "./cli-BVD3QITm.js";
|
|
5
5
|
|
|
6
6
|
//#region src/generator.ts
|
|
7
7
|
/**
|
|
8
8
|
* Generate the command usage.
|
|
9
9
|
* @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`.
|
|
10
10
|
* @param entry - A {@link Command | entry command}
|
|
11
|
-
* @param
|
|
11
|
+
* @param options - A {@link CliOptions | cli options}
|
|
12
12
|
* @returns A rendered usage.
|
|
13
13
|
*/
|
|
14
|
-
async function generate(command, entry,
|
|
14
|
+
async function generate(command, entry, options = {}) {
|
|
15
15
|
const args = ["-h"];
|
|
16
16
|
if (command != null) args.unshift(command);
|
|
17
|
-
return await cli(args, entry,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
return await cli(args, entry, {
|
|
18
|
+
...create(),
|
|
19
|
+
...options,
|
|
20
|
+
usageSilent: true
|
|
21
|
+
}) || "";
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
//#endregion
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader,
|
|
2
|
-
import { define$1 as define, lazy$1 as lazy } from "./definition-
|
|
1
|
+
import { CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-BDWiiycu.js";
|
|
2
|
+
import { define$1 as define, lazy$1 as lazy } from "./definition-zTfMFgKw.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
|
|
6
|
+
/**
|
|
7
|
+
* Run the command.
|
|
8
|
+
* @param args Command line arguments
|
|
9
|
+
* @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
10
|
+
* @param options A {@link CliOptions | CLI options}
|
|
11
|
+
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
12
|
+
*/
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Run the command.
|
|
16
|
+
* @param args Command line arguments
|
|
17
|
+
* @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
18
|
+
* @param options A {@link CliOptions | CLI options}
|
|
19
|
+
* @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
|
|
20
|
+
*/
|
|
21
|
+
declare function cli<A extends Args$1 = Args$1>(argv: string[], entry: Command<A> | CommandRunner<A> | LazyCommand<A>, options?: CliOptions<A>): Promise<string | undefined>;
|
|
8
22
|
|
|
9
23
|
//#endregion
|
|
10
24
|
//#region src/translation.d.ts
|
|
@@ -18,4 +32,4 @@ declare class DefaultTranslation implements TranslationAdapter {
|
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
//#endregion
|
|
21
|
-
export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader,
|
|
35
|
+
export { ArgSchema, ArgValues, Args, CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, 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-D41C8Abf.js";
|
|
2
|
+
import { DefaultTranslation } from "./context-COFfMm-R.js";
|
|
3
3
|
import { define, lazy } from "./definition-DyVBFqB7.js";
|
|
4
|
-
import "./renderer-
|
|
5
|
-
import { cli } from "./cli-
|
|
4
|
+
import "./renderer-kzo45gaB.js";
|
|
5
|
+
import { cli } from "./cli-BVD3QITm.js";
|
|
6
6
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
7
7
|
|
|
8
8
|
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, lazy, parseArgs, resolveArgs };
|
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-D41C8Abf.js";
|
|
2
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-kzo45gaB.js";
|
|
3
3
|
|
|
4
4
|
export { renderHeader, renderUsage, renderValidationErrors };
|
|
@@ -2,7 +2,7 @@ import { ArgToken, ArgValues, Args } from "args-tokens";
|
|
|
2
2
|
|
|
3
3
|
//#region rolldown:runtime
|
|
4
4
|
declare namespace constants_d_exports {
|
|
5
|
-
export { ARG_PREFIX, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE, NOOP };
|
|
5
|
+
export { ANONYMOUS_COMMAND_NAME, ARG_PREFIX, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE, NOOP };
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* The default locale string, which format is BCP 47 language tag.
|
|
@@ -11,6 +11,7 @@ declare const DEFAULT_LOCALE = "en-US";
|
|
|
11
11
|
declare const BUILT_IN_PREFIX = "_";
|
|
12
12
|
declare const ARG_PREFIX = "arg";
|
|
13
13
|
declare const BUILT_IN_KEY_SEPARATOR = ":";
|
|
14
|
+
declare const ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
14
15
|
declare const NOOP: () => void;
|
|
15
16
|
type CommonArgType = {
|
|
16
17
|
readonly help: {
|
|
@@ -25,7 +26,7 @@ type CommonArgType = {
|
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
declare const COMMON_ARGS: CommonArgType;
|
|
28
|
-
declare const COMMAND_OPTIONS_DEFAULT:
|
|
29
|
+
declare const COMMAND_OPTIONS_DEFAULT: CliOptions<Args>;
|
|
29
30
|
declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES"];
|
|
30
31
|
|
|
31
32
|
//#endregion
|
|
@@ -72,58 +73,58 @@ type CommandArgKeys<A extends Args> = GenerateNamespacedKey<KeyOfArgs<RemovedInd
|
|
|
72
73
|
interface CommandEnvironment<A extends Args = Args> {
|
|
73
74
|
/**
|
|
74
75
|
* Current working directory.
|
|
75
|
-
* @see {@link
|
|
76
|
+
* @see {@link CliOptions.cwd}
|
|
76
77
|
*/
|
|
77
78
|
cwd: string | undefined;
|
|
78
79
|
/**
|
|
79
80
|
* Command name.
|
|
80
|
-
* @see {@link
|
|
81
|
+
* @see {@link CliOptions.name}
|
|
81
82
|
*/
|
|
82
83
|
name: string | undefined;
|
|
83
84
|
/**
|
|
84
85
|
* Command description.
|
|
85
|
-
* @see {@link
|
|
86
|
+
* @see {@link CliOptions.description}
|
|
86
87
|
*
|
|
87
88
|
*/
|
|
88
89
|
description: string | undefined;
|
|
89
90
|
/**
|
|
90
91
|
* Command version.
|
|
91
|
-
* @see {@link
|
|
92
|
+
* @see {@link CliOptions.version}
|
|
92
93
|
*/
|
|
93
94
|
version: string | undefined;
|
|
94
95
|
/**
|
|
95
96
|
* Left margin of the command output.
|
|
96
97
|
* @default 2
|
|
97
|
-
* @see {@link
|
|
98
|
+
* @see {@link CliOptions.leftMargin}
|
|
98
99
|
*/
|
|
99
100
|
leftMargin: number;
|
|
100
101
|
/**
|
|
101
102
|
* Middle margin of the command output.
|
|
102
103
|
* @default 10
|
|
103
|
-
* @see {@link
|
|
104
|
+
* @see {@link CliOptions.middleMargin}
|
|
104
105
|
*/
|
|
105
106
|
middleMargin: number;
|
|
106
107
|
/**
|
|
107
108
|
* Whether to display the usage option type.
|
|
108
109
|
* @default false
|
|
109
|
-
* @see {@link
|
|
110
|
+
* @see {@link CliOptions.usageOptionType}
|
|
110
111
|
*/
|
|
111
112
|
usageOptionType: boolean;
|
|
112
113
|
/**
|
|
113
114
|
* Whether to display the option value.
|
|
114
115
|
* @default true
|
|
115
|
-
* @see {@link
|
|
116
|
+
* @see {@link CliOptions.usageOptionValue}
|
|
116
117
|
*/
|
|
117
118
|
usageOptionValue: boolean;
|
|
118
119
|
/**
|
|
119
120
|
* Whether to display the command usage.
|
|
120
121
|
* @default false
|
|
121
|
-
* @see {@link
|
|
122
|
+
* @see {@link CliOptions.usageSilent}
|
|
122
123
|
*/
|
|
123
124
|
usageSilent: boolean;
|
|
124
125
|
/**
|
|
125
126
|
* Sub commands.
|
|
126
|
-
* @see {@link
|
|
127
|
+
* @see {@link CliOptions.subCommands}
|
|
127
128
|
*/
|
|
128
129
|
subCommands: Map<string, Command<any> | LazyCommand<any>> | undefined;
|
|
129
130
|
/**
|
|
@@ -140,9 +141,9 @@ interface CommandEnvironment<A extends Args = Args> {
|
|
|
140
141
|
renderValidationErrors: ((ctx: CommandContext<A>, error: AggregateError) => Promise<string>) | null | undefined;
|
|
141
142
|
}
|
|
142
143
|
/**
|
|
143
|
-
*
|
|
144
|
+
* CLI options of `cli` function.
|
|
144
145
|
*/
|
|
145
|
-
interface
|
|
146
|
+
interface CliOptions<A extends Args = Args> {
|
|
146
147
|
/**
|
|
147
148
|
* Current working directory.
|
|
148
149
|
*/
|
|
@@ -426,4 +427,4 @@ type LazyCommand<A extends Args = Args> = {
|
|
|
426
427
|
* Define a command type.
|
|
427
428
|
*/
|
|
428
429
|
type Commandable<A extends Args> = Command<A> | LazyCommand<A>; //#endregion
|
|
429
|
-
export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader,
|
|
430
|
+
export { CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
|
@@ -6,6 +6,7 @@ const DEFAULT_LOCALE = "en-US";
|
|
|
6
6
|
const BUILT_IN_PREFIX = "_";
|
|
7
7
|
const ARG_PREFIX = "arg";
|
|
8
8
|
const BUILT_IN_KEY_SEPARATOR = ":";
|
|
9
|
+
const ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
9
10
|
const NOOP = () => {};
|
|
10
11
|
const COMMON_ARGS = {
|
|
11
12
|
help: {
|
|
@@ -38,9 +39,12 @@ const COMMAND_OPTIONS_DEFAULT = {
|
|
|
38
39
|
|
|
39
40
|
//#endregion
|
|
40
41
|
//#region src/utils.ts
|
|
42
|
+
function isLazyCommand(cmd) {
|
|
43
|
+
return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
|
|
44
|
+
}
|
|
41
45
|
async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
42
46
|
let command;
|
|
43
|
-
if (
|
|
47
|
+
if (isLazyCommand(cmd)) {
|
|
44
48
|
command = Object.assign(create(), {
|
|
45
49
|
name: cmd.commandName,
|
|
46
50
|
description: cmd.description,
|
|
@@ -96,4 +100,4 @@ function deepFreeze(obj) {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
//#endregion
|
|
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 };
|
|
103
|
+
export { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, isLazyCommand, 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.23.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -103,11 +103,11 @@
|
|
|
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.
|
|
106
|
+
"gunshi019": "npm:gunshi@0.23.0",
|
|
107
107
|
"jsr": "^0.13.4",
|
|
108
108
|
"jsr-exports-lint": "^0.2.0",
|
|
109
109
|
"knip": "^5.53.0",
|
|
110
|
-
"lint-staged": "^
|
|
110
|
+
"lint-staged": "^16.0.0",
|
|
111
111
|
"messageformat": "4.0.0-11",
|
|
112
112
|
"mitata": "^1.0.34",
|
|
113
113
|
"pkg-pr-new": "^0.0.43",
|