@rushstack/ts-command-line 4.23.4 → 4.23.6
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 +27 -0
- package/CHANGELOG.md +11 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/providers/AliasCommandLineAction.js +32 -14
- package/lib/providers/AliasCommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineParameterProvider.js +21 -8
- package/lib/providers/CommandLineParameterProvider.js.map +1 -1
- package/lib/providers/CommandLineParser.js +4 -1
- package/lib/providers/CommandLineParser.js.map +1 -1
- package/lib/providers/CommandLineParserExitError.js +17 -7
- package/lib/providers/CommandLineParserExitError.js.map +1 -1
- package/lib/providers/ScopedCommandLineAction.js +13 -2
- package/lib/providers/ScopedCommandLineAction.js.map +1 -1
- package/lib/providers/TabCompletionAction.js +55 -95
- package/lib/providers/TabCompletionAction.js.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/ts-command-line",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "4.23.6",
|
|
6
|
+
"tag": "@rushstack/ts-command-line_v4.23.6",
|
|
7
|
+
"date": "Tue, 11 Mar 2025 02:12:33 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"dependency": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.15.1`"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.12.0`"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"version": "4.23.5",
|
|
21
|
+
"tag": "@rushstack/ts-command-line_v4.23.5",
|
|
22
|
+
"date": "Wed, 12 Feb 2025 01:10:52 GMT",
|
|
23
|
+
"comments": {
|
|
24
|
+
"dependency": [
|
|
25
|
+
{
|
|
26
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.15.0`"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
4
31
|
{
|
|
5
32
|
"version": "4.23.4",
|
|
6
33
|
"tag": "@rushstack/ts-command-line_v4.23.4",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Change Log - @rushstack/ts-command-line
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 11 Mar 2025 02:12:33 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.23.6
|
|
6
|
+
Tue, 11 Mar 2025 02:12:33 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.23.5
|
|
11
|
+
Wed, 12 Feb 2025 01:10:52 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
4
14
|
|
|
5
15
|
## 4.23.4
|
|
6
16
|
Thu, 30 Jan 2025 01:11:42 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.AliasCommandLineAction = void 0;
|
|
29
39
|
const argparse = __importStar(require("argparse"));
|
|
@@ -69,25 +79,33 @@ class AliasCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
69
79
|
};
|
|
70
80
|
switch (kind) {
|
|
71
81
|
case BaseClasses_1.CommandLineParameterKind.Choice:
|
|
72
|
-
aliasParameter = this.defineChoiceParameter(
|
|
82
|
+
aliasParameter = this.defineChoiceParameter({
|
|
83
|
+
...nameOptions,
|
|
84
|
+
...parameter,
|
|
85
|
+
alternatives: [...parameter.alternatives]
|
|
86
|
+
});
|
|
73
87
|
break;
|
|
74
88
|
case BaseClasses_1.CommandLineParameterKind.ChoiceList:
|
|
75
|
-
aliasParameter = this.defineChoiceListParameter(
|
|
89
|
+
aliasParameter = this.defineChoiceListParameter({
|
|
90
|
+
...nameOptions,
|
|
91
|
+
...parameter,
|
|
92
|
+
alternatives: [...parameter.alternatives]
|
|
93
|
+
});
|
|
76
94
|
break;
|
|
77
95
|
case BaseClasses_1.CommandLineParameterKind.Flag:
|
|
78
|
-
aliasParameter = this.defineFlagParameter(
|
|
96
|
+
aliasParameter = this.defineFlagParameter({ ...nameOptions, ...parameter });
|
|
79
97
|
break;
|
|
80
98
|
case BaseClasses_1.CommandLineParameterKind.Integer:
|
|
81
|
-
aliasParameter = this.defineIntegerParameter(
|
|
99
|
+
aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...parameter });
|
|
82
100
|
break;
|
|
83
101
|
case BaseClasses_1.CommandLineParameterKind.IntegerList:
|
|
84
|
-
aliasParameter = this.defineIntegerListParameter(
|
|
102
|
+
aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...parameter });
|
|
85
103
|
break;
|
|
86
104
|
case BaseClasses_1.CommandLineParameterKind.String:
|
|
87
|
-
aliasParameter = this.defineStringParameter(
|
|
105
|
+
aliasParameter = this.defineStringParameter({ ...nameOptions, ...parameter });
|
|
88
106
|
break;
|
|
89
107
|
case BaseClasses_1.CommandLineParameterKind.StringList:
|
|
90
|
-
aliasParameter = this.defineStringListParameter(
|
|
108
|
+
aliasParameter = this.defineStringListParameter({ ...nameOptions, ...parameter });
|
|
91
109
|
break;
|
|
92
110
|
default:
|
|
93
111
|
throw new Error(`Unsupported parameter kind: ${kind}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAImC;AA+BnC;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC,CAAC,EAC5D,IAAI,CAAC;QAEL,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7B,OAAO;YACP,aAAa,EACX,GAAG,OAAO,oDAAoD;gBAC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B,CAAC,CAAC;YAEpF,yFAAyF;YACzF,IAAI,eAAe,EAAE,CAAC;gBACpB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAwC,EAAE,IAA4B;QAC9F,oGAAoG;QACpG,MAAM,UAAU,GAA2B;YACzC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;YACpC,WAAW,EAAE,IAAI,CAAC,MAAM;YACxB,kBAAkB,EAAE,IAAI,CAAC,aAAa;SACvC,CAAC;QACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,yFAAyF;YACzF,qFAAqF;YACrF,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAuB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrE,UAAU,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,GAAG,CAAC,GAAG,KAAK,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,SAAS;QACvB,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;IAC1C,CAAC;CACF;AA3ID,wDA2IC","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 * as argparse from 'argparse';\n\nimport { CommandLineAction } from './CommandLineAction';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\n\n/**\n * Options for the AliasCommandLineAction constructor.\n * @public\n */\nexport interface IAliasCommandLineActionOptions {\n /**\n * The name of your tool when invoked from the command line. Used for generating help text.\n */\n toolFilename: string;\n\n /**\n * The name of the alias. For example, if the tool is called \"example\",\n * then the \"build\" alias might be invoked as: \"example build -q --some-other-option\"\n */\n aliasName: string;\n\n /**\n * A list of default parameters to pass to the target action.\n */\n defaultParameters?: string[];\n\n /**\n * The action that this alias invokes.\n */\n targetAction: CommandLineAction;\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * The sub-command is an alias for another existing action.\n *\n * The alias name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\").\n *\n * @public\n */\nexport class AliasCommandLineAction extends CommandLineAction {\n /**\n * The action that this alias invokes.\n */\n public readonly targetAction: CommandLineAction;\n\n /**\n * A list of default arguments to pass to the target action.\n */\n public readonly defaultParameters: ReadonlyArray<string>;\n\n private _parameterKeyMap: Map<string, string> = new Map();\n\n public constructor(options: IAliasCommandLineActionOptions) {\n const toolFilename: string = options.toolFilename;\n const targetActionName: string = options.targetAction.actionName;\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\n defaultParametersString ? ` ${defaultParametersString}` : ''\n }\".`;\n\n super({\n actionName: options.aliasName,\n summary,\n documentation:\n `${summary} For more information on the aliased command, use ` +\n `\"${toolFilename} ${targetActionName} --help\".`\n });\n\n this.targetAction = options.targetAction;\n this.defaultParameters = options.defaultParameters || [];\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n /* override */\n // All parameters are going to be defined by the target action. Re-use the target action parameters\n // for this action.\n for (const parameter of this.targetAction.parameters as CommandLineParameter[]) {\n const { kind, longName, shortName } = parameter;\n let aliasParameter: CommandLineParameterBase;\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\n parameterLongName: longName,\n parameterShortName: shortName\n };\n switch (kind) {\n case CommandLineParameterKind.Choice:\n aliasParameter = this.defineChoiceParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.ChoiceList:\n aliasParameter = this.defineChoiceListParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.Flag:\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.Integer:\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.IntegerList:\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.String:\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.StringList:\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...parameter });\n break;\n default:\n throw new Error(`Unsupported parameter kind: ${kind}`);\n }\n\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\n // and all parameters that we have access to have already been defined.\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\n }\n\n // We also need to register the remainder parameter if the target action has one. The parser\n // key for this parameter is constant.\n if (this.targetAction.remainder) {\n this.defineCommandLineRemainder(this.targetAction.remainder);\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\n }\n\n // Finally, register the parameters with the parser. We need to make sure that the target action\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\n // during registration. This will no-op if the target action is already registered.\n this.targetAction._registerDefinedParameters(state);\n super._registerDefinedParameters(state);\n\n // We need to re-map the ambiguous parameters after they are defined by calling\n // super._registerDefinedParameters()\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n const targetParserKey: string | undefined =\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\n\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n if (targetParserKey) {\n this._parameterKeyMap.set(parserKey, targetParserKey);\n }\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // Re-map the parsed data to the target action's parameters and execute the target action processor.\n const targetData: ICommandLineParserData = {\n action: this.targetAction.actionName,\n aliasAction: data.action,\n aliasDocumentation: this.documentation\n };\n for (const [key, value] of Object.entries(data)) {\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n // Skip over the action key though, since we've already re-mapped it to \"aliasAction\"\n if (key === 'action') {\n continue;\n }\n const targetKey: string | undefined = this._parameterKeyMap.get(key);\n targetData[targetKey ?? key] = value;\n }\n this.targetAction._processParsedData(parserOptions, targetData);\n }\n\n /**\n * Executes the target action.\n */\n protected async onExecute(): Promise<void> {\n await this.targetAction._executeAsync();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAImC;AA+BnC;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC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AAC,aAAa,EAAE,CAAC;IAC1C,CAAC;CACF;AA3ID,wDA2IC","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 * as argparse from 'argparse';\n\nimport { CommandLineAction } from './CommandLineAction';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\n\n/**\n * Options for the AliasCommandLineAction constructor.\n * @public\n */\nexport interface IAliasCommandLineActionOptions {\n /**\n * The name of your tool when invoked from the command line. Used for generating help text.\n */\n toolFilename: string;\n\n /**\n * The name of the alias. For example, if the tool is called \"example\",\n * then the \"build\" alias might be invoked as: \"example build -q --some-other-option\"\n */\n aliasName: string;\n\n /**\n * A list of default parameters to pass to the target action.\n */\n defaultParameters?: string[];\n\n /**\n * The action that this alias invokes.\n */\n targetAction: CommandLineAction;\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * The sub-command is an alias for another existing action.\n *\n * The alias name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\").\n *\n * @public\n */\nexport class AliasCommandLineAction extends CommandLineAction {\n /**\n * The action that this alias invokes.\n */\n public readonly targetAction: CommandLineAction;\n\n /**\n * A list of default arguments to pass to the target action.\n */\n public readonly defaultParameters: ReadonlyArray<string>;\n\n private _parameterKeyMap: Map<string, string> = new Map();\n\n public constructor(options: IAliasCommandLineActionOptions) {\n const toolFilename: string = options.toolFilename;\n const targetActionName: string = options.targetAction.actionName;\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\n defaultParametersString ? ` ${defaultParametersString}` : ''\n }\".`;\n\n super({\n actionName: options.aliasName,\n summary,\n documentation:\n `${summary} For more information on the aliased command, use ` +\n `\"${toolFilename} ${targetActionName} --help\".`\n });\n\n this.targetAction = options.targetAction;\n this.defaultParameters = options.defaultParameters || [];\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n /* override */\n // All parameters are going to be defined by the target action. Re-use the target action parameters\n // for this action.\n for (const parameter of this.targetAction.parameters as CommandLineParameter[]) {\n const { kind, longName, shortName } = parameter;\n let aliasParameter: CommandLineParameterBase;\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\n parameterLongName: longName,\n parameterShortName: shortName\n };\n switch (kind) {\n case CommandLineParameterKind.Choice:\n aliasParameter = this.defineChoiceParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.ChoiceList:\n aliasParameter = this.defineChoiceListParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.Flag:\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.Integer:\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.IntegerList:\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.String:\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.StringList:\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...parameter });\n break;\n default:\n throw new Error(`Unsupported parameter kind: ${kind}`);\n }\n\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\n // and all parameters that we have access to have already been defined.\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\n }\n\n // We also need to register the remainder parameter if the target action has one. The parser\n // key for this parameter is constant.\n if (this.targetAction.remainder) {\n this.defineCommandLineRemainder(this.targetAction.remainder);\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\n }\n\n // Finally, register the parameters with the parser. We need to make sure that the target action\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\n // during registration. This will no-op if the target action is already registered.\n this.targetAction._registerDefinedParameters(state);\n super._registerDefinedParameters(state);\n\n // We need to re-map the ambiguous parameters after they are defined by calling\n // super._registerDefinedParameters()\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n const targetParserKey: string | undefined =\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\n\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n if (targetParserKey) {\n this._parameterKeyMap.set(parserKey, targetParserKey);\n }\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // Re-map the parsed data to the target action's parameters and execute the target action processor.\n const targetData: ICommandLineParserData = {\n action: this.targetAction.actionName,\n aliasAction: data.action,\n aliasDocumentation: this.documentation\n };\n for (const [key, value] of Object.entries(data)) {\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n // Skip over the action key though, since we've already re-mapped it to \"aliasAction\"\n if (key === 'action') {\n continue;\n }\n const targetKey: string | undefined = this._parameterKeyMap.get(key);\n targetData[targetKey ?? key] = value;\n }\n this.targetAction._processParsedData(parserOptions, targetData);\n }\n\n /**\n * Executes the target action.\n */\n protected async onExecute(): Promise<void> {\n await this.targetAction._executeAsync();\n }\n}\n"]}
|
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.CommandLineParameterProvider = void 0;
|
|
29
39
|
const argparse = __importStar(require("argparse"));
|
|
@@ -633,7 +643,10 @@ class CommandLineParameterProvider {
|
|
|
633
643
|
}
|
|
634
644
|
}
|
|
635
645
|
if (undocumentedSynonyms === null || undocumentedSynonyms === void 0 ? void 0 : undocumentedSynonyms.length) {
|
|
636
|
-
argumentGroup.addArgument(undocumentedSynonyms,
|
|
646
|
+
argumentGroup.addArgument(undocumentedSynonyms, {
|
|
647
|
+
...argparseOptions,
|
|
648
|
+
help: argparse.Const.SUPPRESS
|
|
649
|
+
});
|
|
637
650
|
}
|
|
638
651
|
// Register the parameter names so that we can detect ambiguous parameters
|
|
639
652
|
for (const name of [...names, ...(undocumentedSynonyms || [])]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAarC,2DAKmC;AACnC,yFAGkD;AAClD,iGAA8F;AAC9F,2FAGmD;AACnD,mGAAgG;AAChG,qFAAkF;AAClF,yF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rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as argparse from 'argparse';\n\nimport type {\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineRemainderDefinition\n} from '../parameters/CommandLineDefinition';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\nimport {\n type CommandLineParameterBase,\n type CommandLineParameterWithArgument,\n CommandLineParameterKind,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\nimport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from '../parameters/CommandLineIntegerParameter';\nimport { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\nimport { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\nimport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from '../parameters/CommandLineStringParameter';\nimport { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';\nimport { CommandLineRemainder } from '../parameters/CommandLineRemainder';\nimport { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\n\n/**\n * The result containing the parsed parameter long name and scope. Returned when calling\n * {@link CommandLineParameterProvider.parseScopedLongName}.\n *\n * @public\n */\nexport interface IScopedLongNameParseResult {\n /**\n * The long name parsed from the scoped long name, e.g. \"--my-scope:my-parameter\" -\\> \"--my-parameter\"\n */\n longName: string;\n\n /**\n * The scope parsed from the scoped long name or undefined if no scope was found,\n * e.g. \"--my-scope:my-parameter\" -\\> \"my-scope\"\n */\n scope: string | undefined;\n}\n\n/**\n * An object containing the state of the\n *\n * @internal\n */\nexport interface IRegisterDefinedParametersState {\n /**\n * A set of all defined parameter names registered by parent {@link CommandLineParameterProvider}\n * objects.\n */\n parentParameterNames: Set<string>;\n}\n\n/**\n * This is the argparse result data object\n * @internal\n */\nexport interface ICommandLineParserData {\n action: string;\n aliasAction?: string;\n aliasDocumentation?: string;\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nconst SCOPE_GROUP_NAME: string = 'scope';\nconst LONG_NAME_GROUP_NAME: string = 'longName';\nconst POSSIBLY_SCOPED_LONG_NAME_REGEXP: RegExp =\n /^--((?<scope>[a-z0-9]+(-[a-z0-9]+)*):)?(?<longName>[a-z0-9]+((-[a-z0-9]+)+)?)$/;\n\ninterface IExtendedArgumentGroup extends argparse.ArgumentGroup {\n // The types are incorrect - this function returns the constructed argument\n // object, which looks like the argument options type.\n addArgument(nameOrFlags: string | string[], options: argparse.ArgumentOptions): argparse.ArgumentOptions;\n}\n\ninterface IExtendedArgumentParser extends argparse.ArgumentParser {\n // This function throws\n error(message: string): never;\n}\n\n/**\n * This is the common base class for CommandLineAction and CommandLineParser\n * that provides functionality for defining command-line parameters.\n *\n * @public\n */\nexport abstract class CommandLineParameterProvider {\n private static _keyCounter: number = 0;\n\n /** @internal */\n public readonly _ambiguousParameterParserKeysByName: Map<string, string>;\n /** @internal */\n protected readonly _registeredParameterParserKeysByName: Map<string, string>;\n\n private readonly _parameters: CommandLineParameter[];\n private readonly _parametersByLongName: Map<string, CommandLineParameter[]>;\n private readonly _parametersByShortName: Map<string, CommandLineParameter[]>;\n private readonly _parameterGroupsByName: Map<\n string | typeof SCOPING_PARAMETER_GROUP,\n argparse.ArgumentGroup\n >;\n private _parametersHaveBeenRegistered: boolean;\n private _parametersHaveBeenProcessed: boolean;\n private _remainder: CommandLineRemainder | undefined;\n\n /** @internal */\n // Third party code should not inherit subclasses or call this constructor\n public constructor() {\n this._parameters = [];\n this._parametersByLongName = new Map();\n this._parametersByShortName = new Map();\n this._parameterGroupsByName = new Map();\n this._ambiguousParameterParserKeysByName = new Map();\n this._registeredParameterParserKeysByName = new Map();\n this._parametersHaveBeenRegistered = false;\n this._parametersHaveBeenProcessed = false;\n }\n\n /**\n * Returns a collection of the parameters that were defined for this object.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n return this._parameters;\n }\n\n /**\n * Informs the caller if the argparse data has been processed into parameters.\n */\n public get parametersProcessed(): boolean {\n return this._parametersHaveBeenProcessed;\n }\n\n /**\n * If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,\n * this object captures any remaining command line arguments after the recognized portion.\n */\n public get remainder(): CommandLineRemainder | undefined {\n return this._remainder;\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum).\n *\n * @remarks\n * Example of a choice parameter:\n * ```\n * example-tool --log-level warn\n * ```\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & {\n required: false | undefined;\n defaultValue: undefined;\n }\n ): CommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { required: true }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { defaultValue: TChoice }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice>;\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice> {\n const parameter: CommandLineChoiceParameter<TChoice> = new CommandLineChoiceParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Choice, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum). The parameter can be specified multiple times to\n * build a list.\n *\n * @remarks\n * Example of a choice list parameter:\n * ```\n * example-tool --allow-color red --allow-color green\n * ```\n */\n public defineChoiceListParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceListDefinition<TChoice>\n ): CommandLineChoiceListParameter<TChoice> {\n const parameter: CommandLineChoiceListParameter<TChoice> = new CommandLineChoiceListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineChoiceListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.ChoiceList, parameterScope);\n }\n\n /**\n * Defines a command-line switch whose boolean value is true if the switch is provided,\n * and false otherwise.\n *\n * @remarks\n * Example usage of a flag parameter:\n * ```\n * example-tool --debug\n * ```\n */\n public defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter {\n const parameter: CommandLineFlagParameter = new CommandLineFlagParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineFlagParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getFlagParameter(parameterLongName: string, parameterScope?: string): CommandLineFlagParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Flag, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer.\n *\n * @remarks\n * Example usage of an integer parameter:\n * ```\n * example-tool --max-attempts 5\n * ```\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { required: true }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { defaultValue: number }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter;\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter {\n const parameter: CommandLineIntegerParameter = new CommandLineIntegerParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Integer, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer. The parameter can be specified\n * multiple times to build a list.\n *\n * @remarks\n * Example usage of an integer list parameter:\n * ```\n * example-tool --avoid 4 --avoid 13\n * ```\n */\n public defineIntegerListParameter(\n definition: ICommandLineIntegerListDefinition\n ): CommandLineIntegerListParameter {\n const parameter: CommandLineIntegerListParameter = new CommandLineIntegerListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.IntegerList, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is a single text string.\n *\n * @remarks\n * Example usage of a string parameter:\n * ```\n * example-tool --message \"Hello, world!\"\n * ```\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { required: true }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { defaultValue: string }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter;\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter {\n const parameter: CommandLineStringParameter = new CommandLineStringParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineStringParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringParameter(parameterLongName: string, parameterScope?: string): CommandLineStringParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.String, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is a single text string. The parameter can be\n * specified multiple times to build a list.\n *\n * @remarks\n * Example usage of a string list parameter:\n * ```\n * example-tool --add file1.txt --add file2.txt --add file3.txt\n * ```\n */\n public defineStringListParameter(\n definition: ICommandLineStringListDefinition\n ): CommandLineStringListParameter {\n const parameter: CommandLineStringListParameter = new CommandLineStringListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @remarks\n * This feature is useful for commands that pass their arguments along to an external tool, relying on\n * that tool to perform validation. (It could also be used to parse parameters without any validation\n * or documentation, but that is not recommended.)\n *\n * Example of capturing the remainder after an optional flag parameter.\n * ```\n * example-tool --my-flag this is the remainder\n * ```\n *\n * In the \"--help\" documentation, the remainder rule will be represented as \"...\".\n */\n public defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder {\n if (this._remainder) {\n throw new Error('defineRemainingArguments() has already been called for this provider');\n }\n this._remainder = new CommandLineRemainder(definition);\n return this._remainder;\n }\n\n /**\n * Returns the CommandLineStringListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineStringListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.StringList, parameterScope);\n }\n\n /**\n * Generates the command-line help text.\n */\n public renderHelpText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatHelp();\n }\n\n /**\n * Generates the command-line usage text.\n */\n public renderUsageText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatUsage();\n }\n\n /**\n * Returns a object which maps the long name of each parameter in this.parameters\n * to the stringified form of its value. This is useful for logging telemetry, but\n * it is not the proper way of accessing parameters or their values.\n */\n public getParameterStringMap(): Record<string, string> {\n const parameterMap: Record<string, string> = {};\n for (const parameter of this.parameters) {\n const parameterName: string = parameter.scopedLongName || parameter.longName;\n switch (parameter.kind) {\n case CommandLineParameterKind.Flag:\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.String:\n case CommandLineParameterKind.Integer:\n parameterMap[parameterName] = JSON.stringify(\n (\n parameter as\n | CommandLineFlagParameter\n | CommandLineIntegerParameter\n | CommandLineChoiceParameter\n | CommandLineStringParameter\n ).value\n );\n break;\n case CommandLineParameterKind.StringList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.ChoiceList:\n const arrayValue: ReadonlyArray<string | number> | undefined = (\n parameter as\n | CommandLineIntegerListParameter\n | CommandLineStringListParameter\n | CommandLineChoiceListParameter\n ).values;\n parameterMap[parameterName] = arrayValue ? arrayValue.join(',') : '';\n break;\n }\n }\n return parameterMap;\n }\n\n /**\n * Returns an object with the parsed scope (if present) and the long name of the parameter.\n */\n public parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult {\n const result: RegExpExecArray | null = POSSIBLY_SCOPED_LONG_NAME_REGEXP.exec(scopedLongName);\n if (!result || !result.groups) {\n throw new Error(`The parameter long name \"${scopedLongName}\" is not valid.`);\n }\n return {\n longName: `--${result.groups[LONG_NAME_GROUP_NAME]}`,\n scope: result.groups[SCOPE_GROUP_NAME]\n };\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n if (this._parametersHaveBeenRegistered) {\n // We prevent new parameters from being defined after the first call to _registerDefinedParameters,\n // so we can already ensure that all parameters were registered.\n return;\n }\n\n // First, loop through all parameters with short names. If there are any duplicates, disable the short names\n // since we can't prefix scopes to short names in order to deduplicate them. The duplicate short names will\n // be reported as errors if the user attempts to use them.\n const parametersWithDuplicateShortNames: Set<CommandLineParameterBase> = new Set();\n for (const [shortName, shortNameParameters] of this._parametersByShortName.entries()) {\n if (shortNameParameters.length > 1) {\n for (const parameter of shortNameParameters) {\n this._defineAmbiguousParameter(shortName);\n parametersWithDuplicateShortNames.add(parameter);\n }\n }\n }\n\n // Then, loop through all parameters and register them. If there are any duplicates, ensure that they have\n // provided a scope and register them with the scope. The duplicate long names will be reported as an error\n // if the user attempts to use them.\n for (const longNameParameters of this._parametersByLongName.values()) {\n const useScopedLongName: boolean = longNameParameters.length > 1;\n for (const parameter of longNameParameters) {\n if (useScopedLongName) {\n if (!parameter.parameterScope) {\n throw new Error(\n `The parameter \"${parameter.longName}\" is defined multiple times with the same long name. ` +\n 'Parameters with the same long name must define a scope.'\n );\n }\n this._defineAmbiguousParameter(parameter.longName);\n }\n\n const ignoreShortName: boolean = parametersWithDuplicateShortNames.has(parameter);\n this._registerParameter(parameter, useScopedLongName, ignoreShortName);\n }\n }\n\n // Register the existing parameters as ambiguous parameters. These are generally provided by the\n // parent action.\n const { parentParameterNames } = state;\n for (const parentParameterName of parentParameterNames) {\n this._defineAmbiguousParameter(parentParameterName);\n }\n\n // We also need to loop through the defined ambiguous parameters and register them. These will be reported\n // as errors if the user attempts to use them.\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n // Only register the ambiguous parameter if it hasn't already been registered. We will still handle these\n // already-registered parameters as ambiguous, but by avoiding registering again, we will defer errors\n // until the user actually attempts to use the parameter.\n if (!this._registeredParameterParserKeysByName.has(ambiguousParameterName)) {\n this._registerAmbiguousParameter(ambiguousParameterName, parserKey);\n }\n }\n\n // Need to add the remainder parameter last\n if (this._remainder) {\n const argparseOptions: argparse.ArgumentOptions = {\n help: this._remainder.description,\n nargs: argparse.Const.REMAINDER,\n metavar: '\"...\"'\n };\n\n this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);\n }\n\n this._parametersHaveBeenRegistered = true;\n }\n\n /**\n * @deprecated - Define parameters in the constructor\n */\n protected onDefineParameters?(): void;\n\n /**\n * Retrieves the argparse object.\n * @internal\n */\n protected abstract _getArgumentParser(): argparse.ArgumentParser;\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _preParse(): void {\n for (const parameter of this._parameters) {\n parameter._preParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync} before `printUsage` is called\n * @internal\n */\n public _postParse(): void {\n for (const parameter of this._parameters) {\n parameter._postParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n if (!this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have not been registered');\n }\n\n if (this._parametersHaveBeenProcessed) {\n throw new Error('Command Line Parser Data was already processed');\n }\n\n // Search for any ambiguous parameters and throw an error if any are found\n for (const [parameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n if (data[parserKey]) {\n // When the parser key matches the actually registered parameter, we know that this is an ambiguous\n // parameter sourced from the parent action or tool\n if (this._registeredParameterParserKeysByName.get(parameterName) === parserKey) {\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n\n // Determine if the ambiguous parameter is a short name or a long name, since the process of finding\n // the non-ambiguous name is different for each.\n const duplicateShortNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByShortName.get(parameterName);\n if (duplicateShortNameParameters) {\n // We also need to make sure we get the non-ambiguous long name for the parameter, since it is\n // possible for that the long name is ambiguous as well.\n const nonAmbiguousLongNames: string[] = [];\n for (const parameter of duplicateShortNameParameters) {\n const matchingLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameter.longName);\n if (!matchingLongNameParameters?.length) {\n // This should never happen\n throw new Error(\n `Unable to find long name parameters for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n // If there is more than one matching long name parameter, then we know that we need to use the\n // scoped long name for the parameter. The scoped long name should always be provided.\n if (matchingLongNameParameters.length > 1) {\n if (!parameter.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n nonAmbiguousLongNames.push(parameter.scopedLongName);\n } else {\n nonAmbiguousLongNames.push(parameter.longName);\n }\n }\n\n // Throw an error including the non-ambiguous long names for the parameters that have the ambiguous\n // short name, ex.\n // Error: Ambiguous option \"-p\" could match \"--param1\", \"--param2\"\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n const duplicateLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterName);\n if (duplicateLongNameParameters) {\n const nonAmbiguousLongNames: string[] = duplicateLongNameParameters.map(\n (p: CommandLineParameterBase) => {\n // The scoped long name should always be provided\n if (!p.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous long name parameter \"${parameterName}\".`\n );\n }\n return p.scopedLongName;\n }\n );\n\n // Throw an error including the non-ambiguous scoped long names for the parameters that have the\n // ambiguous long name, ex.\n // Error: Ambiguous option: \"--param\" could match --scope1:param, --scope2:param\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n // This shouldn't happen, but we also shouldn't allow the user to use the ambiguous parameter\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n }\n\n // Fill in the values for the parameters\n for (const parameter of this._parameters) {\n const value: unknown = data[parameter._parserKey!];\n parameter._setValue(value);\n parameter._validateValue?.();\n }\n\n if (this.remainder) {\n this.remainder._setValue(data[argparse.Const.REMAINDER]);\n }\n\n this._parametersHaveBeenProcessed = true;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Generate and set the parser key at definition time\n parameter._parserKey = this._generateKey();\n\n this._parameters.push(parameter);\n\n // Collect all parameters with the same long name. We will perform conflict resolution at registration.\n let longNameParameters: CommandLineParameter[] | undefined = this._parametersByLongName.get(\n parameter.longName\n );\n if (!longNameParameters) {\n longNameParameters = [];\n this._parametersByLongName.set(parameter.longName, longNameParameters);\n }\n longNameParameters.push(parameter);\n\n // Collect all parameters with the same short name. We will perform conflict resolution at registration.\n if (parameter.shortName) {\n let shortNameParameters: CommandLineParameter[] | undefined = this._parametersByShortName.get(\n parameter.shortName\n );\n if (!shortNameParameters) {\n shortNameParameters = [];\n this._parametersByShortName.set(parameter.shortName, shortNameParameters);\n }\n shortNameParameters.push(parameter);\n }\n }\n\n /** @internal */\n protected _defineAmbiguousParameter(name: string): string {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Only generate a new parser key if the ambiguous parameter hasn't been defined yet,\n // either as an existing parameter or as another ambiguous parameter\n let existingParserKey: string | undefined =\n this._registeredParameterParserKeysByName.get(name) ||\n this._ambiguousParameterParserKeysByName.get(name);\n if (!existingParserKey) {\n existingParserKey = this._generateKey();\n }\n\n this._ambiguousParameterParserKeysByName.set(name, existingParserKey);\n return existingParserKey;\n }\n\n /** @internal */\n protected _registerParameter(\n parameter: CommandLineParameter,\n useScopedLongName: boolean,\n ignoreShortName: boolean\n ): void {\n const {\n shortName,\n longName,\n scopedLongName,\n description,\n kind,\n required,\n environmentVariable,\n parameterGroup,\n undocumentedSynonyms,\n _parserKey: parserKey\n } = parameter;\n\n const names: string[] = [];\n if (shortName && !ignoreShortName) {\n names.push(shortName);\n }\n\n // Use the original long name unless otherwise requested\n if (!useScopedLongName) {\n names.push(longName);\n }\n\n // Add the scoped long name if it exists\n if (scopedLongName) {\n names.push(scopedLongName);\n }\n\n let finalDescription: string = description;\n\n const supplementaryNotes: string[] = [];\n parameter._getSupplementaryNotes(supplementaryNotes);\n if (supplementaryNotes.length > 0) {\n // If they left the period off the end of their sentence, then add one.\n if (finalDescription.match(/[a-z0-9]\"?\\s*$/i)) {\n finalDescription = finalDescription.trimEnd() + '.';\n }\n // Append the supplementary text\n finalDescription += ' ' + supplementaryNotes.join(' ');\n }\n\n let choices: string[] | undefined;\n let action: string | undefined;\n let type: string | undefined;\n switch (kind) {\n case CommandLineParameterKind.Choice: {\n choices = Array.from(parameter.alternatives);\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n choices = Array.from(parameter.alternatives);\n action = 'append';\n break;\n }\n case CommandLineParameterKind.Flag:\n action = 'storeTrue';\n break;\n case CommandLineParameterKind.Integer:\n type = 'int';\n break;\n case CommandLineParameterKind.IntegerList:\n type = 'int';\n action = 'append';\n break;\n case CommandLineParameterKind.String:\n break;\n case CommandLineParameterKind.StringList:\n action = 'append';\n break;\n }\n\n // NOTE: Our \"environmentVariable\" feature takes precedence over argparse's \"defaultValue\",\n // so we have to reimplement that feature.\n const argparseOptions: argparse.ArgumentOptions = {\n help: finalDescription,\n dest: parserKey,\n metavar: (parameter as CommandLineParameterWithArgument).argumentName,\n required,\n choices,\n action,\n type\n };\n\n const argumentParser: IExtendedArgumentParser = this._getArgumentParser() as IExtendedArgumentParser;\n let argumentGroup: argparse.ArgumentGroup | undefined;\n if (parameterGroup) {\n argumentGroup = this._parameterGroupsByName.get(parameterGroup);\n if (!argumentGroup) {\n let parameterGroupName: string;\n if (typeof parameterGroup === 'string') {\n parameterGroupName = parameterGroup;\n } else if (parameterGroup === SCOPING_PARAMETER_GROUP) {\n parameterGroupName = 'scoping';\n } else {\n throw new Error('Unexpected parameter group: ' + parameterGroup);\n }\n\n argumentGroup = argumentParser.addArgumentGroup({\n title: `Optional ${parameterGroupName} arguments`\n });\n this._parameterGroupsByName.set(parameterGroup, argumentGroup);\n }\n } else {\n argumentGroup = argumentParser;\n }\n\n const argparseArgument: argparse.ArgumentOptions = (argumentGroup as IExtendedArgumentGroup).addArgument(\n names,\n argparseOptions\n );\n if (required && environmentVariable) {\n // Add some special-cased logic to handle required parameters with environment variables\n\n const originalPreParse: (() => void) | undefined = parameter._preParse?.bind(parameter);\n parameter._preParse = () => {\n originalPreParse?.();\n // Set the value as non-required before parsing. We'll validate it explicitly\n argparseArgument.required = false;\n };\n\n const originalPostParse: (() => void) | undefined = parameter._postParse?.bind(parameter);\n parameter._postParse = () => {\n // Reset the required value to make the usage text correct\n argparseArgument.required = true;\n originalPostParse?.();\n };\n\n function throwMissingParameterError(): never {\n argumentParser.error(`Argument \"${longName}\" is required`);\n }\n\n const originalValidateValue: (() => void) | undefined = parameter._validateValue?.bind(parameter);\n // For these values, we have to perform explicit validation because they're requested\n // as required, but we disabled argparse's required flag to allow the environment variable\n // to potentially fill the value.\n switch (kind) {\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.Integer:\n case CommandLineParameterKind.String:\n parameter._validateValue = function () {\n if (this.value === undefined || this.value === null) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n case CommandLineParameterKind.ChoiceList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.StringList:\n parameter._validateValue = function () {\n if (this.values.length === 0) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n }\n }\n\n if (undocumentedSynonyms?.length) {\n argumentGroup.addArgument(undocumentedSynonyms, {\n ...argparseOptions,\n help: argparse.Const.SUPPRESS\n });\n }\n\n // Register the parameter names so that we can detect ambiguous parameters\n for (const name of [...names, ...(undocumentedSynonyms || [])]) {\n this._registeredParameterParserKeysByName.set(name, parserKey!);\n }\n }\n\n protected _registerAmbiguousParameter(name: string, parserKey: string): void {\n this._getArgumentParser().addArgument(name, {\n dest: parserKey,\n // We don't know if this argument takes parameters or not, so we need to accept any number of args\n nargs: '*',\n // Ensure that the argument is not shown in the help text, since these parameters are only included\n // to inform the user that ambiguous parameters are present\n help: argparse.Const.SUPPRESS\n });\n }\n\n private _generateKey(): string {\n return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();\n }\n\n private _getParameter<T extends CommandLineParameterBase>(\n parameterLongName: string,\n expectedKind: CommandLineParameterKind,\n parameterScope?: string\n ): T {\n // Support the parameter long name being prefixed with the scope\n const { scope, longName } = this.parseScopedLongName(parameterLongName);\n parameterLongName = longName;\n parameterScope = scope || parameterScope;\n\n const parameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterLongName);\n if (!parameters) {\n throw new Error(`The parameter \"${parameterLongName}\" is not defined`);\n }\n\n let parameter: CommandLineParameterBase | undefined = parameters.find(\n (p) => p.parameterScope === parameterScope\n );\n if (!parameter) {\n if (parameterScope !== undefined) {\n throw new Error(\n `The parameter \"${parameterLongName}\" with scope \"${parameterScope}\" is not defined.`\n );\n }\n if (parameters.length !== 1) {\n throw new Error(`The parameter \"${parameterLongName}\" is ambiguous. You must specify a scope.`);\n }\n parameter = parameters[0];\n }\n\n if (parameter.kind !== expectedKind) {\n throw new Error(\n `The parameter \"${parameterLongName}\" is of type \"${CommandLineParameterKind[parameter.kind]}\"` +\n ` whereas the caller was expecting \"${CommandLineParameterKind[expectedKind]}\".`\n );\n }\n\n return parameter as T;\n }\n\n private _throwParserExitError(\n parserOptions: ICommandLineParserOptions,\n data: ICommandLineParserData,\n errorCode: number,\n message: string\n ): never {\n // Write out the usage text to make it easier for the user to find the correct parameter name\n const targetActionName: string = data.aliasAction || data.action || '';\n const errorPrefix: string =\n `Error: ${parserOptions.toolFilename}` +\n // Handle aliases, actions, and actionless parameter providers\n `${targetActionName ? ' ' : ''}${targetActionName}: error: `;\n\n // eslint-disable-next-line no-console\n console.log(this.renderUsageText());\n throw new CommandLineParserExitError(errorCode, `${errorPrefix}${message.trimStart().trimEnd()}\\n`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAarC,2DAKmC;AACnC,yFAGkD;AAClD,iGAA8F;AAC9F,2FAGmD;AACnD,mGAAgG;AAChG,qFAAkF;AAClF,yFAGkD;AAClD,iGAA8F;AAC9F,6EAA0E;AAC1E,4CAAuD;AACvD,6EAA0E;AA6C1E,MAAM,gBAAgB,GAAW,OAAO,CAAC;AACzC,MAAM,oBAAoB,GAAW,UAAU,CAAC;AAChD,MAAM,gCAAgC,GACpC,gFAAgF,CAAC;AAanF;;;;;GAKG;AACH,MAAsB,4BAA4B;IAmBhD,gBAAgB;IAChB,0EAA0E;IAC1E;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;QACvC,IAAI,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,mC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,CAAC,GAAG;gBAC7F,sCAAsC,sCAAwB,CAAC,YAAY,CAAC,IAAI,CACnF,CAAC;QACJ,CAAC;QAED,OAAO,SAAc,CAAC;IACxB,CAAC;IAEO,qBAAqB,CAC3B,aAAwC,EACxC,IAA4B,EAC5B,SAAiB,EACjB,OAAe;QAEf,6FAA6F;QAC7F,MAAM,gBAAgB,GAAW,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QACvE,MAAM,WAAW,GACf,UAAU,aAAa,CAAC,YAAY,EAAE;YACtC,8DAA8D;YAC9D,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,WAAW,CAAC;QAE/D,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QACpC,MAAM,IAAI,uDAA0B,CAAC,SAAS,EAAE,GAAG,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;;AAl6BH,oEAm6BC;AAl6BgB,wCAAW,GAAW,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\nimport * as argparse from 'argparse';\n\nimport type {\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineRemainderDefinition\n} from '../parameters/CommandLineDefinition';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\nimport {\n type CommandLineParameterBase,\n type CommandLineParameterWithArgument,\n CommandLineParameterKind,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\nimport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from '../parameters/CommandLineIntegerParameter';\nimport { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\nimport { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\nimport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from '../parameters/CommandLineStringParameter';\nimport { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';\nimport { CommandLineRemainder } from '../parameters/CommandLineRemainder';\nimport { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\n\n/**\n * The result containing the parsed parameter long name and scope. Returned when calling\n * {@link CommandLineParameterProvider.parseScopedLongName}.\n *\n * @public\n */\nexport interface IScopedLongNameParseResult {\n /**\n * The long name parsed from the scoped long name, e.g. \"--my-scope:my-parameter\" -\\> \"--my-parameter\"\n */\n longName: string;\n\n /**\n * The scope parsed from the scoped long name or undefined if no scope was found,\n * e.g. \"--my-scope:my-parameter\" -\\> \"my-scope\"\n */\n scope: string | undefined;\n}\n\n/**\n * An object containing the state of the\n *\n * @internal\n */\nexport interface IRegisterDefinedParametersState {\n /**\n * A set of all defined parameter names registered by parent {@link CommandLineParameterProvider}\n * objects.\n */\n parentParameterNames: Set<string>;\n}\n\n/**\n * This is the argparse result data object\n * @internal\n */\nexport interface ICommandLineParserData {\n action: string;\n aliasAction?: string;\n aliasDocumentation?: string;\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nconst SCOPE_GROUP_NAME: string = 'scope';\nconst LONG_NAME_GROUP_NAME: string = 'longName';\nconst POSSIBLY_SCOPED_LONG_NAME_REGEXP: RegExp =\n /^--((?<scope>[a-z0-9]+(-[a-z0-9]+)*):)?(?<longName>[a-z0-9]+((-[a-z0-9]+)+)?)$/;\n\ninterface IExtendedArgumentGroup extends argparse.ArgumentGroup {\n // The types are incorrect - this function returns the constructed argument\n // object, which looks like the argument options type.\n addArgument(nameOrFlags: string | string[], options: argparse.ArgumentOptions): argparse.ArgumentOptions;\n}\n\ninterface IExtendedArgumentParser extends argparse.ArgumentParser {\n // This function throws\n error(message: string): never;\n}\n\n/**\n * This is the common base class for CommandLineAction and CommandLineParser\n * that provides functionality for defining command-line parameters.\n *\n * @public\n */\nexport abstract class CommandLineParameterProvider {\n private static _keyCounter: number = 0;\n\n /** @internal */\n public readonly _ambiguousParameterParserKeysByName: Map<string, string>;\n /** @internal */\n protected readonly _registeredParameterParserKeysByName: Map<string, string>;\n\n private readonly _parameters: CommandLineParameter[];\n private readonly _parametersByLongName: Map<string, CommandLineParameter[]>;\n private readonly _parametersByShortName: Map<string, CommandLineParameter[]>;\n private readonly _parameterGroupsByName: Map<\n string | typeof SCOPING_PARAMETER_GROUP,\n argparse.ArgumentGroup\n >;\n private _parametersHaveBeenRegistered: boolean;\n private _parametersHaveBeenProcessed: boolean;\n private _remainder: CommandLineRemainder | undefined;\n\n /** @internal */\n // Third party code should not inherit subclasses or call this constructor\n public constructor() {\n this._parameters = [];\n this._parametersByLongName = new Map();\n this._parametersByShortName = new Map();\n this._parameterGroupsByName = new Map();\n this._ambiguousParameterParserKeysByName = new Map();\n this._registeredParameterParserKeysByName = new Map();\n this._parametersHaveBeenRegistered = false;\n this._parametersHaveBeenProcessed = false;\n }\n\n /**\n * Returns a collection of the parameters that were defined for this object.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n return this._parameters;\n }\n\n /**\n * Informs the caller if the argparse data has been processed into parameters.\n */\n public get parametersProcessed(): boolean {\n return this._parametersHaveBeenProcessed;\n }\n\n /**\n * If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,\n * this object captures any remaining command line arguments after the recognized portion.\n */\n public get remainder(): CommandLineRemainder | undefined {\n return this._remainder;\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum).\n *\n * @remarks\n * Example of a choice parameter:\n * ```\n * example-tool --log-level warn\n * ```\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & {\n required: false | undefined;\n defaultValue: undefined;\n }\n ): CommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { required: true }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { defaultValue: TChoice }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice>;\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice> {\n const parameter: CommandLineChoiceParameter<TChoice> = new CommandLineChoiceParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Choice, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum). The parameter can be specified multiple times to\n * build a list.\n *\n * @remarks\n * Example of a choice list parameter:\n * ```\n * example-tool --allow-color red --allow-color green\n * ```\n */\n public defineChoiceListParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceListDefinition<TChoice>\n ): CommandLineChoiceListParameter<TChoice> {\n const parameter: CommandLineChoiceListParameter<TChoice> = new CommandLineChoiceListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineChoiceListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.ChoiceList, parameterScope);\n }\n\n /**\n * Defines a command-line switch whose boolean value is true if the switch is provided,\n * and false otherwise.\n *\n * @remarks\n * Example usage of a flag parameter:\n * ```\n * example-tool --debug\n * ```\n */\n public defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter {\n const parameter: CommandLineFlagParameter = new CommandLineFlagParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineFlagParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getFlagParameter(parameterLongName: string, parameterScope?: string): CommandLineFlagParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Flag, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer.\n *\n * @remarks\n * Example usage of an integer parameter:\n * ```\n * example-tool --max-attempts 5\n * ```\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { required: true }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { defaultValue: number }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter;\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter {\n const parameter: CommandLineIntegerParameter = new CommandLineIntegerParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Integer, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer. The parameter can be specified\n * multiple times to build a list.\n *\n * @remarks\n * Example usage of an integer list parameter:\n * ```\n * example-tool --avoid 4 --avoid 13\n * ```\n */\n public defineIntegerListParameter(\n definition: ICommandLineIntegerListDefinition\n ): CommandLineIntegerListParameter {\n const parameter: CommandLineIntegerListParameter = new CommandLineIntegerListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.IntegerList, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is a single text string.\n *\n * @remarks\n * Example usage of a string parameter:\n * ```\n * example-tool --message \"Hello, world!\"\n * ```\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { required: true }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { defaultValue: string }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter;\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter {\n const parameter: CommandLineStringParameter = new CommandLineStringParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineStringParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringParameter(parameterLongName: string, parameterScope?: string): CommandLineStringParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.String, parameterScope);\n }\n\n /**\n * Defines a command-line parameter whose argument is a single text string. The parameter can be\n * specified multiple times to build a list.\n *\n * @remarks\n * Example usage of a string list parameter:\n * ```\n * example-tool --add file1.txt --add file2.txt --add file3.txt\n * ```\n */\n public defineStringListParameter(\n definition: ICommandLineStringListDefinition\n ): CommandLineStringListParameter {\n const parameter: CommandLineStringListParameter = new CommandLineStringListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @remarks\n * This feature is useful for commands that pass their arguments along to an external tool, relying on\n * that tool to perform validation. (It could also be used to parse parameters without any validation\n * or documentation, but that is not recommended.)\n *\n * Example of capturing the remainder after an optional flag parameter.\n * ```\n * example-tool --my-flag this is the remainder\n * ```\n *\n * In the \"--help\" documentation, the remainder rule will be represented as \"...\".\n */\n public defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder {\n if (this._remainder) {\n throw new Error('defineRemainingArguments() has already been called for this provider');\n }\n this._remainder = new CommandLineRemainder(definition);\n return this._remainder;\n }\n\n /**\n * Returns the CommandLineStringListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringListParameter(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineStringListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.StringList, parameterScope);\n }\n\n /**\n * Generates the command-line help text.\n */\n public renderHelpText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatHelp();\n }\n\n /**\n * Generates the command-line usage text.\n */\n public renderUsageText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatUsage();\n }\n\n /**\n * Returns a object which maps the long name of each parameter in this.parameters\n * to the stringified form of its value. This is useful for logging telemetry, but\n * it is not the proper way of accessing parameters or their values.\n */\n public getParameterStringMap(): Record<string, string> {\n const parameterMap: Record<string, string> = {};\n for (const parameter of this.parameters) {\n const parameterName: string = parameter.scopedLongName || parameter.longName;\n switch (parameter.kind) {\n case CommandLineParameterKind.Flag:\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.String:\n case CommandLineParameterKind.Integer:\n parameterMap[parameterName] = JSON.stringify(\n (\n parameter as\n | CommandLineFlagParameter\n | CommandLineIntegerParameter\n | CommandLineChoiceParameter\n | CommandLineStringParameter\n ).value\n );\n break;\n case CommandLineParameterKind.StringList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.ChoiceList:\n const arrayValue: ReadonlyArray<string | number> | undefined = (\n parameter as\n | CommandLineIntegerListParameter\n | CommandLineStringListParameter\n | CommandLineChoiceListParameter\n ).values;\n parameterMap[parameterName] = arrayValue ? arrayValue.join(',') : '';\n break;\n }\n }\n return parameterMap;\n }\n\n /**\n * Returns an object with the parsed scope (if present) and the long name of the parameter.\n */\n public parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult {\n const result: RegExpExecArray | null = POSSIBLY_SCOPED_LONG_NAME_REGEXP.exec(scopedLongName);\n if (!result || !result.groups) {\n throw new Error(`The parameter long name \"${scopedLongName}\" is not valid.`);\n }\n return {\n longName: `--${result.groups[LONG_NAME_GROUP_NAME]}`,\n scope: result.groups[SCOPE_GROUP_NAME]\n };\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n if (this._parametersHaveBeenRegistered) {\n // We prevent new parameters from being defined after the first call to _registerDefinedParameters,\n // so we can already ensure that all parameters were registered.\n return;\n }\n\n // First, loop through all parameters with short names. If there are any duplicates, disable the short names\n // since we can't prefix scopes to short names in order to deduplicate them. The duplicate short names will\n // be reported as errors if the user attempts to use them.\n const parametersWithDuplicateShortNames: Set<CommandLineParameterBase> = new Set();\n for (const [shortName, shortNameParameters] of this._parametersByShortName.entries()) {\n if (shortNameParameters.length > 1) {\n for (const parameter of shortNameParameters) {\n this._defineAmbiguousParameter(shortName);\n parametersWithDuplicateShortNames.add(parameter);\n }\n }\n }\n\n // Then, loop through all parameters and register them. If there are any duplicates, ensure that they have\n // provided a scope and register them with the scope. The duplicate long names will be reported as an error\n // if the user attempts to use them.\n for (const longNameParameters of this._parametersByLongName.values()) {\n const useScopedLongName: boolean = longNameParameters.length > 1;\n for (const parameter of longNameParameters) {\n if (useScopedLongName) {\n if (!parameter.parameterScope) {\n throw new Error(\n `The parameter \"${parameter.longName}\" is defined multiple times with the same long name. ` +\n 'Parameters with the same long name must define a scope.'\n );\n }\n this._defineAmbiguousParameter(parameter.longName);\n }\n\n const ignoreShortName: boolean = parametersWithDuplicateShortNames.has(parameter);\n this._registerParameter(parameter, useScopedLongName, ignoreShortName);\n }\n }\n\n // Register the existing parameters as ambiguous parameters. These are generally provided by the\n // parent action.\n const { parentParameterNames } = state;\n for (const parentParameterName of parentParameterNames) {\n this._defineAmbiguousParameter(parentParameterName);\n }\n\n // We also need to loop through the defined ambiguous parameters and register them. These will be reported\n // as errors if the user attempts to use them.\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n // Only register the ambiguous parameter if it hasn't already been registered. We will still handle these\n // already-registered parameters as ambiguous, but by avoiding registering again, we will defer errors\n // until the user actually attempts to use the parameter.\n if (!this._registeredParameterParserKeysByName.has(ambiguousParameterName)) {\n this._registerAmbiguousParameter(ambiguousParameterName, parserKey);\n }\n }\n\n // Need to add the remainder parameter last\n if (this._remainder) {\n const argparseOptions: argparse.ArgumentOptions = {\n help: this._remainder.description,\n nargs: argparse.Const.REMAINDER,\n metavar: '\"...\"'\n };\n\n this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);\n }\n\n this._parametersHaveBeenRegistered = true;\n }\n\n /**\n * @deprecated - Define parameters in the constructor\n */\n protected onDefineParameters?(): void;\n\n /**\n * Retrieves the argparse object.\n * @internal\n */\n protected abstract _getArgumentParser(): argparse.ArgumentParser;\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _preParse(): void {\n for (const parameter of this._parameters) {\n parameter._preParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync} before `printUsage` is called\n * @internal\n */\n public _postParse(): void {\n for (const parameter of this._parameters) {\n parameter._postParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n if (!this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have not been registered');\n }\n\n if (this._parametersHaveBeenProcessed) {\n throw new Error('Command Line Parser Data was already processed');\n }\n\n // Search for any ambiguous parameters and throw an error if any are found\n for (const [parameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n if (data[parserKey]) {\n // When the parser key matches the actually registered parameter, we know that this is an ambiguous\n // parameter sourced from the parent action or tool\n if (this._registeredParameterParserKeysByName.get(parameterName) === parserKey) {\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n\n // Determine if the ambiguous parameter is a short name or a long name, since the process of finding\n // the non-ambiguous name is different for each.\n const duplicateShortNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByShortName.get(parameterName);\n if (duplicateShortNameParameters) {\n // We also need to make sure we get the non-ambiguous long name for the parameter, since it is\n // possible for that the long name is ambiguous as well.\n const nonAmbiguousLongNames: string[] = [];\n for (const parameter of duplicateShortNameParameters) {\n const matchingLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameter.longName);\n if (!matchingLongNameParameters?.length) {\n // This should never happen\n throw new Error(\n `Unable to find long name parameters for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n // If there is more than one matching long name parameter, then we know that we need to use the\n // scoped long name for the parameter. The scoped long name should always be provided.\n if (matchingLongNameParameters.length > 1) {\n if (!parameter.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n nonAmbiguousLongNames.push(parameter.scopedLongName);\n } else {\n nonAmbiguousLongNames.push(parameter.longName);\n }\n }\n\n // Throw an error including the non-ambiguous long names for the parameters that have the ambiguous\n // short name, ex.\n // Error: Ambiguous option \"-p\" could match \"--param1\", \"--param2\"\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n const duplicateLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterName);\n if (duplicateLongNameParameters) {\n const nonAmbiguousLongNames: string[] = duplicateLongNameParameters.map(\n (p: CommandLineParameterBase) => {\n // The scoped long name should always be provided\n if (!p.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous long name parameter \"${parameterName}\".`\n );\n }\n return p.scopedLongName;\n }\n );\n\n // Throw an error including the non-ambiguous scoped long names for the parameters that have the\n // ambiguous long name, ex.\n // Error: Ambiguous option: \"--param\" could match --scope1:param, --scope2:param\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n // This shouldn't happen, but we also shouldn't allow the user to use the ambiguous parameter\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n }\n\n // Fill in the values for the parameters\n for (const parameter of this._parameters) {\n const value: unknown = data[parameter._parserKey!];\n parameter._setValue(value);\n parameter._validateValue?.();\n }\n\n if (this.remainder) {\n this.remainder._setValue(data[argparse.Const.REMAINDER]);\n }\n\n this._parametersHaveBeenProcessed = true;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Generate and set the parser key at definition time\n parameter._parserKey = this._generateKey();\n\n this._parameters.push(parameter);\n\n // Collect all parameters with the same long name. We will perform conflict resolution at registration.\n let longNameParameters: CommandLineParameter[] | undefined = this._parametersByLongName.get(\n parameter.longName\n );\n if (!longNameParameters) {\n longNameParameters = [];\n this._parametersByLongName.set(parameter.longName, longNameParameters);\n }\n longNameParameters.push(parameter);\n\n // Collect all parameters with the same short name. We will perform conflict resolution at registration.\n if (parameter.shortName) {\n let shortNameParameters: CommandLineParameter[] | undefined = this._parametersByShortName.get(\n parameter.shortName\n );\n if (!shortNameParameters) {\n shortNameParameters = [];\n this._parametersByShortName.set(parameter.shortName, shortNameParameters);\n }\n shortNameParameters.push(parameter);\n }\n }\n\n /** @internal */\n protected _defineAmbiguousParameter(name: string): string {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Only generate a new parser key if the ambiguous parameter hasn't been defined yet,\n // either as an existing parameter or as another ambiguous parameter\n let existingParserKey: string | undefined =\n this._registeredParameterParserKeysByName.get(name) ||\n this._ambiguousParameterParserKeysByName.get(name);\n if (!existingParserKey) {\n existingParserKey = this._generateKey();\n }\n\n this._ambiguousParameterParserKeysByName.set(name, existingParserKey);\n return existingParserKey;\n }\n\n /** @internal */\n protected _registerParameter(\n parameter: CommandLineParameter,\n useScopedLongName: boolean,\n ignoreShortName: boolean\n ): void {\n const {\n shortName,\n longName,\n scopedLongName,\n description,\n kind,\n required,\n environmentVariable,\n parameterGroup,\n undocumentedSynonyms,\n _parserKey: parserKey\n } = parameter;\n\n const names: string[] = [];\n if (shortName && !ignoreShortName) {\n names.push(shortName);\n }\n\n // Use the original long name unless otherwise requested\n if (!useScopedLongName) {\n names.push(longName);\n }\n\n // Add the scoped long name if it exists\n if (scopedLongName) {\n names.push(scopedLongName);\n }\n\n let finalDescription: string = description;\n\n const supplementaryNotes: string[] = [];\n parameter._getSupplementaryNotes(supplementaryNotes);\n if (supplementaryNotes.length > 0) {\n // If they left the period off the end of their sentence, then add one.\n if (finalDescription.match(/[a-z0-9]\"?\\s*$/i)) {\n finalDescription = finalDescription.trimEnd() + '.';\n }\n // Append the supplementary text\n finalDescription += ' ' + supplementaryNotes.join(' ');\n }\n\n let choices: string[] | undefined;\n let action: string | undefined;\n let type: string | undefined;\n switch (kind) {\n case CommandLineParameterKind.Choice: {\n choices = Array.from(parameter.alternatives);\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n choices = Array.from(parameter.alternatives);\n action = 'append';\n break;\n }\n case CommandLineParameterKind.Flag:\n action = 'storeTrue';\n break;\n case CommandLineParameterKind.Integer:\n type = 'int';\n break;\n case CommandLineParameterKind.IntegerList:\n type = 'int';\n action = 'append';\n break;\n case CommandLineParameterKind.String:\n break;\n case CommandLineParameterKind.StringList:\n action = 'append';\n break;\n }\n\n // NOTE: Our \"environmentVariable\" feature takes precedence over argparse's \"defaultValue\",\n // so we have to reimplement that feature.\n const argparseOptions: argparse.ArgumentOptions = {\n help: finalDescription,\n dest: parserKey,\n metavar: (parameter as CommandLineParameterWithArgument).argumentName,\n required,\n choices,\n action,\n type\n };\n\n const argumentParser: IExtendedArgumentParser = this._getArgumentParser() as IExtendedArgumentParser;\n let argumentGroup: argparse.ArgumentGroup | undefined;\n if (parameterGroup) {\n argumentGroup = this._parameterGroupsByName.get(parameterGroup);\n if (!argumentGroup) {\n let parameterGroupName: string;\n if (typeof parameterGroup === 'string') {\n parameterGroupName = parameterGroup;\n } else if (parameterGroup === SCOPING_PARAMETER_GROUP) {\n parameterGroupName = 'scoping';\n } else {\n throw new Error('Unexpected parameter group: ' + parameterGroup);\n }\n\n argumentGroup = argumentParser.addArgumentGroup({\n title: `Optional ${parameterGroupName} arguments`\n });\n this._parameterGroupsByName.set(parameterGroup, argumentGroup);\n }\n } else {\n argumentGroup = argumentParser;\n }\n\n const argparseArgument: argparse.ArgumentOptions = (argumentGroup as IExtendedArgumentGroup).addArgument(\n names,\n argparseOptions\n );\n if (required && environmentVariable) {\n // Add some special-cased logic to handle required parameters with environment variables\n\n const originalPreParse: (() => void) | undefined = parameter._preParse?.bind(parameter);\n parameter._preParse = () => {\n originalPreParse?.();\n // Set the value as non-required before parsing. We'll validate it explicitly\n argparseArgument.required = false;\n };\n\n const originalPostParse: (() => void) | undefined = parameter._postParse?.bind(parameter);\n parameter._postParse = () => {\n // Reset the required value to make the usage text correct\n argparseArgument.required = true;\n originalPostParse?.();\n };\n\n function throwMissingParameterError(): never {\n argumentParser.error(`Argument \"${longName}\" is required`);\n }\n\n const originalValidateValue: (() => void) | undefined = parameter._validateValue?.bind(parameter);\n // For these values, we have to perform explicit validation because they're requested\n // as required, but we disabled argparse's required flag to allow the environment variable\n // to potentially fill the value.\n switch (kind) {\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.Integer:\n case CommandLineParameterKind.String:\n parameter._validateValue = function () {\n if (this.value === undefined || this.value === null) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n case CommandLineParameterKind.ChoiceList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.StringList:\n parameter._validateValue = function () {\n if (this.values.length === 0) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n }\n }\n\n if (undocumentedSynonyms?.length) {\n argumentGroup.addArgument(undocumentedSynonyms, {\n ...argparseOptions,\n help: argparse.Const.SUPPRESS\n });\n }\n\n // Register the parameter names so that we can detect ambiguous parameters\n for (const name of [...names, ...(undocumentedSynonyms || [])]) {\n this._registeredParameterParserKeysByName.set(name, parserKey!);\n }\n }\n\n protected _registerAmbiguousParameter(name: string, parserKey: string): void {\n this._getArgumentParser().addArgument(name, {\n dest: parserKey,\n // We don't know if this argument takes parameters or not, so we need to accept any number of args\n nargs: '*',\n // Ensure that the argument is not shown in the help text, since these parameters are only included\n // to inform the user that ambiguous parameters are present\n help: argparse.Const.SUPPRESS\n });\n }\n\n private _generateKey(): string {\n return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();\n }\n\n private _getParameter<T extends CommandLineParameterBase>(\n parameterLongName: string,\n expectedKind: CommandLineParameterKind,\n parameterScope?: string\n ): T {\n // Support the parameter long name being prefixed with the scope\n const { scope, longName } = this.parseScopedLongName(parameterLongName);\n parameterLongName = longName;\n parameterScope = scope || parameterScope;\n\n const parameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterLongName);\n if (!parameters) {\n throw new Error(`The parameter \"${parameterLongName}\" is not defined`);\n }\n\n let parameter: CommandLineParameterBase | undefined = parameters.find(\n (p) => p.parameterScope === parameterScope\n );\n if (!parameter) {\n if (parameterScope !== undefined) {\n throw new Error(\n `The parameter \"${parameterLongName}\" with scope \"${parameterScope}\" is not defined.`\n );\n }\n if (parameters.length !== 1) {\n throw new Error(`The parameter \"${parameterLongName}\" is ambiguous. You must specify a scope.`);\n }\n parameter = parameters[0];\n }\n\n if (parameter.kind !== expectedKind) {\n throw new Error(\n `The parameter \"${parameterLongName}\" is of type \"${CommandLineParameterKind[parameter.kind]}\"` +\n ` whereas the caller was expecting \"${CommandLineParameterKind[expectedKind]}\".`\n );\n }\n\n return parameter as T;\n }\n\n private _throwParserExitError(\n parserOptions: ICommandLineParserOptions,\n data: ICommandLineParserData,\n errorCode: number,\n message: string\n ): never {\n // Write out the usage text to make it easier for the user to find the correct parameter name\n const targetActionName: string = data.aliasAction || data.action || '';\n const errorPrefix: string =\n `Error: ${parserOptions.toolFilename}` +\n // Handle aliases, actions, and actionless parameter providers\n `${targetActionName ? ' ' : ''}${targetActionName}: error: `;\n\n // eslint-disable-next-line no-console\n console.log(this.renderUsageText());\n throw new CommandLineParserExitError(errorCode, `${errorPrefix}${message.trimStart().trimEnd()}\\n`);\n }\n}\n"]}
|
|
@@ -247,7 +247,10 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
247
247
|
...parentParameterNames,
|
|
248
248
|
...this._registeredParameterParserKeysByName.keys()
|
|
249
249
|
]);
|
|
250
|
-
const parentState =
|
|
250
|
+
const parentState = {
|
|
251
|
+
...state,
|
|
252
|
+
parentParameterNames: updatedParentParameterNames
|
|
253
|
+
};
|
|
251
254
|
for (const action of this._actions) {
|
|
252
255
|
action._registerDefinedParameters(parentState);
|
|
253
256
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAA+C;AAI/C,iFAIwC;AACxC,6EAAgG;AAChG,+DAA0D;AAC1D,kDAAqE;AA6BrE;;;;;;;;;GASG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAgB1E,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,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;QAE3D,IAAI,CAAC,eAAe,GAAG,IAAI,iDAAoB,CAAC;YAC9C,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;YAChC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe;YAC1C,MAAM,EAAE,mBAAQ,CAAC,IAAI,CACnB,MAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,mCACtB,oDAAoD,IAAI,CAAC,QAAQ,CAAC,YAAY,eAAe,CAChG;SACF,CAAC,CAAC;QAEH,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAC;IAC9B,CAAC;IA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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,mCACZ,KAAK,KACR,oBAAoB,EAAE,2BAA2B,GAClD,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,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;IACO,kBAAkB;QAC1B,WAAW;QACX,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AAjTD,8CAiTC","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';\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';\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 abstract 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 abstract 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 _actions: CommandLineAction[];\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._actions = [];\n this._actionsByName = new Map<string, CommandLineAction>();\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: this._options.toolFilename,\n description: this._options.toolDescription,\n epilog: Colorize.bold(\n this._options.toolEpilog ??\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\n )\n });\n\n this.onDefineParameters?.();\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 this._actions;\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._actions.push(action);\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 * @deprecated Use {@link CommandLineParser.executeAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async execute(args?: string[]): Promise<boolean> {\n return await this.executeAsync(args);\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.onExecute();\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 /**\n * @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\n await this.executeWithoutErrorHandlingAsync(args);\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._actions) {\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 _getArgumentParser(): argparse.ArgumentParser {\n // override\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 onExecute(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._executeAsync();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAA+C;AAI/C,iFAIwC;AACxC,6EAAgG;AAChG,+DAA0D;AAC1D,kDAAqE;AA6BrE;;;;;;;;;GASG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAgB1E,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,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;QAE3D,IAAI,CAAC,eAAe,GAAG,IAAI,iDAAoB,CAAC;YAC9C,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;YAChC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe;YAC1C,MAAM,EAAE,mBAAQ,CAAC,IAAI,CACnB,MAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,mCACtB,oDAAoD,IAAI,CAAC,QAAQ,CAAC,YAA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I,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC;IACpD,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,QAAQ,EAAE,CAAC;YACnC,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;IACO,kBAAkB;QAC1B,WAAW;QACX,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AAjTD,8CAiTC","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';\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';\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 abstract 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 abstract 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 _actions: CommandLineAction[];\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._actions = [];\n this._actionsByName = new Map<string, CommandLineAction>();\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: this._options.toolFilename,\n description: this._options.toolDescription,\n epilog: Colorize.bold(\n this._options.toolEpilog ??\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\n )\n });\n\n this.onDefineParameters?.();\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 this._actions;\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._actions.push(action);\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 * @deprecated Use {@link CommandLineParser.executeAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async execute(args?: string[]): Promise<boolean> {\n return await this.executeAsync(args);\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.onExecute();\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 /**\n * @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\n await this.executeWithoutErrorHandlingAsync(args);\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._actions) {\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 _getArgumentParser(): argparse.ArgumentParser {\n // override\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 onExecute(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._executeAsync();\n }\n }\n}\n"]}
|
|
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
17
17
|
}) : function(o, v) {
|
|
18
18
|
o["default"] = v;
|
|
19
19
|
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
27
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
38
|
exports.CustomArgumentParser = exports.CommandLineParserExitError = void 0;
|
|
29
39
|
const argparse = __importStar(require("argparse"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParserExitError.js","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D
|
|
1
|
+
{"version":3,"file":"CommandLineParserExitError.js","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,MAAa,0BAA2B,SAAQ,KAAK;IAGnD,YAAmB,QAAgB,EAAE,OAAe;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,sGAAsG;QACtG,6IAA6I;QAC7I,EAAE;QACF,4EAA4E;QAC3E,IAAY,CAAC,SAAS,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC,yDAAyD;QAEzH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAdD,gEAcC;AAED,MAAa,oBAAqB,SAAQ,QAAQ,CAAC,cAAc;IACxD,IAAI,CAAC,MAAc,EAAE,OAAe;QACzC,WAAW;QACX,MAAM,IAAI,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,GAAmB;QAC9B,WAAW;QACX,kFAAkF;QAClF,IAAI,GAAG,YAAY,0BAA0B,EAAE,CAAC;YAC9C,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AAfD,oDAeC","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 * as argparse from 'argparse';\n\nexport class CommandLineParserExitError extends Error {\n public readonly exitCode: number;\n\n public constructor(exitCode: number, message: string) {\n super(message);\n\n // Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc\n // https://github.com/microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n //\n // Note: the prototype must also be set on any classes which extend this one\n (this as any).__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n this.exitCode = exitCode;\n }\n}\n\nexport class CustomArgumentParser extends argparse.ArgumentParser {\n public exit(status: number, message: string): void {\n // override\n throw new CommandLineParserExitError(status, message);\n }\n\n public error(err: Error | string): void {\n // override\n // Ensure the ParserExitError bubbles up to the top without any special processing\n if (err instanceof CommandLineParserExitError) {\n throw err;\n }\n\n super.error(err);\n }\n}\n"]}
|
|
@@ -117,7 +117,15 @@ class ScopedCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
117
117
|
this._unscopedParserOptions = parserOptions;
|
|
118
118
|
// Generate the scoped parser using the parent parser information. We can only create this after we
|
|
119
119
|
// have parsed the data, since the parameter values are used during construction.
|
|
120
|
-
this._scopedCommandLineParser = new InternalScopedCommandLineParser(
|
|
120
|
+
this._scopedCommandLineParser = new InternalScopedCommandLineParser({
|
|
121
|
+
...parserOptions,
|
|
122
|
+
actionOptions: this._options,
|
|
123
|
+
aliasAction: data.aliasAction,
|
|
124
|
+
aliasDocumentation: data.aliasDocumentation,
|
|
125
|
+
unscopedActionParameters: this.parameters,
|
|
126
|
+
registerDefinedParametersState: this._subparserState,
|
|
127
|
+
onDefineScopedParameters: this.onDefineScopedParameters.bind(this)
|
|
128
|
+
});
|
|
121
129
|
}
|
|
122
130
|
/**
|
|
123
131
|
* {@inheritdoc CommandLineAction._executeAsync}
|
|
@@ -169,7 +177,10 @@ class ScopedCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
169
177
|
...parentParameterNames,
|
|
170
178
|
...this._registeredParameterParserKeysByName.keys()
|
|
171
179
|
]);
|
|
172
|
-
this._subparserState =
|
|
180
|
+
this._subparserState = {
|
|
181
|
+
...state,
|
|
182
|
+
parentParameterNames: updatedParentParameterNames
|
|
183
|
+
};
|
|
173
184
|
}
|
|
174
185
|
/**
|
|
175
186
|
* Retrieves the scoped CommandLineParser, which is populated after the ScopedCommandLineAction is executed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopedCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/ScopedCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,4CAAuD;AACvD,2DAAwF;AACxF,2DAAwF;AACxF,6EAA0E;AAiB1E;;;GAGG;AACH,MAAM,+BAAgC,SAAQ,qCAAiB;IAI7D,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,YAAmB,OAAgD;QACjE,MAAM,EAAE,aAAa,EAAE,wBAAwB,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAC9F,OAAO,CAAC;QAEV,MAAM,WAAW,GAAW,GAAG,YAAY,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QAC1E,6FAA6F;QAC7F,MAAM,qBAAqB,GAAW,GAAG,YAAY,IAAI,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QACnG,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,KAAK,MAAM,SAAS,IAAI,wBAAwB,EAAE,CAAC;YACjD,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,KAAK,GAAW,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE5C,2FAA2F;QAC3F,+EAA+E;QAC/E,MAAM,8BAA8B,GAA8B;YAChE,wFAAwF;YACxF,8BAA8B;YAC9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,GAAG,oBAAoB;YACvB,GAAG,IAAI,CAAC,oCAAoC,CAAC,IAAI,EAAE;SACpD,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,mCACf,KAAK,KACR,oBAAoB,EAAE,2BAA2B,GAClD,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,2BAA2B;QACnC,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;QAClG,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,SAA+B;QACxD,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,SAAS,CAAC,cAAc,KAAK,uBAAuB,CAAC,qBAAqB,EAAE,CAAC;YAC/E,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;;AA9JH,0DAoLC;AA7KC;;;GAGG;AACoB,6CAAqB,GAAmC,mCAAuB,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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineAction, type ICommandLineActionOptions } from './CommandLineAction';\nimport { CommandLineParser, type ICommandLineParserOptions } from './CommandLineParser';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\nimport type { CommandLineParameter, CommandLineParameterBase } from '../parameters/BaseClasses';\nimport type {\n CommandLineParameterProvider,\n ICommandLineParserData,\n IRegisterDefinedParametersState\n} from './CommandLineParameterProvider';\n\ninterface IInternalScopedCommandLineParserOptions extends ICommandLineParserOptions {\n readonly actionOptions: ICommandLineActionOptions;\n readonly unscopedActionParameters: ReadonlyArray<CommandLineParameter>;\n readonly onDefineScopedParameters: (commandLineParameterProvider: CommandLineParameterProvider) => void;\n readonly aliasAction?: string;\n readonly aliasDocumentation?: string;\n readonly registerDefinedParametersState: IRegisterDefinedParametersState;\n}\n\n/**\n * A CommandLineParser used exclusively to parse the scoped command-line parameters\n * for a ScopedCommandLineAction.\n */\nclass InternalScopedCommandLineParser extends CommandLineParser {\n private _canExecute: boolean;\n private readonly _internalOptions: IInternalScopedCommandLineParserOptions;\n\n public get canExecute(): boolean {\n return this._canExecute;\n }\n\n public constructor(options: IInternalScopedCommandLineParserOptions) {\n const { actionOptions, unscopedActionParameters, toolFilename, aliasAction, aliasDocumentation } =\n options;\n\n const toolCommand: string = `${toolFilename} ${actionOptions.actionName}`;\n // When coming from an alias command, we want to show the alias command name in the help text\n const toolCommandForLogging: string = `${toolFilename} ${aliasAction ?? actionOptions.actionName}`;\n const scopingArgs: string[] = [];\n for (const parameter of unscopedActionParameters) {\n parameter.appendToArgList(scopingArgs);\n }\n const scope: string = scopingArgs.join(' ');\n\n // We can run the parser directly because we are not going to use it for any other actions,\n // so construct a special options object to make the \"--help\" text more useful.\n const scopedCommandLineParserOptions: ICommandLineParserOptions = {\n // Strip the scoping args if coming from an alias command, since they are not applicable\n // to the alias command itself\n toolFilename: `${toolCommandForLogging}${scope && !aliasAction ? ` ${scope} --` : ''}`,\n toolDescription: aliasDocumentation ?? actionOptions.documentation,\n toolEpilog: `For more information on available unscoped parameters, use \"${toolCommand} --help\"`,\n enableTabCompletionAction: false\n };\n\n super(scopedCommandLineParserOptions);\n this._canExecute = false;\n this._internalOptions = options;\n this._internalOptions.onDefineScopedParameters(this);\n }\n\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n // Since we are in a separate parser, we need to register the parameters using the state\n // from the parent parser.\n super._registerDefinedParameters(this._internalOptions.registerDefinedParametersState);\n }\n\n protected async onExecute(): Promise<void> {\n // override\n // Only set if we made it this far, which may not be the case if an error occurred or\n // if '--help' was specified.\n this._canExecute = true;\n }\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command-line.\n * Applications should create subclasses of ScopedCommandLineAction corresponding to\n * each action that they want to expose.\n *\n * The action name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\n * \"docs:serve\", etc).\n *\n * Scoped commands allow for different parameters to be specified for different\n * provided scoping values. For example, the \"scoped-action --scope A\" command\n * may allow for different scoped arguments to be specified than the \"scoped-action\n * --scope B\" command.\n *\n * Scoped arguments are specified after the \"--\" pseudo-argument. For example,\n * \"scoped-action --scope A -- --scopedFoo --scopedBar\".\n *\n * @public\n */\nexport abstract class ScopedCommandLineAction extends CommandLineAction {\n private _options: ICommandLineActionOptions;\n private _scopingParameters: CommandLineParameter[];\n private _unscopedParserOptions: ICommandLineParserOptions | undefined;\n private _scopedCommandLineParser: InternalScopedCommandLineParser | undefined;\n private _subparserState: IRegisterDefinedParametersState | undefined;\n\n /**\n * The required group name to apply to all scoping parameters. At least one parameter\n * must be defined with this group name.\n */\n public static readonly ScopingParameterGroup: typeof SCOPING_PARAMETER_GROUP = SCOPING_PARAMETER_GROUP;\n\n public constructor(options: ICommandLineActionOptions) {\n super(options);\n\n this._options = options;\n this._scopingParameters = [];\n\n // Consume the remainder of the command-line, which will later be passed the scoped parser.\n // This will also prevent developers from calling this.defineCommandLineRemainder(...) since\n // we will have already defined it.\n this.defineCommandLineRemainder({\n description:\n 'Scoped parameters. Must be prefixed with \"--\", ex. \"-- --scopedParameter ' +\n 'foo --scopedFlag\". For more information on available scoped parameters, use \"-- --help\".'\n });\n\n this.onDefineUnscopedParameters?.();\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider.parameters}\n *\n * @internalremarks\n * TODO: Replace this type with `CommandLineParameter` in the next major bump.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n if (this._scopedCommandLineParser) {\n return [...super.parameters, ...this._scopedCommandLineParser.parameters];\n } else {\n return super.parameters;\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // override\n super._processParsedData(parserOptions, data);\n\n // This should never happen because the super method should throw if parameters haven't been registered,\n // but guard against this just in-case.\n if (this._subparserState === undefined) {\n throw new Error('Parameters have not been registered');\n }\n\n this._unscopedParserOptions = parserOptions;\n\n // Generate the scoped parser using the parent parser information. We can only create this after we\n // have parsed the data, since the parameter values are used during construction.\n this._scopedCommandLineParser = new InternalScopedCommandLineParser({\n ...parserOptions,\n actionOptions: this._options,\n aliasAction: data.aliasAction,\n aliasDocumentation: data.aliasDocumentation,\n unscopedActionParameters: this.parameters as CommandLineParameter[],\n registerDefinedParametersState: this._subparserState,\n onDefineScopedParameters: this.onDefineScopedParameters.bind(this)\n });\n }\n\n /**\n * {@inheritdoc CommandLineAction._executeAsync}\n * @internal\n */\n public async _executeAsync(): Promise<void> {\n // override\n if (!this._unscopedParserOptions || !this._scopedCommandLineParser) {\n throw new Error('The CommandLineAction parameters must be processed before execution.');\n }\n if (!this.remainder) {\n throw new Error('CommandLineAction.onDefineParameters must be called before execution.');\n }\n\n // The '--' argument is required to separate the action parameters from the scoped parameters,\n // so it needs to be trimmed. If remainder values are provided but no '--' is found, then throw.\n const scopedArgs: string[] = [];\n if (this.remainder.values.length) {\n if (this.remainder.values[0] !== '--') {\n throw new CommandLineParserExitError(\n // argparse sets exit code 2 for invalid arguments\n 2,\n // model the message off of the built-in \"unrecognized arguments\" message\n `${this.renderUsageText()}\\n${this._unscopedParserOptions.toolFilename} ${this.actionName}: ` +\n `error: Unrecognized arguments: ${this.remainder.values[0]}.\\n`\n );\n }\n for (const scopedArg of this.remainder.values.slice(1)) {\n scopedArgs.push(scopedArg);\n }\n }\n\n // Call the scoped parser using only the scoped args to handle parsing\n await this._scopedCommandLineParser.executeWithoutErrorHandlingAsync(scopedArgs);\n\n // Only call execute if the parser reached the execute stage. This may not be true if\n // the parser exited early due to a specified '--help' parameter.\n if (this._scopedCommandLineParser.canExecute) {\n await super._executeAsync();\n }\n\n return;\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n if (!this._scopingParameters.length) {\n throw new Error(\n 'No scoping parameters defined. At least one scoping parameter must be defined. ' +\n 'Scoping parameters are defined by setting the parameterGroupName to ' +\n 'ScopedCommandLineAction.ScopingParameterGroupName.'\n );\n }\n\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 this._subparserState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n }\n\n /**\n * Retrieves the scoped CommandLineParser, which is populated after the ScopedCommandLineAction is executed.\n * @internal\n */\n protected _getScopedCommandLineParser(): CommandLineParser {\n if (!this._scopedCommandLineParser) {\n throw new Error('The scoped CommandLineParser is only populated after the action is executed.');\n }\n return this._scopedCommandLineParser;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n super._defineParameter(parameter);\n if (parameter.parameterGroup === ScopedCommandLineAction.ScopingParameterGroup) {\n this._scopingParameters.push(parameter);\n }\n }\n\n /**\n * @deprecated - Define parameters in the constructor\n */\n protected onDefineUnscopedParameters?(): void;\n\n /**\n * The child class should implement this hook to define its scoped command-line\n * parameters, e.g. by calling scopedParameterProvider.defineFlagParameter(). These\n * parameters will only be available if the action is invoked with a scope.\n *\n * @remarks\n * onDefineScopedParameters is called after the unscoped parameters have been parsed.\n * The values they provide can be used to vary the defined scope parameters.\n */\n protected abstract onDefineScopedParameters(scopedParameterProvider: CommandLineParameterProvider): void;\n\n /**\n * {@inheritDoc CommandLineAction.onExecute}\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ScopedCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/ScopedCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;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+B;QACxD,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,SAAS,CAAC,cAAc,KAAK,uBAAuB,CAAC,qBAAqB,EAAE,CAAC;YAC/E,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;;AA9JH,0DAoLC;AA7KC;;;GAGG;AACoB,6CAAqB,GAAmC,mCAAuB,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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineAction, type ICommandLineActionOptions } from './CommandLineAction';\nimport { CommandLineParser, type ICommandLineParserOptions } from './CommandLineParser';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\nimport type { CommandLineParameter, CommandLineParameterBase } from '../parameters/BaseClasses';\nimport type {\n CommandLineParameterProvider,\n ICommandLineParserData,\n IRegisterDefinedParametersState\n} from './CommandLineParameterProvider';\n\ninterface IInternalScopedCommandLineParserOptions extends ICommandLineParserOptions {\n readonly actionOptions: ICommandLineActionOptions;\n readonly unscopedActionParameters: ReadonlyArray<CommandLineParameter>;\n readonly onDefineScopedParameters: (commandLineParameterProvider: CommandLineParameterProvider) => void;\n readonly aliasAction?: string;\n readonly aliasDocumentation?: string;\n readonly registerDefinedParametersState: IRegisterDefinedParametersState;\n}\n\n/**\n * A CommandLineParser used exclusively to parse the scoped command-line parameters\n * for a ScopedCommandLineAction.\n */\nclass InternalScopedCommandLineParser extends CommandLineParser {\n private _canExecute: boolean;\n private readonly _internalOptions: IInternalScopedCommandLineParserOptions;\n\n public get canExecute(): boolean {\n return this._canExecute;\n }\n\n public constructor(options: IInternalScopedCommandLineParserOptions) {\n const { actionOptions, unscopedActionParameters, toolFilename, aliasAction, aliasDocumentation } =\n options;\n\n const toolCommand: string = `${toolFilename} ${actionOptions.actionName}`;\n // When coming from an alias command, we want to show the alias command name in the help text\n const toolCommandForLogging: string = `${toolFilename} ${aliasAction ?? actionOptions.actionName}`;\n const scopingArgs: string[] = [];\n for (const parameter of unscopedActionParameters) {\n parameter.appendToArgList(scopingArgs);\n }\n const scope: string = scopingArgs.join(' ');\n\n // We can run the parser directly because we are not going to use it for any other actions,\n // so construct a special options object to make the \"--help\" text more useful.\n const scopedCommandLineParserOptions: ICommandLineParserOptions = {\n // Strip the scoping args if coming from an alias command, since they are not applicable\n // to the alias command itself\n toolFilename: `${toolCommandForLogging}${scope && !aliasAction ? ` ${scope} --` : ''}`,\n toolDescription: aliasDocumentation ?? actionOptions.documentation,\n toolEpilog: `For more information on available unscoped parameters, use \"${toolCommand} --help\"`,\n enableTabCompletionAction: false\n };\n\n super(scopedCommandLineParserOptions);\n this._canExecute = false;\n this._internalOptions = options;\n this._internalOptions.onDefineScopedParameters(this);\n }\n\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n // Since we are in a separate parser, we need to register the parameters using the state\n // from the parent parser.\n super._registerDefinedParameters(this._internalOptions.registerDefinedParametersState);\n }\n\n protected async onExecute(): Promise<void> {\n // override\n // Only set if we made it this far, which may not be the case if an error occurred or\n // if '--help' was specified.\n this._canExecute = true;\n }\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command-line.\n * Applications should create subclasses of ScopedCommandLineAction corresponding to\n * each action that they want to expose.\n *\n * The action name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\n * \"docs:serve\", etc).\n *\n * Scoped commands allow for different parameters to be specified for different\n * provided scoping values. For example, the \"scoped-action --scope A\" command\n * may allow for different scoped arguments to be specified than the \"scoped-action\n * --scope B\" command.\n *\n * Scoped arguments are specified after the \"--\" pseudo-argument. For example,\n * \"scoped-action --scope A -- --scopedFoo --scopedBar\".\n *\n * @public\n */\nexport abstract class ScopedCommandLineAction extends CommandLineAction {\n private _options: ICommandLineActionOptions;\n private _scopingParameters: CommandLineParameter[];\n private _unscopedParserOptions: ICommandLineParserOptions | undefined;\n private _scopedCommandLineParser: InternalScopedCommandLineParser | undefined;\n private _subparserState: IRegisterDefinedParametersState | undefined;\n\n /**\n * The required group name to apply to all scoping parameters. At least one parameter\n * must be defined with this group name.\n */\n public static readonly ScopingParameterGroup: typeof SCOPING_PARAMETER_GROUP = SCOPING_PARAMETER_GROUP;\n\n public constructor(options: ICommandLineActionOptions) {\n super(options);\n\n this._options = options;\n this._scopingParameters = [];\n\n // Consume the remainder of the command-line, which will later be passed the scoped parser.\n // This will also prevent developers from calling this.defineCommandLineRemainder(...) since\n // we will have already defined it.\n this.defineCommandLineRemainder({\n description:\n 'Scoped parameters. Must be prefixed with \"--\", ex. \"-- --scopedParameter ' +\n 'foo --scopedFlag\". For more information on available scoped parameters, use \"-- --help\".'\n });\n\n this.onDefineUnscopedParameters?.();\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider.parameters}\n *\n * @internalremarks\n * TODO: Replace this type with `CommandLineParameter` in the next major bump.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n if (this._scopedCommandLineParser) {\n return [...super.parameters, ...this._scopedCommandLineParser.parameters];\n } else {\n return super.parameters;\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // override\n super._processParsedData(parserOptions, data);\n\n // This should never happen because the super method should throw if parameters haven't been registered,\n // but guard against this just in-case.\n if (this._subparserState === undefined) {\n throw new Error('Parameters have not been registered');\n }\n\n this._unscopedParserOptions = parserOptions;\n\n // Generate the scoped parser using the parent parser information. We can only create this after we\n // have parsed the data, since the parameter values are used during construction.\n this._scopedCommandLineParser = new InternalScopedCommandLineParser({\n ...parserOptions,\n actionOptions: this._options,\n aliasAction: data.aliasAction,\n aliasDocumentation: data.aliasDocumentation,\n unscopedActionParameters: this.parameters as CommandLineParameter[],\n registerDefinedParametersState: this._subparserState,\n onDefineScopedParameters: this.onDefineScopedParameters.bind(this)\n });\n }\n\n /**\n * {@inheritdoc CommandLineAction._executeAsync}\n * @internal\n */\n public async _executeAsync(): Promise<void> {\n // override\n if (!this._unscopedParserOptions || !this._scopedCommandLineParser) {\n throw new Error('The CommandLineAction parameters must be processed before execution.');\n }\n if (!this.remainder) {\n throw new Error('CommandLineAction.onDefineParameters must be called before execution.');\n }\n\n // The '--' argument is required to separate the action parameters from the scoped parameters,\n // so it needs to be trimmed. If remainder values are provided but no '--' is found, then throw.\n const scopedArgs: string[] = [];\n if (this.remainder.values.length) {\n if (this.remainder.values[0] !== '--') {\n throw new CommandLineParserExitError(\n // argparse sets exit code 2 for invalid arguments\n 2,\n // model the message off of the built-in \"unrecognized arguments\" message\n `${this.renderUsageText()}\\n${this._unscopedParserOptions.toolFilename} ${this.actionName}: ` +\n `error: Unrecognized arguments: ${this.remainder.values[0]}.\\n`\n );\n }\n for (const scopedArg of this.remainder.values.slice(1)) {\n scopedArgs.push(scopedArg);\n }\n }\n\n // Call the scoped parser using only the scoped args to handle parsing\n await this._scopedCommandLineParser.executeWithoutErrorHandlingAsync(scopedArgs);\n\n // Only call execute if the parser reached the execute stage. This may not be true if\n // the parser exited early due to a specified '--help' parameter.\n if (this._scopedCommandLineParser.canExecute) {\n await super._executeAsync();\n }\n\n return;\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n if (!this._scopingParameters.length) {\n throw new Error(\n 'No scoping parameters defined. At least one scoping parameter must be defined. ' +\n 'Scoping parameters are defined by setting the parameterGroupName to ' +\n 'ScopedCommandLineAction.ScopingParameterGroupName.'\n );\n }\n\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 this._subparserState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n }\n\n /**\n * Retrieves the scoped CommandLineParser, which is populated after the ScopedCommandLineAction is executed.\n * @internal\n */\n protected _getScopedCommandLineParser(): CommandLineParser {\n if (!this._scopedCommandLineParser) {\n throw new Error('The scoped CommandLineParser is only populated after the action is executed.');\n }\n return this._scopedCommandLineParser;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n super._defineParameter(parameter);\n if (parameter.parameterGroup === ScopedCommandLineAction.ScopingParameterGroup) {\n this._scopingParameters.push(parameter);\n }\n }\n\n /**\n * @deprecated - Define parameters in the constructor\n */\n protected onDefineUnscopedParameters?(): void;\n\n /**\n * The child class should implement this hook to define its scoped command-line\n * parameters, e.g. by calling scopedParameterProvider.defineFlagParameter(). These\n * parameters will only be available if the action is invoked with a scope.\n *\n * @remarks\n * onDefineScopedParameters is called after the unscoped parameters have been parsed.\n * The values they provide can be used to vary the defined scope parameters.\n */\n protected abstract onDefineScopedParameters(scopedParameterProvider: CommandLineParameterProvider): void;\n\n /**\n * {@inheritDoc CommandLineAction.onExecute}\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
@@ -1,31 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
5
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
6
|
-
var m = o[Symbol.asyncIterator], i;
|
|
7
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
8
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
9
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
10
|
-
};
|
|
11
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
-
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
13
|
-
var i, p;
|
|
14
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
15
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
16
|
-
};
|
|
17
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
18
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
19
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
20
|
-
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
21
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
22
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
23
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
24
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
25
|
-
function fulfill(value) { resume("next", value); }
|
|
26
|
-
function reject(value) { resume("throw", value); }
|
|
27
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
28
|
-
};
|
|
29
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
6
|
};
|
|
@@ -77,92 +52,77 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
77
52
|
});
|
|
78
53
|
}
|
|
79
54
|
async onExecute() {
|
|
80
|
-
var _a, e_1, _b, _c;
|
|
81
55
|
const commandLine = this._wordToCompleteParameter.value;
|
|
82
56
|
const caretPosition = this._positionParameter.value || commandLine.length;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
_d = false;
|
|
87
|
-
const value = _c;
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
console.log(value);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
93
|
-
finally {
|
|
94
|
-
try {
|
|
95
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
96
|
-
}
|
|
97
|
-
finally { if (e_1) throw e_1.error; }
|
|
57
|
+
for await (const value of this.getCompletionsAsync(commandLine, caretPosition)) {
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.log(value);
|
|
98
60
|
}
|
|
99
61
|
}
|
|
100
|
-
getCompletionsAsync(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
yield yield __await(actionName);
|
|
122
|
-
}
|
|
62
|
+
async *getCompletionsAsync(commandLine, caretPosition = commandLine.length) {
|
|
63
|
+
const actions = this._actions;
|
|
64
|
+
if (!commandLine || !caretPosition) {
|
|
65
|
+
yield* this._getAllActions();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const tokens = Array.from(this.tokenizeCommandLine(commandLine));
|
|
69
|
+
// offset arguments by the number of global params in the input
|
|
70
|
+
const globalParameterOffset = this._getGlobalParameterOffset(tokens);
|
|
71
|
+
if (tokens.length < 2 + globalParameterOffset) {
|
|
72
|
+
yield* this._getAllActions();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const lastToken = tokens[tokens.length - 1];
|
|
76
|
+
const secondLastToken = tokens[tokens.length - 2];
|
|
77
|
+
const lastCharacterIsWhitespace = !commandLine.slice(-1).trim();
|
|
78
|
+
const completePartialWord = caretPosition === commandLine.length && !lastCharacterIsWhitespace;
|
|
79
|
+
if (completePartialWord && tokens.length === 2 + globalParameterOffset) {
|
|
80
|
+
for (const actionName of actions.keys()) {
|
|
81
|
+
if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) {
|
|
82
|
+
yield actionName;
|
|
123
83
|
}
|
|
124
84
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
for (const actionName of actions.keys()) {
|
|
88
|
+
if (actionName === tokens[1 + globalParameterOffset]) {
|
|
89
|
+
const parameterNameMap = actions.get(actionName);
|
|
90
|
+
const parameterNames = Array.from(parameterNameMap.keys());
|
|
91
|
+
if (completePartialWord) {
|
|
92
|
+
for (const parameterName of parameterNames) {
|
|
93
|
+
if (parameterName === secondLastToken) {
|
|
94
|
+
const values = await this._getParameterValueCompletionsAsync(parameterNameMap.get(parameterName));
|
|
95
|
+
if (values.size > 0) {
|
|
96
|
+
yield* this._completeParameterValues(values, lastToken);
|
|
97
|
+
return;
|
|
138
98
|
}
|
|
139
99
|
}
|
|
140
|
-
yield __await(yield* __asyncDelegator(__asyncValues(this._completeParameterValues(parameterNames, lastToken))));
|
|
141
100
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
101
|
+
yield* this._completeParameterValues(parameterNames, lastToken);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
for (const parameterName of parameterNames) {
|
|
105
|
+
if (parameterName === lastToken) {
|
|
106
|
+
const values = await this._getParameterValueCompletionsAsync(parameterNameMap.get(parameterName));
|
|
107
|
+
if (values.size > 0) {
|
|
108
|
+
yield* values;
|
|
109
|
+
return;
|
|
150
110
|
}
|
|
151
111
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
112
|
+
}
|
|
113
|
+
for (const parameterName of parameterNames) {
|
|
114
|
+
if (parameterName === lastToken &&
|
|
115
|
+
parameterNameMap.get(parameterName).kind !== BaseClasses_1.CommandLineParameterKind.Flag) {
|
|
116
|
+
// The parameter is expecting a value, so don't suggest parameter names again
|
|
117
|
+
return;
|
|
158
118
|
}
|
|
159
|
-
yield __await(yield* __asyncDelegator(__asyncValues(parameterNames)));
|
|
160
119
|
}
|
|
161
|
-
|
|
120
|
+
yield* parameterNames;
|
|
162
121
|
}
|
|
122
|
+
break;
|
|
163
123
|
}
|
|
164
124
|
}
|
|
165
|
-
}
|
|
125
|
+
}
|
|
166
126
|
}
|
|
167
127
|
*_getAllActions() {
|
|
168
128
|
yield* this._actions.keys();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabCompletionAction.js","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,8DAAqC;AAIrC,2DAKmC;AACnC,yFAAsF;AACtF,2DAAwD;AACxD,4CAAoD;AAEpD,MAAM,4BAA4B,GAAW,EAAE,CAAC;AAChD,MAAM,gBAAgB,GAAW,CAAC,CAAC;AAEnC,MAAa,iBAAkB,SAAQ,qCAAiB;IAMtD,YACE,OAAyC,EACzC,gBAAyD;QAEzD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AC,MAAM,EAAE,EAAE,CAAC;gBACxD,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,SAAS,EAAE,CAAC;oBACtF,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,CAAC,wBAAwB,CAC/B,qBAAkE,EAClE,SAAiB;QAEjB,KAAK,MAAM,oBAAoB,IAAI,qBAAqB,EAAE,CAAC;YACzD,IAAI,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,MAAM,oBAAoB,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9MD,8CA8MC","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 stringArgv from 'string-argv';\n\nimport type { IRequiredCommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport type { IRequiredCommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n CommandLineParameterWithArgument,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineAction } from './CommandLineAction';\nimport { CommandLineConstants } from '../Constants';\n\nconst DEFAULT_WORD_TO_AUTOCOMPLETE: string = '';\nconst DEFAULT_POSITION: number = 0;\n\nexport class TabCompleteAction extends CommandLineAction {\n private readonly _wordToCompleteParameter: IRequiredCommandLineStringParameter;\n private readonly _positionParameter: IRequiredCommandLineIntegerParameter;\n private readonly _actions: Map<string, Map<string, CommandLineParameter>>;\n private readonly _globalParameters: Map<string, CommandLineParameter>;\n\n public constructor(\n actions: ReadonlyArray<CommandLineAction>,\n globalParameters: ReadonlyArray<CommandLineParameterBase>\n ) {\n super({\n actionName: CommandLineConstants.TabCompletionActionName,\n summary: 'Provides tab completion.',\n documentation: 'Provides tab completion.'\n });\n\n this._actions = new Map();\n for (const action of actions) {\n const parameterNameToParameterInfoMap: Map<string, CommandLineParameter> = new Map();\n for (const parameter of action.parameters) {\n parameterNameToParameterInfoMap.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n parameterNameToParameterInfoMap.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n this._actions.set(action.actionName, parameterNameToParameterInfoMap);\n }\n\n this._globalParameters = new Map<string, CommandLineParameter>();\n for (const parameter of globalParameters) {\n this._globalParameters.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n this._globalParameters.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n\n this._wordToCompleteParameter = this.defineStringParameter({\n parameterLongName: '--word',\n argumentName: 'WORD',\n description: `The word to complete.`,\n defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE\n });\n\n this._positionParameter = this.defineIntegerParameter({\n parameterLongName: '--position',\n argumentName: 'INDEX',\n description: `The position in the word to be completed.`,\n defaultValue: DEFAULT_POSITION\n });\n }\n\n protected async onExecute(): Promise<void> {\n const commandLine: string = this._wordToCompleteParameter.value;\n const caretPosition: number = this._positionParameter.value || commandLine.length;\n\n for await (const value of this.getCompletionsAsync(commandLine, caretPosition)) {\n // eslint-disable-next-line no-console\n console.log(value);\n }\n }\n\n public async *getCompletionsAsync(\n commandLine: string,\n caretPosition: number = commandLine.length\n ): AsyncIterable<string> {\n const actions: Map<string, Map<string, CommandLineParameter>> = this._actions;\n\n if (!commandLine || !caretPosition) {\n yield* this._getAllActions();\n return;\n }\n\n const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine));\n\n // offset arguments by the number of global params in the input\n const globalParameterOffset: number = this._getGlobalParameterOffset(tokens);\n\n if (tokens.length < 2 + globalParameterOffset) {\n yield* this._getAllActions();\n return;\n }\n\n const lastToken: string = tokens[tokens.length - 1];\n const secondLastToken: string = tokens[tokens.length - 2];\n\n const lastCharacterIsWhitespace: boolean = !commandLine.slice(-1).trim();\n const completePartialWord: boolean = caretPosition === commandLine.length && !lastCharacterIsWhitespace;\n\n if (completePartialWord && tokens.length === 2 + globalParameterOffset) {\n for (const actionName of actions.keys()) {\n if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) {\n yield actionName;\n }\n }\n } else {\n for (const actionName of actions.keys()) {\n if (actionName === tokens[1 + globalParameterOffset]) {\n const parameterNameMap: Map<string, CommandLineParameter> = actions.get(actionName)!;\n\n const parameterNames: string[] = Array.from(parameterNameMap.keys());\n\n if (completePartialWord) {\n for (const parameterName of parameterNames) {\n if (parameterName === secondLastToken) {\n const values: ReadonlySet<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.size > 0) {\n yield* this._completeParameterValues(values, lastToken);\n return;\n }\n }\n }\n yield* this._completeParameterValues(parameterNames, lastToken);\n } else {\n for (const parameterName of parameterNames) {\n if (parameterName === lastToken) {\n const values: ReadonlySet<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.size > 0) {\n yield* values;\n return;\n }\n }\n }\n for (const parameterName of parameterNames) {\n if (\n parameterName === lastToken &&\n parameterNameMap.get(parameterName)!.kind !== CommandLineParameterKind.Flag\n ) {\n // The parameter is expecting a value, so don't suggest parameter names again\n return;\n }\n }\n\n yield* parameterNames;\n }\n\n break;\n }\n }\n }\n }\n\n private *_getAllActions(): IterableIterator<string> {\n yield* this._actions.keys();\n yield* this._globalParameters.keys();\n }\n\n public tokenizeCommandLine(commandLine: string): string[] {\n return stringArgv(commandLine);\n }\n\n private async _getParameterValueCompletionsAsync(\n parameter: CommandLineParameter\n ): Promise<ReadonlySet<string>> {\n let choiceParameterValues: ReadonlySet<string> | undefined;\n if (parameter.kind === CommandLineParameterKind.Choice) {\n choiceParameterValues = parameter.alternatives;\n } else if (parameter.kind !== CommandLineParameterKind.Flag) {\n let parameterWithArgumentOrChoices:\n | CommandLineParameterWithArgument\n | CommandLineChoiceParameter\n | undefined = undefined;\n if (\n parameter instanceof CommandLineParameterWithArgument ||\n parameter instanceof CommandLineChoiceParameter\n ) {\n parameterWithArgumentOrChoices = parameter;\n }\n\n const completionValues: ReadonlyArray<string> | ReadonlySet<string> | undefined =\n await parameterWithArgumentOrChoices?.completions?.();\n choiceParameterValues = completionValues instanceof Set ? completionValues : new Set(completionValues);\n }\n\n return choiceParameterValues ?? new Set();\n }\n\n private _getGlobalParameterOffset(tokens: string[]): number {\n const globalParameters: Map<string, CommandLineParameter> = this._globalParameters;\n let count: number = 0;\n\n outer: for (let i: number = 1; i < tokens.length; i++) {\n for (const globalParameter of globalParameters.values()) {\n if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) {\n break outer;\n }\n }\n count++;\n }\n\n return count;\n }\n\n private *_completeParameterValues(\n choiceParameterValues: ReadonlyArray<string> | ReadonlySet<string>,\n lastToken: string\n ): IterableIterator<string> {\n for (const choiceParameterValue of choiceParameterValues) {\n if (choiceParameterValue.indexOf(lastToken) === 0) {\n yield choiceParameterValue;\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TabCompletionAction.js","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,8DAAqC;AAIrC,2DAKmC;AACnC,yFAAsF;AACtF,2DAAwD;AACxD,4CAAoD;AAEpD,MAAM,4BAA4B,GAAW,EAAE,CAAC;AAChD,MAAM,gBAAgB,GAAW,CAAC,CAAC;AAEnC,MAAa,iBAAkB,SAAQ,qCAAiB;IAMtD,YACE,OAAyC,EACzC,gBAAyD;QAEzD,KAAK,CAAC;YACJ,UAAU,EAAE,gCAAoB,CAAC,uBAAuB;YACxD,OAAO,EAAE,0BAA0B;YACnC,aAAa,EAAE,0BAA0B;SAC1C,CAAC,CAAC;QAEH,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AM,oBAAoB,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9MD,8CA8MC","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 stringArgv from 'string-argv';\n\nimport type { IRequiredCommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport type { IRequiredCommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n CommandLineParameterWithArgument,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineAction } from './CommandLineAction';\nimport { CommandLineConstants } from '../Constants';\n\nconst DEFAULT_WORD_TO_AUTOCOMPLETE: string = '';\nconst DEFAULT_POSITION: number = 0;\n\nexport class TabCompleteAction extends CommandLineAction {\n private readonly _wordToCompleteParameter: IRequiredCommandLineStringParameter;\n private readonly _positionParameter: IRequiredCommandLineIntegerParameter;\n private readonly _actions: Map<string, Map<string, CommandLineParameter>>;\n private readonly _globalParameters: Map<string, CommandLineParameter>;\n\n public constructor(\n actions: ReadonlyArray<CommandLineAction>,\n globalParameters: ReadonlyArray<CommandLineParameterBase>\n ) {\n super({\n actionName: CommandLineConstants.TabCompletionActionName,\n summary: 'Provides tab completion.',\n documentation: 'Provides tab completion.'\n });\n\n this._actions = new Map();\n for (const action of actions) {\n const parameterNameToParameterInfoMap: Map<string, CommandLineParameter> = new Map();\n for (const parameter of action.parameters) {\n parameterNameToParameterInfoMap.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n parameterNameToParameterInfoMap.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n this._actions.set(action.actionName, parameterNameToParameterInfoMap);\n }\n\n this._globalParameters = new Map<string, CommandLineParameter>();\n for (const parameter of globalParameters) {\n this._globalParameters.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n this._globalParameters.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n\n this._wordToCompleteParameter = this.defineStringParameter({\n parameterLongName: '--word',\n argumentName: 'WORD',\n description: `The word to complete.`,\n defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE\n });\n\n this._positionParameter = this.defineIntegerParameter({\n parameterLongName: '--position',\n argumentName: 'INDEX',\n description: `The position in the word to be completed.`,\n defaultValue: DEFAULT_POSITION\n });\n }\n\n protected async onExecute(): Promise<void> {\n const commandLine: string = this._wordToCompleteParameter.value;\n const caretPosition: number = this._positionParameter.value || commandLine.length;\n\n for await (const value of this.getCompletionsAsync(commandLine, caretPosition)) {\n // eslint-disable-next-line no-console\n console.log(value);\n }\n }\n\n public async *getCompletionsAsync(\n commandLine: string,\n caretPosition: number = commandLine.length\n ): AsyncIterable<string> {\n const actions: Map<string, Map<string, CommandLineParameter>> = this._actions;\n\n if (!commandLine || !caretPosition) {\n yield* this._getAllActions();\n return;\n }\n\n const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine));\n\n // offset arguments by the number of global params in the input\n const globalParameterOffset: number = this._getGlobalParameterOffset(tokens);\n\n if (tokens.length < 2 + globalParameterOffset) {\n yield* this._getAllActions();\n return;\n }\n\n const lastToken: string = tokens[tokens.length - 1];\n const secondLastToken: string = tokens[tokens.length - 2];\n\n const lastCharacterIsWhitespace: boolean = !commandLine.slice(-1).trim();\n const completePartialWord: boolean = caretPosition === commandLine.length && !lastCharacterIsWhitespace;\n\n if (completePartialWord && tokens.length === 2 + globalParameterOffset) {\n for (const actionName of actions.keys()) {\n if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) {\n yield actionName;\n }\n }\n } else {\n for (const actionName of actions.keys()) {\n if (actionName === tokens[1 + globalParameterOffset]) {\n const parameterNameMap: Map<string, CommandLineParameter> = actions.get(actionName)!;\n\n const parameterNames: string[] = Array.from(parameterNameMap.keys());\n\n if (completePartialWord) {\n for (const parameterName of parameterNames) {\n if (parameterName === secondLastToken) {\n const values: ReadonlySet<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.size > 0) {\n yield* this._completeParameterValues(values, lastToken);\n return;\n }\n }\n }\n yield* this._completeParameterValues(parameterNames, lastToken);\n } else {\n for (const parameterName of parameterNames) {\n if (parameterName === lastToken) {\n const values: ReadonlySet<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.size > 0) {\n yield* values;\n return;\n }\n }\n }\n for (const parameterName of parameterNames) {\n if (\n parameterName === lastToken &&\n parameterNameMap.get(parameterName)!.kind !== CommandLineParameterKind.Flag\n ) {\n // The parameter is expecting a value, so don't suggest parameter names again\n return;\n }\n }\n\n yield* parameterNames;\n }\n\n break;\n }\n }\n }\n }\n\n private *_getAllActions(): IterableIterator<string> {\n yield* this._actions.keys();\n yield* this._globalParameters.keys();\n }\n\n public tokenizeCommandLine(commandLine: string): string[] {\n return stringArgv(commandLine);\n }\n\n private async _getParameterValueCompletionsAsync(\n parameter: CommandLineParameter\n ): Promise<ReadonlySet<string>> {\n let choiceParameterValues: ReadonlySet<string> | undefined;\n if (parameter.kind === CommandLineParameterKind.Choice) {\n choiceParameterValues = parameter.alternatives;\n } else if (parameter.kind !== CommandLineParameterKind.Flag) {\n let parameterWithArgumentOrChoices:\n | CommandLineParameterWithArgument\n | CommandLineChoiceParameter\n | undefined = undefined;\n if (\n parameter instanceof CommandLineParameterWithArgument ||\n parameter instanceof CommandLineChoiceParameter\n ) {\n parameterWithArgumentOrChoices = parameter;\n }\n\n const completionValues: ReadonlyArray<string> | ReadonlySet<string> | undefined =\n await parameterWithArgumentOrChoices?.completions?.();\n choiceParameterValues = completionValues instanceof Set ? completionValues : new Set(completionValues);\n }\n\n return choiceParameterValues ?? new Set();\n }\n\n private _getGlobalParameterOffset(tokens: string[]): number {\n const globalParameters: Map<string, CommandLineParameter> = this._globalParameters;\n let count: number = 0;\n\n outer: for (let i: number = 1; i < tokens.length; i++) {\n for (const globalParameter of globalParameters.values()) {\n if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) {\n break outer;\n }\n }\n count++;\n }\n\n return count;\n }\n\n private *_completeParameterValues(\n choiceParameterValues: ReadonlyArray<string> | ReadonlySet<string>,\n lastToken: string\n ): IterableIterator<string> {\n for (const choiceParameterValue of choiceParameterValues) {\n if (choiceParameterValue.indexOf(lastToken) === 0) {\n yield choiceParameterValue;\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/ts-command-line",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.6",
|
|
4
4
|
"description": "An object-oriented command-line parser for TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
"@types/argparse": "1.0.38",
|
|
15
15
|
"argparse": "~1.0.9",
|
|
16
16
|
"string-argv": "~0.3.1",
|
|
17
|
-
"@rushstack/terminal": "0.
|
|
17
|
+
"@rushstack/terminal": "0.15.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@rushstack/heft": "0.
|
|
21
|
-
"@rushstack/heft-node-rig": "2.
|
|
20
|
+
"@rushstack/heft": "0.69.2",
|
|
21
|
+
"@rushstack/heft-node-rig": "2.7.0",
|
|
22
22
|
"@types/heft-jest": "1.0.1",
|
|
23
|
-
"@types/node": "
|
|
24
|
-
"local-eslint-config": "1.0.0"
|
|
23
|
+
"@types/node": "20.17.19",
|
|
24
|
+
"local-eslint-config": "1.0.0",
|
|
25
|
+
"@rushstack/node-core-library": "5.12.0"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "heft build --clean",
|