@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
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/ts-command-line",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "5.3.0",
|
|
6
|
+
"tag": "@rushstack/ts-command-line_v5.3.0",
|
|
7
|
+
"date": "Thu, 19 Feb 2026 00:04:53 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"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`."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.22.0`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.0`"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"version": "5.2.0",
|
|
26
|
+
"tag": "@rushstack/ts-command-line_v5.2.0",
|
|
27
|
+
"date": "Wed, 04 Feb 2026 16:13:27 GMT",
|
|
28
|
+
"comments": {
|
|
29
|
+
"minor": [
|
|
30
|
+
{
|
|
31
|
+
"comment": "Remove `abstract` modifier from `CommandLineParser` class to allow direct instantiation. Remove redundant `_actions` array field."
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
4
36
|
{
|
|
5
37
|
"version": "5.1.7",
|
|
6
38
|
"tag": "@rushstack/ts-command-line_v5.1.7",
|
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 Thu, 19 Feb 2026 00:04:53 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.3.0
|
|
6
|
+
Thu, 19 Feb 2026 00:04:53 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- 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`.
|
|
11
|
+
|
|
12
|
+
## 5.2.0
|
|
13
|
+
Wed, 04 Feb 2026 16:13:27 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Remove `abstract` modifier from `CommandLineParser` class to allow direct instantiation. Remove redundant `_actions` array field.
|
|
4
18
|
|
|
5
19
|
## 5.1.7
|
|
6
20
|
Wed, 07 Jan 2026 01:12:25 GMT
|
|
@@ -578,13 +578,13 @@ export declare abstract class CommandLineParameterWithArgument extends CommandLi
|
|
|
578
578
|
* The "argparse" library is a relatively advanced command-line parser with features such
|
|
579
579
|
* as word-wrapping and intelligible error messages (that are lacking in other similar
|
|
580
580
|
* libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
|
|
581
|
-
* is awkward to use. The
|
|
581
|
+
* is awkward to use. The base classes CommandLineParser and CommandLineAction
|
|
582
582
|
* provide a wrapper for "argparse" that makes defining and consuming arguments quick
|
|
583
583
|
* and simple, and enforces that appropriate documentation is provided for each parameter.
|
|
584
584
|
*
|
|
585
585
|
* @public
|
|
586
586
|
*/
|
|
587
|
-
export declare
|
|
587
|
+
export declare class CommandLineParser extends CommandLineParameterProvider {
|
|
588
588
|
/**
|
|
589
589
|
* Reports which CommandLineAction was specified on the command line.
|
|
590
590
|
* @remarks
|
|
@@ -594,7 +594,6 @@ export declare abstract class CommandLineParser extends CommandLineParameterProv
|
|
|
594
594
|
private readonly _argumentParser;
|
|
595
595
|
private _actionsSubParser;
|
|
596
596
|
private readonly _options;
|
|
597
|
-
private readonly _actions;
|
|
598
597
|
private readonly _actionsByName;
|
|
599
598
|
private _executed;
|
|
600
599
|
private _tabCompleteActionWasAdded;
|
|
@@ -13,7 +13,7 @@ const escapeSprintf_1 = require("../escapeSprintf");
|
|
|
13
13
|
* The "argparse" library is a relatively advanced command-line parser with features such
|
|
14
14
|
* as word-wrapping and intelligible error messages (that are lacking in other similar
|
|
15
15
|
* libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
|
|
16
|
-
* is awkward to use. The
|
|
16
|
+
* is awkward to use. The base classes CommandLineParser and CommandLineAction
|
|
17
17
|
* provide a wrapper for "argparse" that makes defining and consuming arguments quick
|
|
18
18
|
* and simple, and enforces that appropriate documentation is provided for each parameter.
|
|
19
19
|
*
|
|
@@ -25,7 +25,6 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
25
25
|
this._executed = false;
|
|
26
26
|
this._tabCompleteActionWasAdded = false;
|
|
27
27
|
this._options = options;
|
|
28
|
-
this._actions = [];
|
|
29
28
|
this._actionsByName = new Map();
|
|
30
29
|
const { toolFilename, toolDescription, toolEpilog } = options;
|
|
31
30
|
this._argumentParser = new CommandLineParserExitError_1.CustomArgumentParser({
|
|
@@ -39,7 +38,7 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
39
38
|
* Returns the list of actions that were defined for this CommandLineParser object.
|
|
40
39
|
*/
|
|
41
40
|
get actions() {
|
|
42
|
-
return this.
|
|
41
|
+
return Array.from(this._actionsByName.values());
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
44
|
* Defines a new action that can be used with the CommandLineParser instance.
|
|
@@ -52,7 +51,6 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
action._buildParser(this._actionsSubParser);
|
|
55
|
-
this._actions.push(action);
|
|
56
54
|
this._actionsByName.set(action.actionName, action);
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
@@ -237,7 +235,7 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
237
235
|
...state,
|
|
238
236
|
parentParameterNames: updatedParentParameterNames
|
|
239
237
|
};
|
|
240
|
-
for (const action of this.
|
|
238
|
+
for (const action of this._actionsByName.values()) {
|
|
241
239
|
action._registerDefinedParameters(parentState);
|
|
242
240
|
}
|
|
243
241
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D,kDAA+C;AAI/C,iFAIwC;AACxC,6EAAgG;AAChG,+DAA0D;AAC1D,kDAAqE;AACrE,oDAAiD;AA6BjD;;;;;;;;;GASG;AACH,MAAa,iBAAkB,SAAQ,2DAA4B;IAejE,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAJF,cAAS,GAAY,KAAK,CAAC;QAC3B,+BAA0B,GAAY,KAAK,CAAC;QAKlD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,IA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,CAAC;oBAED,OAAO;gBACT,CAAC;YACH,CAAC;YAED,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAED,gBAAgB;IACT,0BAA0B,CAAC,KAAsC;QACtE,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAExC,MAAM,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC;QACvC,MAAM,2BAA2B,GAAgB,IAAI,GAAG,CAAC;YACvD,GAAG,oBAAoB;YACvB,GAAG,IAAI,CAAC,oCAAoC,CAAC,IAAI,EAAE;SACpD,CAAC,CAAC;QAEH,MAAM,WAAW,GAAoC;YACnD,GAAG,KAAK;YACR,oBAAoB,EAAE,2BAA2B;SAClD,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,MAAM,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9C,+CAA+C;YAC/C,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;QACxG,CAAC;IACH,CAAC;IAED;;;OAGG;IACgB,kBAAkB;QACnC,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,cAAc;QAC5B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AA9RD,8CA8RC","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 * as argparse from 'argparse';\n\nimport { Colorize } from '@rushstack/terminal';\n\nimport type { CommandLineAction } from './CommandLineAction';\nimport type { AliasCommandLineAction } from './AliasCommandLineAction';\nimport {\n CommandLineParameterProvider,\n type IRegisterDefinedParametersState,\n type ICommandLineParserData\n} from './CommandLineParameterProvider';\nimport { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError';\nimport { TabCompleteAction } from './TabCompletionAction';\nimport { TypeUuid, uuidAlreadyReportedError } from '../TypeUuidLite';\nimport { escapeSprintf } from '../escapeSprintf';\n\n/**\n * Options for the {@link CommandLineParser} constructor.\n * @public\n */\nexport interface ICommandLineParserOptions {\n /**\n * The name of your tool when invoked from the command line\n */\n toolFilename: string;\n\n /**\n * General documentation that is included in the \"--help\" main page\n */\n toolDescription: string;\n\n /**\n * An optional string to append at the end of the \"--help\" main page. If not provided, an epilog\n * will be automatically generated based on the toolFilename.\n */\n toolEpilog?: string;\n\n /**\n * Set to true to auto-define a tab completion action. False by default.\n */\n enableTabCompletionAction?: boolean;\n}\n\n/**\n * The \"argparse\" library is a relatively advanced command-line parser with features such\n * as word-wrapping and intelligible error messages (that are lacking in other similar\n * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API\n * is awkward to use. The base classes CommandLineParser and CommandLineAction\n * provide a wrapper for \"argparse\" that makes defining and consuming arguments quick\n * and simple, and enforces that appropriate documentation is provided for each parameter.\n *\n * @public\n */\nexport class CommandLineParser extends CommandLineParameterProvider {\n /**\n * Reports which CommandLineAction was specified on the command line.\n * @remarks\n * The value will be assigned before onExecute() is invoked.\n */\n public selectedAction: CommandLineAction | undefined;\n\n private readonly _argumentParser: argparse.ArgumentParser;\n private _actionsSubParser: argparse.SubParser | undefined;\n private readonly _options: ICommandLineParserOptions;\n private readonly _actionsByName: Map<string, CommandLineAction>;\n private _executed: boolean = false;\n private _tabCompleteActionWasAdded: boolean = false;\n\n public constructor(options: ICommandLineParserOptions) {\n super();\n\n this._options = options;\n this._actionsByName = new Map<string, CommandLineAction>();\n\n const { toolFilename, toolDescription, toolEpilog } = options;\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: toolFilename,\n description: escapeSprintf(toolDescription),\n epilog: Colorize.bold(\n escapeSprintf(\n toolEpilog ?? `For detailed help about a specific command, use: ${toolFilename} <command> -h`\n )\n )\n });\n }\n\n /**\n * Returns the list of actions that were defined for this CommandLineParser object.\n */\n public get actions(): ReadonlyArray<CommandLineAction> {\n return Array.from(this._actionsByName.values());\n }\n\n /**\n * Defines a new action that can be used with the CommandLineParser instance.\n */\n public addAction(action: CommandLineAction): void {\n if (!this._actionsSubParser) {\n this._actionsSubParser = this._argumentParser.addSubparsers({\n metavar: '<command>',\n dest: 'action'\n });\n }\n\n action._buildParser(this._actionsSubParser);\n this._actionsByName.set(action.actionName, action);\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * an exception is thrown.\n */\n public getAction(actionName: string): CommandLineAction {\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n if (!action) {\n throw new Error(`The action \"${actionName}\" was not defined`);\n }\n return action;\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * undefined is returned.\n */\n public tryGetAction(actionName: string): CommandLineAction | undefined {\n return this._actionsByName.get(actionName);\n }\n\n /**\n * The program entry point will call this method to begin parsing command-line arguments\n * and executing the corresponding action.\n *\n * @remarks\n * The returned promise will never reject: If an error occurs, it will be printed\n * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.\n * This simplifies the most common usage scenario where the program entry point doesn't\n * want to be involved with the command-line logic, and will discard the promise without\n * a then() or catch() block.\n *\n * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandlingAsync}\n * instead.\n *\n * @param args - the command-line arguments to be parsed; if omitted, then\n * the process.argv will be used\n */\n public async executeAsync(args?: string[]): Promise<boolean> {\n if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {\n this.addAction(new TabCompleteAction(this.actions, this.parameters));\n this._tabCompleteActionWasAdded = true;\n }\n\n try {\n await this.executeWithoutErrorHandlingAsync(args);\n return true;\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n // executeWithoutErrorHandlingAsync() handles the successful cases,\n // so here we can assume err has a nonzero exit code\n if (err.message) {\n // eslint-disable-next-line no-console\n console.error(err.message);\n }\n if (!process.exitCode) {\n process.exitCode = err.exitCode;\n }\n } else if (TypeUuid.isInstanceOf(err, uuidAlreadyReportedError)) {\n // AlreadyReportedError\n if (!process.exitCode) {\n process.exitCode = 1;\n }\n } else {\n let message: string = ((err as Error).message || 'An unknown error occurred').trim();\n\n // If the message doesn't already start with \"Error:\" then add a prefix\n if (!/^(error|internal error|warning)\\b/i.test(message)) {\n message = 'Error: ' + message;\n }\n\n // eslint-disable-next-line no-console\n console.error();\n // eslint-disable-next-line no-console\n console.error(Colorize.red(message));\n\n if (!process.exitCode) {\n process.exitCode = 1;\n }\n }\n\n return false;\n }\n }\n\n /**\n * This is similar to {@link CommandLineParser.executeAsync}, except that execution errors\n * simply cause the promise to reject. It is the caller's responsibility to trap\n */\n public async executeWithoutErrorHandlingAsync(args?: string[]): Promise<void> {\n try {\n if (this._executed) {\n // In the future we could allow the same parser to be invoked multiple times\n // with different arguments. We'll do that work as soon as someone encounters\n // a real world need for it.\n throw new Error('executeAsync() was already called for this parser instance');\n }\n this._executed = true;\n\n this._validateDefinitions();\n\n // Register the parameters before we print help or parse the CLI\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n\n if (!args) {\n // 0=node.exe, 1=script name\n args = process.argv.slice(2);\n }\n if (this.actions.length > 0) {\n if (args.length === 0) {\n // Parsers that use actions should print help when 0 args are provided. Allow\n // actionless parsers to continue on zero args.\n this._argumentParser.printHelp();\n return;\n }\n // Alias actions may provide a list of default params to add after the action name.\n // Since we don't know which params are required and which are optional, perform a\n // manual search for the action name to obtain the default params and insert them if\n // any are found. We will guess that the action name is the first arg that doesn't\n // start with a hyphen.\n const actionNameIndex: number | undefined = args.findIndex((x) => !x.startsWith('-'));\n if (actionNameIndex !== undefined) {\n const actionName: string = args[actionNameIndex];\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n const aliasAction: AliasCommandLineAction | undefined = action as AliasCommandLineAction;\n if (aliasAction?.defaultParameters?.length) {\n const insertIndex: number = actionNameIndex + 1;\n args = args.slice(0, insertIndex).concat(aliasAction.defaultParameters, args.slice(insertIndex));\n }\n }\n }\n\n const postParse: () => void = () => {\n this._postParse();\n for (const action of this.actions) {\n action._postParse();\n }\n };\n\n function patchFormatUsageForArgumentParser(argumentParser: argparse.ArgumentParser): void {\n const originalFormatUsage: () => string = argumentParser.formatUsage.bind(argumentParser);\n argumentParser.formatUsage = () => {\n postParse();\n return originalFormatUsage();\n };\n }\n\n this._preParse();\n patchFormatUsageForArgumentParser(this._argumentParser);\n for (const action of this.actions) {\n action._preParse();\n patchFormatUsageForArgumentParser(action._getArgumentParser());\n }\n\n const data: ICommandLineParserData = this._argumentParser.parseArgs(args);\n\n postParse();\n this._processParsedData(this._options, data);\n\n this.selectedAction = this.tryGetAction(data.action);\n if (this.actions.length > 0 && !this.selectedAction) {\n const actions: string[] = this.actions.map((x) => x.actionName);\n throw new Error(`An action must be specified (${actions.join(', ')})`);\n }\n\n this.selectedAction?._processParsedData(this._options, data);\n await this.onExecuteAsync();\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n if (!err.exitCode) {\n // non-error exit modeled using exception handling\n if (err.message) {\n // eslint-disable-next-line no-console\n console.log(err.message);\n }\n\n return;\n }\n }\n\n throw err;\n }\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n super._registerDefinedParameters(state);\n\n const { parentParameterNames } = state;\n const updatedParentParameterNames: Set<string> = new Set([\n ...parentParameterNames,\n ...this._registeredParameterParserKeysByName.keys()\n ]);\n\n const parentState: IRegisterDefinedParametersState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n for (const action of this._actionsByName.values()) {\n action._registerDefinedParameters(parentState);\n }\n }\n\n private _validateDefinitions(): void {\n if (this.remainder && this.actions.length > 0) {\n // This is apparently not supported by argparse\n throw new Error('defineCommandLineRemainder() cannot be called for a CommandLineParser with actions');\n }\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider._getArgumentParser}\n * @internal\n */\n protected override _getArgumentParser(): argparse.ArgumentParser {\n return this._argumentParser;\n }\n\n /**\n * This hook allows the subclass to perform additional operations before or after\n * the chosen action is executed.\n */\n protected async onExecuteAsync(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._executeAsync();\n }\n }\n}\n"]}
|
|
@@ -28,13 +28,13 @@ export interface ICommandLineParserOptions {
|
|
|
28
28
|
* The "argparse" library is a relatively advanced command-line parser with features such
|
|
29
29
|
* as word-wrapping and intelligible error messages (that are lacking in other similar
|
|
30
30
|
* libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
|
|
31
|
-
* is awkward to use. The
|
|
31
|
+
* is awkward to use. The base classes CommandLineParser and CommandLineAction
|
|
32
32
|
* provide a wrapper for "argparse" that makes defining and consuming arguments quick
|
|
33
33
|
* and simple, and enforces that appropriate documentation is provided for each parameter.
|
|
34
34
|
*
|
|
35
35
|
* @public
|
|
36
36
|
*/
|
|
37
|
-
export declare
|
|
37
|
+
export declare class CommandLineParser extends CommandLineParameterProvider {
|
|
38
38
|
/**
|
|
39
39
|
* Reports which CommandLineAction was specified on the command line.
|
|
40
40
|
* @remarks
|
|
@@ -44,7 +44,6 @@ export declare abstract class CommandLineParser extends CommandLineParameterProv
|
|
|
44
44
|
private readonly _argumentParser;
|
|
45
45
|
private _actionsSubParser;
|
|
46
46
|
private readonly _options;
|
|
47
|
-
private readonly _actions;
|
|
48
47
|
private readonly _actionsByName;
|
|
49
48
|
private _executed;
|
|
50
49
|
private _tabCompleteActionWasAdded;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandLineParser.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAI1C,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B;IACT,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,IAAI;IAkB/E,OAAO,CAAC,oBAAoB;IAO5B;;;OAGG;cACgB,kBAAkB,IAAI,QAAQ,CAAC,cAAc;IAIhE;;;OAGG;cACa,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAKhD"}
|
|
@@ -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,CAA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AI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACtG,CAAC;IAES,oBAAoB,CAAC,eAAwB;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
|