@rushstack/ts-command-line 4.9.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.
Files changed (91) hide show
  1. package/CHANGELOG.json +1329 -0
  2. package/CHANGELOG.md +704 -0
  3. package/LICENSE +24 -0
  4. package/README.md +251 -0
  5. package/dist/ts-command-line.d.ts +878 -0
  6. package/dist/tsdoc-metadata.json +11 -0
  7. package/lib/CommandLineHelper.d.ts +14 -0
  8. package/lib/CommandLineHelper.d.ts.map +1 -0
  9. package/lib/CommandLineHelper.js +22 -0
  10. package/lib/CommandLineHelper.js.map +1 -0
  11. package/lib/Constants.d.ts +12 -0
  12. package/lib/Constants.d.ts.map +1 -0
  13. package/lib/Constants.js +5 -0
  14. package/lib/Constants.js.map +1 -0
  15. package/lib/index.d.ts +23 -0
  16. package/lib/index.d.ts.map +1 -0
  17. package/lib/index.js +42 -0
  18. package/lib/index.js.map +1 -0
  19. package/lib/parameters/BaseClasses.d.ts +100 -0
  20. package/lib/parameters/BaseClasses.d.ts.map +1 -0
  21. package/lib/parameters/BaseClasses.js +148 -0
  22. package/lib/parameters/BaseClasses.js.map +1 -0
  23. package/lib/parameters/CommandLineChoiceListParameter.d.ts +33 -0
  24. package/lib/parameters/CommandLineChoiceListParameter.d.ts.map +1 -0
  25. package/lib/parameters/CommandLineChoiceListParameter.js +84 -0
  26. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -0
  27. package/lib/parameters/CommandLineChoiceParameter.d.ts +40 -0
  28. package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -0
  29. package/lib/parameters/CommandLineChoiceParameter.js +95 -0
  30. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -0
  31. package/lib/parameters/CommandLineDefinition.d.ts +207 -0
  32. package/lib/parameters/CommandLineDefinition.d.ts.map +1 -0
  33. package/lib/parameters/CommandLineDefinition.js +5 -0
  34. package/lib/parameters/CommandLineDefinition.js.map +1 -0
  35. package/lib/parameters/CommandLineFlagParameter.d.ts +29 -0
  36. package/lib/parameters/CommandLineFlagParameter.d.ts.map +1 -0
  37. package/lib/parameters/CommandLineFlagParameter.js +72 -0
  38. package/lib/parameters/CommandLineFlagParameter.js.map +1 -0
  39. package/lib/parameters/CommandLineIntegerListParameter.d.ts +29 -0
  40. package/lib/parameters/CommandLineIntegerListParameter.d.ts.map +1 -0
  41. package/lib/parameters/CommandLineIntegerListParameter.js +82 -0
  42. package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -0
  43. package/lib/parameters/CommandLineIntegerParameter.d.ts +36 -0
  44. package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -0
  45. package/lib/parameters/CommandLineIntegerParameter.js +86 -0
  46. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -0
  47. package/lib/parameters/CommandLineRemainder.d.ts +28 -0
  48. package/lib/parameters/CommandLineRemainder.d.ts.map +1 -0
  49. package/lib/parameters/CommandLineRemainder.js +48 -0
  50. package/lib/parameters/CommandLineRemainder.js.map +1 -0
  51. package/lib/parameters/CommandLineStringListParameter.d.ts +29 -0
  52. package/lib/parameters/CommandLineStringListParameter.d.ts.map +1 -0
  53. package/lib/parameters/CommandLineStringListParameter.js +73 -0
  54. package/lib/parameters/CommandLineStringListParameter.js.map +1 -0
  55. package/lib/parameters/CommandLineStringParameter.d.ts +36 -0
  56. package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -0
  57. package/lib/parameters/CommandLineStringParameter.js +85 -0
  58. package/lib/parameters/CommandLineStringParameter.js.map +1 -0
  59. package/lib/parameters/EnvironmentVariableParser.d.ts +10 -0
  60. package/lib/parameters/EnvironmentVariableParser.d.ts.map +1 -0
  61. package/lib/parameters/EnvironmentVariableParser.js +51 -0
  62. package/lib/parameters/EnvironmentVariableParser.js.map +1 -0
  63. package/lib/providers/CommandLineAction.d.ts +76 -0
  64. package/lib/providers/CommandLineAction.d.ts.map +1 -0
  65. package/lib/providers/CommandLineAction.js +73 -0
  66. package/lib/providers/CommandLineAction.js.map +1 -0
  67. package/lib/providers/CommandLineParameterProvider.d.ts +202 -0
  68. package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -0
  69. package/lib/providers/CommandLineParameterProvider.js +374 -0
  70. package/lib/providers/CommandLineParameterProvider.js.map +1 -0
  71. package/lib/providers/CommandLineParser.d.ts +100 -0
  72. package/lib/providers/CommandLineParser.d.ts.map +1 -0
  73. package/lib/providers/CommandLineParser.js +204 -0
  74. package/lib/providers/CommandLineParser.js.map +1 -0
  75. package/lib/providers/CommandLineParserExitError.d.ts +10 -0
  76. package/lib/providers/CommandLineParserExitError.d.ts.map +1 -0
  77. package/lib/providers/CommandLineParserExitError.js +53 -0
  78. package/lib/providers/CommandLineParserExitError.js.map +1 -0
  79. package/lib/providers/DynamicCommandLineAction.d.ts +9 -0
  80. package/lib/providers/DynamicCommandLineAction.d.ts.map +1 -0
  81. package/lib/providers/DynamicCommandLineAction.js +21 -0
  82. package/lib/providers/DynamicCommandLineAction.js.map +1 -0
  83. package/lib/providers/DynamicCommandLineParser.d.ts +8 -0
  84. package/lib/providers/DynamicCommandLineParser.d.ts.map +1 -0
  85. package/lib/providers/DynamicCommandLineParser.js +16 -0
  86. package/lib/providers/DynamicCommandLineParser.js.map +1 -0
  87. package/lib/providers/TabCompletionAction.d.ts +18 -0
  88. package/lib/providers/TabCompletionAction.d.ts.map +1 -0
  89. package/lib/providers/TabCompletionAction.js +211 -0
  90. package/lib/providers/TabCompletionAction.js.map +1 -0
  91. package/package.json +28 -0
