@rushstack/ts-command-line 5.1.7 → 5.3.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/CHANGELOG.json +32 -0
- package/CHANGELOG.md +15 -1
- package/dist/ts-command-line.d.ts +2 -3
- package/{lib → lib-commonjs}/providers/CommandLineParser.js +3 -5
- package/lib-commonjs/providers/CommandLineParser.js.map +1 -0
- package/{lib → lib-dts}/providers/CommandLineParser.d.ts +2 -3
- package/lib-dts/providers/CommandLineParser.d.ts.map +1 -0
- package/lib-esm/CommandLineHelper.js +19 -0
- package/lib-esm/CommandLineHelper.js.map +1 -0
- package/lib-esm/Constants.js +16 -0
- package/lib-esm/Constants.js.map +1 -0
- package/lib-esm/TypeUuidLite.js +28 -0
- package/lib-esm/TypeUuidLite.js.map +1 -0
- package/lib-esm/escapeSprintf.js +9 -0
- package/lib-esm/escapeSprintf.js.map +1 -0
- package/lib-esm/index.js +26 -0
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/parameters/BaseClasses.js +163 -0
- package/lib-esm/parameters/BaseClasses.js.map +1 -0
- package/lib-esm/parameters/CommandLineChoiceListParameter.js +79 -0
- package/lib-esm/parameters/CommandLineChoiceListParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineChoiceParameter.js +90 -0
- package/lib-esm/parameters/CommandLineChoiceParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineDefinition.js +4 -0
- package/lib-esm/parameters/CommandLineDefinition.js.map +1 -0
- package/lib-esm/parameters/CommandLineFlagParameter.js +65 -0
- package/lib-esm/parameters/CommandLineFlagParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineIntegerListParameter.js +75 -0
- package/lib-esm/parameters/CommandLineIntegerListParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineIntegerParameter.js +79 -0
- package/lib-esm/parameters/CommandLineIntegerParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineRemainder.js +43 -0
- package/lib-esm/parameters/CommandLineRemainder.js.map +1 -0
- package/lib-esm/parameters/CommandLineStringListParameter.js +66 -0
- package/lib-esm/parameters/CommandLineStringListParameter.js.map +1 -0
- package/lib-esm/parameters/CommandLineStringParameter.js +78 -0
- package/lib-esm/parameters/CommandLineStringParameter.js.map +1 -0
- package/lib-esm/parameters/EnvironmentVariableParser.js +47 -0
- package/lib-esm/parameters/EnvironmentVariableParser.js.map +1 -0
- package/lib-esm/providers/AliasCommandLineAction.js +131 -0
- package/lib-esm/providers/AliasCommandLineAction.js.map +1 -0
- package/lib-esm/providers/CommandLineAction.js +76 -0
- package/lib-esm/providers/CommandLineAction.js.map +1 -0
- package/lib-esm/providers/CommandLineParameterProvider.js +671 -0
- package/lib-esm/providers/CommandLineParameterProvider.js.map +1 -0
- package/lib-esm/providers/CommandLineParser.js +262 -0
- package/lib-esm/providers/CommandLineParser.js.map +1 -0
- package/lib-esm/providers/CommandLineParserExitError.js +27 -0
- package/lib-esm/providers/CommandLineParserExitError.js.map +1 -0
- package/lib-esm/providers/DynamicCommandLineAction.js +13 -0
- package/lib-esm/providers/DynamicCommandLineAction.js.map +1 -0
- package/lib-esm/providers/DynamicCommandLineParser.js +9 -0
- package/lib-esm/providers/DynamicCommandLineParser.js.map +1 -0
- package/lib-esm/providers/ScopedCommandLineAction.js +197 -0
- package/lib-esm/providers/ScopedCommandLineAction.js.map +1 -0
- package/lib-esm/providers/TabCompletionAction.js +166 -0
- package/lib-esm/providers/TabCompletionAction.js.map +1 -0
- package/package.json +28 -6
- package/lib/providers/CommandLineParser.d.ts.map +0 -1
- package/lib/providers/CommandLineParser.js.map +0 -1
- /package/{lib → lib-commonjs}/CommandLineHelper.js +0 -0
- /package/{lib → lib-commonjs}/CommandLineHelper.js.map +0 -0
- /package/{lib → lib-commonjs}/Constants.js +0 -0
- /package/{lib → lib-commonjs}/Constants.js.map +0 -0
- /package/{lib → lib-commonjs}/TypeUuidLite.js +0 -0
- /package/{lib → lib-commonjs}/TypeUuidLite.js.map +0 -0
- /package/{lib → lib-commonjs}/escapeSprintf.js +0 -0
- /package/{lib → lib-commonjs}/escapeSprintf.js.map +0 -0
- /package/{lib → lib-commonjs}/index.js +0 -0
- /package/{lib → lib-commonjs}/index.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/BaseClasses.js +0 -0
- /package/{lib → lib-commonjs}/parameters/BaseClasses.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineChoiceListParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineChoiceListParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineChoiceParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineChoiceParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineDefinition.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineDefinition.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineFlagParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineFlagParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineIntegerListParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineIntegerListParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineIntegerParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineIntegerParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineRemainder.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineRemainder.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineStringListParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineStringListParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineStringParameter.js +0 -0
- /package/{lib → lib-commonjs}/parameters/CommandLineStringParameter.js.map +0 -0
- /package/{lib → lib-commonjs}/parameters/EnvironmentVariableParser.js +0 -0
- /package/{lib → lib-commonjs}/parameters/EnvironmentVariableParser.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/AliasCommandLineAction.js +0 -0
- /package/{lib → lib-commonjs}/providers/AliasCommandLineAction.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineAction.js +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineAction.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineParameterProvider.js +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineParameterProvider.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineParserExitError.js +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineParserExitError.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/DynamicCommandLineAction.js +0 -0
- /package/{lib → lib-commonjs}/providers/DynamicCommandLineAction.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/DynamicCommandLineParser.js +0 -0
- /package/{lib → lib-commonjs}/providers/DynamicCommandLineParser.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/ScopedCommandLineAction.js +0 -0
- /package/{lib → lib-commonjs}/providers/ScopedCommandLineAction.js.map +0 -0
- /package/{lib → lib-commonjs}/providers/TabCompletionAction.js +0 -0
- /package/{lib → lib-commonjs}/providers/TabCompletionAction.js.map +0 -0
- /package/{lib → lib-dts}/CommandLineHelper.d.ts +0 -0
- /package/{lib → lib-dts}/CommandLineHelper.d.ts.map +0 -0
- /package/{lib → lib-dts}/Constants.d.ts +0 -0
- /package/{lib → lib-dts}/Constants.d.ts.map +0 -0
- /package/{lib → lib-dts}/TypeUuidLite.d.ts +0 -0
- /package/{lib → lib-dts}/TypeUuidLite.d.ts.map +0 -0
- /package/{lib → lib-dts}/escapeSprintf.d.ts +0 -0
- /package/{lib → lib-dts}/escapeSprintf.d.ts.map +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/BaseClasses.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/BaseClasses.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineChoiceListParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineChoiceListParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineChoiceParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineChoiceParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineDefinition.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineDefinition.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineFlagParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineFlagParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineIntegerListParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineIntegerListParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineIntegerParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineIntegerParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineRemainder.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineRemainder.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineStringListParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineStringListParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineStringParameter.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/CommandLineStringParameter.d.ts.map +0 -0
- /package/{lib → lib-dts}/parameters/EnvironmentVariableParser.d.ts +0 -0
- /package/{lib → lib-dts}/parameters/EnvironmentVariableParser.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/AliasCommandLineAction.d.ts +0 -0
- /package/{lib → lib-dts}/providers/AliasCommandLineAction.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/CommandLineAction.d.ts +0 -0
- /package/{lib → lib-dts}/providers/CommandLineAction.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/CommandLineParameterProvider.d.ts +0 -0
- /package/{lib → lib-dts}/providers/CommandLineParameterProvider.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/CommandLineParserExitError.d.ts +0 -0
- /package/{lib → lib-dts}/providers/CommandLineParserExitError.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/DynamicCommandLineAction.d.ts +0 -0
- /package/{lib → lib-dts}/providers/DynamicCommandLineAction.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/DynamicCommandLineParser.d.ts +0 -0
- /package/{lib → lib-dts}/providers/DynamicCommandLineParser.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/ScopedCommandLineAction.d.ts +0 -0
- /package/{lib → lib-dts}/providers/ScopedCommandLineAction.d.ts.map +0 -0
- /package/{lib → lib-dts}/providers/TabCompletionAction.d.ts +0 -0
- /package/{lib → lib-dts}/providers/TabCompletionAction.d.ts.map +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineChoiceListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAG3D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,MAAM,OAAO,8BAEX,SAAQ,wBAAwB;IAYhC,gBAAgB;IAChB,YAAmB,UAAqD;QACtE,KAAK,CAAC,UAAU,CAAC,CAAC;QAVZ,YAAO,GAAc,EAAE,CAAC;QAKhC,kDAAkD;QAClC,SAAI,GAAwC,wBAAwB,CAAC,UAAU,CAAC;QAK9F,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;QAEjD,MAAM,eAAe,GAAiB,YAAY,YAAY,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QACzG,IAAI,eAAe,CA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AC;oBACJ,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,OAAO,GAAG,MAAmB,CAAC;gBACnC,OAAO;YACT,CAAC;QACH,CAAC;QAED,sCAAsC;QAEtC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;CACF","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 { ICommandLineChoiceListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.\n * @public\n */\nexport class CommandLineChoiceListParameter<\n TChoice extends string = string\n> extends CommandLineParameterBase {\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\n public readonly alternatives: ReadonlySet<TChoice>;\n\n private _values: TChoice[] = [];\n\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\n public readonly completions: (() => Promise<ReadonlyArray<TChoice> | ReadonlySet<TChoice>>) | undefined;\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.ChoiceList = CommandLineParameterKind.ChoiceList;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceListDefinition<TChoice>) {\n super(definition);\n const { alternatives, completions } = definition;\n\n const alternativesSet: Set<TChoice> = alternatives instanceof Set ? alternatives : new Set(alternatives);\n if (alternativesSet.size < 1) {\n throw new Error(\n `When defining a choice list parameter, the alternatives list must contain at least one value.`\n );\n }\n\n this.alternatives = alternativesSet;\n this.completions = completions;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'string') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n for (const value of values) {\n if (!this.alternatives.has(value as TChoice)) {\n const choices: string = '\"' + Array.from(this.alternatives).join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\n }\n\n this._values = values as TChoice[];\n return;\n }\n }\n\n // (No default value for choice lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a choice list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get values(): ReadonlyArray<TChoice> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value);\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
/**
|
|
5
|
+
* The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:1)}.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class CommandLineChoiceParameter extends CommandLineParameterBase {
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition) {
|
|
11
|
+
super(definition);
|
|
12
|
+
this._value = undefined;
|
|
13
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
14
|
+
this.kind = -CommandLineParameterKind.Choice;
|
|
15
|
+
const { alternatives, defaultValue, completions } = definition;
|
|
16
|
+
const alternativesSet = alternatives instanceof Set ? alternatives : new Set(alternatives);
|
|
17
|
+
if (alternativesSet.size < 1) {
|
|
18
|
+
throw new Error(`When defining a choice parameter, the alternatives list must contain at least one value.`);
|
|
19
|
+
}
|
|
20
|
+
if (defaultValue && !alternativesSet.has(defaultValue)) {
|
|
21
|
+
throw new Error(`The specified default value "${defaultValue}"` +
|
|
22
|
+
` is not one of the available options: ${alternatives.toString()}`);
|
|
23
|
+
}
|
|
24
|
+
this.alternatives = alternativesSet;
|
|
25
|
+
this.defaultValue = defaultValue;
|
|
26
|
+
this.validateDefaultValue(!!this.defaultValue);
|
|
27
|
+
this.completions = completions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_setValue(data) {
|
|
34
|
+
// abstract
|
|
35
|
+
if (data !== null && data !== undefined) {
|
|
36
|
+
if (typeof data !== 'string') {
|
|
37
|
+
this.reportInvalidData(data);
|
|
38
|
+
}
|
|
39
|
+
this._value = data;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (this.environmentVariable !== undefined) {
|
|
43
|
+
// Try reading the environment variable
|
|
44
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
45
|
+
if (environmentValue !== undefined && environmentValue !== '') {
|
|
46
|
+
if (!this.alternatives.has(environmentValue)) {
|
|
47
|
+
const choices = '"' + Array.from(this.alternatives).join('", "') + '"';
|
|
48
|
+
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
|
|
49
|
+
` ${this.environmentVariable}. Valid choices are: ${choices}`);
|
|
50
|
+
}
|
|
51
|
+
this._value = environmentValue;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (this.defaultValue !== undefined) {
|
|
56
|
+
this._value = this.defaultValue;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._value = undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
_getSupplementaryNotes(supplementaryNotes) {
|
|
66
|
+
// virtual
|
|
67
|
+
super._getSupplementaryNotes(supplementaryNotes);
|
|
68
|
+
if (this.defaultValue !== undefined) {
|
|
69
|
+
supplementaryNotes.push(`The default value is "${this.defaultValue}".`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the argument value for a choice parameter that was parsed from the command line.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The return value will be `undefined` if the command-line has not been parsed yet,
|
|
77
|
+
* or if the parameter was omitted and has no default value.
|
|
78
|
+
*/
|
|
79
|
+
get value() {
|
|
80
|
+
return this._value;
|
|
81
|
+
}
|
|
82
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
83
|
+
appendToArgList(argList) {
|
|
84
|
+
if (this.value !== undefined) {
|
|
85
|
+
argList.push(this.longName);
|
|
86
|
+
argList.push(this.value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=CommandLineChoiceParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineChoiceParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceParameter.ts"],"names":[],"mappings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G;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","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 { ICommandLineChoiceDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:2)}.\n * @public\n */\nexport interface IRequiredCommandLineChoiceParameter<TChoice extends string = string>\n extends CommandLineChoiceParameter<TChoice> {\n readonly value: TChoice;\n}\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineChoiceParameter:1)}.\n * @public\n */\nexport class CommandLineChoiceParameter<TChoice extends string = string> extends CommandLineParameterBase {\n /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */\n public readonly alternatives: ReadonlySet<TChoice>;\n\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: TChoice | undefined;\n\n private _value: TChoice | undefined = undefined;\n\n /** {@inheritDoc ICommandLineChoiceDefinition.completions} */\n public readonly completions: (() => Promise<ReadonlyArray<TChoice> | ReadonlySet<TChoice>>) | undefined;\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.Choice = -CommandLineParameterKind.Choice;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceDefinition<TChoice>) {\n super(definition);\n const { alternatives, defaultValue, completions } = definition;\n\n const alternativesSet: Set<TChoice> = alternatives instanceof Set ? alternatives : new Set(alternatives);\n if (alternativesSet.size < 1) {\n throw new Error(\n `When defining a choice parameter, the alternatives list must contain at least one value.`\n );\n }\n if (defaultValue && !alternativesSet.has(defaultValue)) {\n throw new Error(\n `The specified default value \"${defaultValue}\"` +\n ` is not one of the available options: ${alternatives.toString()}`\n );\n }\n\n this.alternatives = alternativesSet;\n this.defaultValue = defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n this.completions = completions;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'string') {\n this.reportInvalidData(data);\n }\n this._value = data as TChoice;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined && environmentValue !== '') {\n if (!this.alternatives.has(environmentValue as TChoice)) {\n const choices: string = '\"' + Array.from(this.alternatives).join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\n\n this._value = environmentValue as TChoice;\n return;\n }\n }\n\n if (this.defaultValue !== undefined) {\n this._value = this.defaultValue;\n return;\n }\n\n this._value = undefined;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n super._getSupplementaryNotes(supplementaryNotes);\n if (this.defaultValue !== undefined) {\n supplementaryNotes.push(`The default value is \"${this.defaultValue}\".`);\n }\n }\n\n /**\n * Returns the argument value for a choice parameter that was parsed from the command line.\n *\n * @remarks\n * The return value will be `undefined` if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get value(): TChoice | undefined {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value !== undefined) {\n argList.push(this.longName);\n argList.push(this.value);\n }\n }\n}\n"]}
|
|
@@ -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.\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. To disable this validation, set\n * `{@link IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames}`\n * to `true`.\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 * Allows for the use of environment variable names that do not conform to the standard\n * described by the Shell and Utilities volume of IEEE Std 1003.1-2001. This disables\n * the validation that is performed on the provided\n * {@link IBaseCommandLineDefinition.environmentVariable} value by default.\n *\n * @remarks\n * if this is set to `true`, environment variable discovery will vary based on the\n * platform in use. For example, Windows environment variable names are case-insensitive,\n * while on Linux, environment variable names are case-sensitive. It is recommended that\n * this option be used only when necessary based on environmental constraints.\n */\n allowNonStandardEnvironmentVariableNames?: boolean;\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 getCompletionsAsync?: () => Promise<ReadonlyArray<string> | ReadonlySet<string>>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineChoiceParameter:1)} and\n * {@link CommandLineParameterProvider.(defineChoiceParameter:2)}, this interface\n * defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: ReadonlyArray<TChoice> | ReadonlySet<TChoice>;\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: TChoice;\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<ReadonlyArray<TChoice> | ReadonlySet<TChoice>>;\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<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: ReadonlyArray<TChoice> | ReadonlySet<TChoice>;\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<ReadonlyArray<TChoice> | ReadonlySet<TChoice>>;\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:1)},\n * {@link CommandLineParameterProvider.(defineIntegerParameter:2)}, this interface\n * 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:1)} and\n * {@link CommandLineParameterProvider.(defineStringParameter:2)}, this interface\n * 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"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
/**
|
|
5
|
+
* The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class CommandLineFlagParameter extends CommandLineParameterBase {
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition) {
|
|
11
|
+
super(definition);
|
|
12
|
+
this._value = false;
|
|
13
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
14
|
+
this.kind = CommandLineParameterKind.Flag;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_setValue(data) {
|
|
21
|
+
// abstract
|
|
22
|
+
if (data !== null && data !== undefined) {
|
|
23
|
+
if (typeof data !== 'boolean') {
|
|
24
|
+
this.reportInvalidData(data);
|
|
25
|
+
}
|
|
26
|
+
// If the flag is omitted, then argparse sets the data to "false" instead of "undefined".
|
|
27
|
+
// This design prevents a syntax such as "--flag=false", probably because argparse prefers "--no-flag".
|
|
28
|
+
// If we switch to a new CLI parser, we should try to add support for "--flag=false".
|
|
29
|
+
if (data) {
|
|
30
|
+
this._value = data;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (this.environmentVariable !== undefined) {
|
|
35
|
+
// Try reading the environment variable
|
|
36
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
37
|
+
if (environmentValue !== undefined && environmentValue !== '') {
|
|
38
|
+
if (environmentValue !== '0' && environmentValue !== '1') {
|
|
39
|
+
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
|
|
40
|
+
` ${this.environmentVariable}. Valid choices are 0 or 1.`);
|
|
41
|
+
}
|
|
42
|
+
this._value = environmentValue === '1';
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
this._value = false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns a boolean indicating whether the parameter was included in the command line.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* The return value will be false if the command-line has not been parsed yet,
|
|
53
|
+
* or if the flag was not used.
|
|
54
|
+
*/
|
|
55
|
+
get value() {
|
|
56
|
+
return this._value;
|
|
57
|
+
}
|
|
58
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
59
|
+
appendToArgList(argList) {
|
|
60
|
+
if (this.value) {
|
|
61
|
+
argList.push(this.longName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# 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,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEnF;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,wBAAwB;IAMpE,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,WAAM,GAAY,KAAK,CAAC;QAEhC,kDAAkD;QAClC,SAAI,GAAkC,wBAAwB,CAAC,IAAI,CAAC;IAKpF,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,IAAa;QAC5B,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC9B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YAED,yFAAyF;YACzF,uGAAuG;YACvG,qFAAqF;YACrF,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,OAAO;YACT,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC3C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,EAAE,EAAE,CAAC;gBAC9D,IAAI,gBAAgB,KAAK,GAAG,IAAI,gBAAgB,KAAK,GAAG,EAAE,CAAC;oBACzD,MAAM,IAAI,KAAK,CACb,kBAAkB,gBAAgB,gCAAgC;wBAChE,IAAI,IAAI,CAAC,mBAAmB,8BAA8B,CAC7D,CAAC;gBACJ,CAAC;gBACD,IAAI,CAAC,MAAM,GAAG,gBAAgB,KAAK,GAAG,CAAC;gBACvC,OAAO;YACT,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF","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 { ICommandLineFlagDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.\n * @public\n */\nexport class CommandLineFlagParameter extends CommandLineParameterBase {\n private _value: boolean = false;\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.Flag = CommandLineParameterKind.Flag;\n\n /** @internal */\n public constructor(definition: ICommandLineFlagDefinition) {\n super(definition);\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'boolean') {\n this.reportInvalidData(data);\n }\n\n // If the flag is omitted, then argparse sets the data to \"false\" instead of \"undefined\".\n // This design prevents a syntax such as \"--flag=false\", probably because argparse prefers \"--no-flag\".\n // If we switch to a new CLI parser, we should try to add support for \"--flag=false\".\n if (data) {\n this._value = data;\n return;\n }\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined && environmentValue !== '') {\n if (environmentValue !== '0' && environmentValue !== '1') {\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are 0 or 1.`\n );\n }\n this._value = environmentValue === '1';\n return;\n }\n }\n\n this._value = false;\n }\n\n /**\n * Returns a boolean indicating whether the parameter was included in the command line.\n *\n * @remarks\n * The return value will be false if the command-line has not been parsed yet,\n * or if the flag was not used.\n */\n public get value(): boolean {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value) {\n argList.push(this.longName);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
import { EnvironmentVariableParser } from './EnvironmentVariableParser';
|
|
5
|
+
/**
|
|
6
|
+
* The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {
|
|
10
|
+
/** @internal */
|
|
11
|
+
constructor(definition) {
|
|
12
|
+
super(definition);
|
|
13
|
+
this._values = [];
|
|
14
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
15
|
+
this.kind = CommandLineParameterKind.IntegerList;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_setValue(data) {
|
|
22
|
+
// If argparse passed us a value, confirm it is valid
|
|
23
|
+
if (data !== null && data !== undefined) {
|
|
24
|
+
if (!Array.isArray(data)) {
|
|
25
|
+
this.reportInvalidData(data);
|
|
26
|
+
}
|
|
27
|
+
for (const arrayItem of data) {
|
|
28
|
+
if (typeof arrayItem !== 'number') {
|
|
29
|
+
this.reportInvalidData(data);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this._values = data;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// If an environment variable exists, attempt to parse it as a list
|
|
36
|
+
if (this.environmentVariable !== undefined) {
|
|
37
|
+
const values = EnvironmentVariableParser.parseAsList(this.environmentVariable);
|
|
38
|
+
if (values) {
|
|
39
|
+
const parsedValues = [];
|
|
40
|
+
for (const value of values) {
|
|
41
|
+
const parsed = parseInt(value, 10);
|
|
42
|
+
if (isNaN(parsed) || value.indexOf('.') >= 0) {
|
|
43
|
+
throw new Error(`Invalid value "${value}" for the environment variable` +
|
|
44
|
+
` ${this.environmentVariable}. It must be an integer value.`);
|
|
45
|
+
}
|
|
46
|
+
parsedValues.push(parsed);
|
|
47
|
+
}
|
|
48
|
+
this._values = parsedValues;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// (No default value for integer lists)
|
|
53
|
+
this._values = [];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the integer arguments for an integer list parameter that was parsed from the command line.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* The array will be empty if the command-line has not been parsed yet,
|
|
60
|
+
* or if the parameter was omitted and has no default value.
|
|
61
|
+
*/
|
|
62
|
+
get values() {
|
|
63
|
+
return this._values;
|
|
64
|
+
}
|
|
65
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
66
|
+
appendToArgList(argList) {
|
|
67
|
+
if (this.values.length > 0) {
|
|
68
|
+
for (const value of this.values) {
|
|
69
|
+
argList.push(this.longName);
|
|
70
|
+
argList.push(value.toString());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# 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,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,MAAM,OAAO,+BAAgC,SAAQ,gCAAgC;IAMnF,gBAAgB;IAChB,YAAmB,UAA6C;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,YAAO,GAAa,EAAE,CAAC;QAE/B,kDAAkD;QAClC,SAAI,GAAyC,wBAAwB,CAAC,WAAW,CAAC;IAKlG,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,IAAa;QAC5B,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;gBAC7B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAClC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;QACT,CAAC;QAED,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAyB,yBAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,YAAY,GAAa,EAAE,CAAC;gBAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC3B,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,CAAC;wBAC7C,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,gCAAgC;4BACrD,IAAI,IAAI,CAAC,mBAAmB,iCAAiC,CAChE,CAAC;oBACJ,CAAC;oBACD,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC5B,CAAC;gBACD,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;gBAC5B,OAAO;YACT,CAAC;QACH,CAAC;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,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;CACF","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 { ICommandLineIntegerListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.\n * @public\n */\nexport class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {\n private _values: number[] = [];\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.IntegerList = CommandLineParameterKind.IntegerList;\n\n /** @internal */\n public constructor(definition: ICommandLineIntegerListDefinition) {\n super(definition);\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'number') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n const parsedValues: number[] = [];\n for (const value of values) {\n const parsed: number = parseInt(value, 10);\n if (isNaN(parsed) || value.indexOf('.') >= 0) {\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. It must be an integer value.`\n );\n }\n parsedValues.push(parsed);\n }\n this._values = parsedValues;\n return;\n }\n }\n\n // (No default value for integer lists)\n\n this._values = [];\n }\n\n /**\n * Returns the integer arguments for an integer list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get values(): ReadonlyArray<number> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value.toString());\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
/**
|
|
5
|
+
* The data type returned by {@link CommandLineParameterProvider.(defineIntegerParameter:1)}.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class CommandLineIntegerParameter extends CommandLineParameterWithArgument {
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition) {
|
|
11
|
+
super(definition);
|
|
12
|
+
this._value = undefined;
|
|
13
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
14
|
+
this.kind = CommandLineParameterKind.Integer;
|
|
15
|
+
this.defaultValue = definition.defaultValue;
|
|
16
|
+
this.validateDefaultValue(!!this.defaultValue);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
_setValue(data) {
|
|
23
|
+
// abstract
|
|
24
|
+
if (data !== null && data !== undefined) {
|
|
25
|
+
if (typeof data !== 'number') {
|
|
26
|
+
this.reportInvalidData(data);
|
|
27
|
+
}
|
|
28
|
+
this._value = data;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.environmentVariable !== undefined) {
|
|
32
|
+
// Try reading the environment variable
|
|
33
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
34
|
+
if (environmentValue !== undefined && environmentValue !== '') {
|
|
35
|
+
const parsed = parseInt(environmentValue, 10);
|
|
36
|
+
if (isNaN(parsed) || environmentValue.indexOf('.') >= 0) {
|
|
37
|
+
throw new Error(`Invalid value "${environmentValue}" for the environment variable` +
|
|
38
|
+
` ${this.environmentVariable}. It must be an integer value.`);
|
|
39
|
+
}
|
|
40
|
+
this._value = parsed;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (this.defaultValue !== undefined) {
|
|
45
|
+
this._value = this.defaultValue;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this._value = undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
_getSupplementaryNotes(supplementaryNotes) {
|
|
55
|
+
// virtual
|
|
56
|
+
super._getSupplementaryNotes(supplementaryNotes);
|
|
57
|
+
if (this.defaultValue !== undefined) {
|
|
58
|
+
supplementaryNotes.push(`The default value is ${this.defaultValue}.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the argument value for an integer parameter that was parsed from the command line.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* The return value will be undefined if the command-line has not been parsed yet,
|
|
66
|
+
* or if the parameter was omitted and has no default value.
|
|
67
|
+
*/
|
|
68
|
+
get value() {
|
|
69
|
+
return this._value;
|
|
70
|
+
}
|
|
71
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
72
|
+
appendToArgList(argList) {
|
|
73
|
+
if (this.value !== undefined) {
|
|
74
|
+
argList.push(this.longName);
|
|
75
|
+
argList.push(this.value.toString());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=CommandLineIntegerParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineIntegerParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerParameter.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAG3D,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAU3F;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,gCAAgC;IAS/E,gBAAgB;IAChB,YAAmB,UAAyC;QAC1D,KA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,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YAChC,OAAO;QACT,CAAC;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,CAAC;YACpC,kBAAkB,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;CACF","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 { ICommandLineIntegerDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineIntegerParameter:2)}.\n * @public\n */\nexport interface IRequiredCommandLineIntegerParameter extends CommandLineIntegerParameter {\n readonly value: number;\n}\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineIntegerParameter:1)}.\n * @public\n */\nexport class CommandLineIntegerParameter extends CommandLineParameterWithArgument {\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: number | undefined;\n\n private _value: number | undefined = undefined;\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.Integer = CommandLineParameterKind.Integer;\n\n /** @internal */\n public constructor(definition: ICommandLineIntegerDefinition) {\n super(definition);\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'number') {\n this.reportInvalidData(data);\n }\n this._value = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined && environmentValue !== '') {\n const parsed: number = parseInt(environmentValue, 10);\n if (isNaN(parsed) || environmentValue.indexOf('.') >= 0) {\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. It must be an integer value.`\n );\n }\n this._value = parsed;\n return;\n }\n }\n\n if (this.defaultValue !== undefined) {\n this._value = this.defaultValue;\n return;\n }\n\n this._value = undefined;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n super._getSupplementaryNotes(supplementaryNotes);\n if (this.defaultValue !== undefined) {\n supplementaryNotes.push(`The default value is ${this.defaultValue}.`);\n }\n }\n\n /**\n * Returns the argument value for an integer parameter that was parsed from the command line.\n *\n * @remarks\n * The return value will be undefined if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get value(): number | undefined {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value !== undefined) {\n argList.push(this.longName);\n argList.push(this.value.toString());\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
/**
|
|
4
|
+
* The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class CommandLineRemainder {
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor(definition) {
|
|
10
|
+
this._values = [];
|
|
11
|
+
this.description = definition.description;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns any remaining command line arguments after the recognized portion
|
|
15
|
+
* that was parsed from the command line.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The array will be empty if the command-line has not been parsed yet.
|
|
19
|
+
*/
|
|
20
|
+
get values() {
|
|
21
|
+
return this._values;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
_setValue(data) {
|
|
28
|
+
// abstract
|
|
29
|
+
if (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {
|
|
30
|
+
throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));
|
|
31
|
+
}
|
|
32
|
+
this._values.push(...data);
|
|
33
|
+
}
|
|
34
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
35
|
+
appendToArgList(argList) {
|
|
36
|
+
if (this.values.length > 0) {
|
|
37
|
+
for (const value of this.values) {
|
|
38
|
+
argList.push(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=CommandLineRemainder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineRemainder.js","sourceRoot":"","sources":["../../src/parameters/CommandLineRemainder.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAI3D;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAM/B,gBAAgB;IAChB,YAAmB,UAA2C;QANtD,YAAO,GAAa,EAAE,CAAC;QAO7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,IAAa;QAC5B,WAAW;QACX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QACnF,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;CACF","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 { ICommandLineRemainderDefinition } from './CommandLineDefinition';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.\n * @public\n */\nexport class CommandLineRemainder {\n private _values: string[] = [];\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** @internal */\n public constructor(definition: ICommandLineRemainderDefinition) {\n this.description = definition.description;\n }\n\n /**\n * Returns any remaining command line arguments after the recognized portion\n * that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet.\n */\n public get values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // abstract\n if (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {\n throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));\n }\n\n this._values.push(...data);\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(value);\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
import { EnvironmentVariableParser } from './EnvironmentVariableParser';
|
|
5
|
+
/**
|
|
6
|
+
* The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class CommandLineStringListParameter extends CommandLineParameterWithArgument {
|
|
10
|
+
/** @internal */
|
|
11
|
+
constructor(definition) {
|
|
12
|
+
super(definition);
|
|
13
|
+
this._values = [];
|
|
14
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
15
|
+
this.kind = CommandLineParameterKind.StringList;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_setValue(data) {
|
|
22
|
+
// If argparse passed us a value, confirm it is valid
|
|
23
|
+
if (data !== null && data !== undefined) {
|
|
24
|
+
if (!Array.isArray(data)) {
|
|
25
|
+
this.reportInvalidData(data);
|
|
26
|
+
}
|
|
27
|
+
for (const arrayItem of data) {
|
|
28
|
+
if (typeof arrayItem !== 'string') {
|
|
29
|
+
this.reportInvalidData(data);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this._values = data;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// If an environment variable exists, attempt to parse it as a list
|
|
36
|
+
if (this.environmentVariable !== undefined) {
|
|
37
|
+
const values = EnvironmentVariableParser.parseAsList(this.environmentVariable);
|
|
38
|
+
if (values) {
|
|
39
|
+
this._values = values;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// (No default value for string lists)
|
|
44
|
+
this._values = [];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the string arguments for a string list parameter that was parsed from the command line.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* The array will be empty if the command-line has not been parsed yet,
|
|
51
|
+
* or if the parameter was omitted and has no default value.
|
|
52
|
+
*/
|
|
53
|
+
get values() {
|
|
54
|
+
return this._values;
|
|
55
|
+
}
|
|
56
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
57
|
+
appendToArgList(argList) {
|
|
58
|
+
if (this.values.length > 0) {
|
|
59
|
+
for (const value of this.values) {
|
|
60
|
+
argList.push(this.longName);
|
|
61
|
+
argList.push(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=CommandLineStringListParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineStringListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringListParameter.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAG3D,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,MAAM,OAAO,8BAA+B,SAAQ,gCAAgC;IAMlF,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC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AC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;CACF","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 { ICommandLineStringListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.\n * @public\n */\nexport class CommandLineStringListParameter extends CommandLineParameterWithArgument {\n private _values: string[] = [];\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.StringList = CommandLineParameterKind.StringList;\n\n /** @internal */\n public constructor(definition: ICommandLineStringListDefinition) {\n super(definition);\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'string') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n this._values = values;\n return;\n }\n }\n\n // (No default value for string lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a string list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value);\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
/**
|
|
5
|
+
* The data type returned by {@link CommandLineParameterProvider.(defineStringParameter:1)}.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class CommandLineStringParameter extends CommandLineParameterWithArgument {
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(definition) {
|
|
11
|
+
super(definition);
|
|
12
|
+
this._value = undefined;
|
|
13
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
14
|
+
this.kind = CommandLineParameterKind.String;
|
|
15
|
+
this.defaultValue = definition.defaultValue;
|
|
16
|
+
this.validateDefaultValue(!!this.defaultValue);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
_setValue(data) {
|
|
23
|
+
// abstract
|
|
24
|
+
if (data !== null && data !== undefined) {
|
|
25
|
+
if (typeof data !== 'string') {
|
|
26
|
+
this.reportInvalidData(data);
|
|
27
|
+
}
|
|
28
|
+
this._value = data;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.environmentVariable !== undefined) {
|
|
32
|
+
// Try reading the environment variable
|
|
33
|
+
const environmentValue = process.env[this.environmentVariable];
|
|
34
|
+
if (environmentValue !== undefined) {
|
|
35
|
+
// NOTE: If the environment variable is defined as an empty string,
|
|
36
|
+
// here we will accept the empty string as our value. (For number/flag we don't do that.)
|
|
37
|
+
this._value = environmentValue;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (this.defaultValue !== undefined) {
|
|
42
|
+
this._value = this.defaultValue;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this._value = undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
_getSupplementaryNotes(supplementaryNotes) {
|
|
52
|
+
// virtual
|
|
53
|
+
super._getSupplementaryNotes(supplementaryNotes);
|
|
54
|
+
if (this.defaultValue !== undefined) {
|
|
55
|
+
if (this.defaultValue.length < 160) {
|
|
56
|
+
supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the argument value for a string parameter that was parsed from the command line.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* The return value will be undefined if the command-line has not been parsed yet,
|
|
65
|
+
* or if the parameter was omitted and has no default value.
|
|
66
|
+
*/
|
|
67
|
+
get value() {
|
|
68
|
+
return this._value;
|
|
69
|
+
}
|
|
70
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
71
|
+
appendToArgList(argList) {
|
|
72
|
+
if (this.value !== undefined) {
|
|
73
|
+
argList.push(this.longName);
|
|
74
|
+
argList.push(this.value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=CommandLineStringParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineStringParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringParameter.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAG3D,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAU3F;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,gCAAgC;IAS9E,gBAAgB;IAChB,YAAmB,UAAwC;QACzD,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,WAAM,GAAuB,SAAS,C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,kBAAkB,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACxF,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,uEAAuE;IAChE,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","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 { ICommandLineStringDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineStringParameter:2)}.\n * @public\n */\nexport interface IRequiredCommandLineStringParameter extends CommandLineStringParameter {\n readonly value: string;\n}\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.(defineStringParameter:1)}.\n * @public\n */\nexport class CommandLineStringParameter extends CommandLineParameterWithArgument {\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: string | undefined;\n\n private _value: string | undefined = undefined;\n\n /** {@inheritDoc CommandLineParameterBase.kind} */\n public readonly kind: CommandLineParameterKind.String = CommandLineParameterKind.String;\n\n /** @internal */\n public constructor(definition: ICommandLineStringDefinition) {\n super(definition);\n\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._setValue}\n * @internal\n */\n public _setValue(data: unknown): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'string') {\n this.reportInvalidData(data);\n }\n this._value = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined) {\n // NOTE: If the environment variable is defined as an empty string,\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\n this._value = environmentValue;\n return;\n }\n }\n\n if (this.defaultValue !== undefined) {\n this._value = this.defaultValue;\n return;\n }\n\n this._value = undefined;\n }\n\n /**\n * {@inheritDoc CommandLineParameterBase._getSupplementaryNotes}\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n super._getSupplementaryNotes(supplementaryNotes);\n if (this.defaultValue !== undefined) {\n if (this.defaultValue.length < 160) {\n supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);\n }\n }\n }\n\n /**\n * Returns the argument value for a string parameter that was parsed from the command line.\n *\n * @remarks\n * The return value will be undefined if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get value(): string | undefined {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value !== undefined) {\n argList.push(this.longName);\n argList.push(this.value);\n }\n }\n}\n"]}
|