Skip to content

Commit d5f256f

Browse files
committed
Fixing getCommand
1 parent d87e4b7 commit d5f256f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/bin/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function cli(pkg: any) {
111111

112112
if (!handlePreviewToggles(args)) {
113113
// If this is a help command, load all commands so we can display them.
114-
const isHelp = !args.length || args[0] === "help";
114+
const isHelp = !args.length || args[0] === "help" || (args.length === 1 && args[0] === "ext");
115115
if (isHelp) {
116116
const seen = new Set();
117117
const loadAll = (obj: any) => {

src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ const client: CLIClient = {
3434
return client.cli.commands[i];
3535
}
3636
}
37+
const keys = name.split(":");
38+
let obj: any = client;
39+
for (const key of keys) {
40+
if (!obj || (typeof obj !== "object" && typeof obj !== "function")) {
41+
return;
42+
}
43+
const nextKey = Object.keys(obj).find((k) => k.toLowerCase() === key.toLowerCase());
44+
if (!nextKey) {
45+
return;
46+
}
47+
obj = obj[nextKey];
48+
}
49+
if (isCommandModule(obj)) {
50+
obj.load();
51+
for (let i = 0; i < client.cli.commands.length; i++) {
52+
if (client.cli.commands[i]._name === name) {
53+
return client.cli.commands[i];
54+
}
55+
}
56+
}
3757
return;
3858
},
3959
};
@@ -82,7 +102,7 @@ program.action((_, args) => {
82102
let obj = client;
83103
let hit = true;
84104
for (const key of keys) {
85-
if (!obj || typeof obj !== "object") {
105+
if (!obj || (typeof obj !== "object" && typeof obj !== "function")) {
86106
hit = false;
87107
break;
88108
}

0 commit comments

Comments
 (0)