@@ -0,0 +1,878 @@
1
+ /**
2
+ * An object-oriented command-line parser for TypeScript projects.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import * as argparse from 'argparse';
8
+
9
+ /**
10
+ * Represents a sub-command that is part of the CommandLineParser command line.
11
+ * Applications should create subclasses of CommandLineAction corresponding to
12
+ * each action that they want to expose.
13
+ *
14
+ * The action name should be comprised of lower case words separated by hyphens
15
+ * or colons. The name should include an English verb (e.g. "deploy"). Use a
16
+ * hyphen to separate words (e.g. "upload-docs"). A group of related commands
17
+ * can be prefixed with a colon (e.g. "docs:generate", "docs:deploy",
18
+ * "docs:serve", etc).
19
+ *
20
+ * @public
21
+ */
22
+ export declare abstract class CommandLineAction extends CommandLineParameterProvider {
23
+ private static _actionNameRegExp;
24
+ /** {@inheritDoc ICommandLineActionOptions.actionName} */
25
+ readonly actionName: string;
26
+ /** {@inheritDoc ICommandLineActionOptions.summary} */
27
+ readonly summary: string;
28
+ /** {@inheritDoc ICommandLineActionOptions.documentation} */
29
+ readonly documentation: string;
30
+ private _argumentParser;
31
+ constructor(options: ICommandLineActionOptions);
32
+ /* Excluded from this release type: _buildParser */
33
+ /* Excluded from this release type: _processParsedData */
34
+ /* Excluded from this release type: _execute */
35
+ /* Excluded from this release type: _getArgumentParser */
36
+ /**
37
+ * {@inheritDoc CommandLineParameterProvider.onDefineParameters}
38
+ */
39
+ protected abstract onDefineParameters(): void;
40
+ /**
41
+ * Your subclass should implement this hook to perform the operation.
42
+ */
43
+ protected abstract onExecute(): Promise<void>;
44
+ }
45
+
46
+ /**
47
+ * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
48
+ * @public
49
+ */
50
+ export declare class CommandLineChoiceListParameter extends CommandLineParameter {
51
+ /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */
52
+ readonly alternatives: ReadonlyArray<string>;
53
+ private _values;
54
+ /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */
55
+ readonly completions: (() => Promise<string[]>) | undefined;
56
+ /* Excluded from this release type: __constructor */
57
+ /** {@inheritDoc CommandLineParameter.kind} */
58
+ get kind(): CommandLineParameterKind;
59
+ /* Excluded from this release type: _setValue */
60
+ /**
61
+ * Returns the string arguments for a choice list parameter that was parsed from the command line.
62
+ *
63
+ * @remarks
64
+ * The array will be empty if the command-line has not been parsed yet,
65
+ * or if the parameter was omitted and has no default value.
66
+ */
67
+ get values(): ReadonlyArray<string>;
68
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
69
+ appendToArgList(argList: string[]): void;
70
+ }
71
+
72
+ /**
73
+ * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
74
+ * @public
75
+ */
76
+ export declare class CommandLineChoiceParameter extends CommandLineParameter {
77
+ /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */
78
+ readonly alternatives: ReadonlyArray<string>;
79
+ /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
80
+ readonly defaultValue: string | undefined;
81
+ private _value;
82
+ /** {@inheritDoc ICommandLineChoiceDefinition.completions} */
83
+ readonly completions: (() => Promise<string[]>) | undefined;
84
+ /* Excluded from this release type: __constructor */
85
+ /** {@inheritDoc CommandLineParameter.kind} */
86
+ get kind(): CommandLineParameterKind;
87
+ /* Excluded from this release type: _setValue */
88
+ /* Excluded from this release type: _getSupplementaryNotes */
89
+ /**
90
+ * Returns the argument value for a choice parameter that was parsed from the command line.
91
+ *
92
+ * @remarks
93
+ * The return value will be `undefined` if the command-line has not been parsed yet,
94
+ * or if the parameter was omitted and has no default value.
95
+ */
96
+ get value(): string | undefined;
97
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
98
+ appendToArgList(argList: string[]): void;
99
+ }
100
+
101
+ /**
102
+ * String constants for command line processing.
103
+ *
104
+ * @public
105
+ */
106
+ export declare const enum CommandLineConstants {
107
+ /**
108
+ * The name of the built-in action that serves suggestions for tab-completion
109
+ */
110
+ TabCompletionActionName = "tab-complete"
111
+ }
112
+
113
+ /**
114
+ * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
115
+ * @public
116
+ */
117
+ export declare class CommandLineFlagParameter extends CommandLineParameter {
118
+ private _value;
119
+ /* Excluded from this release type: __constructor */
120
+ /** {@inheritDoc CommandLineParameter.kind} */
121
+ get kind(): CommandLineParameterKind;
122
+ /* Excluded from this release type: _setValue */
123
+ /**
124
+ * Returns a boolean indicating whether the parameter was included in the command line.
125
+ *
126
+ * @remarks
127
+ * The return value will be false if the command-line has not been parsed yet,
128
+ * or if the flag was not used.
129
+ */
130
+ get value(): boolean;
131
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
132
+ appendToArgList(argList: string[]): void;
133
+ }
134
+
135
+ /**
136
+ * Helpers for working with the ts-command-line API.
137
+ *
138
+ * @public
139
+ */
140
+ export declare class CommandLineHelper {
141
+ /**
142
+ * Returns true if the current command line action is tab-complete.
143
+ *
144
+ * @public
145
+ */
146
+ static isTabCompletionActionRequest(argv: string[]): boolean;
147
+ }
148
+
149
+ /**
150
+ * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
151
+ * @public
152
+ */
153
+ export declare class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {
154
+ private _values;
155
+ /* Excluded from this release type: __constructor */
156
+ /** {@inheritDoc CommandLineParameter.kind} */
157
+ get kind(): CommandLineParameterKind;
158
+ /* Excluded from this release type: _setValue */
159
+ /**
160
+ * Returns the integer arguments for an integer list parameter that was parsed from the command line.
161
+ *
162
+ * @remarks
163
+ * The array will be empty if the command-line has not been parsed yet,
164
+ * or if the parameter was omitted and has no default value.
165
+ */
166
+ get values(): ReadonlyArray<number>;
167
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
168
+ appendToArgList(argList: string[]): void;
169
+ }
170
+
171
+ /**
172
+ * The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.
173
+ * @public
174
+ */
175
+ export declare class CommandLineIntegerParameter extends CommandLineParameterWithArgument {
176
+ /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
177
+ readonly defaultValue: number | undefined;
178
+ private _value;
179
+ /* Excluded from this release type: __constructor */
180
+ /** {@inheritDoc CommandLineParameter.kind} */
181
+ get kind(): CommandLineParameterKind;
182
+ /* Excluded from this release type: _setValue */
183
+ /* Excluded from this release type: _getSupplementaryNotes */
184
+ /**
185
+ * Returns the argument value for an integer parameter that was parsed from the command line.
186
+ *
187
+ * @remarks
188
+ * The return value will be undefined if the command-line has not been parsed yet,
189
+ * or if the parameter was omitted and has no default value.
190
+ */
191
+ get value(): number | undefined;
192
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
193
+ appendToArgList(argList: string[]): void;
194
+ }
195
+
196
+ /**
197
+ * The base class for the various command-line parameter types.
198
+ * @public
199
+ */
200
+ export declare abstract class CommandLineParameter {
201
+ private static _longNameRegExp;
202
+ private static _shortNameRegExp;
203
+ private static _environmentVariableRegExp;
204
+ /* Excluded from this release type: _parserKey */
205
+ /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
206
+ readonly longName: string;
207
+ /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
208
+ readonly shortName: string | undefined;
209
+ /** {@inheritDoc IBaseCommandLineDefinition.description} */
210
+ readonly description: string;
211
+ /** {@inheritDoc IBaseCommandLineDefinition.required} */
212
+ readonly required: boolean;
213
+ /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */
214
+ readonly environmentVariable: string | undefined;
215
+ /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */
216
+ readonly undocumentedSynonyms: string[] | undefined;
217
+ /* Excluded from this release type: __constructor */
218
+ /* Excluded from this release type: _setValue */
219
+ /* Excluded from this release type: _getSupplementaryNotes */
220
+ /**
221
+ * Indicates the type of parameter.
222
+ */
223
+ abstract get kind(): CommandLineParameterKind;
224
+ /**
225
+ * Append the parsed values to the provided string array.
226
+ * @remarks
227
+ * Sometimes a command line parameter is not used directly, but instead gets passed through to another
228
+ * tool that will use it. For example if our parameter comes in as "--max-count 3", then we might want to
229
+ * call `child_process.spawn()` and append ["--max-count", "3"] to the args array for that tool.
230
+ * appendToArgList() appends zero or more strings to the provided array, based on the input command-line
231
+ * that we parsed.
232
+ *
233
+ * If the parameter was omitted from our command-line and has no default value, then
234
+ * nothing will be appended. If the short name was used, the long name will be appended instead.
235
+ * @param argList - the parsed strings will be appended to this string array
236
+ */
237
+ abstract appendToArgList(argList: string[]): void;
238
+ /**
239
+ * Internal usage only. Used to report unexpected output from the argparse library.
240
+ */
241
+ protected reportInvalidData(data: any): never;
242
+ protected validateDefaultValue(hasDefaultValue: boolean): void;
243
+ }
244
+
245
+ /**
246
+ * Identifies the kind of a CommandLineParameter.
247
+ * @public
248
+ */
249
+ export declare enum CommandLineParameterKind {
250
+ /** Indicates a CommandLineChoiceParameter */
251
+ Choice = 0,
252
+ /** Indicates a CommandLineFlagParameter */
253
+ Flag = 1,
254
+ /** Indicates a CommandLineIntegerParameter */
255
+ Integer = 2,
256
+ /** Indicates a CommandLineStringParameter */
257
+ String = 3,
258
+ /** Indicates a CommandLineStringListParameter */
259
+ StringList = 4,
260
+ /** Indicates a CommandLineChoiceListParameter */
261
+ ChoiceList = 5,
262
+ /** Indicates a CommandLineIntegerListParameter */
263
+ IntegerList = 6
264
+ }
265
+
266
+ /**
267
+ * This is the common base class for CommandLineAction and CommandLineParser
268
+ * that provides functionality for defining command-line parameters.
269
+ *
270
+ * @public
271
+ */
272
+ export declare abstract class CommandLineParameterProvider {
273
+ private static _keyCounter;
274
+ private _parameters;
275
+ private _parametersByLongName;
276
+ private _remainder;
277
+ /* Excluded from this release type: __constructor */
278
+ /**
279
+ * Returns a collection of the parameters that were defined for this object.
280
+ */
281
+ get parameters(): ReadonlyArray<CommandLineParameter>;
282
+ /**
283
+ * If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,
284
+ * this object captures any remaining command line arguments after the recognized portion.
285
+ */
286
+ get remainder(): CommandLineRemainder | undefined;
287
+ /**
288
+ * Defines a command-line parameter whose value must be a string from a fixed set of
289
+ * allowable choices (similar to an enum).
290
+ *
291
+ * @remarks
292
+ * Example of a choice parameter:
293
+ * ```
294
+ * example-tool --log-level warn
295
+ * ```
296
+ */
297
+ defineChoiceParameter(definition: ICommandLineChoiceDefinition): CommandLineChoiceParameter;
298
+ /**
299
+ * Returns the CommandLineChoiceParameter with the specified long name.
300
+ * @remarks
301
+ * This method throws an exception if the parameter is not defined.
302
+ */
303
+ getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter;
304
+ /**
305
+ * Defines a command-line parameter whose value must be a string from a fixed set of
306
+ * allowable choices (similar to an enum). The parameter can be specified multiple times to
307
+ * build a list.
308
+ *
309
+ * @remarks
310
+ * Example of a choice list parameter:
311
+ * ```
312
+ * example-tool --allow-color red --allow-color green
313
+ * ```
314
+ */
315
+ defineChoiceListParameter(definition: ICommandLineChoiceListDefinition): CommandLineChoiceListParameter;
316
+ /**
317
+ * Returns the CommandLineChoiceListParameter with the specified long name.
318
+ * @remarks
319
+ * This method throws an exception if the parameter is not defined.
320
+ */
321
+ getChoiceListParameter(parameterLongName: string): CommandLineChoiceListParameter;
322
+ /**
323
+ * Defines a command-line switch whose boolean value is true if the switch is provided,
324
+ * and false otherwise.
325
+ *
326
+ * @remarks
327
+ * Example usage of a flag parameter:
328
+ * ```
329
+ * example-tool --debug
330
+ * ```
331
+ */
332
+ defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter;
333
+ /**
334
+ * Returns the CommandLineFlagParameter with the specified long name.
335
+ * @remarks
336
+ * This method throws an exception if the parameter is not defined.
337
+ */
338
+ getFlagParameter(parameterLongName: string): CommandLineFlagParameter;
339
+ /**
340
+ * Defines a command-line parameter whose argument is an integer.
341
+ *
342
+ * @remarks
343
+ * Example usage of an integer parameter:
344
+ * ```
345
+ * example-tool --max-attempts 5
346
+ * ```
347
+ */
348
+ defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter;
349
+ /**
350
+ * Returns the CommandLineIntegerParameter with the specified long name.
351
+ * @remarks
352
+ * This method throws an exception if the parameter is not defined.
353
+ */
354
+ getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter;
355
+ /**
356
+ * Defines a command-line parameter whose argument is an integer. The parameter can be specified
357
+ * multiple times to build a list.
358
+ *
359
+ * @remarks
360
+ * Example usage of an integer list parameter:
361
+ * ```
362
+ * example-tool --avoid 4 --avoid 13
363
+ * ```
364
+ */
365
+ defineIntegerListParameter(definition: ICommandLineIntegerListDefinition): CommandLineIntegerListParameter;
366
+ /**
367
+ * Returns the CommandLineIntegerParameter with the specified long name.
368
+ * @remarks
369
+ * This method throws an exception if the parameter is not defined.
370
+ */
371
+ getIntegerListParameter(parameterLongName: string): CommandLineIntegerListParameter;
372
+ /**
373
+ * Defines a command-line parameter whose argument is a single text string.
374
+ *
375
+ * @remarks
376
+ * Example usage of a string parameter:
377
+ * ```
378
+ * example-tool --message "Hello, world!"
379
+ * ```
380
+ */
381
+ defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter;
382
+ /**
383
+ * Returns the CommandLineStringParameter with the specified long name.
384
+ * @remarks
385
+ * This method throws an exception if the parameter is not defined.
386
+ */
387
+ getStringParameter(parameterLongName: string): CommandLineStringParameter;
388
+ /**
389
+ * Defines a command-line parameter whose argument is a single text string. The parameter can be
390
+ * specified multiple times to build a list.
391
+ *
392
+ * @remarks
393
+ * Example usage of a string list parameter:
394
+ * ```
395
+ * example-tool --add file1.txt --add file2.txt --add file3.txt
396
+ * ```
397
+ */
398
+ defineStringListParameter(definition: ICommandLineStringListDefinition): CommandLineStringListParameter;
399
+ /**
400
+ * Defines a rule that captures any remaining command line arguments after the recognized portion.
401
+ *
402
+ * @remarks
403
+ * This feature is useful for commands that pass their arguments along to an external tool, relying on
404
+ * that tool to perform validation. (It could also be used to parse parameters without any validation
405
+ * or documentation, but that is not recommended.)
406
+ *
407
+ * Example of capturing the remainder after an optional flag parameter.
408
+ * ```
409
+ * example-tool --my-flag this is the remainder
410
+ * ```
411
+ *
412
+ * In the "--help" documentation, the remainder rule will be represented as "...".
413
+ */
414
+ defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder;
415
+ /**
416
+ * Returns the CommandLineStringListParameter with the specified long name.
417
+ * @remarks
418
+ * This method throws an exception if the parameter is not defined.
419
+ */
420
+ getStringListParameter(parameterLongName: string): CommandLineStringListParameter;
421
+ /**
422
+ * Generates the command-line help text.
423
+ */
424
+ renderHelpText(): string;
425
+ /**
426
+ * Returns a object which maps the long name of each parameter in this.parameters
427
+ * to the stringified form of its value. This is useful for logging telemetry, but
428
+ * it is not the proper way of accessing parameters or their values.
429
+ */
430
+ getParameterStringMap(): Record<string, string>;
431
+ /**
432
+ * The child class should implement this hook to define its command-line parameters,
433
+ * e.g. by calling defineFlagParameter().
434
+ */
435
+ protected abstract onDefineParameters(): void;
436
+ /* Excluded from this release type: _getArgumentParser */
437
+ /* Excluded from this release type: _processParsedData */
438
+ private _generateKey;
439
+ private _getParameter;
440
+ private _defineParameter;
441
+ }
442
+
443
+ /**
444
+ * The common base class for parameters types that receive an argument.
445
+ *
446
+ * @remarks
447
+ * An argument is an accompanying command-line token, such as "123" in the
448
+ * example "--max-count 123".
449
+ * @public
450
+ */
451
+ export declare abstract class CommandLineParameterWithArgument extends CommandLineParameter {
452
+ private static _invalidArgumentNameRegExp;
453
+ /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */
454
+ readonly argumentName: string;
455
+ /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */
456
+ readonly completions: (() => Promise<string[]>) | undefined;
457
+ /* Excluded from this release type: __constructor */
458
+ }
459
+
460
+ /**
461
+ * The "argparse" library is a relatively advanced command-line parser with features such
462
+ * as word-wrapping and intelligible error messages (that are lacking in other similar
463
+ * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
464
+ * is awkward to use. The abstract base classes CommandLineParser and CommandLineAction
465
+ * provide a wrapper for "argparse" that makes defining and consuming arguments quick
466
+ * and simple, and enforces that appropriate documentation is provided for each parameter.
467
+ *
468
+ * @public
469
+ */
470
+ export declare abstract class CommandLineParser extends CommandLineParameterProvider {
471
+ /**
472
+ * Reports which CommandLineAction was specified on the command line.
473
+ * @remarks
474
+ * The value will be assigned before onExecute() is invoked.
475
+ */
476
+ selectedAction: CommandLineAction | undefined;
477
+ private _argumentParser;
478
+ private _actionsSubParser;
479
+ private _options;
480
+ private _actions;
481
+ private _actionsByName;
482
+ private _executed;
483
+ private _tabCompleteActionWasAdded;
484
+ constructor(options: ICommandLineParserOptions);
485
+ /**
486
+ * Returns the list of actions that were defined for this CommandLineParser object.
487
+ */
488
+ get actions(): ReadonlyArray<CommandLineAction>;
489
+ /**
490
+ * Defines a new action that can be used with the CommandLineParser instance.
491
+ */
492
+ addAction(action: CommandLineAction): void;
493
+ /**
494
+ * Retrieves the action with the specified name. If no matching action is found,
495
+ * an exception is thrown.
496
+ */
497
+ getAction(actionName: string): CommandLineAction;
498
+ /**
499
+ * Retrieves the action with the specified name. If no matching action is found,
500
+ * undefined is returned.
501
+ */
502
+ tryGetAction(actionName: string): CommandLineAction | undefined;
503
+ /**
504
+ * The program entry point will call this method to begin parsing command-line arguments
505
+ * and executing the corresponding action.
506
+ *
507
+ * @remarks
508
+ * The returned promise will never reject: If an error occurs, it will be printed
509
+ * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
510
+ * This simplifies the most common usage scenario where the program entry point doesn't
511
+ * want to be involved with the command-line logic, and will discard the promise without
512
+ * a then() or catch() block.
513
+ *
514
+ * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
515
+ * instead.
516
+ *
517
+ * @param args - the command-line arguments to be parsed; if omitted, then
518
+ * the process.argv will be used
519
+ */
520
+ execute(args?: string[]): Promise<boolean>;
521
+ /**
522
+ * This is similar to {@link CommandLineParser.execute}, except that execution errors
523
+ * simply cause the promise to reject. It is the caller's responsibility to trap
524
+ */
525
+ executeWithoutErrorHandling(args?: string[]): Promise<void>;
526
+ private _validateDefinitions;
527
+ /* Excluded from this release type: _getArgumentParser */
528
+ /**
529
+ * This hook allows the subclass to perform additional operations before or after
530
+ * the chosen action is executed.
531
+ */
532
+ protected onExecute(): Promise<void>;
533
+ }
534
+
535
+ /**
536
+ * The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.
537
+ * @public
538
+ */
539
+ export declare class CommandLineRemainder {
540
+ private _values;
541
+ /** {@inheritDoc IBaseCommandLineDefinition.description} */
542
+ readonly description: string;
543
+ /* Excluded from this release type: __constructor */
544
+ /**
545
+ * Returns any remaining command line arguments after the recognized portion
546
+ * that was parsed from the command line.
547
+ *
548
+ * @remarks
549
+ * The array will be empty if the command-line has not been parsed yet.
550
+ */
551
+ get values(): ReadonlyArray<string>;
552
+ /* Excluded from this release type: _setValue */
553
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
554
+ appendToArgList(argList: string[]): void;
555
+ }
556
+
557
+ /**
558
+ * The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.
559
+ * @public
560
+ */
561
+ export declare class CommandLineStringListParameter extends CommandLineParameterWithArgument {
562
+ private _values;
563
+ /* Excluded from this release type: __constructor */
564
+ /** {@inheritDoc CommandLineParameter.kind} */
565
+ get kind(): CommandLineParameterKind;
566
+ /* Excluded from this release type: _setValue */
567
+ /**
568
+ * Returns the string arguments for a string list parameter that was parsed from the command line.
569
+ *
570
+ * @remarks
571
+ * The array will be empty if the command-line has not been parsed yet,
572
+ * or if the parameter was omitted and has no default value.
573
+ */
574
+ get values(): ReadonlyArray<string>;
575
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
576
+ appendToArgList(argList: string[]): void;
577
+ }
578
+
579
+ /**
580
+ * The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.
581
+ * @public
582
+ */
583
+ export declare class CommandLineStringParameter extends CommandLineParameterWithArgument {
584
+ /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
585
+ readonly defaultValue: string | undefined;
586
+ private _value;
587
+ /* Excluded from this release type: __constructor */
588
+ /** {@inheritDoc CommandLineParameter.kind} */
589
+ get kind(): CommandLineParameterKind;
590
+ /* Excluded from this release type: _setValue */
591
+ /* Excluded from this release type: _getSupplementaryNotes */
592
+ /**
593
+ * Returns the argument value for a string parameter that was parsed from the command line.
594
+ *
595
+ * @remarks
596
+ * The return value will be undefined if the command-line has not been parsed yet,
597
+ * or if the parameter was omitted and has no default value.
598
+ */
599
+ get value(): string | undefined;
600
+ /** {@inheritDoc CommandLineParameter.appendToArgList} @override */
601
+ appendToArgList(argList: string[]): void;
602
+ }
603
+
604
+ /**
605
+ * @public
606
+ */
607
+ export declare class DynamicCommandLineAction extends CommandLineAction {
608
+ protected onDefineParameters(): void;
609
+ protected onExecute(): Promise<void>;
610
+ }
611
+
612
+ /**
613
+ * @public
614
+ */
615
+ export declare class DynamicCommandLineParser extends CommandLineParser {
616
+ protected onDefineParameters(): void;
617
+ }
618
+
619
+ /**
620
+ * For use with CommandLineParser, this interface represents a generic command-line parameter
621
+ *
622
+ * @public
623
+ */
624
+ export declare interface IBaseCommandLineDefinition {
625
+ /**
626
+ * The long name of the flag including double dashes, e.g. "--do-something"
627
+ */
628
+ parameterLongName: string;
629
+ /**
630
+ * An optional short name for the flag including the dash, e.g. "-d"
631
+ */
632
+ parameterShortName?: string;
633
+ /**
634
+ * Documentation for the parameter that will be shown when invoking the tool with "--help"
635
+ */
636
+ description: string;
637
+ /**
638
+ * If true, then an error occurs if the parameter was not included on the command-line.
639
+ */
640
+ required?: boolean;
641
+ /**
642
+ * The name of an environment variable that the parameter value will be read from,
643
+ * if it was omitted from the command-line. An error will be reported if the
644
+ * environment value cannot be parsed.
645
+ *
646
+ * @remarks
647
+ * The environment variable name must consist only of upper-case letters, numbers,
648
+ * and underscores. It may not start with a number.
649
+ *
650
+ * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,
651
+ * because in that case the environmentVariable would never be used.
652
+ *
653
+ * Syntax notes for environment variable values:
654
+ *
655
+ * - Choice Parameter: The value must match one of the defined choices,
656
+ * otherwise a validation error is reported.
657
+ * An empty string causes the environment variable to be ignored.
658
+ *
659
+ * - Flag Parameter: The value must be `1` for true, or `0` for false,
660
+ * otherwise a validation error is reported.
661
+ * An empty string causes the environment variable to be ignored.
662
+ *
663
+ * - Integer Parameter: The value must be an integer number,
664
+ * otherwise a validation error is reported.
665
+ * An empty string causes the environment variable to be ignored.
666
+ *
667
+ * - String Parameter: Any value is accepted, including an empty string.
668
+ *
669
+ * - String List Parameter: If the string starts with `[` (ignoring whitespace)
670
+ * then it will be parsed as a JSON array, whose elements must be strings,
671
+ * numbers, or boolean values.
672
+ * If the string does not start with `[`, then it behaves like an
673
+ * ordinary String Parameter: Any value is accepted, including an empty string.
674
+ */
675
+ environmentVariable?: string;
676
+ /**
677
+ * Specifies additional names for this parameter that are accepted but not displayed
678
+ * in the command line help.
679
+ *
680
+ * @remarks
681
+ * This option can be used in cases where a command-line parameter may have been renamed,
682
+ * but the developer doesn't want to break backwards compatibility with systems that may
683
+ * still be using the old name. Only the `parameterLongName` syntax is currently allowed.
684
+ */
685
+ undocumentedSynonyms?: string[];
686
+ }
687
+
688
+ /**
689
+ * The common base interface for parameter types that accept an argument.
690
+ *
691
+ * @remarks
692
+ * An argument is an accompanying command-line token, such as "123" in the
693
+ * example "--max-count 123".
694
+ * @public
695
+ */
696
+ export declare interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {
697
+ /**
698
+ * The name of the argument, which will be shown in the command-line help.
699
+ *
700
+ * @remarks
701
+ * For example, if the parameter name is '--count" and the argument name is "NUMBER",
702
+ * then the command-line help would display "--count NUMBER". The argument name must
703
+ * be comprised of upper-case letters, numbers, and underscores. It should be kept short.
704
+ */
705
+ argumentName: string;
706
+ /**
707
+ * An optional callback that provides a list of custom choices for tab completion.
708
+ * @remarks
709
+ * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
710
+ * is enabled.
711
+ */
712
+ completions?: () => Promise<string[]>;
713
+ }
714
+
715
+ /**
716
+ * Options for the CommandLineAction constructor.
717
+ * @public
718
+ */
719
+ export declare interface ICommandLineActionOptions {
720
+ /**
721
+ * The name of the action. For example, if the tool is called "example",
722
+ * then the "build" action might be invoked as: "example build -q --some-other-option"
723
+ */
724
+ actionName: string;
725
+ /**
726
+ * A quick summary that is shown on the main help page, which is displayed
727
+ * by the command "example --help"
728
+ */
729
+ summary: string;
730
+ /**
731
+ * A detailed description that is shown on the action help page, which is displayed
732
+ * by the command "example build --help", e.g. for actionName="build".
733
+ */
734
+ documentation: string;
735
+ }
736
+
737
+ /**
738
+ * For use with {@link CommandLineParameterProvider.defineChoiceParameter},
739
+ * this interface defines a command line parameter which is constrained to a list of possible
740
+ * options.
741
+ *
742
+ * @public
743
+ */
744
+ export declare interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {
745
+ /**
746
+ * A list of strings (which contain no spaces), of possible options which can be selected
747
+ */
748
+ alternatives: string[];
749
+ /**
750
+ * {@inheritDoc ICommandLineStringDefinition.defaultValue}
751
+ */
752
+ defaultValue?: string;
753
+ /**
754
+ * An optional callback that provides a list of custom choices for tab completion.
755
+ * @remarks
756
+ * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
757
+ * is enabled.
758
+ */
759
+ completions?: () => Promise<string[]>;
760
+ }
761
+
762
+ /**
763
+ * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},
764
+ * this interface defines a command line parameter which is constrained to a list of possible
765
+ * options. The parameter can be specified multiple times to build a list.
766
+ *
767
+ * @public
768
+ */
769
+ export declare interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {
770
+ /**
771
+ * A list of strings (which contain no spaces), of possible options which can be selected
772
+ */
773
+ alternatives: string[];
774
+ /**
775
+ * An optional callback that provides a list of custom choices for tab completion.
776
+ * @remarks
777
+ * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
778
+ * is enabled.
779
+ */
780
+ completions?: () => Promise<string[]>;
781
+ }
782
+
783
+ /**
784
+ * For use with {@link CommandLineParameterProvider.defineFlagParameter},
785
+ * this interface defines a command line parameter that is a boolean flag.
786
+ *
787
+ * @public
788
+ */
789
+ export declare interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {
790
+ }
791
+
792
+ /**
793
+ * For use with {@link CommandLineParameterProvider.defineIntegerParameter},
794
+ * this interface defines a command line parameter whose argument is an integer value.
795
+ *
796
+ * @public
797
+ */
798
+ export declare interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {
799
+ /**
800
+ * {@inheritDoc ICommandLineStringDefinition.defaultValue}
801
+ */
802
+ defaultValue?: number;
803
+ }
804
+
805
+ /**
806
+ * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},
807
+ * this interface defines a command line parameter whose argument is an integer value. The
808
+ * parameter can be specified multiple times to build a list.
809
+ *
810
+ * @public
811
+ */
812
+ export declare interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {
813
+ }
814
+
815
+ /* Excluded from this release type: _ICommandLineParserData */
816
+
817
+ /**
818
+ * Options for the {@link CommandLineParser} constructor.
819
+ * @public
820
+ */
821
+ export declare interface ICommandLineParserOptions {
822
+ /**
823
+ * The name of your tool when invoked from the command line
824
+ */
825
+ toolFilename: string;
826
+ /**
827
+ * General documentation that is included in the "--help" main page
828
+ */
829
+ toolDescription: string;
830
+ /**
831
+ * Set to true to auto-define a tab completion action. False by default.
832
+ */
833
+ enableTabCompletionAction?: boolean;
834
+ }
835
+
836
+ /**
837
+ * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},
838
+ * this interface defines a rule that captures any remaining command line arguments after the recognized portion.
839
+ *
840
+ * @public
841
+ */
842
+ export declare interface ICommandLineRemainderDefinition {
843
+ /**
844
+ * Documentation for how the remaining arguments will be used. This will be shown when invoking
845
+ * the tool with "--help".
846
+ */
847
+ description: string;
848
+ }
849
+
850
+ /**
851
+ * For use with {@link CommandLineParameterProvider.defineStringParameter},
852
+ * this interface defines a command line parameter whose argument is a string value.
853
+ *
854
+ * @public
855
+ */
856
+ export declare interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {
857
+ /**
858
+ * The default value which will be used if the parameter is omitted from the command line.
859
+ *
860
+ * @remarks
861
+ * If a default value is specified, then {@link IBaseCommandLineDefinition.required}
862
+ * must not be true. Instead, a custom error message should be used to report cases
863
+ * where a default value was not available.
864
+ */
865
+ defaultValue?: string;
866
+ }
867
+
868
+ /**
869
+ * For use with {@link CommandLineParameterProvider.defineStringListParameter},
870
+ * this interface defines a command line parameter whose argument is a single text string.
871
+ * The parameter can be specified multiple times to build a list.
872
+ *
873
+ * @public
874
+ */
875
+ export declare interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {
876
+ }
877
+
878
+ export { }