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