1 |
|
2 | import { EventEmitter } from 'events';
|
3 | import Command, { GlobalCommand, CommandConfig, HelpCallback, CommandExample } from './Command';
|
4 | import { OptionConfig } from './Option';
|
5 | interface ParsedArgv {
|
6 | args: ReadonlyArray<string>;
|
7 | options: {
|
8 | [k: string]: any;
|
9 | };
|
10 | }
|
11 | declare class CAC extends EventEmitter {
|
12 |
|
13 | name: string;
|
14 | commands: Command[];
|
15 | globalCommand: GlobalCommand;
|
16 | matchedCommand?: Command;
|
17 | matchedCommandName?: string;
|
18 | |
19 |
|
20 |
|
21 | rawArgs: string[];
|
22 | |
23 |
|
24 |
|
25 | args: ParsedArgv['args'];
|
26 | |
27 |
|
28 |
|
29 | options: ParsedArgv['options'];
|
30 | private showHelpOnExit;
|
31 | private showVersionOnExit;
|
32 | |
33 |
|
34 |
|
35 | constructor(name?: string);
|
36 | /**
|
37 | * Add a global usage text.
|
38 | *
|
39 | * This is not used by sub-commands.
|
40 | */
|
41 | usage(text: string): this;
|
42 | /**
|
43 | * Add a sub-command
|
44 | */
|
45 | command(rawName: string, description?: string, config?: CommandConfig): Command;
|
46 | /**
|
47 | * Add a global CLI option.
|
48 | *
|
49 | * Which is also applied to sub-commands.
|
50 | */
|
51 | option(rawName: string, description: string, config?: OptionConfig): this;
|
52 | /**
|
53 | * Show help message when `-h, --help` flags appear.
|
54 | *
|
55 | */
|
56 | help(callback?: HelpCallback): this;
|
57 | /**
|
58 | * Show version number when `-v, --version` flags appear.
|
59 | *
|
60 | */
|
61 | version(version: string, customFlags?: string): this;
|
62 | /**
|
63 | * Add a global example.
|
64 | *
|
65 | * This example added here will not be used by sub-commands.
|
66 | */
|
67 | example(example: CommandExample): this;
|
68 | /**
|
69 | * Output the corresponding help message
|
70 | * When a sub-command is matched, output the help message for the command
|
71 | * Otherwise output the global one.
|
72 | *
|
73 | */
|
74 | outputHelp(): void;
|
75 | /**
|
76 | * Output the version number.
|
77 | *
|
78 | */
|
79 | outputVersion(): void;
|
80 | private setParsedInfo;
|
81 | /**
|
82 | * Parse argv
|
83 | */
|
84 | parse(argv?: any[], {
|
85 |
|
86 | run }?: {
|
87 | run?: boolean | undefined;
|
88 | }): ParsedArgv;
|
89 | private mri;
|
90 | runMatchedCommand(): any;
|
91 | }
|
92 | export default CAC;
|