/
mod.ts
38 lines (33 loc) 路 1.26 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Command } from "../command.ts";
import { dim, italic } from "../deps.ts";
import { BashCompletionsCommand } from "./bash.ts";
import { CompleteCommand } from "./complete.ts";
import { FishCompletionsCommand } from "./fish.ts";
import { ZshCompletionsCommand } from "./zsh.ts";
/** Generates shell completion scripts for various shells. */
export class CompletionsCommand extends Command {
#cmd?: Command;
public constructor(cmd?: Command) {
super();
this.#cmd = cmd;
return this
.description(() => {
const baseCmd = this.#cmd || this.getMainCommand();
return `Generate shell completions.
To enable shell completions for this program add the following line to your ${
dim(italic("~/.bashrc"))
} or similar:
${dim(italic(`source <(${baseCmd.getPath()} completions [shell])`))}
For more information run ${
dim(italic(`${baseCmd.getPath()} completions [shell] --help`))
}
`;
})
.action(() => this.showHelp())
.command("bash", new BashCompletionsCommand(this.#cmd))
.command("fish", new FishCompletionsCommand(this.#cmd))
.command("zsh", new ZshCompletionsCommand(this.#cmd))
.command("complete", new CompleteCommand(this.#cmd).hidden())
.reset();
}
}