@rushstack/ts-command-line 5.2.0 → 5.3.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 +40 -0
- package/CHANGELOG.md +15 -1
- package/dist/tsdoc-metadata.json +1 -1
- 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 +31 -7
- /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/CommandLineParser.js +0 -0
- /package/{lib → lib-commonjs}/providers/CommandLineParser.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/CommandLineParser.d.ts +0 -0
- /package/{lib → lib-dts}/providers/CommandLineParser.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
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/ts-command-line",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "5.3.1",
|
|
6
|
+
"tag": "@rushstack/ts-command-line_v5.3.1",
|
|
7
|
+
"date": "Fri, 20 Feb 2026 00:15:04 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add `\"node\"` condition before `\"import\"` in the `\"exports\"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `\"import\"`. Fixes https://github.com/microsoft/rushstack/issues/5644."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.22.1`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.1`"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"version": "5.3.0",
|
|
26
|
+
"tag": "@rushstack/ts-command-line_v5.3.0",
|
|
27
|
+
"date": "Thu, 19 Feb 2026 00:04:53 GMT",
|
|
28
|
+
"comments": {
|
|
29
|
+
"minor": [
|
|
30
|
+
{
|
|
31
|
+
"comment": "Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `\"exports\"` field in `package.json`."
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"dependency": [
|
|
35
|
+
{
|
|
36
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.22.0`"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.0`"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
4
44
|
{
|
|
5
45
|
"version": "5.2.0",
|
|
6
46
|
"tag": "@rushstack/ts-command-line_v5.2.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @rushstack/ts-command-line
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 20 Feb 2026 00:15:04 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.3.1
|
|
6
|
+
Fri, 20 Feb 2026 00:15:04 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Add `"node"` condition before `"import"` in the `"exports"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `"import"`. Fixes https://github.com/microsoft/rushstack/issues/5644.
|
|
11
|
+
|
|
12
|
+
## 5.3.0
|
|
13
|
+
Thu, 19 Feb 2026 00:04:53 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `"exports"` field in `package.json`.
|
|
4
18
|
|
|
5
19
|
## 5.2.0
|
|
6
20
|
Wed, 04 Feb 2026 16:13:27 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
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 { CommandLineConstants } from './Constants';
|
|
4
|
+
/**
|
|
5
|
+
* Helpers for working with the ts-command-line API.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class CommandLineHelper {
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the current command line action is tab-complete.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
static isTabCompletionActionRequest(argv) {
|
|
16
|
+
return argv && argv.length > 2 && argv[2] === CommandLineConstants.TabCompletionActionName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=CommandLineHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineHelper.js","sourceRoot":"","sources":["../src/CommandLineHelper.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;OAIG;IACI,MAAM,CAAC,4BAA4B,CAAC,IAAc;QACvD,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,oBAAoB,CAAC,uBAAuB,CAAC;IAC7F,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 { CommandLineConstants } from './Constants';\n\n/**\n * Helpers for working with the ts-command-line API.\n *\n * @public\n */\nexport class CommandLineHelper {\n /**\n * Returns true if the current command line action is tab-complete.\n *\n * @public\n */\n public static isTabCompletionActionRequest(argv: string[]): boolean {\n return argv && argv.length > 2 && argv[2] === CommandLineConstants.TabCompletionActionName;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* String constants for command line processing.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export var CommandLineConstants;
|
|
9
|
+
(function (CommandLineConstants) {
|
|
10
|
+
/**
|
|
11
|
+
* The name of the built-in action that serves suggestions for tab-completion
|
|
12
|
+
*/
|
|
13
|
+
CommandLineConstants["TabCompletionActionName"] = "tab-complete";
|
|
14
|
+
})(CommandLineConstants || (CommandLineConstants = {}));
|
|
15
|
+
export const SCOPING_PARAMETER_GROUP = Symbol('scoping');
|
|
16
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D;;;;GAIG;AACH,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B;;OAEG;IACH,gEAAwC,CAAA;AAC1C,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * String constants for command line processing.\n *\n * @public\n */\nexport enum CommandLineConstants {\n /**\n * The name of the built-in action that serves suggestions for tab-completion\n */\n TabCompletionActionName = 'tab-complete'\n}\n\nexport const SCOPING_PARAMETER_GROUP: unique symbol = Symbol('scoping');\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
const classPrototypeUuidSymbol = Symbol.for('TypeUuid.classPrototypeUuid');
|
|
4
|
+
export const uuidAlreadyReportedError = 'f26b0640-a49b-49d1-9ead-1a516d5920c7';
|
|
5
|
+
// Avoid a dependency on node-core-library to access just this one API:
|
|
6
|
+
export class TypeUuid {
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if the `targetObject` is an instance of a JavaScript class that was previously
|
|
9
|
+
* registered using the specified `typeUuid`. Base classes are also considered.
|
|
10
|
+
*/
|
|
11
|
+
static isInstanceOf(targetObject, typeUuid) {
|
|
12
|
+
if (targetObject === undefined || targetObject === null) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
let objectPrototype = Object.getPrototypeOf(targetObject);
|
|
16
|
+
while (objectPrototype !== undefined && objectPrototype !== null) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
const registeredUuid = objectPrototype[classPrototypeUuidSymbol];
|
|
19
|
+
if (registeredUuid === typeUuid) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
// Walk upwards an examine base class prototypes
|
|
23
|
+
objectPrototype = Object.getPrototypeOf(objectPrototype);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=TypeUuidLite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeUuidLite.js","sourceRoot":"","sources":["../src/TypeUuidLite.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,MAAM,wBAAwB,GAAW,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAEnF,MAAM,CAAC,MAAM,wBAAwB,GAAW,sCAAsC,CAAC;AAEvF,uEAAuE;AACvE,MAAM,OAAO,QAAQ;IACnB;;;OAGG;IACI,MAAM,CAAC,YAAY,CAAC,YAAqB,EAAE,QAAgB;QAChE,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YACxD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,eAAe,GAAO,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;QAC9D,OAAO,eAAe,KAAK,SAAS,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;YACjE,8DAA8D;YAC9D,MAAM,cAAc,GAAY,eAAuB,CAAC,wBAAwB,CAAC,CAAC;YAClF,IAAI,cAAc,KAAK,QAAQ,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,gDAAgD;YAChD,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,KAAK,CAAC;IACf,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\nconst classPrototypeUuidSymbol: symbol = Symbol.for('TypeUuid.classPrototypeUuid');\n\nexport const uuidAlreadyReportedError: string = 'f26b0640-a49b-49d1-9ead-1a516d5920c7';\n\n// Avoid a dependency on node-core-library to access just this one API:\nexport class TypeUuid {\n /**\n * Returns true if the `targetObject` is an instance of a JavaScript class that was previously\n * registered using the specified `typeUuid`. Base classes are also considered.\n */\n public static isInstanceOf(targetObject: unknown, typeUuid: string): boolean {\n if (targetObject === undefined || targetObject === null) {\n return false;\n }\n\n let objectPrototype: {} = Object.getPrototypeOf(targetObject);\n while (objectPrototype !== undefined && objectPrototype !== null) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const registeredUuid: string = (objectPrototype as any)[classPrototypeUuidSymbol];\n if (registeredUuid === typeUuid) {\n return true;\n }\n // Walk upwards an examine base class prototypes\n objectPrototype = Object.getPrototypeOf(objectPrototype);\n }\n\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
export function escapeSprintf(input) {
|
|
4
|
+
// Escape sprintf-style escape characters
|
|
5
|
+
// The primary special character in sprintf format strings is '%'
|
|
6
|
+
// which introduces format specifiers like %s, %d, %f, etc.
|
|
7
|
+
return input.replace(/%/g, '%%');
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=escapeSprintf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeSprintf.js","sourceRoot":"","sources":["../src/escapeSprintf.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,yCAAyC;IACzC,iEAAiE;IACjE,2DAA2D;IAC3D,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport function escapeSprintf(input: string): string {\n // Escape sprintf-style escape characters\n // The primary special character in sprintf format strings is '%'\n // which introduces format specifiers like %s, %d, %f, etc.\n return input.replace(/%/g, '%%');\n}\n"]}
|
package/lib-esm/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* An object-oriented command-line parser for TypeScript projects.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { CommandLineAction } from './providers/CommandLineAction';
|
|
9
|
+
export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';
|
|
10
|
+
export { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';
|
|
11
|
+
export { AliasCommandLineAction } from './providers/AliasCommandLineAction';
|
|
12
|
+
export { CommandLineParameterKind, CommandLineParameterBase, CommandLineParameterWithArgument } from './parameters/BaseClasses';
|
|
13
|
+
export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';
|
|
14
|
+
export { CommandLineStringParameter } from './parameters/CommandLineStringParameter';
|
|
15
|
+
export { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';
|
|
16
|
+
export { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter';
|
|
17
|
+
export { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';
|
|
18
|
+
export { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter';
|
|
19
|
+
export { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';
|
|
20
|
+
export { CommandLineRemainder } from './parameters/CommandLineRemainder';
|
|
21
|
+
export { CommandLineParameterProvider } from './providers/CommandLineParameterProvider';
|
|
22
|
+
export { CommandLineParser } from './providers/CommandLineParser';
|
|
23
|
+
export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';
|
|
24
|
+
export { CommandLineConstants } from './Constants';
|
|
25
|
+
export { CommandLineHelper } from './CommandLineHelper';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAkC,MAAM,+BAA+B,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,sBAAsB,EAEvB,MAAM,oCAAoC,CAAC;AAe5C,OAAO,EAEL,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EACL,0BAA0B,EAE3B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EACL,2BAA2B,EAE5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,EACL,0BAA0B,EAE3B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EACL,4BAA4B,EAI7B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAkC,MAAM,+BAA+B,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * An object-oriented command-line parser for TypeScript projects.\n *\n * @packageDocumentation\n */\n\nexport { CommandLineAction, type ICommandLineActionOptions } from './providers/CommandLineAction';\nexport { DynamicCommandLineAction } from './providers/DynamicCommandLineAction';\nexport { ScopedCommandLineAction } from './providers/ScopedCommandLineAction';\nexport {\n AliasCommandLineAction,\n type IAliasCommandLineActionOptions\n} from './providers/AliasCommandLineAction';\n\nexport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineRemainderDefinition\n} from './parameters/CommandLineDefinition';\n\nexport {\n type CommandLineParameter,\n CommandLineParameterKind,\n CommandLineParameterBase,\n CommandLineParameterWithArgument\n} from './parameters/BaseClasses';\n\nexport { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter';\nexport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from './parameters/CommandLineStringParameter';\nexport { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter';\nexport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from './parameters/CommandLineIntegerParameter';\nexport { CommandLineIntegerListParameter } from './parameters/CommandLineIntegerListParameter';\nexport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from './parameters/CommandLineChoiceParameter';\nexport { CommandLineChoiceListParameter } from './parameters/CommandLineChoiceListParameter';\nexport { CommandLineRemainder } from './parameters/CommandLineRemainder';\n\nexport {\n CommandLineParameterProvider,\n type IScopedLongNameParseResult,\n type ICommandLineParserData as _ICommandLineParserData,\n type IRegisterDefinedParametersState as _IRegisterDefinedParametersState\n} from './providers/CommandLineParameterProvider';\n\nexport { CommandLineParser, type ICommandLineParserOptions } from './providers/CommandLineParser';\nexport { DynamicCommandLineParser } from './providers/DynamicCommandLineParser';\n\nexport { CommandLineConstants } from './Constants';\n\nexport { CommandLineHelper } from './CommandLineHelper';\n"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
* Identifies the kind of a CommandLineParameter.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export var CommandLineParameterKind;
|
|
8
|
+
(function (CommandLineParameterKind) {
|
|
9
|
+
/** Indicates a CommandLineChoiceParameter */
|
|
10
|
+
CommandLineParameterKind[CommandLineParameterKind["Choice"] = 0] = "Choice";
|
|
11
|
+
/** Indicates a CommandLineFlagParameter */
|
|
12
|
+
CommandLineParameterKind[CommandLineParameterKind["Flag"] = 1] = "Flag";
|
|
13
|
+
/** Indicates a CommandLineIntegerParameter */
|
|
14
|
+
CommandLineParameterKind[CommandLineParameterKind["Integer"] = 2] = "Integer";
|
|
15
|
+
/** Indicates a CommandLineStringParameter */
|
|
16
|
+
CommandLineParameterKind[CommandLineParameterKind["String"] = 3] = "String";
|
|
17
|
+
/** Indicates a CommandLineStringListParameter */
|
|
18
|
+
CommandLineParameterKind[CommandLineParameterKind["StringList"] = 4] = "StringList";
|
|
19
|
+
/** Indicates a CommandLineChoiceListParameter */
|
|
20
|
+
CommandLineParameterKind[CommandLineParameterKind["ChoiceList"] = 5] = "ChoiceList";
|
|
21
|
+
/** Indicates a CommandLineIntegerListParameter */
|
|
22
|
+
CommandLineParameterKind[CommandLineParameterKind["IntegerList"] = 6] = "IntegerList";
|
|
23
|
+
})(CommandLineParameterKind || (CommandLineParameterKind = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Matches kebab-case formatted strings prefixed with double dashes.
|
|
26
|
+
* Example: "--do-something"
|
|
27
|
+
*/
|
|
28
|
+
const LONG_NAME_REGEXP = /^-(-[a-z0-9]+)+$/;
|
|
29
|
+
/**
|
|
30
|
+
* Matches a single upper-case or lower-case letter prefixed with a dash.
|
|
31
|
+
* Example: "-d"
|
|
32
|
+
*/
|
|
33
|
+
const SHORT_NAME_REGEXP = /^-[a-zA-Z]$/;
|
|
34
|
+
/**
|
|
35
|
+
* Matches kebab-case formatted strings
|
|
36
|
+
* Example: "my-scope"
|
|
37
|
+
*/
|
|
38
|
+
const SCOPE_REGEXP = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
39
|
+
/**
|
|
40
|
+
* "Environment variable names used by the utilities in the Shell and Utilities volume of
|
|
41
|
+
* IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)
|
|
42
|
+
* from the characters defined in Portable Character Set and do not begin with a digit."
|
|
43
|
+
* Example: "THE_SETTING"
|
|
44
|
+
*/
|
|
45
|
+
const ENVIRONMENT_VARIABLE_NAME_REGEXP = /^[A-Z_][A-Z0-9_]*$/;
|
|
46
|
+
/**
|
|
47
|
+
* The base class for the various command-line parameter types.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export class CommandLineParameterBase {
|
|
51
|
+
/** @internal */
|
|
52
|
+
constructor(definition) {
|
|
53
|
+
this.longName = definition.parameterLongName;
|
|
54
|
+
this._shortNameValue = definition.parameterShortName;
|
|
55
|
+
this.parameterGroup = definition.parameterGroup;
|
|
56
|
+
this.parameterScope = definition.parameterScope;
|
|
57
|
+
this.description = definition.description;
|
|
58
|
+
this.required = !!definition.required;
|
|
59
|
+
this.environmentVariable = definition.environmentVariable;
|
|
60
|
+
this.undocumentedSynonyms = definition.undocumentedSynonyms;
|
|
61
|
+
this.allowNonStandardEnvironmentVariableNames = definition.allowNonStandardEnvironmentVariableNames;
|
|
62
|
+
if (!LONG_NAME_REGEXP.test(this.longName)) {
|
|
63
|
+
throw new Error(`Invalid name: "${this.longName}". The parameter long name must be` +
|
|
64
|
+
` lower-case and use dash delimiters (e.g. "--do-a-thing")`);
|
|
65
|
+
}
|
|
66
|
+
if (this.shortName) {
|
|
67
|
+
if (!SHORT_NAME_REGEXP.test(this.shortName)) {
|
|
68
|
+
throw new Error(`Invalid name: "${this.shortName}". The parameter short name must be` +
|
|
69
|
+
` a dash followed by a single upper-case or lower-case letter (e.g. "-a")`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (this.parameterScope) {
|
|
73
|
+
if (!SCOPE_REGEXP.test(this.parameterScope)) {
|
|
74
|
+
throw new Error(`Invalid scope: "${this.parameterScope}". The parameter scope name must be` +
|
|
75
|
+
` lower-case and use dash delimiters (e.g. "my-scope")`);
|
|
76
|
+
}
|
|
77
|
+
// Parameter long name is guaranteed to start with '--' since this is validated above
|
|
78
|
+
const unprefixedLongName = this.longName.slice(2);
|
|
79
|
+
this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;
|
|
80
|
+
}
|
|
81
|
+
if (this.environmentVariable) {
|
|
82
|
+
if (!this.allowNonStandardEnvironmentVariableNames &&
|
|
83
|
+
!ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {
|
|
84
|
+
throw new Error(`Invalid environment variable name: "${this.environmentVariable}". The name must` +
|
|
85
|
+
` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {
|
|
89
|
+
for (const undocumentedSynonym of this.undocumentedSynonyms) {
|
|
90
|
+
if (this.longName === undocumentedSynonym) {
|
|
91
|
+
throw new Error(`Invalid name: "${undocumentedSynonym}". Undocumented synonyms must not be the same` +
|
|
92
|
+
` as the the long name.`);
|
|
93
|
+
}
|
|
94
|
+
else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {
|
|
95
|
+
throw new Error(`Invalid name: "${undocumentedSynonym}". All undocumented synonyms name must be lower-case and ` +
|
|
96
|
+
'use dash delimiters (e.g. "--do-a-thing")');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */
|
|
102
|
+
get shortName() {
|
|
103
|
+
return this._shortNameValue;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns additional text used by the help formatter.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
_getSupplementaryNotes(supplementaryNotes) {
|
|
110
|
+
// virtual
|
|
111
|
+
if (this.environmentVariable !== undefined) {
|
|
112
|
+
supplementaryNotes.push('This parameter may alternatively be specified via the ' +
|
|
113
|
+
this.environmentVariable +
|
|
114
|
+
' environment variable.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Internal usage only. Used to report unexpected output from the argparse library.
|
|
119
|
+
*/
|
|
120
|
+
reportInvalidData(data) {
|
|
121
|
+
throw new Error(`Unexpected data object for parameter "${this.longName}": ` + JSON.stringify(data));
|
|
122
|
+
}
|
|
123
|
+
validateDefaultValue(hasDefaultValue) {
|
|
124
|
+
if (this.required && hasDefaultValue) {
|
|
125
|
+
// If a parameter is "required", then the user understands that they always need to
|
|
126
|
+
// specify a value for this parameter (either via the command line or via an environment variable).
|
|
127
|
+
// It would be confusing to allow a default value that sometimes allows the "required" parameter
|
|
128
|
+
// to be omitted. If you sometimes don't have a suitable default value, then the better approach
|
|
129
|
+
// is to throw a custom error explaining why the parameter is required in that case.
|
|
130
|
+
throw new Error(`A default value cannot be specified for "${this.longName}" because it is a "required" parameter`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The common base class for parameters types that receive an argument.
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* An argument is an accompanying command-line token, such as "123" in the
|
|
139
|
+
* example "--max-count 123".
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
export class CommandLineParameterWithArgument extends CommandLineParameterBase {
|
|
143
|
+
/** @internal */
|
|
144
|
+
constructor(definition) {
|
|
145
|
+
super(definition);
|
|
146
|
+
if (definition.argumentName === '') {
|
|
147
|
+
throw new Error('The argument name cannot be an empty string. (For the default name, specify undefined.)');
|
|
148
|
+
}
|
|
149
|
+
if (definition.argumentName.toUpperCase() !== definition.argumentName) {
|
|
150
|
+
throw new Error(`Invalid name: "${definition.argumentName}". The argument name must be all upper case.`);
|
|
151
|
+
}
|
|
152
|
+
const match = definition.argumentName.match(CommandLineParameterWithArgument._invalidArgumentNameRegExp);
|
|
153
|
+
if (match) {
|
|
154
|
+
throw new Error(`The argument name "${definition.argumentName}" contains an invalid character "${match[0]}".` +
|
|
155
|
+
` Only upper-case letters, numbers, and underscores are allowed.`);
|
|
156
|
+
}
|
|
157
|
+
this.argumentName = definition.argumentName;
|
|
158
|
+
this.getCompletionsAsync = definition.getCompletionsAsync;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Matches the first character that *isn't* part of a valid upper-case argument name such as "URL_2"
|
|
162
|
+
CommandLineParameterWithArgument._invalidArgumentNameRegExp = /[^A-Z_0-9]/;
|
|
163
|
+
//# sourceMappingURL=BaseClasses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClasses.js","sourceRoot":"","sources":["../../src/parameters/BaseClasses.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAe3D;;;GAGG;AACH,MAAM,CAAN,IAAY,wBAeX;AAfD,WAAY,wBAAwB;IAClC,6CAA6C;IAC7C,2EAAM,CAAA;IACN,2CAA2C;IAC3C,uEAAI,CAAA;IACJ,8CAA8C;IAC9C,6EAAO,CAAA;IACP,6CAA6C;IAC7C,2EAAM,CAAA;IACN,iDAAiD;IACjD,mFAAU,CAAA;IACV,iDAAiD;IACjD,mFAAU,CAAA;IACV,kDAAkD;IAClD,qFAAW,CAAA;AACb,CAAC,EAfW,wBAAwB,KAAxB,wBAAwB,QAenC;AAED;;;GAGG;AACH,MAAM,gBAAgB,GAAW,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,iBAAiB,GAAW,aAAa,CAAC;AAEhD;;;GAGG;AACH,MAAM,YAAY,GAAW,0BAA0B,CAAC;AAExD;;;;;GAKG;AACH,MAAM,gCAAgC,GAAW,oBAAoB,CAAC;AActE;;;GAGG;AACH,MAAM,OAAgB,wBAAwB;IAsD5C,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAA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QACrD,IAAI,IAAI,CAAC,QAAQ,IAAI,eAAe,EAAE,CAAC;YACrC,mFAAmF;YACnF,mGAAmG;YACnG,gGAAgG;YAChG,iGAAiG;YACjG,oFAAoF;YACpF,MAAM,IAAI,KAAK,CACb,4CAA4C,IAAI,CAAC,QAAQ,wCAAwC,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAgB,gCAAiC,SAAQ,wBAAwB;IAYrF,gBAAgB;IAChB,YAAmB,UAAkD;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;QACJ,CAAC;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,mBAAmB,CAAC;IAC5D,CAAC;;AApCD,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument\n} from './CommandLineDefinition';\nimport type { CommandLineChoiceListParameter } from './CommandLineChoiceListParameter';\nimport type { CommandLineChoiceParameter } from './CommandLineChoiceParameter';\nimport type { CommandLineFlagParameter } from './CommandLineFlagParameter';\nimport type { CommandLineIntegerListParameter } from './CommandLineIntegerListParameter';\nimport type { CommandLineIntegerParameter } from './CommandLineIntegerParameter';\nimport type { CommandLineStringListParameter } from './CommandLineStringListParameter';\nimport type { CommandLineStringParameter } from './CommandLineStringParameter';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * Matches kebab-case formatted strings prefixed with double dashes.\n * Example: \"--do-something\"\n */\nconst LONG_NAME_REGEXP: RegExp = /^-(-[a-z0-9]+)+$/;\n\n/**\n * Matches a single upper-case or lower-case letter prefixed with a dash.\n * Example: \"-d\"\n */\nconst SHORT_NAME_REGEXP: RegExp = /^-[a-zA-Z]$/;\n\n/**\n * Matches kebab-case formatted strings\n * Example: \"my-scope\"\n */\nconst SCOPE_REGEXP: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/**\n * \"Environment variable names used by the utilities in the Shell and Utilities volume of\n * IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n * from the characters defined in Portable Character Set and do not begin with a digit.\"\n * Example: \"THE_SETTING\"\n */\nconst ENVIRONMENT_VARIABLE_NAME_REGEXP: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\n/**\n * @public\n */\nexport type CommandLineParameter =\n | CommandLineChoiceListParameter\n | CommandLineChoiceParameter\n | CommandLineFlagParameter\n | CommandLineIntegerListParameter\n | CommandLineIntegerParameter\n | CommandLineStringListParameter\n | CommandLineStringParameter;\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameterBase {\n private _shortNameValue: string | undefined;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /**\n * @internal\n */\n public _preParse?: () => void;\n\n /**\n * @internal\n */\n public _postParse?: () => void;\n\n /**\n * @internal\n */\n public _validateValue?: () => void;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /**\n * If a parameterScope is provided, returns the scope-prefixed long name of the flag,\n * including double dashes, eg. \"--scope:do-something\". Otherwise undefined.\n */\n public readonly scopedLongName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */\n public readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */\n public readonly parameterScope: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames} */\n public readonly allowNonStandardEnvironmentVariableNames: boolean | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this._shortNameValue = definition.parameterShortName;\n this.parameterGroup = definition.parameterGroup;\n this.parameterScope = definition.parameterScope;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n this.allowNonStandardEnvironmentVariableNames = definition.allowNonStandardEnvironmentVariableNames;\n\n if (!LONG_NAME_REGEXP.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!SHORT_NAME_REGEXP.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.parameterScope) {\n if (!SCOPE_REGEXP.test(this.parameterScope)) {\n throw new Error(\n `Invalid scope: \"${this.parameterScope}\". The parameter scope name must be` +\n ` lower-case and use dash delimiters (e.g. \"my-scope\")`\n );\n }\n // Parameter long name is guaranteed to start with '--' since this is validated above\n const unprefixedLongName: string = this.longName.slice(2);\n this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;\n }\n\n if (this.environmentVariable) {\n if (\n !this.allowNonStandardEnvironmentVariableNames &&\n !ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)\n ) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented synonyms name must be lower-case and ` +\n 'use dash delimiters (e.g. \"--do-a-thing\")'\n );\n }\n }\n }\n }\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public get shortName(): string | undefined {\n return this._shortNameValue;\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: unknown): void;\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n protected reportInvalidData(data: unknown): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameterBase {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.getCompletionsAsync} */\n public readonly getCompletionsAsync:\n | (() => Promise<ReadonlyArray<string> | ReadonlySet<string>>)\n | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.getCompletionsAsync = definition.getCompletionsAsync;\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 { CommandLineParameterBase, CommandLineParameterKind } from './BaseClasses';
|
|
4
|
+
import { EnvironmentVariableParser } from './EnvironmentVariableParser';
|
|
5
|
+
/**
|
|
6
|
+
* The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class CommandLineChoiceListParameter extends CommandLineParameterBase {
|
|
10
|
+
/** @internal */
|
|
11
|
+
constructor(definition) {
|
|
12
|
+
super(definition);
|
|
13
|
+
this._values = [];
|
|
14
|
+
/** {@inheritDoc CommandLineParameterBase.kind} */
|
|
15
|
+
this.kind = CommandLineParameterKind.ChoiceList;
|
|
16
|
+
const { alternatives, completions } = definition;
|
|
17
|
+
const alternativesSet = alternatives instanceof Set ? alternatives : new Set(alternatives);
|
|
18
|
+
if (alternativesSet.size < 1) {
|
|
19
|
+
throw new Error(`When defining a choice list parameter, the alternatives list must contain at least one value.`);
|
|
20
|
+
}
|
|
21
|
+
this.alternatives = alternativesSet;
|
|
22
|
+
this.completions = completions;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* {@inheritDoc CommandLineParameterBase._setValue}
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
_setValue(data) {
|
|
29
|
+
// If argparse passed us a value, confirm it is valid
|
|
30
|
+
if (data !== null && data !== undefined) {
|
|
31
|
+
if (!Array.isArray(data)) {
|
|
32
|
+
this.reportInvalidData(data);
|
|
33
|
+
}
|
|
34
|
+
for (const arrayItem of data) {
|
|
35
|
+
if (typeof arrayItem !== 'string') {
|
|
36
|
+
this.reportInvalidData(data);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this._values = data;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (this.environmentVariable !== undefined) {
|
|
43
|
+
const values = EnvironmentVariableParser.parseAsList(this.environmentVariable);
|
|
44
|
+
if (values) {
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
if (!this.alternatives.has(value)) {
|
|
47
|
+
const choices = '"' + Array.from(this.alternatives).join('", "') + '"';
|
|
48
|
+
throw new Error(`Invalid value "${value}" for the environment variable` +
|
|
49
|
+
` ${this.environmentVariable}. Valid choices are: ${choices}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this._values = values;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// (No default value for choice lists)
|
|
57
|
+
this._values = [];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns the string arguments for a choice list parameter that was parsed from the command line.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* The array will be empty if the command-line has not been parsed yet,
|
|
64
|
+
* or if the parameter was omitted and has no default value.
|
|
65
|
+
*/
|
|
66
|
+
get values() {
|
|
67
|
+
return this._values;
|
|
68
|
+
}
|
|
69
|
+
/** {@inheritDoc CommandLineParameterBase.appendToArgList} @override */
|
|
70
|
+
appendToArgList(argList) {
|
|
71
|
+
if (this.values.length > 0) {
|
|
72
|
+
for (const value of this.values) {
|
|
73
|
+
argList.push(this.longName);
|
|
74
|
+
argList.push(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=CommandLineChoiceListParameter.js.map
|
|
@@ -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,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;QACpC,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O,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":"AAAA,4FAA4F;AAC5F,2DAA2D;AAG3D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAWnF;;;GAGG;AACH,MAAM,OAAO,0BAA4D,SAA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AS,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"]}
|