-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
mod.ts
35 lines (34 loc) 路 1.08 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
import { Command } from "../command.ts";
import { UnknownCommand } from "../_errors.ts";
import { CommandType } from "../types/command.ts";
/** Generates well formatted and colored help output for specified command. */
export class HelpCommand
extends Command<void, void, void, [commandName?: CommandType]> {
public constructor(cmd?: Command) {
super();
return this
.type("command", new CommandType())
.arguments("[command:command]")
.description("Show this help or the help of a sub-command.")
.noGlobals()
.action(async (_, name?: string) => {
if (!cmd) {
cmd = name
? this.getGlobalParent()?.getBaseCommand(name)
: this.getGlobalParent();
}
if (!cmd) {
const cmds = this.getGlobalParent()?.getCommands();
throw new UnknownCommand(name ?? "", cmds ?? [], [
this.getName(),
...this.getAliases(),
]);
}
await cmd.checkVersion();
cmd.showHelp();
if (this.shouldExit()) {
Deno.exit(0);
}
});
}
}