Skip to content

Commit a201976

Browse files
committed
refactor(plugin-completions): remove extra checking alias
1 parent e19a140 commit a201976

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { TestBaseCli } from "@clerc/test-utils";
2+
import { Cli, Types, friendlyErrorPlugin, helpPlugin, completionsPlugin } from "clerc";
3+
4+
Cli()
5+
.name("my-cli")
6+
.scriptName("my-cli")
7+
.version("1.0.0")
8+
.description("My CLI with completions")
9+
// .use(completionsPlugin())
10+
// .use(friendlyErrorPlugin())
11+
// .parse();
12+
// 啊离开了课件课件
13+
// 12313213123213
14+
.use(friendlyErrorPlugin())
15+
.use(completionsPlugin())
16+
.command("test", "Test command", {
17+
parameters: [
18+
"<param>",
19+
{
20+
key: "<param2>",
21+
type: Types.Enum("a", "b", "c"),
22+
},
23+
{
24+
key: "[range]",
25+
type: Types.Range(1, 10),
26+
}
27+
],
28+
flags: {
29+
bbb: {
30+
required: true,
31+
type: Types.Regex(/^a.*z$/, "starts with a ends with z"),
32+
alias: "a",
33+
},
34+
},
35+
})
36+
.parse();

packages/plugin-completions/src/complete.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,12 @@ export async function getCompletion(
7272
const candidates: CompletionItem[] = [];
7373
for (const [name, def] of Object.entries(flags)) {
7474
const normalized = normalizeFlagValue(def);
75-
candidates.push({
76-
name: formatFlagName(name),
77-
description: normalized.description,
78-
});
79-
if (normalized.alias) {
80-
const aliases = toArray(normalized.alias);
81-
for (const alias of aliases) {
82-
candidates.push({
83-
name: formatFlagName(alias),
84-
description: normalized.description,
85-
});
86-
}
75+
const names = [name, ...toArray(normalized.alias ?? [])];
76+
for (const name of names) {
77+
candidates.push({
78+
name: formatFlagName(name),
79+
description: normalized.description,
80+
});
8781
}
8882
}
8983

0 commit comments

Comments
 (0)