@rushstack/ts-command-line 4.10.10 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-command-line.d.ts +137 -8
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/Constants.d.ts +1 -0
- package/lib/Constants.d.ts.map +1 -1
- package/lib/Constants.js +2 -0
- package/lib/Constants.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -3
- package/lib/index.js.map +1 -1
- package/lib/parameters/BaseClasses.d.ts +11 -0
- package/lib/parameters/BaseClasses.d.ts.map +1 -1
- package/lib/parameters/BaseClasses.js +19 -6
- package/lib/parameters/BaseClasses.js.map +1 -1
- package/lib/parameters/CommandLineDefinition.d.ts +12 -0
- package/lib/parameters/CommandLineDefinition.d.ts.map +1 -1
- package/lib/parameters/CommandLineDefinition.js.map +1 -1
- package/lib/providers/CommandLineAction.d.ts +2 -1
- package/lib/providers/CommandLineAction.d.ts.map +1 -1
- package/lib/providers/CommandLineAction.js +2 -2
- package/lib/providers/CommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineParameterProvider.d.ts +46 -10
- package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
- package/lib/providers/CommandLineParameterProvider.js +151 -47
- package/lib/providers/CommandLineParameterProvider.js.map +1 -1
- package/lib/providers/CommandLineParser.d.ts +7 -0
- package/lib/providers/CommandLineParser.d.ts.map +1 -1
- package/lib/providers/CommandLineParser.js +16 -4
- package/lib/providers/CommandLineParser.js.map +1 -1
- package/lib/providers/CommandLineParserExitError.js +5 -1
- package/lib/providers/CommandLineParserExitError.js.map +1 -1
- package/lib/providers/ScopedCommandLineAction.d.ts +85 -0
- package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -0
- package/lib/providers/ScopedCommandLineAction.js +180 -0
- package/lib/providers/ScopedCommandLineAction.js.map +1 -0
- package/package.json +4 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as argparse from 'argparse';
|
|
2
2
|
import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';
|
|
3
|
+
import type { ICommandLineParserOptions } from './CommandLineParser';
|
|
3
4
|
/**
|
|
4
5
|
* Options for the CommandLineAction constructor.
|
|
5
6
|
* @public
|
|
@@ -53,7 +54,7 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
|
|
|
53
54
|
* This is called internally by CommandLineParser.execute()
|
|
54
55
|
* @internal
|
|
55
56
|
*/
|
|
56
|
-
_processParsedData(data: ICommandLineParserData): void;
|
|
57
|
+
_processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void;
|
|
57
58
|
/**
|
|
58
59
|
* Invoked by CommandLineParser.onExecute().
|
|
59
60
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACtG,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAkB,SAAQ,4BAA4B;IAE1E,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA8C;IAE9E,yDAAyD;IACzD,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,sDAAsD;IACtD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,4DAA4D;IAC5D,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,eAAe,CAAsC;gBAE1C,OAAO,EAAE,yBAAyB;IAiBrD;;;OAGG;IACI,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI;IAS/D;;;OAGG;IACI,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,EAAE,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAIvG;;;OAGG;IACI,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;OAGG;IACH,SAAS,CAAC,kBAAkB,IAAI,QAAQ,CAAC,cAAc;IAUvD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,kBAAkB,IAAI,IAAI;IAE7C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAC9C"}
|
|
@@ -44,8 +44,8 @@ class CommandLineAction extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
44
44
|
* This is called internally by CommandLineParser.execute()
|
|
45
45
|
* @internal
|
|
46
46
|
*/
|
|
47
|
-
_processParsedData(data) {
|
|
48
|
-
super._processParsedData(data);
|
|
47
|
+
_processParsedData(parserOptions, data) {
|
|
48
|
+
super._processParsedData(parserOptions, data);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Invoked by CommandLineParser.onExecute().
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;
|
|
1
|
+
{"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D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iB,GAAW,kCAAkC,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 { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\n\n/**\n * Options for the CommandLineAction constructor.\n * @public\n */\nexport interface ICommandLineActionOptions {\n /**\n * The name of the action. For example, if the tool is called \"example\",\n * then the \"build\" action might be invoked as: \"example build -q --some-other-option\"\n */\n actionName: string;\n\n /**\n * A quick summary that is shown on the main help page, which is displayed\n * by the command \"example --help\"\n */\n summary: string;\n\n /**\n * A detailed description that is shown on the action help page, which is displayed\n * by the command \"example build --help\", e.g. for actionName=\"build\".\n */\n documentation: string;\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * Applications should create subclasses of CommandLineAction 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 * @public\n */\nexport abstract class CommandLineAction extends CommandLineParameterProvider {\n // Example: \"do-something\"\n private static _actionNameRegExp: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\n\n /** {@inheritDoc ICommandLineActionOptions.actionName} */\n public readonly actionName: string;\n\n /** {@inheritDoc ICommandLineActionOptions.summary} */\n public readonly summary: string;\n\n /** {@inheritDoc ICommandLineActionOptions.documentation} */\n public readonly documentation: string;\n\n private _argumentParser: argparse.ArgumentParser | undefined;\n\n public constructor(options: ICommandLineActionOptions) {\n super();\n\n if (!CommandLineAction._actionNameRegExp.test(options.actionName)) {\n throw new Error(\n `Invalid action name \"${options.actionName}\". ` +\n `The name must be comprised of lower-case words optionally separated by hyphens or colons.`\n );\n }\n\n this.actionName = options.actionName;\n this.summary = options.summary;\n this.documentation = options.documentation;\n\n this._argumentParser = undefined;\n }\n\n /**\n * This is called internally by CommandLineParser.addAction()\n * @internal\n */\n public _buildParser(actionsSubParser: argparse.SubParser): void {\n this._argumentParser = actionsSubParser.addParser(this.actionName, {\n help: this.summary,\n description: this.documentation\n });\n\n this.onDefineParameters();\n }\n\n /**\n * This is called internally by CommandLineParser.execute()\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n super._processParsedData(parserOptions, data);\n }\n\n /**\n * Invoked by CommandLineParser.onExecute().\n * @internal\n */\n public _execute(): Promise<void> {\n return this.onExecute();\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider._getArgumentParser}\n * @internal\n */\n protected _getArgumentParser(): argparse.ArgumentParser {\n // override\n if (!this._argumentParser) {\n // We will improve this in the future\n throw new Error('The CommandLineAction must be added to a CommandLineParser before it can be used');\n }\n\n return this._argumentParser;\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider.onDefineParameters}\n */\n protected abstract onDefineParameters(): void;\n\n /**\n * Your subclass should implement this hook to perform the operation.\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as argparse from 'argparse';
|
|
2
|
-
import { ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineRemainderDefinition } from '../parameters/CommandLineDefinition';
|
|
2
|
+
import type { ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineRemainderDefinition } from '../parameters/CommandLineDefinition';
|
|
3
|
+
import type { ICommandLineParserOptions } from './CommandLineParser';
|
|
3
4
|
import { CommandLineParameter } from '../parameters/BaseClasses';
|
|
4
5
|
import { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';
|
|
5
6
|
import { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';
|
|
@@ -9,6 +10,23 @@ import { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter
|
|
|
9
10
|
import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter';
|
|
10
11
|
import { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';
|
|
11
12
|
import { CommandLineRemainder } from '../parameters/CommandLineRemainder';
|
|
13
|
+
/**
|
|
14
|
+
* The result containing the parsed paramter long name and scope. Returned when calling
|
|
15
|
+
* {@link CommandLineParameterProvider.parseScopedLongName}.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface IScopedLongNameParseResult {
|
|
20
|
+
/**
|
|
21
|
+
* The long name parsed from the scoped long name, e.g. "--my-scope:my-parameter" -\> "--my-parameter"
|
|
22
|
+
*/
|
|
23
|
+
longName: string;
|
|
24
|
+
/**
|
|
25
|
+
* The scope parsed from the scoped long name or undefined if no scope was found,
|
|
26
|
+
* e.g. "--my-scope:my-parameter" -\> "my-scope"
|
|
27
|
+
*/
|
|
28
|
+
scope: string | undefined;
|
|
29
|
+
}
|
|
12
30
|
/**
|
|
13
31
|
* This is the argparse result data object
|
|
14
32
|
* @internal
|
|
@@ -24,9 +42,14 @@ export interface ICommandLineParserData {
|
|
|
24
42
|
* @public
|
|
25
43
|
*/
|
|
26
44
|
export declare abstract class CommandLineParameterProvider {
|
|
45
|
+
private static readonly _scopeGroupName;
|
|
46
|
+
private static readonly _longNameGroupName;
|
|
47
|
+
private static readonly _possiblyScopedLongNameRegex;
|
|
27
48
|
private static _keyCounter;
|
|
28
49
|
private _parameters;
|
|
29
50
|
private _parametersByLongName;
|
|
51
|
+
private _parameterGroupsByName;
|
|
52
|
+
private _parametersRegistered;
|
|
30
53
|
private _parametersProcessed;
|
|
31
54
|
private _remainder;
|
|
32
55
|
/** @internal */
|
|
@@ -60,7 +83,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
60
83
|
* @remarks
|
|
61
84
|
* This method throws an exception if the parameter is not defined.
|
|
62
85
|
*/
|
|
63
|
-
getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter;
|
|
86
|
+
getChoiceParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceParameter;
|
|
64
87
|
/**
|
|
65
88
|
* Defines a command-line parameter whose value must be a string from a fixed set of
|
|
66
89
|
* allowable choices (similar to an enum). The parameter can be specified multiple times to
|
|
@@ -78,7 +101,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
78
101
|
* @remarks
|
|
79
102
|
* This method throws an exception if the parameter is not defined.
|
|
80
103
|
*/
|
|
81
|
-
getChoiceListParameter(parameterLongName: string): CommandLineChoiceListParameter;
|
|
104
|
+
getChoiceListParameter(parameterLongName: string, parameterScope?: string): CommandLineChoiceListParameter;
|
|
82
105
|
/**
|
|
83
106
|
* Defines a command-line switch whose boolean value is true if the switch is provided,
|
|
84
107
|
* and false otherwise.
|
|
@@ -95,7 +118,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
95
118
|
* @remarks
|
|
96
119
|
* This method throws an exception if the parameter is not defined.
|
|
97
120
|
*/
|
|
98
|
-
getFlagParameter(parameterLongName: string): CommandLineFlagParameter;
|
|
121
|
+
getFlagParameter(parameterLongName: string, parameterScope?: string): CommandLineFlagParameter;
|
|
99
122
|
/**
|
|
100
123
|
* Defines a command-line parameter whose argument is an integer.
|
|
101
124
|
*
|
|
@@ -111,7 +134,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
111
134
|
* @remarks
|
|
112
135
|
* This method throws an exception if the parameter is not defined.
|
|
113
136
|
*/
|
|
114
|
-
getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter;
|
|
137
|
+
getIntegerParameter(parameterLongName: string, parameterScope?: string): CommandLineIntegerParameter;
|
|
115
138
|
/**
|
|
116
139
|
* Defines a command-line parameter whose argument is an integer. The parameter can be specified
|
|
117
140
|
* multiple times to build a list.
|
|
@@ -128,7 +151,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
128
151
|
* @remarks
|
|
129
152
|
* This method throws an exception if the parameter is not defined.
|
|
130
153
|
*/
|
|
131
|
-
getIntegerListParameter(parameterLongName: string): CommandLineIntegerListParameter;
|
|
154
|
+
getIntegerListParameter(parameterLongName: string, parameterScope?: string): CommandLineIntegerListParameter;
|
|
132
155
|
/**
|
|
133
156
|
* Defines a command-line parameter whose argument is a single text string.
|
|
134
157
|
*
|
|
@@ -144,7 +167,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
144
167
|
* @remarks
|
|
145
168
|
* This method throws an exception if the parameter is not defined.
|
|
146
169
|
*/
|
|
147
|
-
getStringParameter(parameterLongName: string): CommandLineStringParameter;
|
|
170
|
+
getStringParameter(parameterLongName: string, parameterScope?: string): CommandLineStringParameter;
|
|
148
171
|
/**
|
|
149
172
|
* Defines a command-line parameter whose argument is a single text string. The parameter can be
|
|
150
173
|
* specified multiple times to build a list.
|
|
@@ -177,17 +200,27 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
177
200
|
* @remarks
|
|
178
201
|
* This method throws an exception if the parameter is not defined.
|
|
179
202
|
*/
|
|
180
|
-
getStringListParameter(parameterLongName: string): CommandLineStringListParameter;
|
|
203
|
+
getStringListParameter(parameterLongName: string, parameterScope?: string): CommandLineStringListParameter;
|
|
181
204
|
/**
|
|
182
205
|
* Generates the command-line help text.
|
|
183
206
|
*/
|
|
184
207
|
renderHelpText(): string;
|
|
208
|
+
/**
|
|
209
|
+
* Generates the command-line usage text.
|
|
210
|
+
*/
|
|
211
|
+
renderUsageText(): string;
|
|
185
212
|
/**
|
|
186
213
|
* Returns a object which maps the long name of each parameter in this.parameters
|
|
187
214
|
* to the stringified form of its value. This is useful for logging telemetry, but
|
|
188
215
|
* it is not the proper way of accessing parameters or their values.
|
|
189
216
|
*/
|
|
190
217
|
getParameterStringMap(): Record<string, string>;
|
|
218
|
+
/**
|
|
219
|
+
* Returns an object with the parsed scope (if present) and the long name of the parameter.
|
|
220
|
+
*/
|
|
221
|
+
parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult;
|
|
222
|
+
/** @internal */
|
|
223
|
+
_registerDefinedParameters(): void;
|
|
191
224
|
/**
|
|
192
225
|
* The child class should implement this hook to define its command-line parameters,
|
|
193
226
|
* e.g. by calling defineFlagParameter().
|
|
@@ -199,9 +232,12 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
199
232
|
*/
|
|
200
233
|
protected abstract _getArgumentParser(): argparse.ArgumentParser;
|
|
201
234
|
/** @internal */
|
|
202
|
-
protected _processParsedData(data: ICommandLineParserData): void;
|
|
235
|
+
protected _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void;
|
|
236
|
+
/** @internal */
|
|
237
|
+
protected _defineParameter(parameter: CommandLineParameter): void;
|
|
238
|
+
/** @internal */
|
|
239
|
+
protected _registerParameter(parameter: CommandLineParameter, useScopedLongName: boolean): void;
|
|
203
240
|
private _generateKey;
|
|
204
241
|
private _getParameter;
|
|
205
|
-
private _defineParameter;
|
|
206
242
|
}
|
|
207
243
|
//# sourceMappingURL=CommandLineParameterProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParameterProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandLineParameterProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,OAAO,KAAK,EACV,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,EACjC,0BAA0B,EAC1B,4BAA4B,EAC5B,gCAAgC,EAChC,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;IAMlG;;;;OAIG;IACI,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,0BAA0B;IAIzG;;;;;;;;;OASG;IACI,yBAAyB,CAC9B,UAAU,EAAE,gCAAgC,GAC3C,8BAA8B;IAMjC;;;;;;;;;;;;;;OAcG;IACI,0BAA0B,CAAC,UAAU,EAAE,+BAA+B,GAAG,oBAAoB;IAQpG;;;;OAIG;IACI,sBAAsB,CAC3B,iBAAiB,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,MAAM,GACtB,8BAA8B;IAIjC;;OAEG;IACI,cAAc,IAAI,MAAM;IAK/B;;OAEG;IACI,eAAe,IAAI,MAAM;IAKhC;;;;OAIG;IACI,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAmCtD;;OAEG;IACI,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,0BAA0B;IAY9E,gBAAgB;IACT,0BAA0B,IAAI,IAAI;IAiCzC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,kBAAkB,IAAI,IAAI;IAE7C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,kBAAkB,IAAI,QAAQ,CAAC,cAAc;IAEhE,gBAAgB;IAChB,SAAS,CAAC,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,EAAE,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAsB1G,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAqBjE,gBAAgB;IAChB,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,OAAO,GAAG,IAAI;IAmG/F,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;CA8BtB"}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
5
|
if (k2 === undefined) k2 = k;
|
|
6
|
-
Object.
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
7
11
|
}) : (function(o, m, k, k2) {
|
|
8
12
|
if (k2 === undefined) k2 = k;
|
|
9
13
|
o[k2] = m[k];
|
|
@@ -32,6 +36,7 @@ const CommandLineFlagParameter_1 = require("../parameters/CommandLineFlagParamet
|
|
|
32
36
|
const CommandLineStringParameter_1 = require("../parameters/CommandLineStringParameter");
|
|
33
37
|
const CommandLineStringListParameter_1 = require("../parameters/CommandLineStringListParameter");
|
|
34
38
|
const CommandLineRemainder_1 = require("../parameters/CommandLineRemainder");
|
|
39
|
+
const Constants_1 = require("../Constants");
|
|
35
40
|
/**
|
|
36
41
|
* This is the common base class for CommandLineAction and CommandLineParser
|
|
37
42
|
* that provides functionality for defining command-line parameters.
|
|
@@ -44,6 +49,8 @@ class CommandLineParameterProvider {
|
|
|
44
49
|
constructor() {
|
|
45
50
|
this._parameters = [];
|
|
46
51
|
this._parametersByLongName = new Map();
|
|
52
|
+
this._parameterGroupsByName = new Map();
|
|
53
|
+
this._parametersRegistered = false;
|
|
47
54
|
this._parametersProcessed = false;
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
@@ -85,8 +92,8 @@ class CommandLineParameterProvider {
|
|
|
85
92
|
* @remarks
|
|
86
93
|
* This method throws an exception if the parameter is not defined.
|
|
87
94
|
*/
|
|
88
|
-
getChoiceParameter(parameterLongName) {
|
|
89
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Choice);
|
|
95
|
+
getChoiceParameter(parameterLongName, parameterScope) {
|
|
96
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Choice, parameterScope);
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* Defines a command-line parameter whose value must be a string from a fixed set of
|
|
@@ -109,8 +116,8 @@ class CommandLineParameterProvider {
|
|
|
109
116
|
* @remarks
|
|
110
117
|
* This method throws an exception if the parameter is not defined.
|
|
111
118
|
*/
|
|
112
|
-
getChoiceListParameter(parameterLongName) {
|
|
113
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.ChoiceList);
|
|
119
|
+
getChoiceListParameter(parameterLongName, parameterScope) {
|
|
120
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.ChoiceList, parameterScope);
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* Defines a command-line switch whose boolean value is true if the switch is provided,
|
|
@@ -132,8 +139,8 @@ class CommandLineParameterProvider {
|
|
|
132
139
|
* @remarks
|
|
133
140
|
* This method throws an exception if the parameter is not defined.
|
|
134
141
|
*/
|
|
135
|
-
getFlagParameter(parameterLongName) {
|
|
136
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Flag);
|
|
142
|
+
getFlagParameter(parameterLongName, parameterScope) {
|
|
143
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Flag, parameterScope);
|
|
137
144
|
}
|
|
138
145
|
/**
|
|
139
146
|
* Defines a command-line parameter whose argument is an integer.
|
|
@@ -154,8 +161,8 @@ class CommandLineParameterProvider {
|
|
|
154
161
|
* @remarks
|
|
155
162
|
* This method throws an exception if the parameter is not defined.
|
|
156
163
|
*/
|
|
157
|
-
getIntegerParameter(parameterLongName) {
|
|
158
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Integer);
|
|
164
|
+
getIntegerParameter(parameterLongName, parameterScope) {
|
|
165
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.Integer, parameterScope);
|
|
159
166
|
}
|
|
160
167
|
/**
|
|
161
168
|
* Defines a command-line parameter whose argument is an integer. The parameter can be specified
|
|
@@ -177,8 +184,8 @@ class CommandLineParameterProvider {
|
|
|
177
184
|
* @remarks
|
|
178
185
|
* This method throws an exception if the parameter is not defined.
|
|
179
186
|
*/
|
|
180
|
-
getIntegerListParameter(parameterLongName) {
|
|
181
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.IntegerList);
|
|
187
|
+
getIntegerListParameter(parameterLongName, parameterScope) {
|
|
188
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.IntegerList, parameterScope);
|
|
182
189
|
}
|
|
183
190
|
/**
|
|
184
191
|
* Defines a command-line parameter whose argument is a single text string.
|
|
@@ -199,8 +206,8 @@ class CommandLineParameterProvider {
|
|
|
199
206
|
* @remarks
|
|
200
207
|
* This method throws an exception if the parameter is not defined.
|
|
201
208
|
*/
|
|
202
|
-
getStringParameter(parameterLongName) {
|
|
203
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.String);
|
|
209
|
+
getStringParameter(parameterLongName, parameterScope) {
|
|
210
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.String, parameterScope);
|
|
204
211
|
}
|
|
205
212
|
/**
|
|
206
213
|
* Defines a command-line parameter whose argument is a single text string. The parameter can be
|
|
@@ -237,12 +244,6 @@ class CommandLineParameterProvider {
|
|
|
237
244
|
throw new Error('defineRemainingArguments() has already been called for this provider');
|
|
238
245
|
}
|
|
239
246
|
this._remainder = new CommandLineRemainder_1.CommandLineRemainder(definition);
|
|
240
|
-
const argparseOptions = {
|
|
241
|
-
help: this._remainder.description,
|
|
242
|
-
nargs: argparse.Const.REMAINDER,
|
|
243
|
-
metavar: '"..."'
|
|
244
|
-
};
|
|
245
|
-
this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);
|
|
246
247
|
return this._remainder;
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
@@ -250,15 +251,23 @@ class CommandLineParameterProvider {
|
|
|
250
251
|
* @remarks
|
|
251
252
|
* This method throws an exception if the parameter is not defined.
|
|
252
253
|
*/
|
|
253
|
-
getStringListParameter(parameterLongName) {
|
|
254
|
-
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.StringList);
|
|
254
|
+
getStringListParameter(parameterLongName, parameterScope) {
|
|
255
|
+
return this._getParameter(parameterLongName, BaseClasses_1.CommandLineParameterKind.StringList, parameterScope);
|
|
255
256
|
}
|
|
256
257
|
/**
|
|
257
258
|
* Generates the command-line help text.
|
|
258
259
|
*/
|
|
259
260
|
renderHelpText() {
|
|
261
|
+
this._registerDefinedParameters();
|
|
260
262
|
return this._getArgumentParser().formatHelp();
|
|
261
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Generates the command-line usage text.
|
|
266
|
+
*/
|
|
267
|
+
renderUsageText() {
|
|
268
|
+
this._registerDefinedParameters();
|
|
269
|
+
return this._getArgumentParser().formatUsage();
|
|
270
|
+
}
|
|
262
271
|
/**
|
|
263
272
|
* Returns a object which maps the long name of each parameter in this.parameters
|
|
264
273
|
* to the stringified form of its value. This is useful for logging telemetry, but
|
|
@@ -267,25 +276,70 @@ class CommandLineParameterProvider {
|
|
|
267
276
|
getParameterStringMap() {
|
|
268
277
|
const parameterMap = {};
|
|
269
278
|
for (const parameter of this.parameters) {
|
|
279
|
+
const parameterName = parameter.scopedLongName || parameter.longName;
|
|
270
280
|
switch (parameter.kind) {
|
|
271
281
|
case BaseClasses_1.CommandLineParameterKind.Flag:
|
|
272
282
|
case BaseClasses_1.CommandLineParameterKind.Choice:
|
|
273
283
|
case BaseClasses_1.CommandLineParameterKind.String:
|
|
274
284
|
case BaseClasses_1.CommandLineParameterKind.Integer:
|
|
275
|
-
parameterMap[
|
|
285
|
+
parameterMap[parameterName] = JSON.stringify(parameter.value);
|
|
276
286
|
break;
|
|
277
287
|
case BaseClasses_1.CommandLineParameterKind.StringList:
|
|
278
288
|
case BaseClasses_1.CommandLineParameterKind.IntegerList:
|
|
279
289
|
case BaseClasses_1.CommandLineParameterKind.ChoiceList:
|
|
280
290
|
const arrayValue = parameter.values;
|
|
281
|
-
parameterMap[
|
|
291
|
+
parameterMap[parameterName] = arrayValue ? arrayValue.join(',') : '';
|
|
282
292
|
break;
|
|
283
293
|
}
|
|
284
294
|
}
|
|
285
295
|
return parameterMap;
|
|
286
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Returns an object with the parsed scope (if present) and the long name of the parameter.
|
|
299
|
+
*/
|
|
300
|
+
parseScopedLongName(scopedLongName) {
|
|
301
|
+
const result = CommandLineParameterProvider._possiblyScopedLongNameRegex.exec(scopedLongName);
|
|
302
|
+
if (!result || !result.groups) {
|
|
303
|
+
throw new Error(`The parameter long name "${scopedLongName}" is not valid.`);
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
longName: `--${result.groups[CommandLineParameterProvider._longNameGroupName]}`,
|
|
307
|
+
scope: result.groups[CommandLineParameterProvider._scopeGroupName]
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** @internal */
|
|
311
|
+
_registerDefinedParameters() {
|
|
312
|
+
if (this._parametersRegistered) {
|
|
313
|
+
// We prevent new parameters from being defined after the first call to _registerDefinedParameters,
|
|
314
|
+
// so we can already ensure that all parameters were registered.
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this._parametersRegistered = true;
|
|
318
|
+
for (const longNameParameters of this._parametersByLongName.values()) {
|
|
319
|
+
const useScopedLongName = longNameParameters.length > 1;
|
|
320
|
+
for (const parameter of longNameParameters) {
|
|
321
|
+
if (useScopedLongName && !parameter.parameterScope) {
|
|
322
|
+
throw new Error(`The parameter "${parameter.longName}" is defined multiple times with the same long name. ` +
|
|
323
|
+
'Parameters with the same long name must define a scope.');
|
|
324
|
+
}
|
|
325
|
+
this._registerParameter(parameter, useScopedLongName);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// Need to add the remainder parameter last
|
|
329
|
+
if (this._remainder) {
|
|
330
|
+
const argparseOptions = {
|
|
331
|
+
help: this._remainder.description,
|
|
332
|
+
nargs: argparse.Const.REMAINDER,
|
|
333
|
+
metavar: '"..."'
|
|
334
|
+
};
|
|
335
|
+
this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
287
338
|
/** @internal */
|
|
288
|
-
_processParsedData(data) {
|
|
339
|
+
_processParsedData(parserOptions, data) {
|
|
340
|
+
if (!this._parametersRegistered) {
|
|
341
|
+
throw new Error('Parameters have not been registered');
|
|
342
|
+
}
|
|
289
343
|
if (this._parametersProcessed) {
|
|
290
344
|
throw new Error('Command Line Parser Data was already processed');
|
|
291
345
|
}
|
|
@@ -299,31 +353,36 @@ class CommandLineParameterProvider {
|
|
|
299
353
|
}
|
|
300
354
|
this._parametersProcessed = true;
|
|
301
355
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const parameter = this._parametersByLongName.get(parameterLongName);
|
|
307
|
-
if (!parameter) {
|
|
308
|
-
throw new Error(`The parameter "${parameterLongName}" is not defined`);
|
|
356
|
+
/** @internal */
|
|
357
|
+
_defineParameter(parameter) {
|
|
358
|
+
if (this._parametersRegistered) {
|
|
359
|
+
throw new Error('Parameters have already been registered for this provider');
|
|
309
360
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
361
|
+
// Generate and set the parser key at definition time
|
|
362
|
+
parameter._parserKey = this._generateKey();
|
|
363
|
+
this._parameters.push(parameter);
|
|
364
|
+
// Collect all parameters with the same long name. We will perform conflict resolution at registration.
|
|
365
|
+
let longNameParameters = this._parametersByLongName.get(parameter.longName);
|
|
366
|
+
if (!longNameParameters) {
|
|
367
|
+
longNameParameters = [];
|
|
368
|
+
this._parametersByLongName.set(parameter.longName, longNameParameters);
|
|
313
369
|
}
|
|
314
|
-
|
|
370
|
+
longNameParameters.push(parameter);
|
|
315
371
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
throw new Error('defineCommandLineRemainder() was already called for this provider;' +
|
|
319
|
-
' no further parameters can be defined');
|
|
320
|
-
}
|
|
372
|
+
/** @internal */
|
|
373
|
+
_registerParameter(parameter, useScopedLongName) {
|
|
321
374
|
const names = [];
|
|
322
375
|
if (parameter.shortName) {
|
|
323
376
|
names.push(parameter.shortName);
|
|
324
377
|
}
|
|
325
|
-
|
|
326
|
-
|
|
378
|
+
// Use the original long name unless otherwise requested
|
|
379
|
+
if (!useScopedLongName) {
|
|
380
|
+
names.push(parameter.longName);
|
|
381
|
+
}
|
|
382
|
+
// Add the scoped long name if it exists
|
|
383
|
+
if (parameter.scopedLongName) {
|
|
384
|
+
names.push(parameter.scopedLongName);
|
|
385
|
+
}
|
|
327
386
|
let finalDescription = parameter.description;
|
|
328
387
|
const supplementaryNotes = [];
|
|
329
388
|
parameter._getSupplementaryNotes(supplementaryNotes);
|
|
@@ -371,15 +430,60 @@ class CommandLineParameterProvider {
|
|
|
371
430
|
argparseOptions.action = 'append';
|
|
372
431
|
break;
|
|
373
432
|
}
|
|
374
|
-
|
|
375
|
-
|
|
433
|
+
let argumentGroup;
|
|
434
|
+
if (parameter.parameterGroup) {
|
|
435
|
+
argumentGroup = this._parameterGroupsByName.get(parameter.parameterGroup);
|
|
436
|
+
if (!argumentGroup) {
|
|
437
|
+
let parameterGroupName;
|
|
438
|
+
if (typeof parameter.parameterGroup === 'string') {
|
|
439
|
+
parameterGroupName = parameter.parameterGroup;
|
|
440
|
+
}
|
|
441
|
+
else if (parameter.parameterGroup === Constants_1.SCOPING_PARAMETER_GROUP) {
|
|
442
|
+
parameterGroupName = 'scoping';
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
throw new Error('Unexpected parameter group: ' + parameter.parameterGroup);
|
|
446
|
+
}
|
|
447
|
+
argumentGroup = this._getArgumentParser().addArgumentGroup({
|
|
448
|
+
title: `Optional ${parameterGroupName} arguments`
|
|
449
|
+
});
|
|
450
|
+
this._parameterGroupsByName.set(parameter.parameterGroup, argumentGroup);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
argumentGroup = this._getArgumentParser();
|
|
455
|
+
}
|
|
456
|
+
argumentGroup.addArgument(names, Object.assign({}, argparseOptions));
|
|
376
457
|
if (parameter.undocumentedSynonyms && parameter.undocumentedSynonyms.length > 0) {
|
|
377
|
-
|
|
458
|
+
argumentGroup.addArgument(parameter.undocumentedSynonyms, Object.assign(Object.assign({}, argparseOptions), { help: argparse.Const.SUPPRESS }));
|
|
378
459
|
}
|
|
379
|
-
|
|
380
|
-
|
|
460
|
+
}
|
|
461
|
+
_generateKey() {
|
|
462
|
+
return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();
|
|
463
|
+
}
|
|
464
|
+
_getParameter(parameterLongName, expectedKind, parameterScope) {
|
|
465
|
+
// Support the parameter long name being prefixed with the scope
|
|
466
|
+
const { scope, longName } = this.parseScopedLongName(parameterLongName);
|
|
467
|
+
parameterLongName = longName;
|
|
468
|
+
parameterScope = scope || parameterScope;
|
|
469
|
+
const parameters = this._parametersByLongName.get(parameterLongName);
|
|
470
|
+
if (!parameters) {
|
|
471
|
+
throw new Error(`The parameter "${parameterLongName}" is not defined`);
|
|
472
|
+
}
|
|
473
|
+
const parameter = parameters.find((p) => p.parameterScope === parameterScope);
|
|
474
|
+
if (!parameter) {
|
|
475
|
+
throw new Error(`The parameter "${parameterLongName}" with scope "${parameterScope}" is not defined.`);
|
|
476
|
+
}
|
|
477
|
+
if (parameter.kind !== expectedKind) {
|
|
478
|
+
throw new Error(`The parameter "${parameterLongName}" is of type "${BaseClasses_1.CommandLineParameterKind[parameter.kind]}"` +
|
|
479
|
+
` whereas the caller was expecting "${BaseClasses_1.CommandLineParameterKind[expectedKind]}".`);
|
|
480
|
+
}
|
|
481
|
+
return parameter;
|
|
381
482
|
}
|
|
382
483
|
}
|
|
383
484
|
exports.CommandLineParameterProvider = CommandLineParameterProvider;
|
|
485
|
+
CommandLineParameterProvider._scopeGroupName = 'scope';
|
|
486
|
+
CommandLineParameterProvider._longNameGroupName = 'longName';
|
|
487
|
+
CommandLineParameterProvider._possiblyScopedLongNameRegex = /^--((?<scope>[a-z0-9]+(-[a-z0-9]+)*):)?(?<longName>[a-z0-9]+((-[a-z0-9]+)+)?)$/;
|
|
384
488
|
CommandLineParameterProvider._keyCounter = 0;
|
|
385
489
|
//# sourceMappingURL=CommandLineParameterProvider.js.map
|