@stricli/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +1389 -0
- package/dist/index.d.ts +1389 -0
- package/dist/index.js +22 -0
- package/package.json +79 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal expected interface for an output stream; used to narrow the types of NodeJS's stdout/stderr.
|
|
3
|
+
*/
|
|
4
|
+
interface Writable {
|
|
5
|
+
/**
|
|
6
|
+
* Write the provided string to this stream.
|
|
7
|
+
*/
|
|
8
|
+
readonly write: (str: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Determine the available color depth of the underlying stream.
|
|
11
|
+
* Environment variables are also provided to control or suppress color output.
|
|
12
|
+
*/
|
|
13
|
+
readonly getColorDepth?: (env?: Readonly<Partial<Record<string, string>>>) => number;
|
|
14
|
+
}
|
|
15
|
+
interface WritableStreams {
|
|
16
|
+
/**
|
|
17
|
+
* Contains a writable stream connected to stdout (fd 1).
|
|
18
|
+
*/
|
|
19
|
+
readonly stdout: Writable;
|
|
20
|
+
/**
|
|
21
|
+
* Contains a writable stream connected to stderr (fd 2).
|
|
22
|
+
*/
|
|
23
|
+
readonly stderr: Writable;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Command-level context that provides necessary process information and is available to all command runs.
|
|
27
|
+
* This type should be extended to include context specific to your command implementations.
|
|
28
|
+
*/
|
|
29
|
+
interface CommandContext {
|
|
30
|
+
readonly process: WritableStreams;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Simple interface that mirrors NodeJS.Process but only requires the minimum API required by Stricli.
|
|
34
|
+
*/
|
|
35
|
+
interface StricliProcess extends WritableStreams {
|
|
36
|
+
/**
|
|
37
|
+
* Object that stores all available environment variables.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link EnvironmentVariableName} for variable names used by Stricli.
|
|
40
|
+
*/
|
|
41
|
+
readonly env?: Readonly<Partial<Record<string, string>>>;
|
|
42
|
+
/**
|
|
43
|
+
* Set the exit code and end the current process.
|
|
44
|
+
*/
|
|
45
|
+
readonly exit?: (code: number) => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Environment variable names used by Stricli.
|
|
49
|
+
*
|
|
50
|
+
* - `STRICLI_SKIP_VERSION_CHECK` - If specified and non-0, skips the latest version check.
|
|
51
|
+
* - `STRICLI_NO_COLOR` - If specified and non-0, disables ANSI terminal coloring.
|
|
52
|
+
*/
|
|
53
|
+
type EnvironmentVariableName = "STRICLI_SKIP_VERSION_CHECK" | "STRICLI_NO_COLOR";
|
|
54
|
+
/**
|
|
55
|
+
* Top-level context that provides necessary process information to Stricli internals.
|
|
56
|
+
*/
|
|
57
|
+
interface ApplicationContext extends CommandContext {
|
|
58
|
+
readonly process: StricliProcess;
|
|
59
|
+
/**
|
|
60
|
+
* A string that represents the current user's locale.
|
|
61
|
+
* It is passed to {@link LocalizationConfiguration.loadText} which provides the text for Stricli to use
|
|
62
|
+
* when formatting built-in output.
|
|
63
|
+
*/
|
|
64
|
+
readonly locale?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Contextual information about the current command.
|
|
68
|
+
*/
|
|
69
|
+
interface CommandInfo {
|
|
70
|
+
/**
|
|
71
|
+
* Prefix of command line inputs used to navigate to the current command.
|
|
72
|
+
*/
|
|
73
|
+
readonly prefix: readonly string[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Function to build a generic CommandContext given the current command information.
|
|
77
|
+
*/
|
|
78
|
+
type StricliCommandContextBuilder<CONTEXT extends CommandContext> = (info: CommandInfo) => CONTEXT | Promise<CONTEXT>;
|
|
79
|
+
/**
|
|
80
|
+
* Dynamic context for command that contains either the generic CommandContext or simply the more limited
|
|
81
|
+
* ApplicationContext and a method that builds a specific instance of the generic CommandContext.
|
|
82
|
+
*/
|
|
83
|
+
type StricliDynamicCommandContext<CONTEXT extends CommandContext> = ApplicationContext & (CONTEXT | {
|
|
84
|
+
/**
|
|
85
|
+
* Method to build specific CommandContext instance for the current command.
|
|
86
|
+
*/
|
|
87
|
+
readonly forCommand: StricliCommandContextBuilder<CONTEXT>;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Keyword strings used to build help text.
|
|
92
|
+
*/
|
|
93
|
+
interface DocumentationKeywords {
|
|
94
|
+
/**
|
|
95
|
+
* Keyword to be included when flags or arguments have a default value.
|
|
96
|
+
*
|
|
97
|
+
* Defaults to `"default"`.
|
|
98
|
+
*/
|
|
99
|
+
readonly default: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Section header strings used to build help text.
|
|
103
|
+
*/
|
|
104
|
+
interface DocumentationHeaders {
|
|
105
|
+
/**
|
|
106
|
+
* Header for help text section that lists all usage lines.
|
|
107
|
+
*
|
|
108
|
+
* Defaults to `"USAGE"`.
|
|
109
|
+
*/
|
|
110
|
+
readonly usage: string;
|
|
111
|
+
/**
|
|
112
|
+
* Header for help text section that lists all aliases for the route.
|
|
113
|
+
*
|
|
114
|
+
* Defaults to `"ALIASES"`.
|
|
115
|
+
*/
|
|
116
|
+
readonly aliases: string;
|
|
117
|
+
/**
|
|
118
|
+
* Header for help text section that lists all commands in a route map.
|
|
119
|
+
*
|
|
120
|
+
* Defaults to `"COMMANDS"`.
|
|
121
|
+
*/
|
|
122
|
+
readonly commands: string;
|
|
123
|
+
/**
|
|
124
|
+
* Header for help text section that lists all flags accepted by the route.
|
|
125
|
+
*
|
|
126
|
+
* Defaults to `"FLAGS"`.
|
|
127
|
+
*/
|
|
128
|
+
readonly flags: string;
|
|
129
|
+
/**
|
|
130
|
+
* Header for help text section that lists all arguments accepted by the command.
|
|
131
|
+
*
|
|
132
|
+
* Defaults to `"ARGUMENTS"`.
|
|
133
|
+
*/
|
|
134
|
+
readonly arguments: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Short documentation brief strings used to build help text.
|
|
138
|
+
*/
|
|
139
|
+
interface DocumentationBriefs {
|
|
140
|
+
/**
|
|
141
|
+
* Documentation brief to be included alongside `--help` flag in help text.
|
|
142
|
+
*
|
|
143
|
+
* Defaults to `"Print help information and exit"`.
|
|
144
|
+
*/
|
|
145
|
+
readonly help: string;
|
|
146
|
+
/**
|
|
147
|
+
* Documentation brief to be included alongside `--helpAll` flag in help text.
|
|
148
|
+
*
|
|
149
|
+
* Defaults to `"Print help information (including hidden commands/flags) and exit"`.
|
|
150
|
+
*/
|
|
151
|
+
readonly helpAll: string;
|
|
152
|
+
/**
|
|
153
|
+
* Documentation brief to be included alongside `--version` flag in help text.
|
|
154
|
+
*
|
|
155
|
+
* Defaults to `"Print version information and exit"`.
|
|
156
|
+
*/
|
|
157
|
+
readonly version: string;
|
|
158
|
+
/**
|
|
159
|
+
* Documentation brief to be included alongside `--` escape sequence in help text.
|
|
160
|
+
* Only present when `scanner.allowArgumentEscapeSequence` is `true`.
|
|
161
|
+
*
|
|
162
|
+
* Defaults to `"All subsequent inputs should be interpreted as arguments"`.
|
|
163
|
+
*/
|
|
164
|
+
readonly argumentEscapeSequence: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Strings used to build help text.
|
|
168
|
+
*/
|
|
169
|
+
interface DocumentationText {
|
|
170
|
+
/**
|
|
171
|
+
* Keyword strings used to build help text.
|
|
172
|
+
*/
|
|
173
|
+
readonly keywords: DocumentationKeywords;
|
|
174
|
+
/**
|
|
175
|
+
* Section header strings used to build help text.
|
|
176
|
+
*/
|
|
177
|
+
readonly headers: DocumentationHeaders;
|
|
178
|
+
/**
|
|
179
|
+
* Short documentation brief strings used to build help text.
|
|
180
|
+
*/
|
|
181
|
+
readonly briefs: DocumentationBriefs;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Methods to customize the formatting of stderr messages handled by command execution.
|
|
185
|
+
*/
|
|
186
|
+
interface CommandErrorFormatting {
|
|
187
|
+
/**
|
|
188
|
+
* Formatted error message for the case where some exception was thrown while parsing the arguments.
|
|
189
|
+
*
|
|
190
|
+
* Exceptions intentionally thrown by this library while parsing arguments will extend from ArgumentScannerError.
|
|
191
|
+
* These subclasses provide additional context about the specific error.
|
|
192
|
+
* Use the {@link formatMessageForArgumentScannerError} helper to handle the different error types.
|
|
193
|
+
*
|
|
194
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
195
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
196
|
+
*/
|
|
197
|
+
readonly exceptionWhileParsingArguments: (exc: unknown, ansiColor: boolean) => string;
|
|
198
|
+
/**
|
|
199
|
+
* Formatted error message for the case where some exception was thrown while loading the command function.
|
|
200
|
+
* This likely indicates an issue with the application itself or possibly the user's installation of the application.
|
|
201
|
+
*
|
|
202
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
203
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
204
|
+
*/
|
|
205
|
+
readonly exceptionWhileLoadingCommandFunction: (exc: unknown, ansiColor: boolean) => string;
|
|
206
|
+
/**
|
|
207
|
+
* Formatted error message for the case where some exception was thrown while loading the context for the command run.
|
|
208
|
+
* This likely indicates an issue with the application itself or possibly the user's installation of the application.
|
|
209
|
+
*
|
|
210
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
211
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
212
|
+
*/
|
|
213
|
+
readonly exceptionWhileLoadingCommandContext: (exc: unknown, ansiColor: boolean) => string;
|
|
214
|
+
/**
|
|
215
|
+
* Formatted error message for the case where some exception was thrown while running the command.
|
|
216
|
+
* Users are most likely to hit this case, so make sure that the error text provides practical, usable feedback.
|
|
217
|
+
*
|
|
218
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
219
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
220
|
+
*/
|
|
221
|
+
readonly exceptionWhileRunningCommand: (exc: unknown, ansiColor: boolean) => string;
|
|
222
|
+
/**
|
|
223
|
+
* Formatted error message for the case where an Error was safely returned from the command.
|
|
224
|
+
* Users are most likely to hit this case, so make sure that the error text provides practical, usable feedback.
|
|
225
|
+
*
|
|
226
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
227
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
228
|
+
*/
|
|
229
|
+
readonly commandErrorResult: (err: Error, ansiColor: boolean) => string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Methods to customize the formatting of stderr messages handled by application execution.
|
|
233
|
+
*/
|
|
234
|
+
interface ApplicationErrorFormatting extends CommandErrorFormatting {
|
|
235
|
+
/**
|
|
236
|
+
* Formatted error message for the case where the supplied command line inputs do not resolve to a registered command.
|
|
237
|
+
* Supplied with arguments for the argument in question, and several possible corrections based on registered commands.
|
|
238
|
+
*
|
|
239
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
240
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
241
|
+
*/
|
|
242
|
+
readonly noCommandRegisteredForInput: (args: {
|
|
243
|
+
readonly input: string;
|
|
244
|
+
readonly corrections: readonly string[];
|
|
245
|
+
readonly ansiColor: boolean;
|
|
246
|
+
}) => string;
|
|
247
|
+
/**
|
|
248
|
+
* Formatted error message for the case where the application does not provide text for the current requested locale.
|
|
249
|
+
* Should indicate that the default locale will be used instead.
|
|
250
|
+
*
|
|
251
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
252
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
253
|
+
*/
|
|
254
|
+
readonly noTextAvailableForLocale: (args: {
|
|
255
|
+
readonly requestedLocale: string;
|
|
256
|
+
readonly defaultLocale: string;
|
|
257
|
+
readonly ansiColor: boolean;
|
|
258
|
+
}) => string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The full set of static text and text-returning callbacks that are necessary for Stricli to write the necessary output.
|
|
262
|
+
*/
|
|
263
|
+
interface ApplicationText extends ApplicationErrorFormatting, DocumentationText {
|
|
264
|
+
/**
|
|
265
|
+
* Generate warning text to be written to stdout when the latest version is not installed.
|
|
266
|
+
* Should include brief instructions for how to update to that version.
|
|
267
|
+
*
|
|
268
|
+
* If `ansiColor` is true, this string can use ANSI terminal codes.
|
|
269
|
+
* Codes may have already been applied so be aware you may have to reset to achieve the desired output.
|
|
270
|
+
*/
|
|
271
|
+
readonly currentVersionIsNotLatest: (args: {
|
|
272
|
+
readonly currentVersion: string;
|
|
273
|
+
readonly latestVersion: string;
|
|
274
|
+
readonly upgradeCommand?: string;
|
|
275
|
+
readonly ansiColor: boolean;
|
|
276
|
+
}) => string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Default English text implementation of {@link ApplicationText}.
|
|
280
|
+
*/
|
|
281
|
+
declare const text_en: ApplicationText;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The weights of various edit operations used when calculating the Damerau-Levenshtein distance.
|
|
285
|
+
*/
|
|
286
|
+
interface DamerauLevenshteinWeights {
|
|
287
|
+
/**
|
|
288
|
+
* The edit cost of inserting a character.
|
|
289
|
+
*
|
|
290
|
+
* Example: `"ab" -> "abc"`
|
|
291
|
+
*/
|
|
292
|
+
readonly insertion: number;
|
|
293
|
+
/**
|
|
294
|
+
* The edit cost of deleting a character.
|
|
295
|
+
*
|
|
296
|
+
* Example: `"abc" -> "ab"`
|
|
297
|
+
*/
|
|
298
|
+
readonly deletion: number;
|
|
299
|
+
/**
|
|
300
|
+
* The edit cost of replacing one character with another.
|
|
301
|
+
*
|
|
302
|
+
* Example: `"abc" -> "arc"`
|
|
303
|
+
*/
|
|
304
|
+
readonly substitution: number;
|
|
305
|
+
/**
|
|
306
|
+
* The edit cost of swapping two adjacent characters.
|
|
307
|
+
*
|
|
308
|
+
* Example: `"acb" -> "abc"`
|
|
309
|
+
*/
|
|
310
|
+
readonly transposition: number;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Customizable options for edit cost weights and threshold when calculating the Damerau-Levenshtein distance.
|
|
314
|
+
*/
|
|
315
|
+
interface DamerauLevenshteinOptions {
|
|
316
|
+
/**
|
|
317
|
+
* The upper threshold for edit distance when considering potential alternatives.
|
|
318
|
+
*/
|
|
319
|
+
readonly threshold: number;
|
|
320
|
+
/**
|
|
321
|
+
* The weights of various edit operations used when calculating the Damerau-Levenshtein distance.
|
|
322
|
+
*/
|
|
323
|
+
readonly weights: DamerauLevenshteinWeights;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Methods to determine application version information for `--version` flag or latest version check.
|
|
328
|
+
*/
|
|
329
|
+
type VersionInfo = ({
|
|
330
|
+
/**
|
|
331
|
+
* Statically known current version.
|
|
332
|
+
*/
|
|
333
|
+
readonly currentVersion: string;
|
|
334
|
+
} | {
|
|
335
|
+
/**
|
|
336
|
+
* Asynchonously determine the current version of this application.
|
|
337
|
+
*/
|
|
338
|
+
readonly getCurrentVersion: (this: ApplicationContext) => Promise<string>;
|
|
339
|
+
}) & {
|
|
340
|
+
/**
|
|
341
|
+
* Asynchonously determine the latest version of this application.
|
|
342
|
+
* If value is retrieved from cache, a change to the current version should invalidate that cache.
|
|
343
|
+
*/
|
|
344
|
+
readonly getLatestVersion?: (this: ApplicationContext, currentVersion: string) => Promise<string | undefined>;
|
|
345
|
+
/**
|
|
346
|
+
* Command to display to the end user that will upgrade this application.
|
|
347
|
+
* Passed to {@link ApplicationText.currentVersionIsNotLatest} to format/localize.
|
|
348
|
+
*/
|
|
349
|
+
readonly upgradeCommand?: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Case style configuration for parsing route and flag names from the command line.
|
|
353
|
+
* Each value has the following behavior:
|
|
354
|
+
* * `original` - Only accepts exact matches.
|
|
355
|
+
* * `allow-kebab-for-camel` - In addition to exact matches, allows kebab-case input for camelCase.
|
|
356
|
+
*/
|
|
357
|
+
type ScannerCaseStyle = "original" | "allow-kebab-for-camel";
|
|
358
|
+
/**
|
|
359
|
+
* Configuration for controlling the behavior of the command and argument scanners.
|
|
360
|
+
*/
|
|
361
|
+
interface ScannerConfiguration {
|
|
362
|
+
/**
|
|
363
|
+
* Case style configuration for scanning route and flag names.
|
|
364
|
+
*
|
|
365
|
+
* Default value is `original`
|
|
366
|
+
*/
|
|
367
|
+
readonly caseStyle: ScannerCaseStyle;
|
|
368
|
+
/**
|
|
369
|
+
* If true, when scanning inputs for a command will treat `--` as an escape sequence.
|
|
370
|
+
* This will force the scanner to treat all remaining inputs as arguments.
|
|
371
|
+
*
|
|
372
|
+
* Example for `false`
|
|
373
|
+
* ```shell
|
|
374
|
+
* $ cli --foo -- --bar
|
|
375
|
+
* # { foo: true, bar: true }, ["--"]
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* Example for `true`
|
|
379
|
+
* ```shell
|
|
380
|
+
* $ cli --foo -- --bar
|
|
381
|
+
* # { foo: true }, ["--bar"]
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* Default value is `false`
|
|
385
|
+
*/
|
|
386
|
+
readonly allowArgumentEscapeSequence: boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Options used when calculating distance for alternative inputs ("did you mean?").
|
|
389
|
+
*
|
|
390
|
+
* Default value is equivalent to the empirically determined values used by git:
|
|
391
|
+
* ```json
|
|
392
|
+
* {
|
|
393
|
+
* "threshold": 7,
|
|
394
|
+
* "weights": {
|
|
395
|
+
* "insertion": 1,
|
|
396
|
+
* "deletion": 3,
|
|
397
|
+
* "substitution": 2,
|
|
398
|
+
* "transposition": 0
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
readonly distanceOptions: DamerauLevenshteinOptions;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Case style configuration for displaying route and flag names in documentation text.
|
|
407
|
+
* Each value has the following behavior:
|
|
408
|
+
* * `original` - Displays the original names unchanged.
|
|
409
|
+
* * `convert-camel-to-kebab` - Converts all camelCase names to kebab-case in output. Only allowed if `scannerCaseStyle` is set to `allow-kebab-for-camel`.
|
|
410
|
+
*/
|
|
411
|
+
type DisplayCaseStyle = "original" | "convert-camel-to-kebab";
|
|
412
|
+
/**
|
|
413
|
+
* Configuration for controlling the content of the printed documentation.
|
|
414
|
+
*/
|
|
415
|
+
interface DocumentationConfiguration {
|
|
416
|
+
/**
|
|
417
|
+
* In addition to the `--help` flag, there is a `--helpAll`/`--help-all` flag that shows all documentation
|
|
418
|
+
* including entries for hidden commands/arguments.
|
|
419
|
+
* The `--helpAll` flag cannot be functionally disabled, but it is hidden when listing the built-in flags by default.
|
|
420
|
+
* Setting this option to `true` forces the output to always include this flag in the list of built-in flags.
|
|
421
|
+
*
|
|
422
|
+
* Defaults to `false`.
|
|
423
|
+
*/
|
|
424
|
+
readonly alwaysShowHelpAllFlag: boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Controls whether or not to include alias of flags in the usage line.
|
|
427
|
+
* Only replaces name with alias when a single alias exists.
|
|
428
|
+
*
|
|
429
|
+
* Defaults to `false`.
|
|
430
|
+
*/
|
|
431
|
+
readonly useAliasInUsageLine: boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Controls whether or not to include optional flags and positional parameters in the usage line.
|
|
434
|
+
* If enabled, all parameters that are optional at runtime (including parameters with defaults) will be hidden.
|
|
435
|
+
*
|
|
436
|
+
* Defaults to `false`.
|
|
437
|
+
*/
|
|
438
|
+
readonly onlyRequiredInUsageLine: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Case style configuration for displaying route and flag names.
|
|
441
|
+
* Cannot be `convert-camel-to-kebab` if {@link ScannerConfiguration.caseStyle} is `original`.
|
|
442
|
+
*
|
|
443
|
+
* Default value is derived from value for {@link ScannerConfiguration.caseStyle}:
|
|
444
|
+
* * Defaults to `original` for `original`.
|
|
445
|
+
* * Defaults to `convert-camel-to-kebab` for `allow-kebab-for-camel`.
|
|
446
|
+
*/
|
|
447
|
+
readonly caseStyle: DisplayCaseStyle;
|
|
448
|
+
/**
|
|
449
|
+
* By default, if the color depth of the stdout stream is greater than 4, ANSI terminal colors will be used.
|
|
450
|
+
* If this value is `true`, disables all ANSI terminal color output.
|
|
451
|
+
*
|
|
452
|
+
* Defaults to `false`.
|
|
453
|
+
*/
|
|
454
|
+
readonly disableAnsiColor: boolean;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Configuration for controlling the behavior of completion proposals.
|
|
458
|
+
*/
|
|
459
|
+
interface CompletionConfiguration {
|
|
460
|
+
/**
|
|
461
|
+
* This flag controls whether or not to include aliases of routes and flags.
|
|
462
|
+
*
|
|
463
|
+
* Defaults to match value of {@link DocumentationConfiguration.useAliasInUsageLine}.
|
|
464
|
+
*/
|
|
465
|
+
readonly includeAliases: boolean;
|
|
466
|
+
/**
|
|
467
|
+
* This flag controls whether or not to include hidden routes.
|
|
468
|
+
*
|
|
469
|
+
* Defaults to `false`.
|
|
470
|
+
*/
|
|
471
|
+
readonly includeHiddenRoutes: boolean;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Configuration for controlling the localization behavior.
|
|
475
|
+
*/
|
|
476
|
+
interface LocalizationConfiguration {
|
|
477
|
+
/**
|
|
478
|
+
* The default locale that should be used if the context does not have a locale.
|
|
479
|
+
*
|
|
480
|
+
* If unspecified, will default to `en`.
|
|
481
|
+
*/
|
|
482
|
+
readonly defaultLocale: string;
|
|
483
|
+
/**
|
|
484
|
+
* Mapping of locale to application text.
|
|
485
|
+
* Locale is optionally provided at runtime by the context.
|
|
486
|
+
*
|
|
487
|
+
* If unspecified, will return the default English implementation {@link text_en} for all "en" locales.
|
|
488
|
+
*/
|
|
489
|
+
readonly loadText: (locale: string) => ApplicationText | undefined;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Configuration for controlling the runtime behavior of the application.
|
|
493
|
+
*/
|
|
494
|
+
interface ApplicationConfiguration {
|
|
495
|
+
/**
|
|
496
|
+
* Unique name for this application.
|
|
497
|
+
* It should match the command that is used to run the application.
|
|
498
|
+
*/
|
|
499
|
+
readonly name: string;
|
|
500
|
+
/**
|
|
501
|
+
* If supplied, application will be aware of version info at runtime.
|
|
502
|
+
*
|
|
503
|
+
* Before every run, the application will fetch the latest version and warn if it differs from the current version.
|
|
504
|
+
* As well, a new flag `--version` (with alias `-v`) will be available on the base route, which will print the current
|
|
505
|
+
* version to stdout.
|
|
506
|
+
*/
|
|
507
|
+
readonly versionInfo?: VersionInfo;
|
|
508
|
+
/**
|
|
509
|
+
* If supplied, customizes the command/argument scanning behavior of the application.
|
|
510
|
+
*
|
|
511
|
+
* See documentation of inner types for default values.
|
|
512
|
+
*/
|
|
513
|
+
readonly scanner: ScannerConfiguration;
|
|
514
|
+
/**
|
|
515
|
+
* If supplied, customizes the formatting of documentation lines in help text.
|
|
516
|
+
*
|
|
517
|
+
* See documentation of inner types for default values.
|
|
518
|
+
*/
|
|
519
|
+
readonly documentation: DocumentationConfiguration;
|
|
520
|
+
/**
|
|
521
|
+
* If supplied, customizes command completion proposal behavior.
|
|
522
|
+
*
|
|
523
|
+
* See documentation of inner types for default values.
|
|
524
|
+
*/
|
|
525
|
+
readonly completion: CompletionConfiguration;
|
|
526
|
+
/**
|
|
527
|
+
* If supplied, customizes text localization.
|
|
528
|
+
*
|
|
529
|
+
* See documentation of inner types for default values.
|
|
530
|
+
*/
|
|
531
|
+
readonly localization: LocalizationConfiguration;
|
|
532
|
+
/**
|
|
533
|
+
* In the case where a command function throws some value unexpectedly or safely returns an Error,
|
|
534
|
+
* this function will translate that into an exit code.
|
|
535
|
+
*
|
|
536
|
+
* If unspecified, the exit code will default to 1 when a command function throws some value.
|
|
537
|
+
*/
|
|
538
|
+
readonly determineExitCode?: (exc: unknown) => number;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Partial configuration for application, see individual description for behavior when each value is unspecified.
|
|
542
|
+
*/
|
|
543
|
+
type PartialApplicationConfiguration = Pick<ApplicationConfiguration, "name" | "versionInfo" | "determineExitCode"> & {
|
|
544
|
+
[K in "scanner" | "documentation" | "completion" | "localization"]?: Partial<ApplicationConfiguration[K]>;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Contextual information used to format the usage text for a route/command.
|
|
549
|
+
*/
|
|
550
|
+
interface UsageFormattingArguments {
|
|
551
|
+
readonly prefix: readonly string[];
|
|
552
|
+
readonly config: DocumentationConfiguration;
|
|
553
|
+
readonly ansiColor: boolean;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
interface BaseFlagParameter {
|
|
557
|
+
/**
|
|
558
|
+
* In-line documentation for this flag.
|
|
559
|
+
*/
|
|
560
|
+
readonly brief: string;
|
|
561
|
+
/**
|
|
562
|
+
* String that serves as placeholder for the value in the generated usage line. Defaults to "value".
|
|
563
|
+
*/
|
|
564
|
+
readonly placeholder?: string;
|
|
565
|
+
}
|
|
566
|
+
interface BaseBooleanFlagParameter extends BaseFlagParameter {
|
|
567
|
+
/**
|
|
568
|
+
* Indicates flag should be treated as a boolean.
|
|
569
|
+
*/
|
|
570
|
+
readonly kind: "boolean";
|
|
571
|
+
readonly optional?: boolean;
|
|
572
|
+
/**
|
|
573
|
+
* Default flag value if input is not provided at runtime.
|
|
574
|
+
*
|
|
575
|
+
* If no value is provided, boolean flags default to `false`.
|
|
576
|
+
*/
|
|
577
|
+
readonly default?: boolean;
|
|
578
|
+
}
|
|
579
|
+
type RequiredBooleanFlagParameter = BaseBooleanFlagParameter & {
|
|
580
|
+
/**
|
|
581
|
+
* Parameter is required and cannot be set as optional.
|
|
582
|
+
*/
|
|
583
|
+
readonly optional?: false;
|
|
584
|
+
} & ({
|
|
585
|
+
/**
|
|
586
|
+
* Parameter is required and cannot be set as hidden without a default value.
|
|
587
|
+
*/
|
|
588
|
+
readonly hidden?: false;
|
|
589
|
+
} | {
|
|
590
|
+
/**
|
|
591
|
+
* Default input value if one is not provided at runtime.
|
|
592
|
+
*/
|
|
593
|
+
readonly default: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
596
|
+
* Only available for runtime-optional parameters.
|
|
597
|
+
*/
|
|
598
|
+
readonly hidden: true;
|
|
599
|
+
});
|
|
600
|
+
interface OptionalBooleanFlagParameter extends BaseBooleanFlagParameter {
|
|
601
|
+
/**
|
|
602
|
+
* Parameter is optional and must be specified as such.
|
|
603
|
+
*/
|
|
604
|
+
readonly optional: true;
|
|
605
|
+
/**
|
|
606
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
607
|
+
* Only available for optional parameters.
|
|
608
|
+
*/
|
|
609
|
+
readonly hidden?: boolean;
|
|
610
|
+
/**
|
|
611
|
+
* Optional parameters should not have default values.
|
|
612
|
+
* This flag should be required if a value will always be provided.
|
|
613
|
+
*/
|
|
614
|
+
readonly default?: undefined;
|
|
615
|
+
}
|
|
616
|
+
type BooleanFlagParameter = RequiredBooleanFlagParameter | OptionalBooleanFlagParameter;
|
|
617
|
+
interface BaseCounterFlagParameter extends BaseFlagParameter {
|
|
618
|
+
/**
|
|
619
|
+
* Indicates flag should be treated as a counter.
|
|
620
|
+
*/
|
|
621
|
+
readonly kind: "counter";
|
|
622
|
+
readonly optional?: boolean;
|
|
623
|
+
}
|
|
624
|
+
interface RequiredCounterFlagParameter extends BaseCounterFlagParameter {
|
|
625
|
+
/**
|
|
626
|
+
* Parameter is required and cannot be set as optional.
|
|
627
|
+
*/
|
|
628
|
+
readonly optional?: false;
|
|
629
|
+
/**
|
|
630
|
+
* Parameter is required and cannot be set as hidden.
|
|
631
|
+
*/
|
|
632
|
+
readonly hidden?: false;
|
|
633
|
+
}
|
|
634
|
+
interface OptionalCounterFlagParameter extends BaseCounterFlagParameter {
|
|
635
|
+
/**
|
|
636
|
+
* Parameter is optional and must be specified as such.
|
|
637
|
+
*/
|
|
638
|
+
readonly optional: true;
|
|
639
|
+
/**
|
|
640
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
641
|
+
* Only available for optional parameters.
|
|
642
|
+
*/
|
|
643
|
+
readonly hidden?: boolean;
|
|
644
|
+
}
|
|
645
|
+
type CounterFlagParameter = RequiredCounterFlagParameter | OptionalCounterFlagParameter;
|
|
646
|
+
interface BaseEnumFlagParameter<T extends string> extends BaseFlagParameter {
|
|
647
|
+
/**
|
|
648
|
+
* Indicates flag should be treated as an enumeration of strings.
|
|
649
|
+
*/
|
|
650
|
+
readonly kind: "enum";
|
|
651
|
+
/**
|
|
652
|
+
* Array of all possible enumerations supported by this flag.
|
|
653
|
+
*/
|
|
654
|
+
readonly values: readonly T[];
|
|
655
|
+
/**
|
|
656
|
+
* Default input value if one is not provided at runtime.
|
|
657
|
+
*/
|
|
658
|
+
readonly default?: T;
|
|
659
|
+
readonly optional?: boolean;
|
|
660
|
+
readonly hidden?: boolean;
|
|
661
|
+
readonly variadic?: boolean;
|
|
662
|
+
}
|
|
663
|
+
interface RequiredEnumFlagParameter<T extends string> extends BaseEnumFlagParameter<T> {
|
|
664
|
+
/**
|
|
665
|
+
* Parameter is required and cannot be set as optional.
|
|
666
|
+
*/
|
|
667
|
+
readonly optional?: false;
|
|
668
|
+
/**
|
|
669
|
+
* Parameter is required and cannot be set as hidden.
|
|
670
|
+
*/
|
|
671
|
+
readonly hidden?: false;
|
|
672
|
+
/**
|
|
673
|
+
* Parameter does not extend array and cannot be set as variadic.
|
|
674
|
+
*/
|
|
675
|
+
readonly variadic?: false;
|
|
676
|
+
}
|
|
677
|
+
interface OptionalEnumFlagParameter<T extends string> extends BaseEnumFlagParameter<T> {
|
|
678
|
+
/**
|
|
679
|
+
* Parameter is optional and must be specified as such.
|
|
680
|
+
*/
|
|
681
|
+
readonly optional: true;
|
|
682
|
+
/**
|
|
683
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
684
|
+
* Only available for optional parameters.
|
|
685
|
+
*/
|
|
686
|
+
readonly hidden?: boolean;
|
|
687
|
+
/**
|
|
688
|
+
* Parameter does not extend array and cannot be set as variadic.
|
|
689
|
+
*/
|
|
690
|
+
readonly variadic?: false;
|
|
691
|
+
}
|
|
692
|
+
interface OptionalVariadicEnumFlagParameter<T extends string> extends BaseEnumFlagParameter<T> {
|
|
693
|
+
/**
|
|
694
|
+
* Default values are not supported for variadic parameters.
|
|
695
|
+
*/
|
|
696
|
+
readonly default?: undefined;
|
|
697
|
+
/**
|
|
698
|
+
* Optional variadic parameter will parse to an empty array if no arguments are found.
|
|
699
|
+
*/
|
|
700
|
+
readonly optional: true;
|
|
701
|
+
/**
|
|
702
|
+
* Parameter is required and cannot be set as hidden.
|
|
703
|
+
*/
|
|
704
|
+
readonly hidden?: false;
|
|
705
|
+
/**
|
|
706
|
+
* Parameter extends array and must be set as variadic.
|
|
707
|
+
*/
|
|
708
|
+
readonly variadic: true;
|
|
709
|
+
}
|
|
710
|
+
interface RequiredVariadicEnumFlagParameter<T extends string> extends BaseEnumFlagParameter<T> {
|
|
711
|
+
/**
|
|
712
|
+
* Default values are not supported for variadic parameters.
|
|
713
|
+
*/
|
|
714
|
+
readonly default?: undefined;
|
|
715
|
+
/**
|
|
716
|
+
* Parameter is required and cannot be set as optional.
|
|
717
|
+
* Expects at least one value to be satisfied.
|
|
718
|
+
*/
|
|
719
|
+
readonly optional?: false;
|
|
720
|
+
/**
|
|
721
|
+
* Parameter is required and cannot be set as hidden.
|
|
722
|
+
*/
|
|
723
|
+
readonly hidden?: false;
|
|
724
|
+
/**
|
|
725
|
+
* Parameter extends array and must be set as variadic.
|
|
726
|
+
*/
|
|
727
|
+
readonly variadic: true;
|
|
728
|
+
}
|
|
729
|
+
interface BaseParsedFlagParameter<T, CONTEXT extends CommandContext> extends ParsedParameter<T, CONTEXT>, BaseFlagParameter {
|
|
730
|
+
/**
|
|
731
|
+
* Indicates flag should be parsed with a specified input parser.
|
|
732
|
+
*/
|
|
733
|
+
readonly kind: "parsed";
|
|
734
|
+
/**
|
|
735
|
+
* Default input value if one is not provided at runtime.
|
|
736
|
+
*/
|
|
737
|
+
readonly default?: string;
|
|
738
|
+
/**
|
|
739
|
+
* If flag is specified with no corresponding input, infer an empty string `""` as the input.
|
|
740
|
+
*/
|
|
741
|
+
readonly inferEmpty?: boolean;
|
|
742
|
+
readonly optional?: boolean;
|
|
743
|
+
readonly variadic?: boolean;
|
|
744
|
+
readonly hidden?: boolean;
|
|
745
|
+
}
|
|
746
|
+
type RequiredParsedFlagParameter<T, CONTEXT extends CommandContext> = BaseParsedFlagParameter<T, CONTEXT> & {
|
|
747
|
+
/**
|
|
748
|
+
* Parameter is required and cannot be set as optional.
|
|
749
|
+
*/
|
|
750
|
+
readonly optional?: false;
|
|
751
|
+
/**
|
|
752
|
+
* Parameter does not extend array and cannot be set as variadic.
|
|
753
|
+
*/
|
|
754
|
+
readonly variadic?: false;
|
|
755
|
+
} & ({
|
|
756
|
+
/**
|
|
757
|
+
* Parameter is required and cannot be set as hidden without a default value.
|
|
758
|
+
*/
|
|
759
|
+
readonly hidden?: false;
|
|
760
|
+
} | {
|
|
761
|
+
/**
|
|
762
|
+
* Default input value if one is not provided at runtime.
|
|
763
|
+
*/
|
|
764
|
+
readonly default: string;
|
|
765
|
+
/**
|
|
766
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
767
|
+
* Only available for runtime-optional parameters.
|
|
768
|
+
*/
|
|
769
|
+
readonly hidden: true;
|
|
770
|
+
});
|
|
771
|
+
interface OptionalParsedFlagParameter<T, CONTEXT extends CommandContext> extends BaseParsedFlagParameter<T, CONTEXT> {
|
|
772
|
+
/**
|
|
773
|
+
* Parameter is optional and must be specified as such.
|
|
774
|
+
*/
|
|
775
|
+
readonly optional: true;
|
|
776
|
+
/**
|
|
777
|
+
* Optional parameters should not have default values.
|
|
778
|
+
* This flag should be required if a value will always be provided.
|
|
779
|
+
*/
|
|
780
|
+
readonly default?: undefined;
|
|
781
|
+
/**
|
|
782
|
+
* Parameter does not extend array and cannot be set as variadic.
|
|
783
|
+
*/
|
|
784
|
+
readonly variadic?: false;
|
|
785
|
+
/**
|
|
786
|
+
* Parameter should be hidden from all help text and proposed completions.
|
|
787
|
+
* Only available for runtime-optional parameters.
|
|
788
|
+
*/
|
|
789
|
+
readonly hidden?: boolean;
|
|
790
|
+
}
|
|
791
|
+
interface OptionalVariadicParsedFlagParameter<T, CONTEXT extends CommandContext> extends BaseParsedFlagParameter<T, CONTEXT> {
|
|
792
|
+
/**
|
|
793
|
+
* Variadic flags are always optional in that they will parse to an empty array if no arguments are found.
|
|
794
|
+
*/
|
|
795
|
+
readonly optional: true;
|
|
796
|
+
/**
|
|
797
|
+
* Parameter extends array and must be set as variadic.
|
|
798
|
+
*/
|
|
799
|
+
readonly variadic: true;
|
|
800
|
+
/**
|
|
801
|
+
* Default values are not supported for variadic parameters.
|
|
802
|
+
*/
|
|
803
|
+
readonly default?: undefined;
|
|
804
|
+
}
|
|
805
|
+
interface RequiredVariadicParsedFlagParameter<T, CONTEXT extends CommandContext> extends BaseParsedFlagParameter<T, CONTEXT> {
|
|
806
|
+
/**
|
|
807
|
+
* Parameter is required and cannot be set as optional.
|
|
808
|
+
* Expects at least one value to be satisfied.
|
|
809
|
+
*/
|
|
810
|
+
readonly optional?: false;
|
|
811
|
+
/**
|
|
812
|
+
* Parameter extends array and must be set as variadic.
|
|
813
|
+
*/
|
|
814
|
+
readonly variadic: true;
|
|
815
|
+
/**
|
|
816
|
+
* Default values are not supported for variadic parameters.
|
|
817
|
+
*/
|
|
818
|
+
readonly default?: undefined;
|
|
819
|
+
}
|
|
820
|
+
type TypedFlagParameter_Optional<T, CONTEXT extends CommandContext> = [T] extends [readonly (infer A)[]] ? [A] extends [string] ? OptionalVariadicParsedFlagParameter<A, CONTEXT> | OptionalVariadicEnumFlagParameter<A> : OptionalVariadicParsedFlagParameter<A, CONTEXT> : [T] extends [boolean] ? OptionalBooleanFlagParameter | OptionalParsedFlagParameter<boolean, CONTEXT> : [T] extends [number] ? OptionalCounterFlagParameter | OptionalParsedFlagParameter<number, CONTEXT> : string extends T ? OptionalParsedFlagParameter<string, CONTEXT> : [T] extends [string] ? OptionalEnumFlagParameter<T> | OptionalParsedFlagParameter<T, CONTEXT> : OptionalParsedFlagParameter<T, CONTEXT>;
|
|
821
|
+
type TypedFlagParameter_Required<T, CONTEXT extends CommandContext> = [T] extends [readonly (infer A)[]] ? [A] extends [string] ? RequiredVariadicParsedFlagParameter<A, CONTEXT> | RequiredVariadicEnumFlagParameter<A> : RequiredVariadicParsedFlagParameter<A, CONTEXT> : [T] extends [boolean] ? RequiredBooleanFlagParameter | RequiredParsedFlagParameter<boolean, CONTEXT> : [T] extends [number] ? RequiredCounterFlagParameter | RequiredParsedFlagParameter<number, CONTEXT> : string extends T ? RequiredParsedFlagParameter<string, CONTEXT> : [T] extends [string] ? RequiredEnumFlagParameter<T> | RequiredParsedFlagParameter<T, CONTEXT> : RequiredParsedFlagParameter<T, CONTEXT>;
|
|
822
|
+
/**
|
|
823
|
+
* Definition of a flag parameter that will eventually be parsed as a flag.
|
|
824
|
+
* Required properties may vary depending on the type argument `T`.
|
|
825
|
+
*/
|
|
826
|
+
type TypedFlagParameter<T, CONTEXT extends CommandContext = CommandContext> = undefined extends T ? TypedFlagParameter_Optional<NonNullable<T>, CONTEXT> : TypedFlagParameter_Required<T, CONTEXT>;
|
|
827
|
+
type FlagParameter<CONTEXT extends CommandContext> = BooleanFlagParameter | CounterFlagParameter | BaseEnumFlagParameter<string> | BaseParsedFlagParameter<unknown, CONTEXT>;
|
|
828
|
+
/**
|
|
829
|
+
* Definition of flags for each named parameter.
|
|
830
|
+
* Required properties may vary depending on the type argument `T`.
|
|
831
|
+
*/
|
|
832
|
+
type FlagParametersForType<T, CONTEXT extends CommandContext = CommandContext> = {
|
|
833
|
+
readonly [K in keyof T]: TypedFlagParameter<T[K], CONTEXT>;
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* Definition of flags for each named parameter.
|
|
837
|
+
* This is a separate version of {@link FlagParametersForType} without a type parameter and is primarily used internally
|
|
838
|
+
* and should only be used after the types are checked.
|
|
839
|
+
*/
|
|
840
|
+
type FlagParameters<CONTEXT extends CommandContext = CommandContext> = Record<string, FlagParameter<CONTEXT>>;
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Generic function that synchronously or asynchronously parses a string to an arbitrary type.
|
|
844
|
+
*/
|
|
845
|
+
type InputParser<T, CONTEXT extends CommandContext = CommandContext> = (this: CONTEXT, input: string) => T | Promise<T>;
|
|
846
|
+
interface ParsedParameter<T, CONTEXT extends CommandContext> {
|
|
847
|
+
/**
|
|
848
|
+
* Function to parse an input string to the type of this parameter.
|
|
849
|
+
*/
|
|
850
|
+
readonly parse: InputParser<T, CONTEXT>;
|
|
851
|
+
/**
|
|
852
|
+
* Propose possible completions for a partial input string.
|
|
853
|
+
*/
|
|
854
|
+
readonly proposeCompletions?: (this: CONTEXT, partial: string) => readonly string[] | Promise<readonly string[]>;
|
|
855
|
+
}
|
|
856
|
+
type LowercaseLetter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
857
|
+
type UppercaseLetter = Capitalize<LowercaseLetter>;
|
|
858
|
+
type ReservedAlias = "h";
|
|
859
|
+
type AvailableAlias = Exclude<LowercaseLetter | UppercaseLetter, ReservedAlias>;
|
|
860
|
+
type Aliases<T> = Readonly<Partial<Record<AvailableAlias, T>>>;
|
|
861
|
+
type BaseFlags = Readonly<Record<string, unknown>>;
|
|
862
|
+
interface TypedCommandFlagParameters<FLAGS extends BaseFlags, CONTEXT extends CommandContext> {
|
|
863
|
+
/**
|
|
864
|
+
* Typed definitions for all flag parameters.
|
|
865
|
+
*/
|
|
866
|
+
readonly flags: FlagParametersForType<FLAGS, CONTEXT>;
|
|
867
|
+
/**
|
|
868
|
+
* Object that aliases single characters to flag names.
|
|
869
|
+
*/
|
|
870
|
+
readonly aliases?: Aliases<keyof FLAGS & string>;
|
|
871
|
+
}
|
|
872
|
+
type TypedCommandFlagParameters_<FLAGS extends BaseFlags, CONTEXT extends CommandContext> = Record<string, never> extends FLAGS ? Partial<TypedCommandFlagParameters<FLAGS, CONTEXT>> : TypedCommandFlagParameters<FLAGS, CONTEXT>;
|
|
873
|
+
interface TypedCommandPositionalParameters<ARGS extends BaseArgs, CONTEXT extends CommandContext> {
|
|
874
|
+
/**
|
|
875
|
+
* Typed definitions for all positional parameters.
|
|
876
|
+
*/
|
|
877
|
+
readonly positional: TypedPositionalParameters<ARGS, CONTEXT>;
|
|
878
|
+
}
|
|
879
|
+
type TypedCommandPositionalParameters_<ARGS extends BaseArgs, CONTEXT extends CommandContext> = [] extends ARGS ? Partial<TypedCommandPositionalParameters<ARGS, CONTEXT>> : TypedCommandPositionalParameters<ARGS, CONTEXT>;
|
|
880
|
+
/**
|
|
881
|
+
* Definitions for all parameters requested by the corresponding command.
|
|
882
|
+
*/
|
|
883
|
+
type TypedCommandParameters<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = TypedCommandFlagParameters_<FLAGS, CONTEXT> & TypedCommandPositionalParameters_<ARGS, CONTEXT>;
|
|
884
|
+
/**
|
|
885
|
+
* Definitions for all parameters requested by the corresponding command.
|
|
886
|
+
* This is a separate version of {@link TypedCommandParameters} without a type parameter and is primarily used
|
|
887
|
+
* internally and should only be used after the types are checked.
|
|
888
|
+
*/
|
|
889
|
+
interface CommandParameters {
|
|
890
|
+
readonly flags?: FlagParameters;
|
|
891
|
+
readonly aliases?: Aliases<string>;
|
|
892
|
+
readonly positional?: PositionalParameters;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
interface BasePositionalParameter<T, CONTEXT extends CommandContext> extends ParsedParameter<T, CONTEXT> {
|
|
896
|
+
/**
|
|
897
|
+
* In-line documentation for this parameter.
|
|
898
|
+
*/
|
|
899
|
+
readonly brief: string;
|
|
900
|
+
/**
|
|
901
|
+
* String that serves as placeholder for the value in the generated usage line.
|
|
902
|
+
* Defaults to "argN" where N is the index of this parameter.
|
|
903
|
+
*/
|
|
904
|
+
readonly placeholder?: string;
|
|
905
|
+
/**
|
|
906
|
+
* Default input value if one is not provided at runtime.
|
|
907
|
+
*/
|
|
908
|
+
readonly default?: string;
|
|
909
|
+
readonly optional?: boolean;
|
|
910
|
+
}
|
|
911
|
+
interface RequiredPositionalParameter<T, CONTEXT extends CommandContext> extends BasePositionalParameter<T, CONTEXT> {
|
|
912
|
+
/**
|
|
913
|
+
* Parameter is required and cannot be set as optional.
|
|
914
|
+
*/
|
|
915
|
+
readonly optional?: false;
|
|
916
|
+
}
|
|
917
|
+
interface OptionalPositionalParameter<T, CONTEXT extends CommandContext> extends BasePositionalParameter<T, CONTEXT> {
|
|
918
|
+
/**
|
|
919
|
+
* Parameter is optional and must be specified as such.
|
|
920
|
+
*/
|
|
921
|
+
readonly optional: true;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Definition of a positional parameter that will eventually be parsed to an argument.
|
|
925
|
+
* Required properties may vary depending on the type argument `T`.
|
|
926
|
+
*/
|
|
927
|
+
type TypedPositionalParameter<T, CONTEXT extends CommandContext = CommandContext> = undefined extends T ? OptionalPositionalParameter<NonNullable<T>, CONTEXT> : RequiredPositionalParameter<T, CONTEXT>;
|
|
928
|
+
type PositionalParameter = BasePositionalParameter<unknown, CommandContext>;
|
|
929
|
+
interface PositionalParameterArray<T, CONTEXT extends CommandContext> {
|
|
930
|
+
readonly kind: "array";
|
|
931
|
+
readonly parameter: TypedPositionalParameter<T, CONTEXT>;
|
|
932
|
+
readonly minimum?: number;
|
|
933
|
+
readonly maximum?: number;
|
|
934
|
+
}
|
|
935
|
+
type PositionalParametersForTuple<T, CONTEXT extends CommandContext> = {
|
|
936
|
+
readonly [K in keyof T]: TypedPositionalParameter<T[K], CONTEXT>;
|
|
937
|
+
};
|
|
938
|
+
interface PositionalParameterTuple<T> {
|
|
939
|
+
readonly kind: "tuple";
|
|
940
|
+
readonly parameters: T;
|
|
941
|
+
}
|
|
942
|
+
type BaseArgs = readonly unknown[];
|
|
943
|
+
/**
|
|
944
|
+
* Definition of all positional parameters.
|
|
945
|
+
* Required properties may vary depending on the type argument `T`.
|
|
946
|
+
*/
|
|
947
|
+
type TypedPositionalParameters<T, CONTEXT extends CommandContext> = [T] extends [readonly (infer E)[]] ? number extends T["length"] ? PositionalParameterArray<E, CONTEXT> : PositionalParameterTuple<PositionalParametersForTuple<T, CONTEXT>> : PositionalParameterTuple<PositionalParametersForTuple<T, CONTEXT>>;
|
|
948
|
+
/**
|
|
949
|
+
* Definition of all positional parameters.
|
|
950
|
+
* This is a separate version of {@link TypedPositionalParameters} without a type parameter and is primarily used
|
|
951
|
+
* internally and should only be used after the types are checked.
|
|
952
|
+
*/
|
|
953
|
+
type PositionalParameters = PositionalParameterArray<unknown, CommandContext> | PositionalParameterTuple<readonly PositionalParameter[]>;
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* All command functions are required to have a general signature:
|
|
957
|
+
* ```ts
|
|
958
|
+
* (flags: {...}, ...args: [...]) => void | Promise<void>
|
|
959
|
+
* ```
|
|
960
|
+
* - `args` should be an array/tuple of any length or type.
|
|
961
|
+
* - `flags` should be an object with any key-value pairs.
|
|
962
|
+
*
|
|
963
|
+
* The specific types of `args` and `flags` are customizable to the individual use case
|
|
964
|
+
* and will be used to determine the structure of the positional arguments and flags.
|
|
965
|
+
*/
|
|
966
|
+
type CommandFunction<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = (this: CONTEXT, flags: FLAGS, ...args: ARGS) => void | Error | Promise<void | Error>;
|
|
967
|
+
/**
|
|
968
|
+
* A command module exposes the target function as the default export.
|
|
969
|
+
*/
|
|
970
|
+
interface CommandModule<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> {
|
|
971
|
+
readonly default: CommandFunction<FLAGS, ARGS, CONTEXT>;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Asynchronously loads a function or a module containing a function to be executed by a command.
|
|
975
|
+
*/
|
|
976
|
+
type CommandFunctionLoader<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = () => Promise<CommandModule<FLAGS, ARGS, CONTEXT> | CommandFunction<FLAGS, ARGS, CONTEXT>>;
|
|
977
|
+
declare const CommandSymbol: unique symbol;
|
|
978
|
+
/**
|
|
979
|
+
* Parsed and validated command instance.
|
|
980
|
+
*/
|
|
981
|
+
interface Command<CONTEXT extends CommandContext> extends DocumentedTarget {
|
|
982
|
+
readonly kind: typeof CommandSymbol;
|
|
983
|
+
readonly loader: CommandFunctionLoader<BaseFlags, BaseArgs, CONTEXT>;
|
|
984
|
+
readonly parameters: CommandParameters;
|
|
985
|
+
readonly usesFlag: (flagName: string) => boolean;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
declare const RouteMapSymbol: unique symbol;
|
|
989
|
+
interface RouteMapEntry<CONTEXT extends CommandContext> {
|
|
990
|
+
readonly name: Readonly<Record<DisplayCaseStyle, string>>;
|
|
991
|
+
readonly target: RoutingTarget<CONTEXT>;
|
|
992
|
+
readonly aliases: readonly string[];
|
|
993
|
+
readonly hidden: boolean;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Route map that stores multiple routes.
|
|
997
|
+
*/
|
|
998
|
+
interface RouteMap<CONTEXT extends CommandContext> extends DocumentedTarget {
|
|
999
|
+
readonly kind: typeof RouteMapSymbol;
|
|
1000
|
+
readonly getRoutingTargetForInput: (input: string) => RoutingTarget<CONTEXT> | undefined;
|
|
1001
|
+
readonly getDefaultCommand: () => Command<CONTEXT> | undefined;
|
|
1002
|
+
readonly getOtherAliasesForInput: (input: string, caseStyle: ScannerCaseStyle) => Readonly<Record<DisplayCaseStyle, readonly string[]>>;
|
|
1003
|
+
readonly getAllEntries: () => readonly RouteMapEntry<CONTEXT>[];
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
interface HelpFormattingArguments extends UsageFormattingArguments {
|
|
1007
|
+
readonly text: DocumentationText;
|
|
1008
|
+
readonly includeHelpAllFlag: boolean;
|
|
1009
|
+
readonly includeVersionFlag: boolean;
|
|
1010
|
+
readonly includeArgumentEscapeSequenceFlag: boolean;
|
|
1011
|
+
readonly includeHidden: boolean;
|
|
1012
|
+
readonly aliases?: readonly string[];
|
|
1013
|
+
}
|
|
1014
|
+
interface DocumentedTarget {
|
|
1015
|
+
readonly brief: string;
|
|
1016
|
+
readonly formatUsageLine: (args: UsageFormattingArguments) => string;
|
|
1017
|
+
readonly formatHelp: (args: HelpFormattingArguments) => string;
|
|
1018
|
+
}
|
|
1019
|
+
type RoutingTarget<CONTEXT extends CommandContext> = Command<CONTEXT> | RouteMap<CONTEXT>;
|
|
1020
|
+
interface RoutingTargetCompletion {
|
|
1021
|
+
readonly kind: "routing-target:command" | "routing-target:route-map";
|
|
1022
|
+
readonly completion: string;
|
|
1023
|
+
readonly brief: string;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Interface for top-level command line application.
|
|
1028
|
+
*/
|
|
1029
|
+
interface Application<CONTEXT extends CommandContext> {
|
|
1030
|
+
readonly root: RoutingTarget<CONTEXT>;
|
|
1031
|
+
readonly config: ApplicationConfiguration;
|
|
1032
|
+
readonly defaultText: ApplicationText;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Builds an application from a top-level route map and configuration.
|
|
1037
|
+
*/
|
|
1038
|
+
declare function buildApplication<CONTEXT extends CommandContext>(root: RouteMap<CONTEXT>, config: PartialApplicationConfiguration): Application<CONTEXT>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Builds an application with a single, top-level command and configuration.
|
|
1041
|
+
*/
|
|
1042
|
+
declare function buildApplication<CONTEXT extends CommandContext>(command: Command<CONTEXT>, appConfig: PartialApplicationConfiguration): Application<CONTEXT>;
|
|
1043
|
+
|
|
1044
|
+
type DocumentedCommand = readonly [route: string, helpText: string];
|
|
1045
|
+
/**
|
|
1046
|
+
* Generate help text in the given locale for each command in this application.
|
|
1047
|
+
* Return value is an array of tuples containing the route to that command and the help text.
|
|
1048
|
+
*
|
|
1049
|
+
* If no locale specified, uses the defaultLocale from the application configuration.
|
|
1050
|
+
*/
|
|
1051
|
+
declare function generateHelpTextForAllCommands({ root, defaultText, config }: Application<CommandContext>, locale?: string): readonly DocumentedCommand[];
|
|
1052
|
+
|
|
1053
|
+
declare class InternalError extends Error {
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Abstract class that all internal argument scanner errors extend from.
|
|
1058
|
+
*/
|
|
1059
|
+
declare abstract class ArgumentScannerError extends InternalError {
|
|
1060
|
+
private readonly _brand;
|
|
1061
|
+
}
|
|
1062
|
+
interface ArgumentScannerErrorType {
|
|
1063
|
+
readonly AliasNotFoundError: AliasNotFoundError;
|
|
1064
|
+
readonly ArgumentParseError: ArgumentParseError;
|
|
1065
|
+
readonly EnumValidationError: EnumValidationError;
|
|
1066
|
+
readonly FlagNotFoundError: FlagNotFoundError;
|
|
1067
|
+
readonly InvalidNegatedFlagSyntaxError: InvalidNegatedFlagSyntaxError;
|
|
1068
|
+
readonly UnexpectedFlagError: UnexpectedFlagError;
|
|
1069
|
+
readonly UnexpectedPositionalError: UnexpectedPositionalError;
|
|
1070
|
+
readonly UnsatisfiedFlagError: UnsatisfiedFlagError;
|
|
1071
|
+
readonly UnsatisfiedPositionalError: UnsatisfiedPositionalError;
|
|
1072
|
+
}
|
|
1073
|
+
type ArgumentScannerErrorFormatter = {
|
|
1074
|
+
readonly [T in keyof ArgumentScannerErrorType]: (error: ArgumentScannerErrorType[T]) => string;
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Utility method for customizing message of argument scanner error
|
|
1078
|
+
* @param error Error thrown by argument scanner
|
|
1079
|
+
* @param formatter For all keys specified, controls message formatting for that specific subtype of error
|
|
1080
|
+
*/
|
|
1081
|
+
declare function formatMessageForArgumentScannerError(error: ArgumentScannerError, formatter: Partial<ArgumentScannerErrorFormatter>): string;
|
|
1082
|
+
/**
|
|
1083
|
+
* Thrown when input suggests an flag, but no flag with that name was found.
|
|
1084
|
+
*/
|
|
1085
|
+
declare class FlagNotFoundError extends ArgumentScannerError {
|
|
1086
|
+
/**
|
|
1087
|
+
* Command line input that triggered this error.
|
|
1088
|
+
*/
|
|
1089
|
+
readonly input: string;
|
|
1090
|
+
/**
|
|
1091
|
+
* Set of proposed suggestions that are similar to the input.
|
|
1092
|
+
*/
|
|
1093
|
+
readonly corrections: readonly string[];
|
|
1094
|
+
/**
|
|
1095
|
+
* Set if error was caused indirectly by an alias.
|
|
1096
|
+
* This indicates that something is wrong with the command configuration itself.
|
|
1097
|
+
*/
|
|
1098
|
+
readonly aliasName?: string;
|
|
1099
|
+
constructor(input: string, corrections: readonly string[], aliasName?: string);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Thrown when input suggests an alias, but no alias with that letter was found.
|
|
1103
|
+
*/
|
|
1104
|
+
declare class AliasNotFoundError extends ArgumentScannerError {
|
|
1105
|
+
/**
|
|
1106
|
+
* Command line input that triggered this error.
|
|
1107
|
+
*/
|
|
1108
|
+
readonly input: string;
|
|
1109
|
+
constructor(input: string);
|
|
1110
|
+
}
|
|
1111
|
+
type Placeholder = string & {
|
|
1112
|
+
readonly __Placeholder: unique symbol;
|
|
1113
|
+
};
|
|
1114
|
+
type ExternalFlagName = string & {
|
|
1115
|
+
readonly __ExternalFlagName: unique symbol;
|
|
1116
|
+
};
|
|
1117
|
+
/**
|
|
1118
|
+
* Thrown when underlying parameter parser throws an exception parsing some input.
|
|
1119
|
+
*/
|
|
1120
|
+
declare class ArgumentParseError extends ArgumentScannerError {
|
|
1121
|
+
/**
|
|
1122
|
+
* External name of flag or placeholder for positional argument that was parsing this input.
|
|
1123
|
+
*/
|
|
1124
|
+
readonly externalFlagNameOrPlaceholder: string;
|
|
1125
|
+
/**
|
|
1126
|
+
* Command line input that triggered this error.
|
|
1127
|
+
*/
|
|
1128
|
+
readonly input: string;
|
|
1129
|
+
/**
|
|
1130
|
+
* Raw exception thrown from parse function.
|
|
1131
|
+
*/
|
|
1132
|
+
readonly exception: unknown;
|
|
1133
|
+
constructor(externalFlagNameOrPlaceholder: ExternalFlagName | Placeholder, input: string, exception: unknown);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Thrown when input fails to match the given values for an enum flag.
|
|
1137
|
+
*/
|
|
1138
|
+
declare class EnumValidationError extends ArgumentScannerError {
|
|
1139
|
+
/**
|
|
1140
|
+
* External name of flag that was parsing this input.
|
|
1141
|
+
*/
|
|
1142
|
+
readonly externalFlagName: string;
|
|
1143
|
+
/**
|
|
1144
|
+
* Command line input that triggered this error.
|
|
1145
|
+
*/
|
|
1146
|
+
readonly input: string;
|
|
1147
|
+
/**
|
|
1148
|
+
* All possible enum values.
|
|
1149
|
+
*/
|
|
1150
|
+
readonly values: readonly string[];
|
|
1151
|
+
constructor(externalFlagName: ExternalFlagName, input: string, values: readonly string[], corrections: readonly string[]);
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Thrown when flag was expecting input that was not provided.
|
|
1155
|
+
*/
|
|
1156
|
+
declare class UnsatisfiedFlagError extends ArgumentScannerError {
|
|
1157
|
+
/**
|
|
1158
|
+
* External name of flag that was active when this error was thrown.
|
|
1159
|
+
*/
|
|
1160
|
+
readonly externalFlagName: string;
|
|
1161
|
+
/**
|
|
1162
|
+
* External name of flag that interrupted the original flag.
|
|
1163
|
+
*/
|
|
1164
|
+
readonly nextFlagName?: string;
|
|
1165
|
+
constructor(externalFlagName: ExternalFlagName, nextFlagName?: ExternalFlagName);
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Thrown when too many positional arguments were encountered.
|
|
1169
|
+
*/
|
|
1170
|
+
declare class UnexpectedPositionalError extends ArgumentScannerError {
|
|
1171
|
+
/**
|
|
1172
|
+
* Expected (maximum) count of positional arguments.
|
|
1173
|
+
*/
|
|
1174
|
+
readonly expectedCount: number;
|
|
1175
|
+
/**
|
|
1176
|
+
* Command line input that triggered this error.
|
|
1177
|
+
*/
|
|
1178
|
+
readonly input: string;
|
|
1179
|
+
constructor(expectedCount: number, input: string);
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Thrown when positional parameter was expecting input that was not provided.
|
|
1183
|
+
*/
|
|
1184
|
+
declare class UnsatisfiedPositionalError extends ArgumentScannerError {
|
|
1185
|
+
/**
|
|
1186
|
+
* Placeholder for positional argument that was active when this error was thrown.
|
|
1187
|
+
*/
|
|
1188
|
+
readonly placeholder: string;
|
|
1189
|
+
/**
|
|
1190
|
+
* If specified, indicates the minimum number of arguments that are expected and the last argument count.
|
|
1191
|
+
*/
|
|
1192
|
+
readonly limit?: [minimum: number, count: number];
|
|
1193
|
+
constructor(placeholder: Placeholder, limit?: [minimum: number, count: number]);
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Thrown when a value is provided for a negated flag.
|
|
1197
|
+
*/
|
|
1198
|
+
declare class InvalidNegatedFlagSyntaxError extends ArgumentScannerError {
|
|
1199
|
+
/**
|
|
1200
|
+
* External name of flag that was active when this error was thrown.
|
|
1201
|
+
*/
|
|
1202
|
+
readonly externalFlagName: string;
|
|
1203
|
+
/**
|
|
1204
|
+
* Input text equivalent to right hand side of input
|
|
1205
|
+
*/
|
|
1206
|
+
readonly valueText: string;
|
|
1207
|
+
constructor(externalFlagName: ExternalFlagName, valueText: string);
|
|
1208
|
+
}
|
|
1209
|
+
interface ArgumentCompletion {
|
|
1210
|
+
readonly kind: "argument:flag" | "argument:value";
|
|
1211
|
+
readonly completion: string;
|
|
1212
|
+
readonly brief: string;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Thrown when single-valued flag encounters more than one value.
|
|
1216
|
+
*/
|
|
1217
|
+
declare class UnexpectedFlagError extends ArgumentScannerError {
|
|
1218
|
+
/**
|
|
1219
|
+
* External name of flag that was parsing this input.
|
|
1220
|
+
*/
|
|
1221
|
+
readonly externalFlagName: string;
|
|
1222
|
+
/**
|
|
1223
|
+
* Command line input that was previously encountered by this flag.
|
|
1224
|
+
*/
|
|
1225
|
+
readonly previousInput: string;
|
|
1226
|
+
/**
|
|
1227
|
+
* Command line input that triggered this error.
|
|
1228
|
+
*/
|
|
1229
|
+
readonly input: string;
|
|
1230
|
+
constructor(externalFlagName: ExternalFlagName, previousInput: string, input: string);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
type InputCompletion = ArgumentCompletion | RoutingTargetCompletion;
|
|
1234
|
+
/**
|
|
1235
|
+
* Propose possible completions for a partial input string.
|
|
1236
|
+
*/
|
|
1237
|
+
declare function proposeCompletionsForApplication<CONTEXT extends CommandContext>({ root, config, defaultText }: Application<CONTEXT>, rawInputs: readonly string[], context: StricliDynamicCommandContext<CONTEXT>): Promise<readonly InputCompletion[]>;
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* Enumeration of all possible exit codes returned by an application.
|
|
1241
|
+
*/
|
|
1242
|
+
declare const ExitCode: {
|
|
1243
|
+
/**
|
|
1244
|
+
* Unable to find a command in the application with the given command line arguments.
|
|
1245
|
+
*/
|
|
1246
|
+
readonly UnknownCommand: -5;
|
|
1247
|
+
/**
|
|
1248
|
+
* Unable to parse the specified arguments.
|
|
1249
|
+
*/
|
|
1250
|
+
readonly InvalidArgument: -4;
|
|
1251
|
+
/**
|
|
1252
|
+
* An error was thrown while loading the context for a command run.
|
|
1253
|
+
*/
|
|
1254
|
+
readonly ContextLoadError: -3;
|
|
1255
|
+
/**
|
|
1256
|
+
* Failed to load command module.
|
|
1257
|
+
*/
|
|
1258
|
+
readonly CommandLoadError: -2;
|
|
1259
|
+
/**
|
|
1260
|
+
* An unexpected error was thrown by or not caught by this library.
|
|
1261
|
+
*/
|
|
1262
|
+
readonly InternalError: -1;
|
|
1263
|
+
/**
|
|
1264
|
+
* Command executed successfully.
|
|
1265
|
+
*/
|
|
1266
|
+
readonly Success: 0;
|
|
1267
|
+
/**
|
|
1268
|
+
* Command module unexpectedly threw an error.
|
|
1269
|
+
*/
|
|
1270
|
+
readonly CommandRunError: 1;
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* Parses input strings as booleans.
|
|
1275
|
+
* Transforms to lowercase and then checks against "true" and "false".
|
|
1276
|
+
*/
|
|
1277
|
+
declare const booleanParser: (input: string) => boolean;
|
|
1278
|
+
/**
|
|
1279
|
+
* Parses input strings as booleans (loosely).
|
|
1280
|
+
* Transforms to lowercase and then checks against "true", "false", "yes", "y", "no", and "n".
|
|
1281
|
+
*/
|
|
1282
|
+
declare const looseBooleanParser: (input: string) => boolean;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Creates an input parser that checks if the input string is found in a list of choices.
|
|
1286
|
+
*/
|
|
1287
|
+
declare function buildChoiceParser<T extends string>(choices: readonly T[]): InputParser<T>;
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Parses input strings as numbers.
|
|
1291
|
+
*/
|
|
1292
|
+
declare const numberParser: (input: string) => number;
|
|
1293
|
+
|
|
1294
|
+
interface CommandDocumentation {
|
|
1295
|
+
/**
|
|
1296
|
+
* In-line documentation for this command.
|
|
1297
|
+
*/
|
|
1298
|
+
readonly brief: string;
|
|
1299
|
+
/**
|
|
1300
|
+
* Longer description of this command's behavior, only printed during `--help`.
|
|
1301
|
+
*/
|
|
1302
|
+
readonly fullDescription?: string;
|
|
1303
|
+
/**
|
|
1304
|
+
* Sample usage to replace the generated usage lines.
|
|
1305
|
+
*/
|
|
1306
|
+
readonly customUsage?: readonly string[];
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
type BaseCommandBuilderArguments<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = {
|
|
1310
|
+
/**
|
|
1311
|
+
* Definitions for all parameters requested by the corresponding command.
|
|
1312
|
+
*/
|
|
1313
|
+
readonly parameters: NoInfer<TypedCommandParameters<FLAGS, ARGS, CONTEXT>>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Help documentation for command.
|
|
1316
|
+
*/
|
|
1317
|
+
readonly docs: CommandDocumentation;
|
|
1318
|
+
};
|
|
1319
|
+
type LazyCommandBuilderArguments<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = {
|
|
1320
|
+
/**
|
|
1321
|
+
* Asynchronously loads a module containing the action to be executed by a command.
|
|
1322
|
+
*/
|
|
1323
|
+
readonly loader: CommandFunctionLoader<FLAGS, ARGS, CONTEXT>;
|
|
1324
|
+
} & NoInfer<BaseCommandBuilderArguments<FLAGS, ARGS, CONTEXT>>;
|
|
1325
|
+
type LocalCommandBuilderArguments<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = {
|
|
1326
|
+
/**
|
|
1327
|
+
* The action to be executed by a command.
|
|
1328
|
+
*/
|
|
1329
|
+
readonly func: CommandFunction<FLAGS, ARGS, CONTEXT>;
|
|
1330
|
+
} & NoInfer<BaseCommandBuilderArguments<FLAGS, ARGS, CONTEXT>>;
|
|
1331
|
+
type CommandBuilderArguments<FLAGS extends BaseFlags, ARGS extends BaseArgs, CONTEXT extends CommandContext> = LazyCommandBuilderArguments<FLAGS, ARGS, CONTEXT> | LocalCommandBuilderArguments<FLAGS, ARGS, CONTEXT>;
|
|
1332
|
+
/**
|
|
1333
|
+
* Build command from loader or local function as action with associated parameters and documentation.
|
|
1334
|
+
*/
|
|
1335
|
+
declare function buildCommand<const FLAGS extends Readonly<Partial<Record<keyof FLAGS, unknown>>>, const ARGS extends BaseArgs, const CONTEXT extends CommandContext = CommandContext>(builderArgs: CommandBuilderArguments<FLAGS, ARGS, CONTEXT>): Command<CONTEXT>;
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Help documentation for route map.
|
|
1339
|
+
*/
|
|
1340
|
+
interface RouteMapDocumentation<R extends string> {
|
|
1341
|
+
/**
|
|
1342
|
+
* In-line documentation for this route map.
|
|
1343
|
+
*/
|
|
1344
|
+
readonly brief: string;
|
|
1345
|
+
/**
|
|
1346
|
+
* Longer description of this route map's behavior, only printed during `--help`.
|
|
1347
|
+
*/
|
|
1348
|
+
readonly fullDescription?: string;
|
|
1349
|
+
/**
|
|
1350
|
+
* Each route name with value `true` will be hidden from all documentation.
|
|
1351
|
+
*/
|
|
1352
|
+
readonly hideRoute?: Readonly<Partial<Record<R, boolean>>>;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
type RouteMapRoutes<R extends string, CONTEXT extends CommandContext> = Readonly<Record<R, RoutingTarget<CONTEXT>>>;
|
|
1356
|
+
type RouteMapAliases<R extends string> = Readonly<Record<Exclude<string, R>, R>>;
|
|
1357
|
+
interface RouteMapBuilderArguments<R extends string, CONTEXT extends CommandContext> {
|
|
1358
|
+
/**
|
|
1359
|
+
* Mapping of names to routing targets (commands or other route maps).
|
|
1360
|
+
* Must contain at least one route to be a valid route map.
|
|
1361
|
+
*/
|
|
1362
|
+
readonly routes: RouteMapRoutes<R, CONTEXT>;
|
|
1363
|
+
/**
|
|
1364
|
+
* When the command line inputs navigate directly to a route map, the default behavior is to print the help text.
|
|
1365
|
+
*
|
|
1366
|
+
* If this value is present, the command at the specified route will be run instead.
|
|
1367
|
+
* This means that otherwise invalid routes will not throw an error and will be considered as arguments/flags to that command.
|
|
1368
|
+
*
|
|
1369
|
+
* The type checking for this property requires it must be a valid route, but it does not type check that this route points to a command.
|
|
1370
|
+
* If this value is a route for a route map instead of a command, that is invalid and `buildRouteMap` will throw an error.
|
|
1371
|
+
*/
|
|
1372
|
+
readonly defaultCommand?: NoInfer<R>;
|
|
1373
|
+
/**
|
|
1374
|
+
* Help documentation for route map.
|
|
1375
|
+
*/
|
|
1376
|
+
readonly docs: RouteMapDocumentation<R>;
|
|
1377
|
+
/**
|
|
1378
|
+
* If specified, aliases can be used instead of the original route name to resolve to a given route.
|
|
1379
|
+
*/
|
|
1380
|
+
readonly aliases?: RouteMapAliases<R>;
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Build route map from name-route mapping with documentation.
|
|
1384
|
+
*/
|
|
1385
|
+
declare function buildRouteMap<R extends string, CONTEXT extends CommandContext = CommandContext>({ routes, defaultCommand: defaultCommandRoute, docs, aliases, }: RouteMapBuilderArguments<R, CONTEXT>): RouteMap<CONTEXT>;
|
|
1386
|
+
|
|
1387
|
+
declare function run<CONTEXT extends CommandContext>(app: Application<CONTEXT>, inputs: readonly string[], context: StricliDynamicCommandContext<CONTEXT>): Promise<void>;
|
|
1388
|
+
|
|
1389
|
+
export { AliasNotFoundError, type Application, type ApplicationConfiguration, type ApplicationContext, type ApplicationErrorFormatting, type ApplicationText, ArgumentParseError, ArgumentScannerError, type Command, type CommandBuilderArguments, type CommandContext, type CommandInfo, type CompletionConfiguration, type DisplayCaseStyle, type DocumentationBriefs, type DocumentationConfiguration, type DocumentationHeaders, type DocumentationKeywords, type DocumentedCommand, EnumValidationError, type EnvironmentVariableName, ExitCode, FlagNotFoundError, type FlagParametersForType, type InputCompletion, type InputParser, InvalidNegatedFlagSyntaxError, type PartialApplicationConfiguration, type RouteMap, type RouteMapBuilderArguments, type ScannerCaseStyle, type ScannerConfiguration, type StricliCommandContextBuilder, type StricliDynamicCommandContext, type StricliProcess, type TypedCommandParameters, type TypedFlagParameter, type TypedPositionalParameter, type TypedPositionalParameters, UnexpectedFlagError, UnexpectedPositionalError, UnsatisfiedFlagError, UnsatisfiedPositionalError, type VersionInfo, booleanParser, buildApplication, buildChoiceParser, buildCommand, buildRouteMap, formatMessageForArgumentScannerError, generateHelpTextForAllCommands, looseBooleanParser, numberParser, proposeCompletionsForApplication as proposeCompletions, run, text_en };
|