generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
237 lines (235 loc) · 6.92 KB
/
index.d.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
/**
* Define a command functionally
*
* @param options Command options
* @returns {Command}
*/
export declare function defineCommand(options: Command): Command
/**
* Run command
*
* **NOTE**: If the given `args` is empty, it will use `process.argv` instead.
*
* **NOTE**: The given `args` should include the nodejs executable and script name.
* For example, if you are running a script `index.js` in the current directory with
* a flag `--foo`, you should pass `["node", "index.js", "--foo"]` as `args`.
*
* @param cmd Command object
* @param args Run with given arguments
* @returns {void}
*/
export declare function run(cmd: Command, args?: Array<string> | undefined | null): void
/**
* Command context
*
* This is the context object that is passed to the command callback.
*/
export interface Context {
/**
* Parsed arguments
*
* This is a js object that contains the parsed arguments.
* The keys of the object are the names of the arguments and
* the values are the parsed values.
*/
args: Record<string, any>
/**
* Raw arguments
*
* The raw arguments parsed by command line or manually given.
*/
rawArgs: Array<string>
}
/** Command metadata */
export interface CommandMeta {
/**
* Command name
*
* This is the name of the command that will be used to call it from the CLI.
* If the command is the main command, the name will be the name of the binary.
* If the command is a subcommand, the name will be the name of the subcommand.
*/
name?: string
/**
* CLI version
*
* This is optional and can be used to display the version of the CLI
* when the command is called with the `--version` flag or `-V` option.
*
* If not provided, the CLI will not display the version and you can't
* call the command with the `--version` flag or `-V` option.
*/
version?: string
/**
* Command description
*
* Command description will be displayed in the help output.
*/
about?: string
/**
* Enable styled mode
*
* Determines whether the CLI output should be displayed in the styled format.
*/
styled?: boolean
}
export interface CommandOption {
/**
* Option type for argument
*
* `type` option and `action` option are used to specify how to parse the argument.
*
* - `option` and (`store` or `store_false`): Boolean flag
* - `option` and `count`: Counter flag
* - `option` and `set`: Option flag
* - `option` and `append`: Multiple option flag
* - `positional` and `set`: Positional argument
* - `positional` and `append`: Multiple positional argument
*
* Defaults to `option` if not specified.
*/
type?: 'positional' | 'option'
/** Specify the value type for the argument. */
parser?: 'string' | 'number' | 'boolean'
/**
* Specify how to react to an argument when parsing it.
*
* - `set`: Overwrite previous values with new ones
* - `append`: Append new values to all previous ones
* - `count`: Count how many times a flag occurs
* - `store`: Store the value as a boolean flag
* - `store_false`: Store the value as a boolean flag with opposite meaning
*
* Defaults to `set` if not specified.
*/
action?: 'set' | 'append' | 'count' | 'store' | 'store_false'
/**
* Short option name
*
* This is a single character that can be used to represent the option
* in the command line. For example, `-v` for the `--verbose` option.
* Panics if the length of the string is empty. If the size of string
* is greater than 1, the first character will be used as the short option.
*
* This option will be ignored if option `type` is not `option`.
*
* Defaults to the first character of the long option name.
*/
short?: string
/**
* Long option name
*
* This is the name of the option that will be used to represent the option,
* preceded by two dashes. For example, `--verbose` option.
*
* This option will be ignored if option `type` is not `option`.
*
* Defaults to the name of the argument.
*/
long?: string
/** Option aliases */
alias?: Array<string>
/** Hidden option aliases */
hiddenAlias?: Array<string>
/** Short option aliases */
shortAlias?: Array<string>
/** Hidden short option aliases */
hiddenShortAlias?: Array<string>
/**
* Value hint for shell completion
*
* Provide the shell a hint about how to complete this argument.
*
* **Warning**: this will implicitly set `action` to `set`.
*/
valueHint?:
| 'any_path'
| 'file'
| 'dir'
| 'executable'
| 'cmd_name'
| 'cmd'
| 'cmd_with_args'
| 'url'
| 'username'
| 'hostname'
| 'email'
/** Option description */
help?: string
/**
* Required argument
*
* If true, the argument is required and the command will fail without it.
*/
required?: boolean
/** Value for the argument when not present */
default?: string
/**
* Value for the argument when the flag is present but no value is specified.
*
* This configuration option is often used to give the user a shortcut and
* allow them to efficiently specify an option argument without requiring an
* explicitly value. The `--color` argument is a common example. By supplying
* a default, such as `default_missing_value("always")`, the user can quickly
* just add `--color` to the command line to produce the desired color output.
*/
defaultMissing?: string
/**
* Limit the count of values for the argument
*
* If the expected number of parameters required is a fixed value, pass in the
* number directly. If you want to limit the number of values to a range, for
* example, pass `1..5` or `1..=4` to specify a range from 1 to 4 inclusive.
*/
numArgs?: string
/** Requires that options use the `--option=val` syntax */
requiredEquals?: boolean
/**
* Hide argument in help output
*
* Do not display the argument in the help message.
*/
hidden?: boolean
/**
* Global argument
*
* Specifies that an argument can be matched to all child subcommands
*/
global?: boolean
/**
* Options that conflict with this argument
*
* This argument is mutually exclusive with the specified arguments.
*/
conflictsWith?: Array<string>
/**
* Exclusive argument
*
* This argument must be passed alone; it conflicts with all other arguments.
*/
exclusive?: boolean
/**
* Hide default value in help output
*
* Do not display the default value of the argument in the help message.
*
* This is useful when default behavior of an arg is explained elsewhere
* in the help text.
*/
hideDefaultValue?: boolean
}
/**
* Command definition
*
* This is the object that defines a command.
* It contains the metadata, options, and callback function.
*/
export interface Command {
meta: CommandMeta
options: Record<string, CommandOption>
callback?: (ctx: Context) => void
subcommands?: Record<string, Command>
}