/
command.ts
125 lines (105 loc) · 3.09 KB
/
command.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {Config, LoadOptions} from './config'
import {ArgInput, BooleanFlagProps, Deprecation, FlagInput, OptionFlagProps} from './parser'
import {Plugin as IPlugin} from './plugin'
export type Example = string | {
description: string;
command: string;
}
export interface CommandProps {
/** A command ID, used mostly in error or verbose reporting. */
id: string;
/** Hide the command from help */
hidden: boolean;
/** Mark the command as a given state (e.g. beta or deprecated) in help */
state?: 'beta' | 'deprecated' | string;
/**
* Provide details to the deprecation warning if state === 'deprecated'
*/
deprecationOptions?: Deprecation;
/** An array of aliases for this command. */
aliases: string[];
/**
* The tweet-sized description for your class, used in a parent-commands
* sub-command listing and as the header for the command help.
*/
summary?: string;
/**
* A full description of how to use the command.
*
* If no summary, the first line of the description will be used as the summary.
*/
description?: string;
/**
* An override string (or strings) for the default usage documentation.
*/
usage?: string | string[];
/**
* An array of examples to show at the end of the command's help.
*
* IF only a string is provide, it will try to look for a line that starts
* with the cmd.bin as the example command and the rest as the description.
* If found, the command will be formatted appropriately.
*
* ```
* EXAMPLES:
* A description of a particular use case.
*
* $ <%= config.bin => command flags
* ```
*/
examples?: Example[];
}
export interface Command extends CommandProps {
type?: string;
pluginName?: string;
pluginType?: string;
pluginAlias?: string;
flags: {[name: string]: Command.Flag};
args: Command.Arg[];
strict: boolean;
hasDynamicHelp?: boolean;
}
export namespace Command {
export interface Arg {
name: string;
description?: string;
required?: boolean;
hidden?: boolean;
default?: string;
options?: string[];
}
export type Flag = Flag.Boolean | Flag.Option
export namespace Flag {
// We can't use "export OptionFlagProps as Option" in the namespace export.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Boolean extends BooleanFlagProps {}
export interface Option extends OptionFlagProps {
default?: string;
defaultHelp?: () => Promise<string>
}
}
export interface Base extends CommandProps {
_base: string;
}
export interface Class extends Base {
plugin?: IPlugin;
flags?: FlagInput<any>;
args?: ArgInput;
strict: boolean;
hasDynamicHelp?: boolean;
new(argv: string[], config: Config): Instance;
run(argv?: string[], config?: LoadOptions): PromiseLike<any>;
}
export interface Instance {
_run(argv: string[]): Promise<any>;
}
export interface Loadable extends Command {
load(): Promise<Class>;
}
/**
* @deprecated use Command.Loadable instead.
*/
export interface Plugin extends Command {
load(): Promise<Class>;
}
}