gunshi 0.6.1 → 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 +5 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -7,10 +7,9 @@ import { parseArgs, resolveArgs } from "args-tokens";
|
|
|
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];
|