UNPKG

2.38 kBTypeScriptView Raw
1import CAC from './CAC';
2import Option, { OptionConfig } from './Option';
3interface CommandArg {
4 required: boolean;
5 value: string;
6 variadic: boolean;
7}
8interface HelpSection {
9 title?: string;
10 body: string;
11}
12interface CommandConfig {
13 allowUnknownOptions?: boolean;
14 ignoreOptionDefaultValue?: boolean;
15}
16declare type HelpCallback = (sections: HelpSection[]) => void;
17declare type CommandExample = ((bin: string) => string) | string;
18declare class Command {
19 rawName: string;
20 description: string;
21 config: CommandConfig;
22 cli: CAC;
23 options: Option[];
24 aliasNames: string[];
25 name: string;
26 args: CommandArg[];
27 commandAction?: (...args: any[]) => any;
28 usageText?: string;
29 versionNumber?: string;
30 examples: CommandExample[];
31 helpCallback?: HelpCallback;
32 globalCommand?: GlobalCommand;
33 constructor(rawName: string, description: string, config: CommandConfig, cli: CAC);
34 usage(text: string): this;
35 allowUnknownOptions(): this;
36 ignoreOptionDefaultValue(): this;
37 version(version: string, customFlags?: string): this;
38 example(example: CommandExample): this;
39 /**
40 * Add a option for this command
41 * @param rawName Raw option name(s)
42 * @param description Option description
43 * @param config Option config
44 */
45 option(rawName: string, description: string, config?: OptionConfig): this;
46 alias(name: string): this;
47 action(callback: (...args: any[]) => any): this;
48 /**
49 * Check if a command name is matched by this command
50 * @param name Command name
51 */
52 isMatched(name: string): boolean;
53 readonly isDefaultCommand: boolean;
54 readonly isGlobalCommand: boolean;
55 /**
56 * Check if an option is registered in this command
57 * @param name Option name
58 */
59 hasOption(name: string): Option | undefined;
60 outputHelp(): void;
61 outputVersion(): void;
62 checkRequiredArgs(): void;
63 /**
64 * Check if the parsed options contain any unknown options
65 *
66 * Exit and output error when true
67 */
68 checkUnknownOptions(): void;
69 /**
70 * Check if the required string-type options exist
71 */
72 checkOptionValue(): void;
73}
74declare class GlobalCommand extends Command {
75 constructor(cli: CAC);
76}
77export { HelpCallback, CommandExample, CommandConfig, GlobalCommand };
78export default Command;