@rushstack/ts-command-line 4.10.10 → 4.12.0
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/dist/ts-command-line.d.ts +137 -8
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/Constants.d.ts +1 -0
- package/lib/Constants.d.ts.map +1 -1
- package/lib/Constants.js +2 -0
- package/lib/Constants.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -3
- package/lib/index.js.map +1 -1
- package/lib/parameters/BaseClasses.d.ts +11 -0
- package/lib/parameters/BaseClasses.d.ts.map +1 -1
- package/lib/parameters/BaseClasses.js +19 -6
- package/lib/parameters/BaseClasses.js.map +1 -1
- package/lib/parameters/CommandLineDefinition.d.ts +12 -0
- package/lib/parameters/CommandLineDefinition.d.ts.map +1 -1
- package/lib/parameters/CommandLineDefinition.js.map +1 -1
- package/lib/providers/CommandLineAction.d.ts +2 -1
- package/lib/providers/CommandLineAction.d.ts.map +1 -1
- package/lib/providers/CommandLineAction.js +2 -2
- package/lib/providers/CommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineParameterProvider.d.ts +46 -10
- package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
- package/lib/providers/CommandLineParameterProvider.js +151 -47
- package/lib/providers/CommandLineParameterProvider.js.map +1 -1
- package/lib/providers/CommandLineParser.d.ts +7 -0
- package/lib/providers/CommandLineParser.d.ts.map +1 -1
- package/lib/providers/CommandLineParser.js +16 -4
- package/lib/providers/CommandLineParser.js.map +1 -1
- package/lib/providers/CommandLineParserExitError.js +5 -1
- package/lib/providers/CommandLineParserExitError.js.map +1 -1
- package/lib/providers/ScopedCommandLineAction.d.ts +85 -0
- package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -0
- package/lib/providers/ScopedCommandLineAction.js +180 -0
- package/lib/providers/ScopedCommandLineAction.js.map +1 -0
- package/package.json +4 -4
|
@@ -200,12 +200,22 @@ export declare class CommandLineIntegerParameter extends CommandLineParameterWit
|
|
|
200
200
|
export declare abstract class CommandLineParameter {
|
|
201
201
|
private static _longNameRegExp;
|
|
202
202
|
private static _shortNameRegExp;
|
|
203
|
+
private static _scopeRegExp;
|
|
203
204
|
private static _environmentVariableRegExp;
|
|
204
205
|
/* Excluded from this release type: _parserKey */
|
|
205
206
|
/** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
|
|
206
207
|
readonly longName: string;
|
|
208
|
+
/**
|
|
209
|
+
* If a parameterScope is provided, returns the scope-prefixed long name of the flag,
|
|
210
|
+
* including double dashes, eg. "--scope:do-something". Otherwise undefined.
|
|
211
|
+
*/
|
|
212
|
+
readonly scopedLongName: string | undefined;
|
|
207
213
|
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
|
|
208
214
|
readonly shortName: string | undefined;
|
|
215
|
+
/** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */
|
|
216
|
+
readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;
|
|
217
|
+
/** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */
|
|
218
|
+
readonly parameterScope: string | undefined;
|
|
209
219
|
/** {@inheritDoc IBaseCommandLineDefinition.description} */
|
|
210
220
|
readonly description: string;
|
|
211
221
|
/** {@inheritDoc IBaseCommandLineDefinition.required} */
|
|
@@ -270,9 +280,14 @@ export declare enum CommandLineParameterKind {
|
|
|
270
280
|
* @public
|
|
271
281
|
*/
|
|
272
282
|
export declare abstract class CommandLineParameterProvider {
|
|
283
|
+
private static readonly _scopeGroupName;
|
|
284
|
+
private static readonly _longNameGroupName;
|
|
285
|
+
private static readonly _possiblyScopedLongNameRegex;
|
|
273
286
|
private static _keyCounter;
|
|
274
287
|
private _parameters;
|
|
275
288
|
private _parametersByLongName;
|
|
289
|
+
private _parameterGroupsByName;
|
|
290
|
+
private _parametersRegistered;
|
|
276
291
|
private _parametersProcessed;
|
|
277
292
|
private _remainder;
|
|
278
293
|
/* Excluded from this release type: __constructor */
|
|
@@ -305,7 +320,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
305
320
|
* @remarks
|
|
306
321
|
* This method throws an exception if the parameter is not defined.
|
|
307
322
|
*/
|
|
308
|
-
getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter;
|
|
323
|
+
getChoiceParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceParameter;
|
|
309
324
|
/**
|
|
310
325
|
* Defines a command-line parameter whose value must be a string from a fixed set of
|
|
311
326
|
* allowable choices (similar to an enum). The parameter can be specified multiple times to
|
|
@@ -323,7 +338,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
323
338
|
* @remarks
|
|
324
339
|
* This method throws an exception if the parameter is not defined.
|
|
325
340
|
*/
|
|
326
|
-
getChoiceListParameter(parameterLongName: string): CommandLineChoiceListParameter;
|
|
341
|
+
getChoiceListParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceListParameter;
|
|
327
342
|
/**
|
|
328
343
|
* Defines a command-line switch whose boolean value is true if the switch is provided,
|
|
329
344
|
* and false otherwise.
|
|
@@ -340,7 +355,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
340
355
|
* @remarks
|
|
341
356
|
* This method throws an exception if the parameter is not defined.
|
|
342
357
|
*/
|
|
343
|
-
getFlagParameter(parameterLongName: string): CommandLineFlagParameter;
|
|
358
|
+
getFlagParameter(parameterLongName: string, parameterScope?: string): CommandLineFlagParameter;
|
|
344
359
|
/**
|
|
345
360
|
* Defines a command-line parameter whose argument is an integer.
|
|
346
361
|
*
|
|
@@ -356,7 +371,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
356
371
|
* @remarks
|
|
357
372
|
* This method throws an exception if the parameter is not defined.
|
|
358
373
|
*/
|
|
359
|
-
getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter;
|
|
374
|
+
getIntegerParameter(parameterLongName: string, parameterScope?: string): CommandLineIntegerParameter;
|
|
360
375
|
/**
|
|
361
376
|
* Defines a command-line parameter whose argument is an integer. The parameter can be specified
|
|
362
377
|
* multiple times to build a list.
|
|
@@ -373,7 +388,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
373
388
|
* @remarks
|
|
374
389
|
* This method throws an exception if the parameter is not defined.
|
|
375
390
|
*/
|
|
376
|
-
getIntegerListParameter(parameterLongName: string): CommandLineIntegerListParameter;
|
|
391
|
+
getIntegerListParameter(parameterLongName: string, parameterScope?: string): CommandLineIntegerListParameter;
|
|
377
392
|
/**
|
|
378
393
|
* Defines a command-line parameter whose argument is a single text string.
|
|
379
394
|
*
|
|
@@ -389,7 +404,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
389
404
|
* @remarks
|
|
390
405
|
* This method throws an exception if the parameter is not defined.
|
|
391
406
|
*/
|
|
392
|
-
getStringParameter(parameterLongName: string): CommandLineStringParameter;
|
|
407
|
+
getStringParameter(parameterLongName: string, parameterScope?: string): CommandLineStringParameter;
|
|
393
408
|
/**
|
|
394
409
|
* Defines a command-line parameter whose argument is a single text string. The parameter can be
|
|
395
410
|
* specified multiple times to build a list.
|
|
@@ -422,17 +437,26 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
422
437
|
* @remarks
|
|
423
438
|
* This method throws an exception if the parameter is not defined.
|
|
424
439
|
*/
|
|
425
|
-
getStringListParameter(parameterLongName: string): CommandLineStringListParameter;
|
|
440
|
+
getStringListParameter(parameterLongName: string, parameterScope?: string): CommandLineStringListParameter;
|
|
426
441
|
/**
|
|
427
442
|
* Generates the command-line help text.
|
|
428
443
|
*/
|
|
429
444
|
renderHelpText(): string;
|
|
445
|
+
/**
|
|
446
|
+
* Generates the command-line usage text.
|
|
447
|
+
*/
|
|
448
|
+
renderUsageText(): string;
|
|
430
449
|
/**
|
|
431
450
|
* Returns a object which maps the long name of each parameter in this.parameters
|
|
432
451
|
* to the stringified form of its value. This is useful for logging telemetry, but
|
|
433
452
|
* it is not the proper way of accessing parameters or their values.
|
|
434
453
|
*/
|
|
435
454
|
getParameterStringMap(): Record<string, string>;
|
|
455
|
+
/**
|
|
456
|
+
* Returns an object with the parsed scope (if present) and the long name of the parameter.
|
|
457
|
+
*/
|
|
458
|
+
parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult;
|
|
459
|
+
/* Excluded from this release type: _registerDefinedParameters */
|
|
436
460
|
/**
|
|
437
461
|
* The child class should implement this hook to define its command-line parameters,
|
|
438
462
|
* e.g. by calling defineFlagParameter().
|
|
@@ -440,9 +464,10 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
440
464
|
protected abstract onDefineParameters(): void;
|
|
441
465
|
/* Excluded from this release type: _getArgumentParser */
|
|
442
466
|
/* Excluded from this release type: _processParsedData */
|
|
467
|
+
/* Excluded from this release type: _defineParameter */
|
|
468
|
+
/* Excluded from this release type: _registerParameter */
|
|
443
469
|
private _generateKey;
|
|
444
470
|
private _getParameter;
|
|
445
|
-
private _defineParameter;
|
|
446
471
|
}
|
|
447
472
|
|
|
448
473
|
/**
|
|
@@ -528,6 +553,7 @@ export declare abstract class CommandLineParser extends CommandLineParameterProv
|
|
|
528
553
|
* simply cause the promise to reject. It is the caller's responsibility to trap
|
|
529
554
|
*/
|
|
530
555
|
executeWithoutErrorHandling(args?: string[]): Promise<void>;
|
|
556
|
+
/* Excluded from this release type: _registerDefinedParameters */
|
|
531
557
|
private _validateDefinitions;
|
|
532
558
|
/* Excluded from this release type: _getArgumentParser */
|
|
533
559
|
/**
|
|
@@ -635,6 +661,17 @@ export declare interface IBaseCommandLineDefinition {
|
|
|
635
661
|
* An optional short name for the flag including the dash, e.g. "-d"
|
|
636
662
|
*/
|
|
637
663
|
parameterShortName?: string;
|
|
664
|
+
/**
|
|
665
|
+
* An optional parameter group name, shown when invoking the tool with "--help"
|
|
666
|
+
*/
|
|
667
|
+
parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;
|
|
668
|
+
/**
|
|
669
|
+
* An optional parameter scope name, used to add a scope-prefixed parameter synonym,
|
|
670
|
+
* e.g. "--scope:do-something". Scopes provide additional flexibility for parameters
|
|
671
|
+
* in conflict resolution since when a scope is specified, parameters that have
|
|
672
|
+
* conflicting long names will be defined using only the scope-prefixed name.
|
|
673
|
+
*/
|
|
674
|
+
parameterScope?: string;
|
|
638
675
|
/**
|
|
639
676
|
* Documentation for the parameter that will be shown when invoking the tool with "--help"
|
|
640
677
|
*/
|
|
@@ -832,6 +869,11 @@ export declare interface ICommandLineParserOptions {
|
|
|
832
869
|
* General documentation that is included in the "--help" main page
|
|
833
870
|
*/
|
|
834
871
|
toolDescription: string;
|
|
872
|
+
/**
|
|
873
|
+
* An optional string to append at the end of the "--help" main page. If not provided, an epilog
|
|
874
|
+
* will be automatically generated based on the toolFilename.
|
|
875
|
+
*/
|
|
876
|
+
toolEpilog?: string;
|
|
835
877
|
/**
|
|
836
878
|
* Set to true to auto-define a tab completion action. False by default.
|
|
837
879
|
*/
|
|
@@ -880,4 +922,91 @@ export declare interface ICommandLineStringDefinition extends IBaseCommandLineDe
|
|
|
880
922
|
export declare interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {
|
|
881
923
|
}
|
|
882
924
|
|
|
925
|
+
/**
|
|
926
|
+
* The result containing the parsed paramter long name and scope. Returned when calling
|
|
927
|
+
* {@link CommandLineParameterProvider.parseScopedLongName}.
|
|
928
|
+
*
|
|
929
|
+
* @public
|
|
930
|
+
*/
|
|
931
|
+
export declare interface IScopedLongNameParseResult {
|
|
932
|
+
/**
|
|
933
|
+
* The long name parsed from the scoped long name, e.g. "--my-scope:my-parameter" -\> "--my-parameter"
|
|
934
|
+
*/
|
|
935
|
+
longName: string;
|
|
936
|
+
/**
|
|
937
|
+
* The scope parsed from the scoped long name or undefined if no scope was found,
|
|
938
|
+
* e.g. "--my-scope:my-parameter" -\> "my-scope"
|
|
939
|
+
*/
|
|
940
|
+
scope: string | undefined;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Represents a sub-command that is part of the CommandLineParser command-line.
|
|
945
|
+
* Applications should create subclasses of ScopedCommandLineAction corresponding to
|
|
946
|
+
* each action that they want to expose.
|
|
947
|
+
*
|
|
948
|
+
* The action name should be comprised of lower case words separated by hyphens
|
|
949
|
+
* or colons. The name should include an English verb (e.g. "deploy"). Use a
|
|
950
|
+
* hyphen to separate words (e.g. "upload-docs"). A group of related commands
|
|
951
|
+
* can be prefixed with a colon (e.g. "docs:generate", "docs:deploy",
|
|
952
|
+
* "docs:serve", etc).
|
|
953
|
+
*
|
|
954
|
+
* Scoped commands allow for different parameters to be specified for different
|
|
955
|
+
* provided scoping values. For example, the "scoped-action --scope A" command
|
|
956
|
+
* may allow for different scoped arguments to be specified than the "scoped-action
|
|
957
|
+
* --scope B" command.
|
|
958
|
+
*
|
|
959
|
+
* Scoped arguments are specified after the "--" pseudo-argument. For example,
|
|
960
|
+
* "scoped-action --scope A -- --scopedFoo --scopedBar".
|
|
961
|
+
*
|
|
962
|
+
* @public
|
|
963
|
+
*/
|
|
964
|
+
export declare abstract class ScopedCommandLineAction extends CommandLineAction {
|
|
965
|
+
private _options;
|
|
966
|
+
private _scopingParameters;
|
|
967
|
+
private _unscopedParserOptions;
|
|
968
|
+
private _scopedCommandLineParser;
|
|
969
|
+
/**
|
|
970
|
+
* The required group name to apply to all scoping parameters. At least one parameter
|
|
971
|
+
* must be defined with this group name.
|
|
972
|
+
*/
|
|
973
|
+
static readonly ScopingParameterGroup: typeof SCOPING_PARAMETER_GROUP;
|
|
974
|
+
constructor(options: ICommandLineActionOptions);
|
|
975
|
+
/**
|
|
976
|
+
* {@inheritDoc CommandLineParameterProvider.parameters}
|
|
977
|
+
*/
|
|
978
|
+
get parameters(): ReadonlyArray<CommandLineParameter>;
|
|
979
|
+
/* Excluded from this release type: _processParsedData */
|
|
980
|
+
/* Excluded from this release type: _execute */
|
|
981
|
+
/**
|
|
982
|
+
* {@inheritdoc CommandLineParameterProvider.onDefineParameters}
|
|
983
|
+
*/
|
|
984
|
+
protected onDefineParameters(): void;
|
|
985
|
+
/* Excluded from this release type: _getScopedCommandLineParser */
|
|
986
|
+
/* Excluded from this release type: _defineParameter */
|
|
987
|
+
/**
|
|
988
|
+
* The child class should implement this hook to define its unscoped command-line parameters,
|
|
989
|
+
* e.g. by calling defineFlagParameter(). At least one scoping parameter must be defined.
|
|
990
|
+
* Scoping parameters are defined by setting the parameterGroupName to
|
|
991
|
+
* ScopedCommandLineAction.ScopingParameterGroupName.
|
|
992
|
+
*/
|
|
993
|
+
protected abstract onDefineUnscopedParameters(): void;
|
|
994
|
+
/**
|
|
995
|
+
* The child class should implement this hook to define its scoped command-line
|
|
996
|
+
* parameters, e.g. by calling scopedParameterProvider.defineFlagParameter(). These
|
|
997
|
+
* parameters will only be available if the action is invoked with a scope.
|
|
998
|
+
*
|
|
999
|
+
* @remarks
|
|
1000
|
+
* onDefineScopedParameters is called after the unscoped parameters have been parsed.
|
|
1001
|
+
* The values they provide can be used to vary the defined scope parameters.
|
|
1002
|
+
*/
|
|
1003
|
+
protected abstract onDefineScopedParameters(scopedParameterProvider: CommandLineParameterProvider): void;
|
|
1004
|
+
/**
|
|
1005
|
+
* {@inheritDoc CommandLineAction.onExecute}
|
|
1006
|
+
*/
|
|
1007
|
+
protected abstract onExecute(): Promise<void>;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
declare const SCOPING_PARAMETER_GROUP: unique symbol;
|
|
1011
|
+
|
|
883
1012
|
export { }
|
package/dist/tsdoc-metadata.json
CHANGED
package/lib/Constants.d.ts
CHANGED
package/lib/Constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,0BAAkB,oBAAoB;IACpC;;OAEG;IACH,uBAAuB,iBAAiB;CACzC"}
|
|
1
|
+
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,0BAAkB,oBAAoB;IACpC;;OAEG;IACH,uBAAuB,iBAAiB;CACzC;AAED,eAAO,MAAM,uBAAuB,EAAE,OAAO,MAA0B,CAAC"}
|
package/lib/Constants.js
CHANGED
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.SCOPING_PARAMETER_GROUP = void 0;
|
|
6
|
+
exports.SCOPING_PARAMETER_GROUP = Symbol('scoping');
|
|
5
7
|
//# sourceMappingURL=Constants.js.map
|
package/lib/Constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * String constants for command line processing.\n *\n * @public\n */\nexport const enum CommandLineConstants {\n /**\n * The name of the built-in action that serves suggestions for tab-completion\n */\n TabCompletionActionName = 'tab-complete'\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAc9C,QAAA,uBAAuB,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * String constants for command line processing.\n *\n * @public\n */\nexport const enum CommandLineConstants {\n /**\n * The name of the built-in action that serves suggestions for tab-completion\n */\n TabCompletionActionName = 'tab-complete'\n}\n\nexport const SCOPING_PARAMETER_GROUP: unique symbol = Symbol('scoping');\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
export { CommandLineAction, ICommandLineActionOptions } from './providers/CommandLineAction';
|
|
7
|
+
export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';
|
|
8
|
+
export { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';
|
|
7
9
|
export { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineRemainderDefinition } from './parameters/CommandLineDefinition';
|
|
8
10
|
export { CommandLineParameterKind, CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses';
|
|
9
11
|
export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';
|
|
@@ -14,9 +16,8 @@ export { CommandLineIntegerListParameter } from './parameters/CommandLineInteger
|
|
|
14
16
|
export { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter';
|
|
15
17
|
export { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';
|
|
16
18
|
export { CommandLineRemainder } from './parameters/CommandLineRemainder';
|
|
17
|
-
export { CommandLineParameterProvider, ICommandLineParserData as _ICommandLineParserData } from './providers/CommandLineParameterProvider';
|
|
19
|
+
export { CommandLineParameterProvider, IScopedLongNameParseResult, ICommandLineParserData as _ICommandLineParserData } from './providers/CommandLineParameterProvider';
|
|
18
20
|
export { ICommandLineParserOptions, CommandLineParser } from './providers/CommandLineParser';
|
|
19
|
-
export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';
|
|
20
21
|
export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';
|
|
21
22
|
export { CommandLineConstants } from './Constants';
|
|
22
23
|
export { CommandLineHelper } from './CommandLineHelper';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EACL,0BAA0B,EAC1B,sCAAsC,EACtC,0BAA0B,EAC1B,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,EACjC,4BAA4B,EAC5B,gCAAgC,EAChC,+BAA+B,EAChC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,IAAI,uBAAuB,EAClD,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.CommandLineHelper = exports.DynamicCommandLineParser = exports.
|
|
5
|
+
exports.CommandLineHelper = exports.DynamicCommandLineParser = exports.CommandLineParser = exports.CommandLineParameterProvider = exports.CommandLineRemainder = exports.CommandLineChoiceListParameter = exports.CommandLineChoiceParameter = exports.CommandLineIntegerListParameter = exports.CommandLineIntegerParameter = exports.CommandLineStringListParameter = exports.CommandLineStringParameter = exports.CommandLineFlagParameter = exports.CommandLineParameterWithArgument = exports.CommandLineParameter = exports.CommandLineParameterKind = exports.ScopedCommandLineAction = exports.DynamicCommandLineAction = exports.CommandLineAction = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* An object-oriented command-line parser for TypeScript projects.
|
|
8
8
|
*
|
|
@@ -10,6 +10,10 @@ exports.CommandLineHelper = exports.DynamicCommandLineParser = exports.DynamicCo
|
|
|
10
10
|
*/
|
|
11
11
|
var CommandLineAction_1 = require("./providers/CommandLineAction");
|
|
12
12
|
Object.defineProperty(exports, "CommandLineAction", { enumerable: true, get: function () { return CommandLineAction_1.CommandLineAction; } });
|
|
13
|
+
var DynamicCommandLineAction_1 = require("./providers/DynamicCommandLineAction");
|
|
14
|
+
Object.defineProperty(exports, "DynamicCommandLineAction", { enumerable: true, get: function () { return DynamicCommandLineAction_1.DynamicCommandLineAction; } });
|
|
15
|
+
var ScopedCommandLineAction_1 = require("./providers/ScopedCommandLineAction");
|
|
16
|
+
Object.defineProperty(exports, "ScopedCommandLineAction", { enumerable: true, get: function () { return ScopedCommandLineAction_1.ScopedCommandLineAction; } });
|
|
13
17
|
var BaseClasses_1 = require("./parameters/BaseClasses");
|
|
14
18
|
Object.defineProperty(exports, "CommandLineParameterKind", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameterKind; } });
|
|
15
19
|
Object.defineProperty(exports, "CommandLineParameter", { enumerable: true, get: function () { return BaseClasses_1.CommandLineParameter; } });
|
|
@@ -34,8 +38,6 @@ var CommandLineParameterProvider_1 = require("./providers/CommandLineParameterPr
|
|
|
34
38
|
Object.defineProperty(exports, "CommandLineParameterProvider", { enumerable: true, get: function () { return CommandLineParameterProvider_1.CommandLineParameterProvider; } });
|
|
35
39
|
var CommandLineParser_1 = require("./providers/CommandLineParser");
|
|
36
40
|
Object.defineProperty(exports, "CommandLineParser", { enumerable: true, get: function () { return CommandLineParser_1.CommandLineParser; } });
|
|
37
|
-
var DynamicCommandLineAction_1 = require("./providers/DynamicCommandLineAction");
|
|
38
|
-
Object.defineProperty(exports, "DynamicCommandLineAction", { enumerable: true, get: function () { return DynamicCommandLineAction_1.DynamicCommandLineAction; } });
|
|
39
41
|
var DynamicCommandLineParser_1 = require("./providers/DynamicCommandLineParser");
|
|
40
42
|
Object.defineProperty(exports, "DynamicCommandLineParser", { enumerable: true, get: function () { return DynamicCommandLineParser_1.DynamicCommandLineParser; } });
|
|
41
43
|
var CommandLineHelper_1 = require("./CommandLineHelper");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;GAIG;AAEH,mEAA6F;AAApF,sHAAA,iBAAiB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;GAIG;AAEH,mEAA6F;AAApF,sHAAA,iBAAiB,OAAA;AAC1B,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AACjC,+EAA8E;AAArE,kIAAA,uBAAuB,OAAA;AAehC,wDAIkC;AAHhC,uHAAA,wBAAwB,OAAA;AACxB,mHAAA,oBAAoB,OAAA;AACpB,+HAAA,gCAAgC,OAAA;AAGlC,kFAAiF;AAAxE,oIAAA,wBAAwB,OAAA;AACjC,sFAAqF;AAA5E,wIAAA,0BAA0B,OAAA;AACnC,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,wFAAuF;AAA9E,0IAAA,2BAA2B,OAAA;AACpC,gGAA+F;AAAtF,kJAAA,+BAA+B,OAAA;AACxC,sFAAqF;AAA5E,wIAAA,0BAA0B,OAAA;AACnC,8FAA6F;AAApF,gJAAA,8BAA8B,OAAA;AACvC,0EAAyE;AAAhE,4HAAA,oBAAoB,OAAA;AAE7B,yFAIkD;AAHhD,4IAAA,4BAA4B,OAAA;AAK9B,mEAA6F;AAAzD,sHAAA,iBAAiB,OAAA;AACrD,iFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AAIjC,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * An object-oriented command-line parser for TypeScript projects.\n *\n * @packageDocumentation\n */\n\nexport { CommandLineAction, ICommandLineActionOptions } from './providers/CommandLineAction';\nexport { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';\nexport { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';\n\nexport {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineRemainderDefinition\n} from './parameters/CommandLineDefinition';\n\nexport {\n CommandLineParameterKind,\n CommandLineParameter,\n CommandLineParameterWithArgument\n} from './parameters/BaseClasses';\n\nexport { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';\nexport { CommandLineStringParameter } from './parameters/CommandLineStringParameter';\nexport { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';\nexport { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter';\nexport { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';\nexport { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter';\nexport { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';\nexport { CommandLineRemainder } from './parameters/CommandLineRemainder';\n\nexport {\n CommandLineParameterProvider,\n IScopedLongNameParseResult,\n ICommandLineParserData as _ICommandLineParserData\n} from './providers/CommandLineParameterProvider';\n\nexport { ICommandLineParserOptions, CommandLineParser } from './providers/CommandLineParser';\nexport { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';\n\nexport { CommandLineConstants } from './Constants';\n\nexport { CommandLineHelper } from './CommandLineHelper';\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SCOPING_PARAMETER_GROUP } from '../Constants';
|
|
1
2
|
import { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument } from './CommandLineDefinition';
|
|
2
3
|
/**
|
|
3
4
|
* Identifies the kind of a CommandLineParameter.
|
|
@@ -26,6 +27,7 @@ export declare enum CommandLineParameterKind {
|
|
|
26
27
|
export declare abstract class CommandLineParameter {
|
|
27
28
|
private static _longNameRegExp;
|
|
28
29
|
private static _shortNameRegExp;
|
|
30
|
+
private static _scopeRegExp;
|
|
29
31
|
private static _environmentVariableRegExp;
|
|
30
32
|
/**
|
|
31
33
|
* A unique internal key used to retrieve the value from the parser's dictionary.
|
|
@@ -34,8 +36,17 @@ export declare abstract class CommandLineParameter {
|
|
|
34
36
|
_parserKey: string | undefined;
|
|
35
37
|
/** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */
|
|
36
38
|
readonly longName: string;
|
|
39
|
+
/**
|
|
40
|
+
* If a parameterScope is provided, returns the scope-prefixed long name of the flag,
|
|
41
|
+
* including double dashes, eg. "--scope:do-something". Otherwise undefined.
|
|
42
|
+
*/
|
|
43
|
+
readonly scopedLongName: string | undefined;
|
|
37
44
|
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
|
|
38
45
|
readonly shortName: string | undefined;
|
|
46
|
+
/** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */
|
|
47
|
+
readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;
|
|
48
|
+
/** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */
|
|
49
|
+
readonly parameterScope: string | undefined;
|
|
39
50
|
/** {@inheritDoc IBaseCommandLineDefinition.description} */
|
|
40
51
|
readonly description: string;
|
|
41
52
|
/** {@inheritDoc IBaseCommandLineDefinition.required} */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClasses.d.ts","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,sCAAsC,EAAE,MAAM,yBAAyB,CAAC;AAE7G;;;GAGG;AACH,oBAAY,wBAAwB;IAClC,6CAA6C;IAC7C,MAAM,IAAA;IACN,2CAA2C;IAC3C,IAAI,IAAA;IACJ,8CAA8C;IAC9C,OAAO,IAAA;IACP,6CAA6C;IAC7C,MAAM,IAAA;IACN,iDAAiD;IACjD,UAAU,IAAA;IACV,iDAAiD;IACjD,UAAU,IAAA;IACV,kDAAkD;IAClD,WAAW,IAAA;CACZ;AAED;;;GAGG;AACH,8BAAsB,oBAAoB;
|
|
1
|
+
{"version":3,"file":"BaseClasses.d.ts","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,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EzD;;;OAGG;aACa,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAE1C;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAWjE;;OAEG;IACH,aAAoB,IAAI,IAAI,wBAAwB,CAAC;IAErD;;;;;;;;;;;;OAYG;aACa,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAExD;;OAEG;IAEH,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,KAAK;IAI7C,SAAS,CAAC,oBAAoB,CAAC,eAAe,EAAE,OAAO,GAAG,IAAI;CAY/D;AAED;;;;;;;GAOG;AACH,8BAAsB,gCAAiC,SAAQ,oBAAoB;IAEjF,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAwB;IAEjE,wEAAwE;IACxE,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,uEAAuE;IACvE,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnE,gBAAgB;gBACG,UAAU,EAAE,sCAAsC;CAyBtE"}
|
|
@@ -33,6 +33,8 @@ class CommandLineParameter {
|
|
|
33
33
|
constructor(definition) {
|
|
34
34
|
this.longName = definition.parameterLongName;
|
|
35
35
|
this.shortName = definition.parameterShortName;
|
|
36
|
+
this.parameterGroup = definition.parameterGroup;
|
|
37
|
+
this.parameterScope = definition.parameterScope;
|
|
36
38
|
this.description = definition.description;
|
|
37
39
|
this.required = !!definition.required;
|
|
38
40
|
this.environmentVariable = definition.environmentVariable;
|
|
@@ -47,6 +49,15 @@ class CommandLineParameter {
|
|
|
47
49
|
` a dash followed by a single upper-case or lower-case letter (e.g. "-a")`);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
52
|
+
if (this.parameterScope) {
|
|
53
|
+
if (!CommandLineParameter._scopeRegExp.test(this.parameterScope)) {
|
|
54
|
+
throw new Error(`Invalid scope: "${this.parameterScope}". The parameter scope name must be` +
|
|
55
|
+
` lower-case and use dash delimiters (e.g. "my-scope")`);
|
|
56
|
+
}
|
|
57
|
+
// Parameter long name is guranteed to start with '--' since this is validated above
|
|
58
|
+
const unprefixedLongName = this.longName.slice(2);
|
|
59
|
+
this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;
|
|
60
|
+
}
|
|
50
61
|
if (this.environmentVariable) {
|
|
51
62
|
if (this.required) {
|
|
52
63
|
// TODO: This constraint is imposed only because argparse enforces "required" parameters, but
|
|
@@ -60,17 +71,14 @@ class CommandLineParameter {
|
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
73
|
if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {
|
|
63
|
-
if (this.required) {
|
|
64
|
-
throw new Error('Undocumented synonyms are not allowed on required parameters.');
|
|
65
|
-
}
|
|
66
74
|
for (const undocumentedSynonym of this.undocumentedSynonyms) {
|
|
67
75
|
if (this.longName === undocumentedSynonym) {
|
|
68
|
-
throw new Error(`Invalid name: "${undocumentedSynonym}". Undocumented
|
|
76
|
+
throw new Error(`Invalid name: "${undocumentedSynonym}". Undocumented synonyms must not be the same` +
|
|
69
77
|
` as the the long name.`);
|
|
70
78
|
}
|
|
71
79
|
else if (!CommandLineParameter._longNameRegExp.test(undocumentedSynonym)) {
|
|
72
|
-
throw new Error(`Invalid name: "${undocumentedSynonym}". All undocumented
|
|
73
|
-
|
|
80
|
+
throw new Error(`Invalid name: "${undocumentedSynonym}". All undocumented synonyms name must be lower-case and ` +
|
|
81
|
+
'use dash delimiters (e.g. "--do-a-thing")');
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -106,10 +114,15 @@ class CommandLineParameter {
|
|
|
106
114
|
}
|
|
107
115
|
}
|
|
108
116
|
exports.CommandLineParameter = CommandLineParameter;
|
|
117
|
+
// Matches kebab-case formatted strings prefixed with double dashes.
|
|
109
118
|
// Example: "--do-something"
|
|
110
119
|
CommandLineParameter._longNameRegExp = /^-(-[a-z0-9]+)+$/;
|
|
120
|
+
// Matches a single upper-case or lower-case letter prefixed with a dash.
|
|
111
121
|
// Example: "-d"
|
|
112
122
|
CommandLineParameter._shortNameRegExp = /^-[a-zA-Z]$/;
|
|
123
|
+
// Matches kebab-case formatted strings
|
|
124
|
+
// Example: "my-scope"
|
|
125
|
+
CommandLineParameter._scopeRegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
113
126
|
// "Environment variable names used by the utilities in the Shell and Utilities volume of
|
|
114
127
|
// IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)
|
|
115
128
|
// from the characters defined in Portable Character Set and do not begin with a digit."
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClasses.js","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D;;;GAGG;AACH,IAAY,wBAeX;AAfD,WAAY,wBAAwB;IAClC,6CAA6C;IAC7C,2EAAM,CAAA;IACN,2CAA2C;IAC3C,uEAAI,CAAA;IACJ,8CAA8C;IAC9C,6EAAO,CAAA;IACP,6CAA6C;IAC7C,2EAAM,CAAA;IACN,iDAAiD;IACjD,mFAAU,CAAA;IACV,iDAAiD;IACjD,mFAAU,CAAA;IACV,kDAAkD;IAClD,qFAAW,CAAA;AACb,CAAC,EAfW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAenC;AAED;;;GAGG;AACH,MAAsB,oBAAoB;IAqCxC,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,kBAAkB,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,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ACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE;YAClC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;SACH;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE;YACrE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;SACH;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;SACH;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;;AAnCH,4EAoCC;AAnCC,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument } from './CommandLineDefinition';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameter {\n // Example: \"--do-something\"\n private static _longNameRegExp: RegExp = /^-(-[a-z0-9]+)+$/;\n\n // Example: \"-d\"\n private static _shortNameRegExp: RegExp = /^-[a-zA-Z]$/;\n\n // \"Environment variable names used by the utilities in the Shell and Utilities volume of\n // IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n // from the characters defined in Portable Character Set and do not begin with a digit.\"\n // Example: \"THE_SETTING\"\n private static _environmentVariableRegExp: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public readonly shortName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this.shortName = definition.parameterShortName;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n\n if (!CommandLineParameter._longNameRegExp.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!CommandLineParameter._shortNameRegExp.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.environmentVariable) {\n if (this.required) {\n // TODO: This constraint is imposed only because argparse enforces \"required\" parameters, but\n // it does not know about ts-command-line environment variable mappings. We should fix this.\n throw new Error(\n `An \"environmentVariable\" cannot be specified for \"${this.longName}\"` +\n ` because it is a required parameter`\n );\n }\n\n if (!CommandLineParameter._environmentVariableRegExp.test(this.environmentVariable)) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n if (this.required) {\n throw new Error('Undocumented synonyms are not allowed on required parameters.');\n }\n\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented Synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!CommandLineParameter._longNameRegExp.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented Synonyms name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n }\n }\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: any): void; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected reportInvalidData(data: any): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameter {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.completions = definition.completions;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BaseClasses.js","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAK3D;;;GAGG;AACH,IAAY,wBAeX;AAfD,WAAY,wBAAwB;IAClC,6CAA6C;IAC7C,2EAAM,CAAA;IACN,2CAA2C;IAC3C,uEAAI,CAAA;IACJ,8CAA8C;IAC9C,6EAAO,CAAA;IACP,6CAA6C;IAC7C,2EAAM,CAAA;IACN,iDAAiD;IACjD,mFAAU,CAAA;IACV,iDAAiD;IACjD,mFAAU,CAAA;IACV,kDAAkD;IAClD,qFAAW,CAAA;AACb,CAAC,EAfW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAenC;AAED;;;GAGG;AACH,MAAsB,oBAAoB;IAuDxC,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,kBAAkB,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAC;QAC1D,IAAI,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;QAE5D,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC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W,0BAA0B,CAAC;AAEjE,yFAAyF;AACzF,6FAA6F;AAC7F,wFAAwF;AACxF,yBAAyB;AACV,+CAA0B,GAAW,oBAAoB,CAAC;AA+K3E;;;;;;;GAOG;AACH,MAAsB,gCAAiC,SAAQ,oBAAoB;IAUjF,gBAAgB;IAChB,YAAmB,UAAkD;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE;YAClC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;SACH;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE;YACrE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;SACH;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;SACH;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;;AAnCH,4EAoCC;AAnCC,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { IBaseCommandLineDefinition, IBaseCommandLineDefinitionWithArgument } from './CommandLineDefinition';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameter {\n // Matches kebab-case formatted strings prefixed with double dashes.\n // Example: \"--do-something\"\n private static _longNameRegExp: RegExp = /^-(-[a-z0-9]+)+$/;\n\n // Matches a single upper-case or lower-case letter prefixed with a dash.\n // Example: \"-d\"\n private static _shortNameRegExp: RegExp = /^-[a-zA-Z]$/;\n\n // Matches kebab-case formatted strings\n // Example: \"my-scope\"\n private static _scopeRegExp: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n // \"Environment variable names used by the utilities in the Shell and Utilities volume of\n // IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n // from the characters defined in Portable Character Set and do not begin with a digit.\"\n // Example: \"THE_SETTING\"\n private static _environmentVariableRegExp: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /**\n * If a parameterScope is provided, returns the scope-prefixed long name of the flag,\n * including double dashes, eg. \"--scope:do-something\". Otherwise undefined.\n */\n public readonly scopedLongName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public readonly shortName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */\n public readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */\n public readonly parameterScope: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this.shortName = definition.parameterShortName;\n this.parameterGroup = definition.parameterGroup;\n this.parameterScope = definition.parameterScope;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n\n if (!CommandLineParameter._longNameRegExp.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!CommandLineParameter._shortNameRegExp.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.parameterScope) {\n if (!CommandLineParameter._scopeRegExp.test(this.parameterScope)) {\n throw new Error(\n `Invalid scope: \"${this.parameterScope}\". The parameter scope name must be` +\n ` lower-case and use dash delimiters (e.g. \"my-scope\")`\n );\n }\n // Parameter long name is guranteed to start with '--' since this is validated above\n const unprefixedLongName: string = this.longName.slice(2);\n this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;\n }\n\n if (this.environmentVariable) {\n if (this.required) {\n // TODO: This constraint is imposed only because argparse enforces \"required\" parameters, but\n // it does not know about ts-command-line environment variable mappings. We should fix this.\n throw new Error(\n `An \"environmentVariable\" cannot be specified for \"${this.longName}\"` +\n ` because it is a required parameter`\n );\n }\n\n if (!CommandLineParameter._environmentVariableRegExp.test(this.environmentVariable)) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!CommandLineParameter._longNameRegExp.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented synonyms name must be lower-case and ` +\n 'use dash delimiters (e.g. \"--do-a-thing\")'\n );\n }\n }\n }\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: any): void; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected reportInvalidData(data: any): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameter {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.completions = definition.completions;\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SCOPING_PARAMETER_GROUP } from '../Constants';
|
|
1
2
|
/**
|
|
2
3
|
* For use with CommandLineParser, this interface represents a generic command-line parameter
|
|
3
4
|
*
|
|
@@ -12,6 +13,17 @@ export interface IBaseCommandLineDefinition {
|
|
|
12
13
|
* An optional short name for the flag including the dash, e.g. "-d"
|
|
13
14
|
*/
|
|
14
15
|
parameterShortName?: string;
|
|
16
|
+
/**
|
|
17
|
+
* An optional parameter group name, shown when invoking the tool with "--help"
|
|
18
|
+
*/
|
|
19
|
+
parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;
|
|
20
|
+
/**
|
|
21
|
+
* An optional parameter scope name, used to add a scope-prefixed parameter synonym,
|
|
22
|
+
* e.g. "--scope:do-something". Scopes provide additional flexibility for parameters
|
|
23
|
+
* in conflict resolution since when a scope is specified, parameters that have
|
|
24
|
+
* conflicting long names will be defined using only the scope-prefixed name.
|
|
25
|
+
*/
|
|
26
|
+
parameterScope?: string;
|
|
15
27
|
/**
|
|
16
28
|
* Documentation for the parameter that will be shown when invoking the tool with "--help"
|
|
17
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineDefinition.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,sCAAuC,SAAQ,0BAA0B;IACxF;;;;;;;OAOG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MA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CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iCAAkC,SAAQ,sCAAsC;CAAG;AAEpG;;;;;GAKG;AACH,MAAM,WAAW,4BAA6B,SAAQ,sCAAsC;IAC1F;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gCAAiC,SAAQ,sCAAsC;CAAG;AAEnG;;;;;GAKG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineDefinition.js","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * For use with CommandLineParser, this interface represents a generic command-line parameter\n *\n * @public\n */\nexport interface IBaseCommandLineDefinition {\n /**\n * The long name of the flag including double dashes, e.g. \"--do-something\"\n */\n parameterLongName: string;\n\n /**\n * An optional short name for the flag including the dash, e.g. \"-d\"\n */\n parameterShortName?: string;\n\n /**\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\n */\n description: string;\n\n /**\n * If true, then an error occurs if the parameter was not included on the command-line.\n */\n required?: boolean;\n\n /**\n * The name of an environment variable that the parameter value will be read from,\n * if it was omitted from the command-line. An error will be reported if the\n * environment value cannot be parsed.\n *\n * @remarks\n * The environment variable name must consist only of upper-case letters, numbers,\n * and underscores. It may not start with a number.\n *\n * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,\n * because in that case the environmentVariable would never be used.\n *\n * Syntax notes for environment variable values:\n *\n * - Choice Parameter: The value must match one of the defined choices,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Integer Parameter: The value must be an integer number,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - String Parameter: Any value is accepted, including an empty string.\n *\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\n * then it will be parsed as a JSON array, whose elements must be strings,\n * numbers, or boolean values.\n * If the string does not start with `[`, then it behaves like an\n * ordinary String Parameter: Any value is accepted, including an empty string.\n */\n environmentVariable?: string;\n\n /**\n * Specifies additional names for this parameter that are accepted but not displayed\n * in the command line help.\n *\n * @remarks\n * This option can be used in cases where a command-line parameter may have been renamed,\n * but the developer doesn't want to break backwards compatibility with systems that may\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\n */\n undocumentedSynonyms?: string[];\n}\n\n/**\n * The common base interface for parameter types that accept an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\n /**\n * The name of the argument, which will be shown in the command-line help.\n *\n * @remarks\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\n * then the command-line help would display \"--count NUMBER\". The argument name must\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\n */\n argumentName: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options. The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\n * this interface defines a command line parameter that is a boolean flag.\n *\n * @public\n */\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerParameter},\n * this interface defines a command line parameter whose argument is an integer value.\n *\n * @public\n */\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: number;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\n * this interface defines a command line parameter whose argument is an integer value. The\n * parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringParameter},\n * this interface defines a command line parameter whose argument is a string value.\n *\n * @public\n */\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * The default value which will be used if the parameter is omitted from the command line.\n *\n * @remarks\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\n * must not be true. Instead, a custom error message should be used to report cases\n * where a default value was not available.\n */\n defaultValue?: string;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\n * this interface defines a command line parameter whose argument is a single text string.\n * The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @public\n */\nexport interface ICommandLineRemainderDefinition {\n /**\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\n * the tool with \"--help\".\n */\n description: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineDefinition.js","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { SCOPING_PARAMETER_GROUP } from '../Constants';\n\n/**\n * For use with CommandLineParser, this interface represents a generic command-line parameter\n *\n * @public\n */\nexport interface IBaseCommandLineDefinition {\n /**\n * The long name of the flag including double dashes, e.g. \"--do-something\"\n */\n parameterLongName: string;\n\n /**\n * An optional short name for the flag including the dash, e.g. \"-d\"\n */\n parameterShortName?: string;\n\n /**\n * An optional parameter group name, shown when invoking the tool with \"--help\"\n */\n parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;\n\n /**\n * An optional parameter scope name, used to add a scope-prefixed parameter synonym,\n * e.g. \"--scope:do-something\". Scopes provide additional flexibility for parameters\n * in conflict resolution since when a scope is specified, parameters that have\n * conflicting long names will be defined using only the scope-prefixed name.\n */\n parameterScope?: string;\n\n /**\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\n */\n description: string;\n\n /**\n * If true, then an error occurs if the parameter was not included on the command-line.\n */\n required?: boolean;\n\n /**\n * The name of an environment variable that the parameter value will be read from,\n * if it was omitted from the command-line. An error will be reported if the\n * environment value cannot be parsed.\n *\n * @remarks\n * The environment variable name must consist only of upper-case letters, numbers,\n * and underscores. It may not start with a number.\n *\n * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,\n * because in that case the environmentVariable would never be used.\n *\n * Syntax notes for environment variable values:\n *\n * - Choice Parameter: The value must match one of the defined choices,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Integer Parameter: The value must be an integer number,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - String Parameter: Any value is accepted, including an empty string.\n *\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\n * then it will be parsed as a JSON array, whose elements must be strings,\n * numbers, or boolean values.\n * If the string does not start with `[`, then it behaves like an\n * ordinary String Parameter: Any value is accepted, including an empty string.\n */\n environmentVariable?: string;\n\n /**\n * Specifies additional names for this parameter that are accepted but not displayed\n * in the command line help.\n *\n * @remarks\n * This option can be used in cases where a command-line parameter may have been renamed,\n * but the developer doesn't want to break backwards compatibility with systems that may\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\n */\n undocumentedSynonyms?: string[];\n}\n\n/**\n * The common base interface for parameter types that accept an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\n /**\n * The name of the argument, which will be shown in the command-line help.\n *\n * @remarks\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\n * then the command-line help would display \"--count NUMBER\". The argument name must\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\n */\n argumentName: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options. The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\n * this interface defines a command line parameter that is a boolean flag.\n *\n * @public\n */\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerParameter},\n * this interface defines a command line parameter whose argument is an integer value.\n *\n * @public\n */\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: number;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\n * this interface defines a command line parameter whose argument is an integer value. The\n * parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringParameter},\n * this interface defines a command line parameter whose argument is a string value.\n *\n * @public\n */\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * The default value which will be used if the parameter is omitted from the command line.\n *\n * @remarks\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\n * must not be true. Instead, a custom error message should be used to report cases\n * where a default value was not available.\n */\n defaultValue?: string;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\n * this interface defines a command line parameter whose argument is a single text string.\n * The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @public\n */\nexport interface ICommandLineRemainderDefinition {\n /**\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\n * the tool with \"--help\".\n */\n description: string;\n}\n"]}
|