@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.
- package/CHANGELOG.json +1329 -0
- package/CHANGELOG.md +704 -0
- package/LICENSE +24 -0
- package/README.md +251 -0
- package/dist/ts-command-line.d.ts +878 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/CommandLineHelper.d.ts +14 -0
- package/lib/CommandLineHelper.d.ts.map +1 -0
- package/lib/CommandLineHelper.js +22 -0
- package/lib/CommandLineHelper.js.map +1 -0
- package/lib/Constants.d.ts +12 -0
- package/lib/Constants.d.ts.map +1 -0
- package/lib/Constants.js +5 -0
- package/lib/Constants.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/lib/parameters/BaseClasses.d.ts +100 -0
- package/lib/parameters/BaseClasses.d.ts.map +1 -0
- package/lib/parameters/BaseClasses.js +148 -0
- package/lib/parameters/BaseClasses.js.map +1 -0
- package/lib/parameters/CommandLineChoiceListParameter.d.ts +33 -0
- package/lib/parameters/CommandLineChoiceListParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineChoiceListParameter.js +84 -0
- package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -0
- package/lib/parameters/CommandLineChoiceParameter.d.ts +40 -0
- package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineChoiceParameter.js +95 -0
- package/lib/parameters/CommandLineChoiceParameter.js.map +1 -0
- package/lib/parameters/CommandLineDefinition.d.ts +207 -0
- package/lib/parameters/CommandLineDefinition.d.ts.map +1 -0
- package/lib/parameters/CommandLineDefinition.js +5 -0
- package/lib/parameters/CommandLineDefinition.js.map +1 -0
- package/lib/parameters/CommandLineFlagParameter.d.ts +29 -0
- package/lib/parameters/CommandLineFlagParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineFlagParameter.js +72 -0
- package/lib/parameters/CommandLineFlagParameter.js.map +1 -0
- package/lib/parameters/CommandLineIntegerListParameter.d.ts +29 -0
- package/lib/parameters/CommandLineIntegerListParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineIntegerListParameter.js +82 -0
- package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -0
- package/lib/parameters/CommandLineIntegerParameter.d.ts +36 -0
- package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineIntegerParameter.js +86 -0
- package/lib/parameters/CommandLineIntegerParameter.js.map +1 -0
- package/lib/parameters/CommandLineRemainder.d.ts +28 -0
- package/lib/parameters/CommandLineRemainder.d.ts.map +1 -0
- package/lib/parameters/CommandLineRemainder.js +48 -0
- package/lib/parameters/CommandLineRemainder.js.map +1 -0
- package/lib/parameters/CommandLineStringListParameter.d.ts +29 -0
- package/lib/parameters/CommandLineStringListParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineStringListParameter.js +73 -0
- package/lib/parameters/CommandLineStringListParameter.js.map +1 -0
- package/lib/parameters/CommandLineStringParameter.d.ts +36 -0
- package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -0
- package/lib/parameters/CommandLineStringParameter.js +85 -0
- package/lib/parameters/CommandLineStringParameter.js.map +1 -0
- package/lib/parameters/EnvironmentVariableParser.d.ts +10 -0
- package/lib/parameters/EnvironmentVariableParser.d.ts.map +1 -0
- package/lib/parameters/EnvironmentVariableParser.js +51 -0
- package/lib/parameters/EnvironmentVariableParser.js.map +1 -0
- package/lib/providers/CommandLineAction.d.ts +76 -0
- package/lib/providers/CommandLineAction.d.ts.map +1 -0
- package/lib/providers/CommandLineAction.js +73 -0
- package/lib/providers/CommandLineAction.js.map +1 -0
- package/lib/providers/CommandLineParameterProvider.d.ts +202 -0
- package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -0
- package/lib/providers/CommandLineParameterProvider.js +374 -0
- package/lib/providers/CommandLineParameterProvider.js.map +1 -0
- package/lib/providers/CommandLineParser.d.ts +100 -0
- package/lib/providers/CommandLineParser.d.ts.map +1 -0
- package/lib/providers/CommandLineParser.js +204 -0
- package/lib/providers/CommandLineParser.js.map +1 -0
- package/lib/providers/CommandLineParserExitError.d.ts +10 -0
- package/lib/providers/CommandLineParserExitError.d.ts.map +1 -0
- package/lib/providers/CommandLineParserExitError.js +53 -0
- package/lib/providers/CommandLineParserExitError.js.map +1 -0
- package/lib/providers/DynamicCommandLineAction.d.ts +9 -0
- package/lib/providers/DynamicCommandLineAction.d.ts.map +1 -0
- package/lib/providers/DynamicCommandLineAction.js +21 -0
- package/lib/providers/DynamicCommandLineAction.js.map +1 -0
- package/lib/providers/DynamicCommandLineParser.d.ts +8 -0
- package/lib/providers/DynamicCommandLineParser.d.ts.map +1 -0
- package/lib/providers/DynamicCommandLineParser.js +16 -0
- package/lib/providers/DynamicCommandLineParser.js.map +1 -0
- package/lib/providers/TabCompletionAction.d.ts +18 -0
- package/lib/providers/TabCompletionAction.d.ts.map +1 -0
- package/lib/providers/TabCompletionAction.js +211 -0
- package/lib/providers/TabCompletionAction.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ICommandLineChoiceDefinition } from './CommandLineDefinition';
|
|
2
|
+
import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
|
|
3
|
+
/**
|
|
4
|
+
* The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommandLineChoiceParameter extends CommandLineParameter {
|
|
8
|
+
/** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */
|
|
9
|
+
readonly alternatives: ReadonlyArray<string>;
|
|
10
|
+
/** {@inheritDoc ICommandLineStringDefinition.defaultValue} */
|
|
11
|
+
readonly defaultValue: string | undefined;
|
|
12
|
+
private _value;
|
|
13
|
+
/** {@inheritDoc ICommandLineChoiceDefinition.completions} */
|
|
14
|
+
readonly completions: (() => Promise<string[]>) | undefined;
|
|
15
|
+
/** @internal */
|
|
16
|
+
constructor(definition: ICommandLineChoiceDefinition);
|
|
17
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
18
|
+
get kind(): CommandLineParameterKind;
|
|
19
|
+
/**
|
|
20
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
_setValue(data: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
_getSupplementaryNotes(supplementaryNotes: string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the argument value for a choice parameter that was parsed from the command line.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* The return value will be `undefined` if the command-line has not been parsed yet,
|
|
34
|
+
* or if the parameter was omitted and has no default value.
|
|
35
|
+
*/
|
|
36
|
+
get value(): string | undefined;
|
|
37
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
38
|
+
appendToArgList(argList: string[]): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=CommandLineChoiceParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineChoiceParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceParameter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE/E;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,oBAAoB;IAClE,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEpD,8DAA8D;IAC9D,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjD,OAAO,CAAC,MAAM,CAAiC;IAE/C,6DAA6D;IAC7D,SAAgB,WAAW,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IAEnE,gBAAgB;gBACG,UAAU,EAAE,4BAA4B;IAqB3D,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkCjC;;;OAGG;IACI,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,IAAI;IAQjE;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,MAAM,GAAG,SAAS,CAErC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAMhD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CommandLineChoiceParameter = void 0;
|
|
6
|
+
const BaseClasses_1 = require("./BaseClasses");
|
|
7
|
+
/**
|
|
8
|
+
* The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class CommandLineChoiceParameter extends BaseClasses_1.CommandLineParameter {
|
|
12
|
+
/** @internal */
|
|
13
|
+
constructor(definition) {
|
|
14
|
+
super(definition);
|
|
15
|
+
this._value = undefined;
|
|
16
|
+
if (definition.alternatives.length < 1) {
|
|
17
|
+
throw new Error(`When defining a choice parameter, the alternatives list must contain at least one value.`);
|
|
18
|
+
}
|
|
19
|
+
if (definition.defaultValue && definition.alternatives.indexOf(definition.defaultValue) === -1) {
|
|
20
|
+
throw new Error(`The specified default value "${definition.defaultValue}"` +
|
|
21
|
+
` is not one of the available options: ${definition.alternatives.toString()}`);
|
|
22
|
+
}
|
|
23
|
+
this.alternatives = definition.alternatives;
|
|
24
|
+
this.defaultValue = definition.defaultValue;
|
|
25
|
+
this.validateDefaultValue(!!this.defaultValue);
|
|
26
|
+
this.completions = definition.completions;
|
|
27
|
+
}
|
|
28
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
29
|
+
get kind() {
|
|
30
|
+
return BaseClasses_1.CommandLineParameterKind.Choice;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
_setValue(data) {
|
|
38
|
+
// abstract
|
|
39
|
+
if (data !== null && data !== undefined) {
|
|
40
|
+
if (typeof data !== 'string') {
|
|
41
|
+
this.reportInvalidData(data);
|
|
42
|
+
}
|
|
43
|
+
this._value = data;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (this.environmentVariable !== undefined) {
|
|
47
|
+
// Try reading the environment variable
|
|
48
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
49
|
+
if (environmentValue !== undefined && environmentValue !== '') {
|
|
50
|
+
if (this.alternatives.indexOf(environmentValue) < 0) {
|
|
51
|
+
const choices = '"' + this.alternatives.join('", "') + '"';
|
|
52
|
+
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
|
|
53
|
+
` ${this.environmentVariable}. Valid choices are: ${choices}`);
|
|
54
|
+
}
|
|
55
|
+
this._value = environmentValue;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (this.defaultValue !== undefined) {
|
|
60
|
+
this._value = this.defaultValue;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._value = undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc CommandLineParameter._getSupplementaryNotes}
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
_getSupplementaryNotes(supplementaryNotes) {
|
|
70
|
+
// virtual
|
|
71
|
+
super._getSupplementaryNotes(supplementaryNotes);
|
|
72
|
+
if (this.defaultValue !== undefined) {
|
|
73
|
+
supplementaryNotes.push(`The default value is "${this.defaultValue}".`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the argument value for a choice parameter that was parsed from the command line.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The return value will be `undefined` if the command-line has not been parsed yet,
|
|
81
|
+
* or if the parameter was omitted and has no default value.
|
|
82
|
+
*/
|
|
83
|
+
get value() {
|
|
84
|
+
return this._value;
|
|
85
|
+
}
|
|
86
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
87
|
+
appendToArgList(argList) {
|
|
88
|
+
if (this.value !== undefined) {
|
|
89
|
+
argList.push(this.longName);
|
|
90
|
+
argList.push(this.value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.CommandLineChoiceParameter = CommandLineChoiceParameter;
|
|
95
|
+
//# sourceMappingURL=CommandLineChoiceParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineChoiceParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAE/E;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,kCAAoB;IAYlE,gBAAgB;IAChB,YAAmB,UAAwC;QACzD,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,WAAM,GAAuB,SAAS,CAAC;QAS7C,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAC;SACH;QACD,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE;YAC9F,MAAM,IAAI,KAAK,CACb,gCAAgC,UAAU,CAAC,YAAY,GAAG;gBACxD,yCAAyC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAChF,CAAC;SACH;QAED,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,OAAO;SACR;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,EAAE,EAAE;gBAC7D,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;oBACnD,MAAM,OAAO,GAAW,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;oBACnE,MAAM,IAAI,KAAK,CACb,kBAAkB,gBAAgB,gCAAgC;wBAChE,IAAI,IAAI,CAAC,mBAAmB,yBAAyB,OAAO,EAAE,CACjE,CAAC;iBACH;gBACD,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC;gBAC/B,OAAO;aACR;SACF;QAED,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;YACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YAChC,OAAO;SACR;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,sBAAsB,CAAC,kBAA4B;QACxD,UAAU;QACV,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;YACnC,kBAAkB,CAAC,IAAI,CAAC,yBAAyB,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;SACzE;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AA5GD,gEA4GC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { ICommandLineChoiceDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.\r\n * @public\r\n */\r\nexport class CommandLineChoiceParameter extends CommandLineParameter {\r\n /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */\r\n public readonly alternatives: ReadonlyArray<string>;\r\n\r\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\r\n public readonly defaultValue: string | undefined;\r\n\r\n private _value: string | undefined = undefined;\r\n\r\n /** {@inheritDoc ICommandLineChoiceDefinition.completions} */\r\n public readonly completions: (() => Promise<string[]>) | undefined;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineChoiceDefinition) {\r\n super(definition);\r\n\r\n if (definition.alternatives.length < 1) {\r\n throw new Error(\r\n `When defining a choice parameter, the alternatives list must contain at least one value.`\r\n );\r\n }\r\n if (definition.defaultValue && definition.alternatives.indexOf(definition.defaultValue) === -1) {\r\n throw new Error(\r\n `The specified default value \"${definition.defaultValue}\"` +\r\n ` is not one of the available options: ${definition.alternatives.toString()}`\r\n );\r\n }\r\n\r\n this.alternatives = definition.alternatives;\r\n this.defaultValue = definition.defaultValue;\r\n this.validateDefaultValue(!!this.defaultValue);\r\n this.completions = definition.completions;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.Choice;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._setValue}\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n public _setValue(data: any): void {\r\n // abstract\r\n if (data !== null && data !== undefined) {\r\n if (typeof data !== 'string') {\r\n this.reportInvalidData(data);\r\n }\r\n this._value = data;\r\n return;\r\n }\r\n\r\n if (this.environmentVariable !== undefined) {\r\n // Try reading the environment variable\r\n const environmentValue: string | undefined = process.env[this.environmentVariable];\r\n if (environmentValue !== undefined && environmentValue !== '') {\r\n if (this.alternatives.indexOf(environmentValue) < 0) {\r\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\r\n throw new Error(\r\n `Invalid value \"${environmentValue}\" for the environment variable` +\r\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\r\n );\r\n }\r\n this._value = environmentValue;\r\n return;\r\n }\r\n }\r\n\r\n if (this.defaultValue !== undefined) {\r\n this._value = this.defaultValue;\r\n return;\r\n }\r\n\r\n this._value = undefined;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._getSupplementaryNotes}\r\n * @internal\r\n */\r\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\r\n // virtual\r\n super._getSupplementaryNotes(supplementaryNotes);\r\n if (this.defaultValue !== undefined) {\r\n supplementaryNotes.push(`The default value is \"${this.defaultValue}\".`);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the argument value for a choice parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The return value will be `undefined` if the command-line has not been parsed yet,\r\n * or if the parameter was omitted and has no default value.\r\n */\r\n public get value(): string | undefined {\r\n return this._value;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.value !== undefined) {\r\n argList.push(this.longName);\r\n argList.push(this.value);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For use with CommandLineParser, this interface represents a generic command-line parameter
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface IBaseCommandLineDefinition {
|
|
7
|
+
/**
|
|
8
|
+
* The long name of the flag including double dashes, e.g. "--do-something"
|
|
9
|
+
*/
|
|
10
|
+
parameterLongName: string;
|
|
11
|
+
/**
|
|
12
|
+
* An optional short name for the flag including the dash, e.g. "-d"
|
|
13
|
+
*/
|
|
14
|
+
parameterShortName?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Documentation for the parameter that will be shown when invoking the tool with "--help"
|
|
17
|
+
*/
|
|
18
|
+
description: string;
|
|
19
|
+
/**
|
|
20
|
+
* If true, then an error occurs if the parameter was not included on the command-line.
|
|
21
|
+
*/
|
|
22
|
+
required?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The name of an environment variable that the parameter value will be read from,
|
|
25
|
+
* if it was omitted from the command-line. An error will be reported if the
|
|
26
|
+
* environment value cannot be parsed.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* The environment variable name must consist only of upper-case letters, numbers,
|
|
30
|
+
* and underscores. It may not start with a number.
|
|
31
|
+
*
|
|
32
|
+
* This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,
|
|
33
|
+
* because in that case the environmentVariable would never be used.
|
|
34
|
+
*
|
|
35
|
+
* Syntax notes for environment variable values:
|
|
36
|
+
*
|
|
37
|
+
* - Choice Parameter: The value must match one of the defined choices,
|
|
38
|
+
* otherwise a validation error is reported.
|
|
39
|
+
* An empty string causes the environment variable to be ignored.
|
|
40
|
+
*
|
|
41
|
+
* - Flag Parameter: The value must be `1` for true, or `0` for false,
|
|
42
|
+
* otherwise a validation error is reported.
|
|
43
|
+
* An empty string causes the environment variable to be ignored.
|
|
44
|
+
*
|
|
45
|
+
* - Integer Parameter: The value must be an integer number,
|
|
46
|
+
* otherwise a validation error is reported.
|
|
47
|
+
* An empty string causes the environment variable to be ignored.
|
|
48
|
+
*
|
|
49
|
+
* - String Parameter: Any value is accepted, including an empty string.
|
|
50
|
+
*
|
|
51
|
+
* - String List Parameter: If the string starts with `[` (ignoring whitespace)
|
|
52
|
+
* then it will be parsed as a JSON array, whose elements must be strings,
|
|
53
|
+
* numbers, or boolean values.
|
|
54
|
+
* If the string does not start with `[`, then it behaves like an
|
|
55
|
+
* ordinary String Parameter: Any value is accepted, including an empty string.
|
|
56
|
+
*/
|
|
57
|
+
environmentVariable?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Specifies additional names for this parameter that are accepted but not displayed
|
|
60
|
+
* in the command line help.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* This option can be used in cases where a command-line parameter may have been renamed,
|
|
64
|
+
* but the developer doesn't want to break backwards compatibility with systems that may
|
|
65
|
+
* still be using the old name. Only the `parameterLongName` syntax is currently allowed.
|
|
66
|
+
*/
|
|
67
|
+
undocumentedSynonyms?: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The common base interface for parameter types that accept an argument.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* An argument is an accompanying command-line token, such as "123" in the
|
|
74
|
+
* example "--max-count 123".
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {
|
|
78
|
+
/**
|
|
79
|
+
* The name of the argument, which will be shown in the command-line help.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* For example, if the parameter name is '--count" and the argument name is "NUMBER",
|
|
83
|
+
* then the command-line help would display "--count NUMBER". The argument name must
|
|
84
|
+
* be comprised of upper-case letters, numbers, and underscores. It should be kept short.
|
|
85
|
+
*/
|
|
86
|
+
argumentName: string;
|
|
87
|
+
/**
|
|
88
|
+
* An optional callback that provides a list of custom choices for tab completion.
|
|
89
|
+
* @remarks
|
|
90
|
+
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
|
|
91
|
+
* is enabled.
|
|
92
|
+
*/
|
|
93
|
+
completions?: () => Promise<string[]>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* For use with {@link CommandLineParameterProvider.defineChoiceParameter},
|
|
97
|
+
* this interface defines a command line parameter which is constrained to a list of possible
|
|
98
|
+
* options.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {
|
|
103
|
+
/**
|
|
104
|
+
* A list of strings (which contain no spaces), of possible options which can be selected
|
|
105
|
+
*/
|
|
106
|
+
alternatives: string[];
|
|
107
|
+
/**
|
|
108
|
+
* {@inheritDoc ICommandLineStringDefinition.defaultValue}
|
|
109
|
+
*/
|
|
110
|
+
defaultValue?: string;
|
|
111
|
+
/**
|
|
112
|
+
* An optional callback that provides a list of custom choices for tab completion.
|
|
113
|
+
* @remarks
|
|
114
|
+
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
|
|
115
|
+
* is enabled.
|
|
116
|
+
*/
|
|
117
|
+
completions?: () => Promise<string[]>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* For use with {@link CommandLineParameterProvider.defineChoiceListParameter},
|
|
121
|
+
* this interface defines a command line parameter which is constrained to a list of possible
|
|
122
|
+
* options. The parameter can be specified multiple times to build a list.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {
|
|
127
|
+
/**
|
|
128
|
+
* A list of strings (which contain no spaces), of possible options which can be selected
|
|
129
|
+
*/
|
|
130
|
+
alternatives: string[];
|
|
131
|
+
/**
|
|
132
|
+
* An optional callback that provides a list of custom choices for tab completion.
|
|
133
|
+
* @remarks
|
|
134
|
+
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
|
|
135
|
+
* is enabled.
|
|
136
|
+
*/
|
|
137
|
+
completions?: () => Promise<string[]>;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* For use with {@link CommandLineParameterProvider.defineFlagParameter},
|
|
141
|
+
* this interface defines a command line parameter that is a boolean flag.
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
*/
|
|
145
|
+
export interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* For use with {@link CommandLineParameterProvider.defineIntegerParameter},
|
|
149
|
+
* this interface defines a command line parameter whose argument is an integer value.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
export interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {
|
|
154
|
+
/**
|
|
155
|
+
* {@inheritDoc ICommandLineStringDefinition.defaultValue}
|
|
156
|
+
*/
|
|
157
|
+
defaultValue?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* For use with {@link CommandLineParameterProvider.defineIntegerListParameter},
|
|
161
|
+
* this interface defines a command line parameter whose argument is an integer value. The
|
|
162
|
+
* parameter can be specified multiple times to build a list.
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
export interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* For use with {@link CommandLineParameterProvider.defineStringParameter},
|
|
170
|
+
* this interface defines a command line parameter whose argument is a string value.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
export interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {
|
|
175
|
+
/**
|
|
176
|
+
* The default value which will be used if the parameter is omitted from the command line.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* If a default value is specified, then {@link IBaseCommandLineDefinition.required}
|
|
180
|
+
* must not be true. Instead, a custom error message should be used to report cases
|
|
181
|
+
* where a default value was not available.
|
|
182
|
+
*/
|
|
183
|
+
defaultValue?: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* For use with {@link CommandLineParameterProvider.defineStringListParameter},
|
|
187
|
+
* this interface defines a command line parameter whose argument is a single text string.
|
|
188
|
+
* The parameter can be specified multiple times to build a list.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
export interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},
|
|
196
|
+
* this interface defines a rule that captures any remaining command line arguments after the recognized portion.
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
export interface ICommandLineRemainderDefinition {
|
|
201
|
+
/**
|
|
202
|
+
* Documentation for how the remaining arguments will be used. This will be shown when invoking
|
|
203
|
+
* the tool with "--help".
|
|
204
|
+
*/
|
|
205
|
+
description: string;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=CommandLineDefinition.d.ts.map
|
|
@@ -0,0 +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,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,4BAA6B,SAAQ,0BAA0B;IAC9E;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gCAAiC,SAAQ,0BAA0B;IAClF;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA2B,SAAQ,0BAA0B;CAAG;AAEjF;;;;;GAKG;AACH,MAAM,WAAW,6BAA8B,SAAQ,sCAAsC;IAC3F;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
//# sourceMappingURL=CommandLineDefinition.js.map
|
|
@@ -0,0 +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.\r\n// See LICENSE in the project root for license information.\r\n\r\n/**\r\n * For use with CommandLineParser, this interface represents a generic command-line parameter\r\n *\r\n * @public\r\n */\r\nexport interface IBaseCommandLineDefinition {\r\n /**\r\n * The long name of the flag including double dashes, e.g. \"--do-something\"\r\n */\r\n parameterLongName: string;\r\n\r\n /**\r\n * An optional short name for the flag including the dash, e.g. \"-d\"\r\n */\r\n parameterShortName?: string;\r\n\r\n /**\r\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\r\n */\r\n description: string;\r\n\r\n /**\r\n * If true, then an error occurs if the parameter was not included on the command-line.\r\n */\r\n required?: boolean;\r\n\r\n /**\r\n * The name of an environment variable that the parameter value will be read from,\r\n * if it was omitted from the command-line. An error will be reported if the\r\n * environment value cannot be parsed.\r\n *\r\n * @remarks\r\n * The environment variable name must consist only of upper-case letters, numbers,\r\n * and underscores. It may not start with a number.\r\n *\r\n * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,\r\n * because in that case the environmentVariable would never be used.\r\n *\r\n * Syntax notes for environment variable values:\r\n *\r\n * - Choice Parameter: The value must match one of the defined choices,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - Integer Parameter: The value must be an integer number,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - String Parameter: Any value is accepted, including an empty string.\r\n *\r\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\r\n * then it will be parsed as a JSON array, whose elements must be strings,\r\n * numbers, or boolean values.\r\n * If the string does not start with `[`, then it behaves like an\r\n * ordinary String Parameter: Any value is accepted, including an empty string.\r\n */\r\n environmentVariable?: string;\r\n\r\n /**\r\n * Specifies additional names for this parameter that are accepted but not displayed\r\n * in the command line help.\r\n *\r\n * @remarks\r\n * This option can be used in cases where a command-line parameter may have been renamed,\r\n * but the developer doesn't want to break backwards compatibility with systems that may\r\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\r\n */\r\n undocumentedSynonyms?: string[];\r\n}\r\n\r\n/**\r\n * The common base interface for parameter types that accept an argument.\r\n *\r\n * @remarks\r\n * An argument is an accompanying command-line token, such as \"123\" in the\r\n * example \"--max-count 123\".\r\n * @public\r\n */\r\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\r\n /**\r\n * The name of the argument, which will be shown in the command-line help.\r\n *\r\n * @remarks\r\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\r\n * then the command-line help would display \"--count NUMBER\". The argument name must\r\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\r\n */\r\n argumentName: string;\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineChoiceParameter},\r\n * this interface defines a command line parameter which is constrained to a list of possible\r\n * options.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {\r\n /**\r\n * A list of strings (which contain no spaces), of possible options which can be selected\r\n */\r\n alternatives: string[];\r\n\r\n /**\r\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\r\n */\r\n defaultValue?: string;\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\r\n * this interface defines a command line parameter which is constrained to a list of possible\r\n * options. The parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {\r\n /**\r\n * A list of strings (which contain no spaces), of possible options which can be selected\r\n */\r\n alternatives: string[];\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\r\n * this interface defines a command line parameter that is a boolean flag.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineIntegerParameter},\r\n * this interface defines a command line parameter whose argument is an integer value.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\r\n /**\r\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\r\n */\r\n defaultValue?: number;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\r\n * this interface defines a command line parameter whose argument is an integer value. The\r\n * parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineStringParameter},\r\n * this interface defines a command line parameter whose argument is a string value.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\r\n /**\r\n * The default value which will be used if the parameter is omitted from the command line.\r\n *\r\n * @remarks\r\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\r\n * must not be true. Instead, a custom error message should be used to report cases\r\n * where a default value was not available.\r\n */\r\n defaultValue?: string;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\r\n * this interface defines a command line parameter whose argument is a single text string.\r\n * The parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\r\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineRemainderDefinition {\r\n /**\r\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\r\n * the tool with \"--help\".\r\n */\r\n description: string;\r\n}\r\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ICommandLineFlagDefinition } from './CommandLineDefinition';
|
|
2
|
+
import { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';
|
|
3
|
+
/**
|
|
4
|
+
* The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommandLineFlagParameter extends CommandLineParameter {
|
|
8
|
+
private _value;
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition: ICommandLineFlagDefinition);
|
|
11
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
12
|
+
get kind(): CommandLineParameterKind;
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
_setValue(data: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a boolean indicating whether the parameter was included in the command line.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* The return value will be false if the command-line has not been parsed yet,
|
|
23
|
+
* or if the flag was not used.
|
|
24
|
+
*/
|
|
25
|
+
get value(): boolean;
|
|
26
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
27
|
+
appendToArgList(argList: string[]): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=CommandLineFlagParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineFlagParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineFlagParameter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE/E;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,oBAAoB;IAChE,OAAO,CAAC,MAAM,CAAkB;IAEhC,gBAAgB;gBACG,UAAU,EAAE,0BAA0B;IAIzD,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAkCjC;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAKhD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CommandLineFlagParameter = void 0;
|
|
6
|
+
const BaseClasses_1 = require("./BaseClasses");
|
|
7
|
+
/**
|
|
8
|
+
* The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class CommandLineFlagParameter extends BaseClasses_1.CommandLineParameter {
|
|
12
|
+
/** @internal */
|
|
13
|
+
constructor(definition) {
|
|
14
|
+
super(definition);
|
|
15
|
+
this._value = false;
|
|
16
|
+
}
|
|
17
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
18
|
+
get kind() {
|
|
19
|
+
return BaseClasses_1.CommandLineParameterKind.Flag;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
_setValue(data) {
|
|
27
|
+
// abstract
|
|
28
|
+
if (data !== null && data !== undefined) {
|
|
29
|
+
if (typeof data !== 'boolean') {
|
|
30
|
+
this.reportInvalidData(data);
|
|
31
|
+
}
|
|
32
|
+
// If the flag is omitted, then argparse sets the data to "false" instead of "undefined".
|
|
33
|
+
// This design prevents a syntax such as "--flag=false", probably because argparse prefers "--no-flag".
|
|
34
|
+
// If we switch to a new CLI parser, we should try to add support for "--flag=false".
|
|
35
|
+
if (data) {
|
|
36
|
+
this._value = data;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (this.environmentVariable !== undefined) {
|
|
41
|
+
// Try reading the environment variable
|
|
42
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
43
|
+
if (environmentValue !== undefined && environmentValue !== '') {
|
|
44
|
+
if (environmentValue !== '0' && environmentValue !== '1') {
|
|
45
|
+
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
|
|
46
|
+
` ${this.environmentVariable}. Valid choices are 0 or 1.`);
|
|
47
|
+
}
|
|
48
|
+
this._value = environmentValue === '1';
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this._value = false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns a boolean indicating whether the parameter was included in the command line.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* The return value will be false if the command-line has not been parsed yet,
|
|
59
|
+
* or if the flag was not used.
|
|
60
|
+
*/
|
|
61
|
+
get value() {
|
|
62
|
+
return this._value;
|
|
63
|
+
}
|
|
64
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
65
|
+
appendToArgList(argList) {
|
|
66
|
+
if (this.value) {
|
|
67
|
+
argList.push(this.longName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.CommandLineFlagParameter = CommandLineFlagParameter;
|
|
72
|
+
//# sourceMappingURL=CommandLineFlagParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineFlagParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineFlagParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAE/E;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,kCAAoB;IAGhE,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAY,KAAK,CAAC;IAKhC,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,IAAI,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE;gBAC7B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YAED,yFAAyF;YACzF,uGAAuG;YACvG,qFAAqF;YACrF,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,OAAO;aACR;SACF;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,EAAE,EAAE;gBAC7D,IAAI,gBAAgB,KAAK,GAAG,IAAI,gBAAgB,KAAK,GAAG,EAAE;oBACxD,MAAM,IAAI,KAAK,CACb,kBAAkB,gBAAgB,gCAAgC;wBAChE,IAAI,IAAI,CAAC,mBAAmB,8BAA8B,CAC7D,CAAC;iBACH;gBACD,IAAI,CAAC,MAAM,GAAG,gBAAgB,KAAK,GAAG,CAAC;gBACvC,OAAO;aACR;SACF;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;CACF;AArED,4DAqEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { ICommandLineFlagDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.\r\n * @public\r\n */\r\nexport class CommandLineFlagParameter extends CommandLineParameter {\r\n private _value: boolean = false;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineFlagDefinition) {\r\n super(definition);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.Flag;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._setValue}\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n public _setValue(data: any): void {\r\n // abstract\r\n if (data !== null && data !== undefined) {\r\n if (typeof data !== 'boolean') {\r\n this.reportInvalidData(data);\r\n }\r\n\r\n // If the flag is omitted, then argparse sets the data to \"false\" instead of \"undefined\".\r\n // This design prevents a syntax such as \"--flag=false\", probably because argparse prefers \"--no-flag\".\r\n // If we switch to a new CLI parser, we should try to add support for \"--flag=false\".\r\n if (data) {\r\n this._value = data;\r\n return;\r\n }\r\n }\r\n\r\n if (this.environmentVariable !== undefined) {\r\n // Try reading the environment variable\r\n const environmentValue: string | undefined = process.env[this.environmentVariable];\r\n if (environmentValue !== undefined && environmentValue !== '') {\r\n if (environmentValue !== '0' && environmentValue !== '1') {\r\n throw new Error(\r\n `Invalid value \"${environmentValue}\" for the environment variable` +\r\n ` ${this.environmentVariable}. Valid choices are 0 or 1.`\r\n );\r\n }\r\n this._value = environmentValue === '1';\r\n return;\r\n }\r\n }\r\n\r\n this._value = false;\r\n }\r\n\r\n /**\r\n * Returns a boolean indicating whether the parameter was included in the command line.\r\n *\r\n * @remarks\r\n * The return value will be false if the command-line has not been parsed yet,\r\n * or if the flag was not used.\r\n */\r\n public get value(): boolean {\r\n return this._value;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.value) {\r\n argList.push(this.longName);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ICommandLineIntegerListDefinition } from './CommandLineDefinition';
|
|
2
|
+
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
|
|
3
|
+
/**
|
|
4
|
+
* The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {
|
|
8
|
+
private _values;
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition: ICommandLineIntegerListDefinition);
|
|
11
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
12
|
+
get kind(): CommandLineParameterKind;
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
_setValue(data: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the integer arguments for an integer list parameter that was parsed from the command line.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* The array will be empty if the command-line has not been parsed yet,
|
|
23
|
+
* or if the parameter was omitted and has no default value.
|
|
24
|
+
*/
|
|
25
|
+
get values(): ReadonlyArray<number>;
|
|
26
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
27
|
+
appendToArgList(argList: string[]): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=CommandLineIntegerListParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineIntegerListParameter.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG3F;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,gCAAgC;IACnF,OAAO,CAAC,OAAO,CAAgB;IAE/B,gBAAgB;gBACG,UAAU,EAAE,iCAAiC;IAIhE,8CAA8C;IAC9C,IAAW,IAAI,IAAI,wBAAwB,CAE1C;IAED;;;OAGG;IAEI,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAwCjC;;;;;;OAMG;IACH,IAAW,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAEzC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;CAQhD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CommandLineIntegerListParameter = void 0;
|
|
6
|
+
const BaseClasses_1 = require("./BaseClasses");
|
|
7
|
+
const EnvironmentVariableParser_1 = require("./EnvironmentVariableParser");
|
|
8
|
+
/**
|
|
9
|
+
* The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class CommandLineIntegerListParameter extends BaseClasses_1.CommandLineParameterWithArgument {
|
|
13
|
+
/** @internal */
|
|
14
|
+
constructor(definition) {
|
|
15
|
+
super(definition);
|
|
16
|
+
this._values = [];
|
|
17
|
+
}
|
|
18
|
+
/** {@inheritDoc CommandLineParameter.kind} */
|
|
19
|
+
get kind() {
|
|
20
|
+
return BaseClasses_1.CommandLineParameterKind.IntegerList;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* {@inheritDoc CommandLineParameter._setValue}
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
_setValue(data) {
|
|
28
|
+
// If argparse passed us a value, confirm it is valid
|
|
29
|
+
if (data !== null && data !== undefined) {
|
|
30
|
+
if (!Array.isArray(data)) {
|
|
31
|
+
this.reportInvalidData(data);
|
|
32
|
+
}
|
|
33
|
+
for (const arrayItem of data) {
|
|
34
|
+
if (typeof arrayItem !== 'number') {
|
|
35
|
+
this.reportInvalidData(data);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this._values = data;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// If an environment variable exists, attempt to parse it as a list
|
|
42
|
+
if (this.environmentVariable !== undefined) {
|
|
43
|
+
const values = EnvironmentVariableParser_1.EnvironmentVariableParser.parseAsList(this.environmentVariable);
|
|
44
|
+
if (values) {
|
|
45
|
+
const parsedValues = [];
|
|
46
|
+
for (const value of values) {
|
|
47
|
+
const parsed = parseInt(value, 10);
|
|
48
|
+
if (isNaN(parsed) || value.indexOf('.') >= 0) {
|
|
49
|
+
throw new Error(`Invalid value "${value}" for the environment variable` +
|
|
50
|
+
` ${this.environmentVariable}. It must be an integer value.`);
|
|
51
|
+
}
|
|
52
|
+
parsedValues.push(parsed);
|
|
53
|
+
}
|
|
54
|
+
this._values = parsedValues;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// (No default value for integer lists)
|
|
59
|
+
this._values = [];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the integer arguments for an integer list parameter that was parsed from the command line.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* The array will be empty if the command-line has not been parsed yet,
|
|
66
|
+
* or if the parameter was omitted and has no default value.
|
|
67
|
+
*/
|
|
68
|
+
get values() {
|
|
69
|
+
return this._values;
|
|
70
|
+
}
|
|
71
|
+
/** {@inheritDoc CommandLineParameter.appendToArgList} @override */
|
|
72
|
+
appendToArgList(argList) {
|
|
73
|
+
if (this.values.length > 0) {
|
|
74
|
+
for (const value of this.values) {
|
|
75
|
+
argList.push(this.longName);
|
|
76
|
+
argList.push(String(value));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.CommandLineIntegerListParameter = CommandLineIntegerListParameter;
|
|
82
|
+
//# sourceMappingURL=CommandLineIntegerListParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineIntegerListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,8CAAgC;IAGnF,gBAAgB;IAChB,YAAmB,UAA6C;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,WAAW,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;gBAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;iBAC9B;aACF;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;SACR;QAED,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,MAAM,MAAM,GAAyB,qDAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE;gBACV,MAAM,YAAY,GAAa,EAAE,CAAC;gBAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;oBAC1B,MAAM,MAAM,GAAW,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAC3C,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;wBAC5C,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,gCAAgC;4BACrD,IAAI,IAAI,CAAC,mBAAmB,iCAAiC,CAChE,CAAC;qBACH;oBACD,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;iBAC3B;gBACD,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;gBAC5B,OAAO;aACR;SACF;QAED,uCAAuC;QAEvC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7B;SACF;IACH,CAAC;CACF;AA9ED,0EA8EC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { ICommandLineIntegerListDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\r\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.\r\n * @public\r\n */\r\nexport class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {\r\n private _values: number[] = [];\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineIntegerListDefinition) {\r\n super(definition);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.IntegerList;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._setValue}\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n public _setValue(data: any): void {\r\n // If argparse passed us a value, confirm it is valid\r\n if (data !== null && data !== undefined) {\r\n if (!Array.isArray(data)) {\r\n this.reportInvalidData(data);\r\n }\r\n for (const arrayItem of data) {\r\n if (typeof arrayItem !== 'number') {\r\n this.reportInvalidData(data);\r\n }\r\n }\r\n this._values = data;\r\n return;\r\n }\r\n\r\n // If an environment variable exists, attempt to parse it as a list\r\n if (this.environmentVariable !== undefined) {\r\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\r\n if (values) {\r\n const parsedValues: number[] = [];\r\n for (const value of values) {\r\n const parsed: number = parseInt(value, 10);\r\n if (isNaN(parsed) || value.indexOf('.') >= 0) {\r\n throw new Error(\r\n `Invalid value \"${value}\" for the environment variable` +\r\n ` ${this.environmentVariable}. It must be an integer value.`\r\n );\r\n }\r\n parsedValues.push(parsed);\r\n }\r\n this._values = parsedValues;\r\n return;\r\n }\r\n }\r\n\r\n // (No default value for integer lists)\r\n\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Returns the integer arguments for an integer list parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The array will be empty if the command-line has not been parsed yet,\r\n * or if the parameter was omitted and has no default value.\r\n */\r\n public get values(): ReadonlyArray<number> {\r\n return this._values;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.values.length > 0) {\r\n for (const value of this.values) {\r\n argList.push(this.longName);\r\n argList.push(String(value));\r\n }\r\n }\r\n }\r\n}\r\n"]}
|