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