@rushstack/ts-command-line 4.16.0 → 4.17.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/LICENSE +23 -23
- package/README.md +251 -251
- package/dist/ts-command-line.d.ts +11 -5
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/CommandLineHelper.js.map +1 -1
- package/lib/Constants.js.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/parameters/BaseClasses.d.ts +1 -6
- package/lib/parameters/BaseClasses.d.ts.map +1 -1
- package/lib/parameters/BaseClasses.js +0 -7
- package/lib/parameters/BaseClasses.js.map +1 -1
- package/lib/parameters/CommandLineChoiceListParameter.d.ts +1 -1
- package/lib/parameters/CommandLineChoiceListParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -1
- package/lib/parameters/CommandLineChoiceParameter.d.ts +1 -1
- package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineChoiceParameter.js.map +1 -1
- package/lib/parameters/CommandLineDefinition.js.map +1 -1
- package/lib/parameters/CommandLineFlagParameter.d.ts +1 -1
- package/lib/parameters/CommandLineFlagParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineFlagParameter.js.map +1 -1
- package/lib/parameters/CommandLineIntegerListParameter.d.ts +1 -1
- package/lib/parameters/CommandLineIntegerListParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -1
- package/lib/parameters/CommandLineIntegerParameter.d.ts +1 -1
- package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineIntegerParameter.js.map +1 -1
- package/lib/parameters/CommandLineRemainder.d.ts +1 -1
- package/lib/parameters/CommandLineRemainder.d.ts.map +1 -1
- package/lib/parameters/CommandLineRemainder.js.map +1 -1
- package/lib/parameters/CommandLineStringListParameter.d.ts +1 -1
- package/lib/parameters/CommandLineStringListParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineStringListParameter.js.map +1 -1
- package/lib/parameters/CommandLineStringParameter.d.ts +1 -1
- package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -1
- package/lib/parameters/CommandLineStringParameter.js.map +1 -1
- package/lib/parameters/EnvironmentVariableParser.js.map +1 -1
- package/lib/providers/AliasCommandLineAction.d.ts +2 -2
- package/lib/providers/AliasCommandLineAction.d.ts.map +1 -1
- package/lib/providers/AliasCommandLineAction.js +15 -3
- package/lib/providers/AliasCommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineAction.d.ts +2 -2
- package/lib/providers/CommandLineAction.d.ts.map +1 -1
- package/lib/providers/CommandLineAction.js +13 -0
- package/lib/providers/CommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineParameterProvider.d.ts +25 -7
- package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
- package/lib/providers/CommandLineParameterProvider.js +85 -37
- package/lib/providers/CommandLineParameterProvider.js.map +1 -1
- package/lib/providers/CommandLineParser.d.ts +3 -3
- package/lib/providers/CommandLineParser.d.ts.map +1 -1
- package/lib/providers/CommandLineParser.js +18 -5
- package/lib/providers/CommandLineParser.js.map +1 -1
- package/lib/providers/CommandLineParserExitError.js.map +1 -1
- package/lib/providers/DynamicCommandLineAction.js.map +1 -1
- package/lib/providers/DynamicCommandLineParser.js.map +1 -1
- package/lib/providers/ScopedCommandLineAction.d.ts +6 -3
- package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -1
- package/lib/providers/ScopedCommandLineAction.js +23 -5
- package/lib/providers/ScopedCommandLineAction.js.map +1 -1
- package/lib/providers/TabCompletionAction.d.ts +1 -1
- package/lib/providers/TabCompletionAction.d.ts.map +1 -1
- package/lib/providers/TabCompletionAction.js +1 -0
- package/lib/providers/TabCompletionAction.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineStringParameter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;IAED;;;OAGG;IACI,sBAAsB,CAAC,kBAA4B;QACxD,UAAU;QACV,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;YACnC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,GAAG,EAAE;gBAClC,kBAAkB,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;aACvF;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AArFD,gEAqFC","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 { ICommandLineStringDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.\n * @public\n */\nexport class CommandLineStringParameter extends CommandLineParameterWithArgument {\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: string | undefined;\n\n private _value: string | undefined = undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineStringDefinition) {\n super(definition);\n\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.String;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._setValue}\n * @internal\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public _setValue(data: any): void {\n // abstract\n if (data !== null && data !== undefined) {\n if (typeof data !== 'string') {\n this.reportInvalidData(data);\n }\n this._value = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n // Try reading the environment variable\n const environmentValue: string | undefined = process.env[this.environmentVariable];\n if (environmentValue !== undefined) {\n // NOTE: If the environment variable is defined as an empty string,\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\n this._value = environmentValue;\n return;\n }\n }\n\n if (this.defaultValue !== undefined) {\n this._value = this.defaultValue;\n return;\n }\n\n this._value = undefined;\n }\n\n /**\n * {@inheritDoc CommandLineParameter._getSupplementaryNotes}\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n super._getSupplementaryNotes(supplementaryNotes);\n if (this.defaultValue !== undefined) {\n if (this.defaultValue.length < 160) {\n supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);\n }\n }\n }\n\n /**\n * Returns the argument value for a string parameter that was parsed from the command line.\n *\n * @remarks\n * The return value will be undefined if the command-line has not been parsed yet,\n * or if the parameter was omitted and has no default value.\n */\n public get value(): string | undefined {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value !== undefined) {\n argList.push(this.longName);\n argList.push(this.value);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineStringParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAE3F;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,8CAAgC;IAM9E,gBAAgB;IAChB,YAAmB,UAAwC;QACzD,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAuB,SAAS,CAAC;QAM7C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,C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C,CAAC;aACvF;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AArFD,gEAqFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport type { ICommandLineStringDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineStringParameter}.\r\n * @public\r\n */\r\nexport class CommandLineStringParameter extends CommandLineParameterWithArgument {\r\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\r\n public readonly defaultValue: string | undefined;\r\n\r\n private _value: string | undefined = undefined;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineStringDefinition) {\r\n super(definition);\r\n\r\n this.defaultValue = definition.defaultValue;\r\n this.validateDefaultValue(!!this.defaultValue);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.String;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._setValue}\r\n * @internal\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n public _setValue(data: any): void {\r\n // abstract\r\n if (data !== null && data !== undefined) {\r\n if (typeof data !== 'string') {\r\n this.reportInvalidData(data);\r\n }\r\n this._value = data;\r\n return;\r\n }\r\n\r\n if (this.environmentVariable !== undefined) {\r\n // Try reading the environment variable\r\n const environmentValue: string | undefined = process.env[this.environmentVariable];\r\n if (environmentValue !== undefined) {\r\n // NOTE: If the environment variable is defined as an empty string,\r\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\r\n this._value = environmentValue;\r\n return;\r\n }\r\n }\r\n\r\n if (this.defaultValue !== undefined) {\r\n this._value = this.defaultValue;\r\n return;\r\n }\r\n\r\n this._value = undefined;\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameter._getSupplementaryNotes}\r\n * @internal\r\n */\r\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\r\n // virtual\r\n super._getSupplementaryNotes(supplementaryNotes);\r\n if (this.defaultValue !== undefined) {\r\n if (this.defaultValue.length < 160) {\r\n supplementaryNotes.push(`The default value is ${JSON.stringify(this.defaultValue)}.`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Returns the argument value for a string parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The return value will be undefined if the command-line has not been parsed yet,\r\n * or if the parameter was omitted and has no default value.\r\n */\r\n public get value(): string | undefined {\r\n return this._value;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.value !== undefined) {\r\n argList.push(this.longName);\r\n argList.push(this.value);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentVariableParser.js","sourceRoot":"","sources":["../../src/parameters/EnvironmentVariableParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;GAKG;AACH,MAAa,yBAAyB;IAC7B,MAAM,CAAC,WAAW,CAAC,UAAkB;QAC1C,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAErE,IAAI,gBAAgB,KAAK,SAAS,EAAE;YAClC,mEAAmE;YACnE,0FAA0F;YAE1F,IAAI,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC1C,iGAAiG;gBACjG,2FAA2F;gBAC3F,iGAAiG;gBACjG,+FAA+F;gBAC/F,mGAAmG;gBACnG,+FAA+F;gBAC/F,2BAA2B;gBAC3B,IAAI;oBACF,MAAM,UAAU,GAAY,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;oBACzD,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;wBAC1B,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,EAClG;wBACA,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,6CAA6C;4BAClE,wDAAwD,CAC3D,CAAC;qBACH;oBACD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAC5C;gBAAC,OAAO,EAAE,EAAE;oBACX,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,qDAAqD;wBAC1E,wBAAwB;wBACvB,EAAY,CAAC,OAAO,CACxB,CAAC;iBACH;aACF;iBAAM;gBACL,gGAAgG;gBAChG,gCAAgC;gBAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC;aAC3B;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5CD,8DA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Some parameter types can receive their values from an environment variable instead of\n * a command line argument. This class provides some utility methods for parsing environment\n * variable values.\n * @internal\n */\nexport class EnvironmentVariableParser {\n public static parseAsList(envVarName: string): string[] | undefined {\n const environmentValue: string | undefined = process.env[envVarName];\n\n if (environmentValue !== undefined) {\n // NOTE: If the environment variable is defined as an empty string,\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\n\n if (environmentValue.trimLeft()[0] === '[') {\n // Specifying multiple items in an environment variable is a somewhat rare case. But environment\n // variables are actually a pretty reliable way for a tool to avoid shell escaping problems\n // when spawning another tool. For this case, we need a reliable way to pass an array of strings\n // that could contain any character. For example, if we simply used \";\" as the list delimiter,\n // then what to do if a string contains that character? We'd need to design an escaping mechanism.\n // Since JSON is simple and standard and can escape every possible string, it's a better option\n // than a custom delimiter.\n try {\n const parsedJson: unknown = JSON.parse(environmentValue);\n if (\n !Array.isArray(parsedJson) ||\n !parsedJson.every((x) => typeof x === 'string' || typeof x === 'boolean' || typeof x === 'number')\n ) {\n throw new Error(\n `The ${environmentValue} environment variable value must be a JSON ` +\n ` array containing only strings, numbers, and booleans.`\n );\n }\n return parsedJson.map((x) => x.toString());\n } catch (ex) {\n throw new Error(\n `The ${environmentValue} environment variable value looks like a JSON array` +\n ` but failed to parse: ` +\n (ex as Error).message\n );\n }\n } else {\n // As a shorthand, a single value may be specified without JSON encoding, as long as it does not\n // start with the \"[\" character.\n return [environmentValue];\n }\n }\n\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EnvironmentVariableParser.js","sourceRoot":"","sources":["../../src/parameters/EnvironmentVariableParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;GAKG;AACH,MAAa,yBAAyB;IAC7B,MAAM,CAAC,WAAW,CAAC,UAAkB;QAC1C,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAErE,IAAI,gBAAgB,KAAK,SAAS,EAAE;YAClC,mEAAmE;YACnE,0FAA0F;YAE1F,IAAI,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC1C,iGAAiG;gBACjG,2FAA2F;gBAC3F,iGAAiG;gBACjG,+FAA+F;gBAC/F,mGAAmG;gBACnG,+FAA+F;gBAC/F,2BAA2B;gBAC3B,IAAI;oBACF,MAAM,UAAU,GAAY,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;oBACzD,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;wBAC1B,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,EAClG;wBACA,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,6CAA6C;4BAClE,wDAAwD,CAC3D,CAAC;qBACH;oBACD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAC5C;gBAAC,OAAO,EAAE,EAAE;oBACX,MAAM,IAAI,KAAK,CACb,OAAO,gBAAgB,qDAAqD;wBAC1E,wBAAwB;wBACvB,EAAY,CAAC,OAAO,CACxB,CAAC;iBACH;aACF;iBAAM;gBACL,gGAAgG;gBAChG,gCAAgC;gBAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC;aAC3B;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5CD,8DA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\n/**\r\n * Some parameter types can receive their values from an environment variable instead of\r\n * a command line argument. This class provides some utility methods for parsing environment\r\n * variable values.\r\n * @internal\r\n */\r\nexport class EnvironmentVariableParser {\r\n public static parseAsList(envVarName: string): string[] | undefined {\r\n const environmentValue: string | undefined = process.env[envVarName];\r\n\r\n if (environmentValue !== undefined) {\r\n // NOTE: If the environment variable is defined as an empty string,\r\n // here we will accept the empty string as our value. (For number/flag we don't do that.)\r\n\r\n if (environmentValue.trimLeft()[0] === '[') {\r\n // Specifying multiple items in an environment variable is a somewhat rare case. But environment\r\n // variables are actually a pretty reliable way for a tool to avoid shell escaping problems\r\n // when spawning another tool. For this case, we need a reliable way to pass an array of strings\r\n // that could contain any character. For example, if we simply used \";\" as the list delimiter,\r\n // then what to do if a string contains that character? We'd need to design an escaping mechanism.\r\n // Since JSON is simple and standard and can escape every possible string, it's a better option\r\n // than a custom delimiter.\r\n try {\r\n const parsedJson: unknown = JSON.parse(environmentValue);\r\n if (\r\n !Array.isArray(parsedJson) ||\r\n !parsedJson.every((x) => typeof x === 'string' || typeof x === 'boolean' || typeof x === 'number')\r\n ) {\r\n throw new Error(\r\n `The ${environmentValue} environment variable value must be a JSON ` +\r\n ` array containing only strings, numbers, and booleans.`\r\n );\r\n }\r\n return parsedJson.map((x) => x.toString());\r\n } catch (ex) {\r\n throw new Error(\r\n `The ${environmentValue} environment variable value looks like a JSON array` +\r\n ` but failed to parse: ` +\r\n (ex as Error).message\r\n );\r\n }\r\n } else {\r\n // As a shorthand, a single value may be specified without JSON encoding, as long as it does not\r\n // start with the \"[\" character.\r\n return [environmentValue];\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandLineAction } from './CommandLineAction';
|
|
2
|
-
import type { ICommandLineParserData } from './CommandLineParameterProvider';
|
|
2
|
+
import type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';
|
|
3
3
|
import type { ICommandLineParserOptions } from './CommandLineParser';
|
|
4
4
|
/**
|
|
5
5
|
* Options for the AliasCommandLineAction constructor.
|
|
@@ -46,7 +46,7 @@ export declare class AliasCommandLineAction extends CommandLineAction {
|
|
|
46
46
|
private _parameterKeyMap;
|
|
47
47
|
constructor(options: IAliasCommandLineActionOptions);
|
|
48
48
|
/** @internal */
|
|
49
|
-
_registerDefinedParameters(): void;
|
|
49
|
+
_registerDefinedParameters(state: IRegisterDefinedParametersState): void;
|
|
50
50
|
/**
|
|
51
51
|
* This is called internally by CommandLineParser.execute()
|
|
52
52
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AliasCommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"AliasCommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AAC9G,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAQrE;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B;;OAEG;IACH,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,SAAQ,iBAAiB;IAC3D;;OAEG;IACH,SAAgB,YAAY,EAAE,iBAAiB,CAAC;IAEhD;;OAEG;IACH,SAAgB,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzD,OAAO,CAAC,gBAAgB,CAAkC;gBAEvC,OAAO,EAAE,8BAA8B;IAoB1D,gBAAgB;IACT,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,IAAI;IAoF/E;;;OAGG;IACI,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,EAAE,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAmBvG;;OAEG;cACa,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
|
@@ -56,7 +56,7 @@ class AliasCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
56
56
|
this.defaultParameters = options.defaultParameters || [];
|
|
57
57
|
}
|
|
58
58
|
/** @internal */
|
|
59
|
-
_registerDefinedParameters() {
|
|
59
|
+
_registerDefinedParameters(state) {
|
|
60
60
|
/* override */
|
|
61
61
|
// All parameters are going to be defined by the target action. Re-use the target action parameters
|
|
62
62
|
// for this action.
|
|
@@ -108,8 +108,20 @@ class AliasCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
108
108
|
this.defineCommandLineRemainder(this.targetAction.remainder);
|
|
109
109
|
this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);
|
|
110
110
|
}
|
|
111
|
-
// Finally, register the parameters with the parser.
|
|
112
|
-
|
|
111
|
+
// Finally, register the parameters with the parser. We need to make sure that the target action
|
|
112
|
+
// is registered, since we need to re-use its parameters, and ambiguous parameters are discovered
|
|
113
|
+
// during registration. This will no-op if the target action is already registered.
|
|
114
|
+
this.targetAction._registerDefinedParameters(state);
|
|
115
|
+
super._registerDefinedParameters(state);
|
|
116
|
+
// We need to re-map the ambiguous parameters after they are defined by calling
|
|
117
|
+
// super._registerDefinedParameters()
|
|
118
|
+
for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {
|
|
119
|
+
const targetParserKey = this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);
|
|
120
|
+
// If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.
|
|
121
|
+
if (targetParserKey) {
|
|
122
|
+
this._parameterKeyMap.set(parserKey, targetParserKey);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
/**
|
|
115
127
|
* This is called internally by CommandLineParser.execute()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2D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CAAC;IAClE,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,SAAS;QACvB,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;CACF;AAnID,wDAmIC","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 { CommandLineParameterKind, type CommandLineParameter } from '../parameters/BaseClasses';\nimport type { ICommandLineParserData } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\nimport type { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport type { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\nimport type { CommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport type { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport type { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\nimport type { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\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(): 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) {\n let aliasParameter: CommandLineParameter;\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\n parameterLongName: parameter.longName,\n parameterShortName: parameter.shortName\n };\n switch (parameter.kind) {\n case CommandLineParameterKind.Choice:\n const choiceParameter: CommandLineChoiceParameter = parameter as CommandLineChoiceParameter;\n aliasParameter = this.defineChoiceParameter({\n ...nameOptions,\n ...choiceParameter,\n alternatives: ([] as string[]).concat(choiceParameter.alternatives)\n });\n break;\n case CommandLineParameterKind.ChoiceList:\n const choiceListParameter: CommandLineChoiceListParameter =\n parameter as CommandLineChoiceListParameter;\n aliasParameter = this.defineChoiceListParameter({\n ...nameOptions,\n ...choiceListParameter,\n alternatives: ([] as string[]).concat(choiceListParameter.alternatives)\n });\n break;\n case CommandLineParameterKind.Flag:\n const flagParameter: CommandLineFlagParameter = parameter as CommandLineFlagParameter;\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...flagParameter });\n break;\n case CommandLineParameterKind.Integer:\n const integerParameter: CommandLineIntegerParameter = parameter as CommandLineIntegerParameter;\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...integerParameter });\n break;\n case CommandLineParameterKind.IntegerList:\n const integerListParameter: CommandLineIntegerListParameter =\n parameter as CommandLineIntegerListParameter;\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...integerListParameter });\n break;\n case CommandLineParameterKind.String:\n const stringParameter: CommandLineStringParameter = parameter as CommandLineStringParameter;\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...stringParameter });\n break;\n case CommandLineParameterKind.StringList:\n const stringListParameter: CommandLineStringParameter = parameter as CommandLineStringParameter;\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...stringListParameter });\n break;\n default:\n throw new Error(`Unsupported parameter kind: ${parameter.kind}`);\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.\n super._registerDefinedParameters();\n }\n\n /**\n * This is called internally by CommandLineParser.execute()\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._execute();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AliasC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AAE,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;YAC/C,yFAAyF;YACzF,qFAAqF;YACrF,IAAI,GAAG,KAAK,QAAQ,EAAE;gBACpB,SAAS;aACV;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;SACtC;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,QAAQ,EAAE,CAAC;IACrC,CAAC;CACF;AAnJD,wDAmJC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as argparse from 'argparse';\r\n\r\nimport { CommandLineAction } from './CommandLineAction';\r\nimport { CommandLineParameterKind, type CommandLineParameter } from '../parameters/BaseClasses';\r\nimport type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';\r\nimport type { ICommandLineParserOptions } from './CommandLineParser';\r\nimport type { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\r\nimport type { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\r\nimport type { CommandLineStringParameter } from '../parameters/CommandLineStringParameter';\r\nimport type { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\r\nimport type { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\r\nimport type { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\r\n\r\n/**\r\n * Options for the AliasCommandLineAction constructor.\r\n * @public\r\n */\r\nexport interface IAliasCommandLineActionOptions {\r\n /**\r\n * The name of your tool when invoked from the command line. Used for generating help text.\r\n */\r\n toolFilename: string;\r\n\r\n /**\r\n * The name of the alias. For example, if the tool is called \"example\",\r\n * then the \"build\" alias might be invoked as: \"example build -q --some-other-option\"\r\n */\r\n aliasName: string;\r\n\r\n /**\r\n * A list of default parameters to pass to the target action.\r\n */\r\n defaultParameters?: string[];\r\n\r\n /**\r\n * The action that this alias invokes.\r\n */\r\n targetAction: CommandLineAction;\r\n}\r\n\r\n/**\r\n * Represents a sub-command that is part of the CommandLineParser command line.\r\n * The sub-command is an alias for another existing action.\r\n *\r\n * The alias name should be comprised of lower case words separated by hyphens\r\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\r\n * hyphen to separate words (e.g. \"upload-docs\").\r\n *\r\n * @public\r\n */\r\nexport class AliasCommandLineAction extends CommandLineAction {\r\n /**\r\n * The action that this alias invokes.\r\n */\r\n public readonly targetAction: CommandLineAction;\r\n\r\n /**\r\n * A list of default arguments to pass to the target action.\r\n */\r\n public readonly defaultParameters: ReadonlyArray<string>;\r\n\r\n private _parameterKeyMap: Map<string, string> = new Map();\r\n\r\n public constructor(options: IAliasCommandLineActionOptions) {\r\n const toolFilename: string = options.toolFilename;\r\n const targetActionName: string = options.targetAction.actionName;\r\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\r\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\r\n defaultParametersString ? ` ${defaultParametersString}` : ''\r\n }\".`;\r\n\r\n super({\r\n actionName: options.aliasName,\r\n summary,\r\n documentation:\r\n `${summary} For more information on the aliased command, use ` +\r\n `\"${toolFilename} ${targetActionName} --help\".`\r\n });\r\n\r\n this.targetAction = options.targetAction;\r\n this.defaultParameters = options.defaultParameters || [];\r\n }\r\n\r\n /** @internal */\r\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\r\n /* override */\r\n // All parameters are going to be defined by the target action. Re-use the target action parameters\r\n // for this action.\r\n for (const parameter of this.targetAction.parameters) {\r\n let aliasParameter: CommandLineParameter;\r\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\r\n parameterLongName: parameter.longName,\r\n parameterShortName: parameter.shortName\r\n };\r\n switch (parameter.kind) {\r\n case CommandLineParameterKind.Choice:\r\n const choiceParameter: CommandLineChoiceParameter = parameter as CommandLineChoiceParameter;\r\n aliasParameter = this.defineChoiceParameter({\r\n ...nameOptions,\r\n ...choiceParameter,\r\n alternatives: ([] as string[]).concat(choiceParameter.alternatives)\r\n });\r\n break;\r\n case CommandLineParameterKind.ChoiceList:\r\n const choiceListParameter: CommandLineChoiceListParameter =\r\n parameter as CommandLineChoiceListParameter;\r\n aliasParameter = this.defineChoiceListParameter({\r\n ...nameOptions,\r\n ...choiceListParameter,\r\n alternatives: ([] as string[]).concat(choiceListParameter.alternatives)\r\n });\r\n break;\r\n case CommandLineParameterKind.Flag:\r\n const flagParameter: CommandLineFlagParameter = parameter as CommandLineFlagParameter;\r\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...flagParameter });\r\n break;\r\n case CommandLineParameterKind.Integer:\r\n const integerParameter: CommandLineIntegerParameter = parameter as CommandLineIntegerParameter;\r\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...integerParameter });\r\n break;\r\n case CommandLineParameterKind.IntegerList:\r\n const integerListParameter: CommandLineIntegerListParameter =\r\n parameter as CommandLineIntegerListParameter;\r\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...integerListParameter });\r\n break;\r\n case CommandLineParameterKind.String:\r\n const stringParameter: CommandLineStringParameter = parameter as CommandLineStringParameter;\r\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...stringParameter });\r\n break;\r\n case CommandLineParameterKind.StringList:\r\n const stringListParameter: CommandLineStringParameter = parameter as CommandLineStringParameter;\r\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...stringListParameter });\r\n break;\r\n default:\r\n throw new Error(`Unsupported parameter kind: ${parameter.kind}`);\r\n }\r\n\r\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\r\n // and all parameters that we have access to have already been defined.\r\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\r\n }\r\n\r\n // We also need to register the remainder parameter if the target action has one. The parser\r\n // key for this parameter is constant.\r\n if (this.targetAction.remainder) {\r\n this.defineCommandLineRemainder(this.targetAction.remainder);\r\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\r\n }\r\n\r\n // Finally, register the parameters with the parser. We need to make sure that the target action\r\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\r\n // during registration. This will no-op if the target action is already registered.\r\n this.targetAction._registerDefinedParameters(state);\r\n super._registerDefinedParameters(state);\r\n\r\n // We need to re-map the ambiguous parameters after they are defined by calling\r\n // super._registerDefinedParameters()\r\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\r\n const targetParserKey: string | undefined =\r\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\r\n\r\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\r\n if (targetParserKey) {\r\n this._parameterKeyMap.set(parserKey, targetParserKey);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * This is called internally by CommandLineParser.execute()\r\n * @internal\r\n */\r\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\r\n // Re-map the parsed data to the target action's parameters and execute the target action processor.\r\n const targetData: ICommandLineParserData = {\r\n action: this.targetAction.actionName,\r\n aliasAction: data.action,\r\n aliasDocumentation: this.documentation\r\n };\r\n for (const [key, value] of Object.entries(data)) {\r\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\r\n // Skip over the action key though, since we've already re-mapped it to \"aliasAction\"\r\n if (key === 'action') {\r\n continue;\r\n }\r\n const targetKey: string | undefined = this._parameterKeyMap.get(key);\r\n targetData[targetKey ?? key] = value;\r\n }\r\n this.targetAction._processParsedData(parserOptions, targetData);\r\n }\r\n\r\n /**\r\n * Executes the target action.\r\n */\r\n protected async onExecute(): Promise<void> {\r\n await this.targetAction._execute();\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as argparse from 'argparse';
|
|
2
|
-
import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';
|
|
1
|
+
import type * as argparse from 'argparse';
|
|
2
|
+
import { CommandLineParameterProvider, type ICommandLineParserData } from './CommandLineParameterProvider';
|
|
3
3
|
import type { ICommandLineParserOptions } from './CommandLineParser';
|
|
4
4
|
/**
|
|
5
5
|
* Options for the CommandLineAction constructor.
|
|
@@ -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,KAAK,QAAQ,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,4BAA4B,EAAE,KAAK,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGrE;;;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;AAOD;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAkB,SAAQ,4BAA4B;IAC1E,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;IAwB/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,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAC9C"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.CommandLineAction = void 0;
|
|
6
6
|
const CommandLineParameterProvider_1 = require("./CommandLineParameterProvider");
|
|
7
|
+
const CommandLineParserExitError_1 = require("./CommandLineParserExitError");
|
|
7
8
|
/**
|
|
8
9
|
* Example: "do-something"
|
|
9
10
|
*/
|
|
@@ -43,6 +44,18 @@ class CommandLineAction extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
43
44
|
help: this.summary,
|
|
44
45
|
description: this.documentation
|
|
45
46
|
});
|
|
47
|
+
// Monkey-patch the error handling for the action parser
|
|
48
|
+
this._argumentParser.exit = (status, message) => {
|
|
49
|
+
throw new CommandLineParserExitError_1.CommandLineParserExitError(status, message);
|
|
50
|
+
};
|
|
51
|
+
const originalArgumentParserErrorFn = this._argumentParser.error.bind(this._argumentParser);
|
|
52
|
+
this._argumentParser.error = (err) => {
|
|
53
|
+
// Ensure the ParserExitError bubbles up to the top without any special processing
|
|
54
|
+
if (err instanceof CommandLineParserExitError_1.CommandLineParserExitError) {
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
originalArgumentParserErrorFn(err);
|
|
58
|
+
};
|
|
46
59
|
(_a = this.onDefineParameters) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
47
60
|
}
|
|
48
61
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D,
|
|
1
|
+
{"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D,iFAA2G;AAE3G,6EAA0E;AA0B1E;;GAEG;AACH,MAAM,kBAAkB,GAAW,kCAAkC,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAY1E,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAChD,MAAM,IAAI,KAAK,CACb,wBAAwB,OAAO,CAAC,UAAU,KAAK;gBAC7C,2FAA2F,CAC9F,CAAC;SACH;QAED,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAE3C,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,gBAAoC;;QACtD,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;YACjE,IAAI,EAAE,IAAI,CAAC,OAAO;YAClB,WAAW,EAAE,IAAI,CAAC,aAAa;SAChC,CAAC,CAAC;QAEH,wDAAwD;QACxD,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE;YAC9D,MAAM,IAAI,uDAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC,CAAC;QACF,MAAM,6BAA6B,GAAkC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,CAClG,IAAI,CAAC,eAAe,CACrB,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,KAAK,GAAG,CAAC,GAAmB,EAAE,EAAE;YACnD,kFAAkF;YAClF,IAAI,GAAG,YAAY,uDAA0B,EAAE;gBAC7C,MAAM,GAAG,CAAC;aACX;YACD,6BAA6B,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAwC,EAAE,IAA4B;QAC9F,KAAK,CAAC,kBAAkB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACO,kBAAkB;QAC1B,WAAW;QACX,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,qCAAqC;YACrC,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;SACrG;QAED,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CAMF;AA3FD,8CA2FC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport type * as argparse from 'argparse';\r\n\r\nimport { CommandLineParameterProvider, type ICommandLineParserData } from './CommandLineParameterProvider';\r\nimport type { ICommandLineParserOptions } from './CommandLineParser';\r\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\r\n\r\n/**\r\n * Options for the CommandLineAction constructor.\r\n * @public\r\n */\r\nexport interface ICommandLineActionOptions {\r\n /**\r\n * The name of the action. For example, if the tool is called \"example\",\r\n * then the \"build\" action might be invoked as: \"example build -q --some-other-option\"\r\n */\r\n actionName: string;\r\n\r\n /**\r\n * A quick summary that is shown on the main help page, which is displayed\r\n * by the command \"example --help\"\r\n */\r\n summary: string;\r\n\r\n /**\r\n * A detailed description that is shown on the action help page, which is displayed\r\n * by the command \"example build --help\", e.g. for actionName=\"build\".\r\n */\r\n documentation: string;\r\n}\r\n\r\n/**\r\n * Example: \"do-something\"\r\n */\r\nconst ACTION_NAME_REGEXP: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\r\n\r\n/**\r\n * Represents a sub-command that is part of the CommandLineParser command line.\r\n * Applications should create subclasses of CommandLineAction corresponding to\r\n * each action that they want to expose.\r\n *\r\n * The action name should be comprised of lower case words separated by hyphens\r\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\r\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\r\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\r\n * \"docs:serve\", etc).\r\n *\r\n * @public\r\n */\r\nexport abstract class CommandLineAction extends CommandLineParameterProvider {\r\n /** {@inheritDoc ICommandLineActionOptions.actionName} */\r\n public readonly actionName: string;\r\n\r\n /** {@inheritDoc ICommandLineActionOptions.summary} */\r\n public readonly summary: string;\r\n\r\n /** {@inheritDoc ICommandLineActionOptions.documentation} */\r\n public readonly documentation: string;\r\n\r\n private _argumentParser: argparse.ArgumentParser | undefined;\r\n\r\n public constructor(options: ICommandLineActionOptions) {\r\n super();\r\n\r\n if (!ACTION_NAME_REGEXP.test(options.actionName)) {\r\n throw new Error(\r\n `Invalid action name \"${options.actionName}\". ` +\r\n `The name must be comprised of lower-case words optionally separated by hyphens or colons.`\r\n );\r\n }\r\n\r\n this.actionName = options.actionName;\r\n this.summary = options.summary;\r\n this.documentation = options.documentation;\r\n\r\n this._argumentParser = undefined;\r\n }\r\n\r\n /**\r\n * This is called internally by CommandLineParser.addAction()\r\n * @internal\r\n */\r\n public _buildParser(actionsSubParser: argparse.SubParser): void {\r\n this._argumentParser = actionsSubParser.addParser(this.actionName, {\r\n help: this.summary,\r\n description: this.documentation\r\n });\r\n\r\n // Monkey-patch the error handling for the action parser\r\n this._argumentParser.exit = (status: number, message: string) => {\r\n throw new CommandLineParserExitError(status, message);\r\n };\r\n const originalArgumentParserErrorFn: (err: Error | string) => void = this._argumentParser.error.bind(\r\n this._argumentParser\r\n );\r\n this._argumentParser.error = (err: Error | string) => {\r\n // Ensure the ParserExitError bubbles up to the top without any special processing\r\n if (err instanceof CommandLineParserExitError) {\r\n throw err;\r\n }\r\n originalArgumentParserErrorFn(err);\r\n };\r\n\r\n this.onDefineParameters?.();\r\n }\r\n\r\n /**\r\n * This is called internally by CommandLineParser.execute()\r\n * @internal\r\n */\r\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\r\n super._processParsedData(parserOptions, data);\r\n }\r\n\r\n /**\r\n * Invoked by CommandLineParser.onExecute().\r\n * @internal\r\n */\r\n public _execute(): Promise<void> {\r\n return this.onExecute();\r\n }\r\n\r\n /**\r\n * {@inheritDoc CommandLineParameterProvider._getArgumentParser}\r\n * @internal\r\n */\r\n protected _getArgumentParser(): argparse.ArgumentParser {\r\n // override\r\n if (!this._argumentParser) {\r\n // We will improve this in the future\r\n throw new Error('The CommandLineAction must be added to a CommandLineParser before it can be used');\r\n }\r\n\r\n return this._argumentParser;\r\n }\r\n\r\n /**\r\n * Your subclass should implement this hook to perform the operation.\r\n */\r\n protected abstract onExecute(): Promise<void>;\r\n}\r\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as argparse from 'argparse';
|
|
2
2
|
import type { ICommandLineChoiceDefinition, ICommandLineChoiceListDefinition, ICommandLineIntegerDefinition, ICommandLineIntegerListDefinition, ICommandLineFlagDefinition, ICommandLineStringDefinition, ICommandLineStringListDefinition, ICommandLineRemainderDefinition } from '../parameters/CommandLineDefinition';
|
|
3
3
|
import type { ICommandLineParserOptions } from './CommandLineParser';
|
|
4
|
-
import { CommandLineParameter } from '../parameters/BaseClasses';
|
|
4
|
+
import { type CommandLineParameter } from '../parameters/BaseClasses';
|
|
5
5
|
import { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';
|
|
6
6
|
import { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';
|
|
7
7
|
import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';
|
|
@@ -27,6 +27,18 @@ export interface IScopedLongNameParseResult {
|
|
|
27
27
|
*/
|
|
28
28
|
scope: string | undefined;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* An object containing the state of the
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export interface IRegisterDefinedParametersState {
|
|
36
|
+
/**
|
|
37
|
+
* A set of all defined parameter names registered by parent {@link CommandLineParameterProvider}
|
|
38
|
+
* objects.
|
|
39
|
+
*/
|
|
40
|
+
parentParameterNames: Set<string>;
|
|
41
|
+
}
|
|
30
42
|
/**
|
|
31
43
|
* This is the argparse result data object
|
|
32
44
|
* @internal
|
|
@@ -45,13 +57,16 @@ export interface ICommandLineParserData {
|
|
|
45
57
|
*/
|
|
46
58
|
export declare abstract class CommandLineParameterProvider {
|
|
47
59
|
private static _keyCounter;
|
|
60
|
+
/** @internal */
|
|
61
|
+
readonly _ambiguousParameterParserKeysByName: Map<string, string>;
|
|
62
|
+
/** @internal */
|
|
63
|
+
protected readonly _registeredParameterParserKeysByName: Map<string, string>;
|
|
48
64
|
private readonly _parameters;
|
|
49
65
|
private readonly _parametersByLongName;
|
|
50
66
|
private readonly _parametersByShortName;
|
|
51
67
|
private readonly _parameterGroupsByName;
|
|
52
|
-
private
|
|
53
|
-
private
|
|
54
|
-
private _parametersProcessed;
|
|
68
|
+
private _parametersHaveBeenRegistered;
|
|
69
|
+
private _parametersHaveBeenProcessed;
|
|
55
70
|
private _remainder;
|
|
56
71
|
/** @internal */
|
|
57
72
|
constructor();
|
|
@@ -221,7 +236,7 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
221
236
|
*/
|
|
222
237
|
parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult;
|
|
223
238
|
/** @internal */
|
|
224
|
-
_registerDefinedParameters(): void;
|
|
239
|
+
_registerDefinedParameters(state: IRegisterDefinedParametersState): void;
|
|
225
240
|
/**
|
|
226
241
|
* The child class should implement this hook to define its command-line parameters,
|
|
227
242
|
* e.g. by calling defineFlagParameter().
|
|
@@ -237,9 +252,12 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
237
252
|
/** @internal */
|
|
238
253
|
protected _defineParameter(parameter: CommandLineParameter): void;
|
|
239
254
|
/** @internal */
|
|
240
|
-
protected
|
|
241
|
-
|
|
255
|
+
protected _defineAmbiguousParameter(name: string): string;
|
|
256
|
+
/** @internal */
|
|
257
|
+
protected _registerParameter(parameter: CommandLineParameter, useScopedLongName: boolean, ignoreShortName: boolean): void;
|
|
258
|
+
protected _registerAmbiguousParameter(name: string, parserKey: string): void;
|
|
242
259
|
private _generateKey;
|
|
243
260
|
private _getParameter;
|
|
261
|
+
private _throwParserExitError;
|
|
244
262
|
}
|
|
245
263
|
//# 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;AAErC,OAAO,KAAK,EACV,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,EACjC,0BAA0B,EAC1B,4BAA4B,EAC5B,gCAAgC,EAChC,+BAA+B,EAChC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,oBAAoB,
|
|
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,+BAA+B,EAChC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,8CAA8C,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,8CAA8C,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAI1E;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CA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;IAyE/E;;;OAGG;IACH,SAAS,CAAC,kBAAkB,CAAC,IAAI,IAAI;IAErC;;;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;IA0G1G,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAiCjE,gBAAgB;IAChB,SAAS,CAAC,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAkBzD,gBAAgB;IAChB,SAAS,CAAC,kBAAkB,CAC1B,SAAS,EAAE,oBAAoB,EAC/B,iBAAiB,EAAE,OAAO,EAC1B,eAAe,EAAE,OAAO,GACvB,IAAI;IAwGP,SAAS,CAAC,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAW5E,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;IAwCrB,OAAO,CAAC,qBAAqB;CAiB9B"}
|
|
@@ -37,6 +37,7 @@ const CommandLineStringParameter_1 = require("../parameters/CommandLineStringPar
|
|
|
37
37
|
const CommandLineStringListParameter_1 = require("../parameters/CommandLineStringListParameter");
|
|
38
38
|
const CommandLineRemainder_1 = require("../parameters/CommandLineRemainder");
|
|
39
39
|
const Constants_1 = require("../Constants");
|
|
40
|
+
const CommandLineParserExitError_1 = require("./CommandLineParserExitError");
|
|
40
41
|
const SCOPE_GROUP_NAME = 'scope';
|
|
41
42
|
const LONG_NAME_GROUP_NAME = 'longName';
|
|
42
43
|
const POSSIBLY_SCOPED_LONG_NAME_REGEXP = /^--((?<scope>[a-z0-9]+(-[a-z0-9]+)*):)?(?<longName>[a-z0-9]+((-[a-z0-9]+)+)?)$/;
|
|
@@ -54,9 +55,10 @@ class CommandLineParameterProvider {
|
|
|
54
55
|
this._parametersByLongName = new Map();
|
|
55
56
|
this._parametersByShortName = new Map();
|
|
56
57
|
this._parameterGroupsByName = new Map();
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
58
|
+
this._ambiguousParameterParserKeysByName = new Map();
|
|
59
|
+
this._registeredParameterParserKeysByName = new Map();
|
|
60
|
+
this._parametersHaveBeenRegistered = false;
|
|
61
|
+
this._parametersHaveBeenProcessed = false;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Returns a collection of the parameters that were defined for this object.
|
|
@@ -68,7 +70,7 @@ class CommandLineParameterProvider {
|
|
|
68
70
|
* Informs the caller if the argparse data has been processed into parameters.
|
|
69
71
|
*/
|
|
70
72
|
get parametersProcessed() {
|
|
71
|
-
return this.
|
|
73
|
+
return this._parametersHaveBeenProcessed;
|
|
72
74
|
}
|
|
73
75
|
/**
|
|
74
76
|
* If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,
|
|
@@ -263,14 +265,20 @@ class CommandLineParameterProvider {
|
|
|
263
265
|
* Generates the command-line help text.
|
|
264
266
|
*/
|
|
265
267
|
renderHelpText() {
|
|
266
|
-
|
|
268
|
+
const initialState = {
|
|
269
|
+
parentParameterNames: new Set()
|
|
270
|
+
};
|
|
271
|
+
this._registerDefinedParameters(initialState);
|
|
267
272
|
return this._getArgumentParser().formatHelp();
|
|
268
273
|
}
|
|
269
274
|
/**
|
|
270
275
|
* Generates the command-line usage text.
|
|
271
276
|
*/
|
|
272
277
|
renderUsageText() {
|
|
273
|
-
|
|
278
|
+
const initialState = {
|
|
279
|
+
parentParameterNames: new Set()
|
|
280
|
+
};
|
|
281
|
+
this._registerDefinedParameters(initialState);
|
|
274
282
|
return this._getArgumentParser().formatUsage();
|
|
275
283
|
}
|
|
276
284
|
/**
|
|
@@ -313,22 +321,21 @@ class CommandLineParameterProvider {
|
|
|
313
321
|
};
|
|
314
322
|
}
|
|
315
323
|
/** @internal */
|
|
316
|
-
_registerDefinedParameters() {
|
|
317
|
-
if (this.
|
|
324
|
+
_registerDefinedParameters(state) {
|
|
325
|
+
if (this._parametersHaveBeenRegistered) {
|
|
318
326
|
// We prevent new parameters from being defined after the first call to _registerDefinedParameters,
|
|
319
327
|
// so we can already ensure that all parameters were registered.
|
|
320
328
|
return;
|
|
321
329
|
}
|
|
322
|
-
this._parametersRegistered = true;
|
|
323
|
-
const ambiguousParameterNames = new Set();
|
|
324
330
|
// First, loop through all parameters with short names. If there are any duplicates, disable the short names
|
|
325
331
|
// since we can't prefix scopes to short names in order to deduplicate them. The duplicate short names will
|
|
326
332
|
// be reported as errors if the user attempts to use them.
|
|
333
|
+
const parametersWithDuplicateShortNames = new Set();
|
|
327
334
|
for (const [shortName, shortNameParameters] of this._parametersByShortName.entries()) {
|
|
328
335
|
if (shortNameParameters.length > 1) {
|
|
329
336
|
for (const parameter of shortNameParameters) {
|
|
330
|
-
|
|
331
|
-
|
|
337
|
+
this._defineAmbiguousParameter(shortName);
|
|
338
|
+
parametersWithDuplicateShortNames.add(parameter);
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
}
|
|
@@ -343,15 +350,27 @@ class CommandLineParameterProvider {
|
|
|
343
350
|
throw new Error(`The parameter "${parameter.longName}" is defined multiple times with the same long name. ` +
|
|
344
351
|
'Parameters with the same long name must define a scope.');
|
|
345
352
|
}
|
|
346
|
-
|
|
353
|
+
this._defineAmbiguousParameter(parameter.longName);
|
|
347
354
|
}
|
|
348
|
-
|
|
355
|
+
const ignoreShortName = parametersWithDuplicateShortNames.has(parameter);
|
|
356
|
+
this._registerParameter(parameter, useScopedLongName, ignoreShortName);
|
|
349
357
|
}
|
|
350
358
|
}
|
|
351
|
-
// Register
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
359
|
+
// Register the existing parameters as ambiguous parameters. These are generally provided by the
|
|
360
|
+
// parent action.
|
|
361
|
+
const { parentParameterNames } = state;
|
|
362
|
+
for (const parentParameterName of parentParameterNames) {
|
|
363
|
+
this._defineAmbiguousParameter(parentParameterName);
|
|
364
|
+
}
|
|
365
|
+
// We also need to loop through the defined ambiguous parameters and register them. These will be reported
|
|
366
|
+
// as errors if the user attempts to use them.
|
|
367
|
+
for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {
|
|
368
|
+
// Only register the ambiguous parameter if it hasn't already been registered. We will still handle these
|
|
369
|
+
// already-registered parameters as ambiguous, but by avoiding registering again, we will defer errors
|
|
370
|
+
// until the user actually attempts to use the parameter.
|
|
371
|
+
if (!this._registeredParameterParserKeysByName.has(ambiguousParameterName)) {
|
|
372
|
+
this._registerAmbiguousParameter(ambiguousParameterName, parserKey);
|
|
373
|
+
}
|
|
355
374
|
}
|
|
356
375
|
// Need to add the remainder parameter last
|
|
357
376
|
if (this._remainder) {
|
|
@@ -362,18 +381,24 @@ class CommandLineParameterProvider {
|
|
|
362
381
|
};
|
|
363
382
|
this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);
|
|
364
383
|
}
|
|
384
|
+
this._parametersHaveBeenRegistered = true;
|
|
365
385
|
}
|
|
366
386
|
/** @internal */
|
|
367
387
|
_processParsedData(parserOptions, data) {
|
|
368
|
-
if (!this.
|
|
388
|
+
if (!this._parametersHaveBeenRegistered) {
|
|
369
389
|
throw new Error('Parameters have not been registered');
|
|
370
390
|
}
|
|
371
|
-
if (this.
|
|
391
|
+
if (this._parametersHaveBeenProcessed) {
|
|
372
392
|
throw new Error('Command Line Parser Data was already processed');
|
|
373
393
|
}
|
|
374
394
|
// Search for any ambiguous parameters and throw an error if any are found
|
|
375
|
-
for (const [
|
|
395
|
+
for (const [parameterName, parserKey] of this._ambiguousParameterParserKeysByName) {
|
|
376
396
|
if (data[parserKey]) {
|
|
397
|
+
// When the parser key matches the actually registered parameter, we know that this is an ambiguous
|
|
398
|
+
// parameter sourced from the parent action or tool
|
|
399
|
+
if (this._registeredParameterParserKeysByName.get(parameterName) === parserKey) {
|
|
400
|
+
this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: "${parameterName}".`);
|
|
401
|
+
}
|
|
377
402
|
// Determine if the ambiguous parameter is a short name or a long name, since the process of finding
|
|
378
403
|
// the non-ambiguous name is different for each.
|
|
379
404
|
const duplicateShortNameParameters = this._parametersByShortName.get(parameterName);
|
|
@@ -402,10 +427,8 @@ class CommandLineParameterProvider {
|
|
|
402
427
|
}
|
|
403
428
|
// Throw an error including the non-ambiguous long names for the parameters that have the ambiguous
|
|
404
429
|
// short name, ex.
|
|
405
|
-
// Error:
|
|
406
|
-
|
|
407
|
-
throw new Error(`The short parameter name "${parameterName}" is ambiguous. It could refer to any of ` +
|
|
408
|
-
`the following parameters: "${nonAmbiguousLongNames.join('", "')}"`);
|
|
430
|
+
// Error: Ambiguous option "-p" could match "--param1", "--param2"
|
|
431
|
+
this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: "${parameterName}" could match ${nonAmbiguousLongNames.join(', ')}.`);
|
|
409
432
|
}
|
|
410
433
|
const duplicateLongNameParameters = this._parametersByLongName.get(parameterName);
|
|
411
434
|
if (duplicateLongNameParameters) {
|
|
@@ -419,13 +442,11 @@ class CommandLineParameterProvider {
|
|
|
419
442
|
});
|
|
420
443
|
// Throw an error including the non-ambiguous scoped long names for the parameters that have the
|
|
421
444
|
// ambiguous long name, ex.
|
|
422
|
-
// Error:
|
|
423
|
-
|
|
424
|
-
throw new Error(`The parameter name "${parameterName}" is ambiguous. It could refer to any of ` +
|
|
425
|
-
`the following parameters: "${nonAmbiguousLongNames.join('", "')}"`);
|
|
445
|
+
// Error: Ambiguous option: "--param" could match --scope1:param, --scope2:param
|
|
446
|
+
this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: "${parameterName}" could match ${nonAmbiguousLongNames.join(', ')}.`);
|
|
426
447
|
}
|
|
427
448
|
// This shouldn't happen, but we also shouldn't allow the user to use the ambiguous parameter
|
|
428
|
-
|
|
449
|
+
this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: "${parameterName}".`);
|
|
429
450
|
}
|
|
430
451
|
}
|
|
431
452
|
// Fill in the values for the parameters
|
|
@@ -436,11 +457,11 @@ class CommandLineParameterProvider {
|
|
|
436
457
|
if (this.remainder) {
|
|
437
458
|
this.remainder._setValue(data[argparse.Const.REMAINDER]);
|
|
438
459
|
}
|
|
439
|
-
this.
|
|
460
|
+
this._parametersHaveBeenProcessed = true;
|
|
440
461
|
}
|
|
441
462
|
/** @internal */
|
|
442
463
|
_defineParameter(parameter) {
|
|
443
|
-
if (this.
|
|
464
|
+
if (this._parametersHaveBeenRegistered) {
|
|
444
465
|
throw new Error('Parameters have already been registered for this provider');
|
|
445
466
|
}
|
|
446
467
|
// Generate and set the parser key at definition time
|
|
@@ -464,10 +485,25 @@ class CommandLineParameterProvider {
|
|
|
464
485
|
}
|
|
465
486
|
}
|
|
466
487
|
/** @internal */
|
|
467
|
-
|
|
488
|
+
_defineAmbiguousParameter(name) {
|
|
489
|
+
if (this._parametersHaveBeenRegistered) {
|
|
490
|
+
throw new Error('Parameters have already been registered for this provider');
|
|
491
|
+
}
|
|
492
|
+
// Only generate a new parser key if the ambiguous parameter hasn't been defined yet,
|
|
493
|
+
// either as an existing parameter or as another ambiguous parameter
|
|
494
|
+
let existingParserKey = this._registeredParameterParserKeysByName.get(name) ||
|
|
495
|
+
this._ambiguousParameterParserKeysByName.get(name);
|
|
496
|
+
if (!existingParserKey) {
|
|
497
|
+
existingParserKey = this._generateKey();
|
|
498
|
+
}
|
|
499
|
+
this._ambiguousParameterParserKeysByName.set(name, existingParserKey);
|
|
500
|
+
return existingParserKey;
|
|
501
|
+
}
|
|
502
|
+
/** @internal */
|
|
503
|
+
_registerParameter(parameter, useScopedLongName, ignoreShortName) {
|
|
468
504
|
var _a;
|
|
469
505
|
const names = [];
|
|
470
|
-
if (parameter.shortName) {
|
|
506
|
+
if (parameter.shortName && !ignoreShortName) {
|
|
471
507
|
names.push(parameter.shortName);
|
|
472
508
|
}
|
|
473
509
|
// Use the original long name unless otherwise requested
|
|
@@ -552,10 +588,12 @@ class CommandLineParameterProvider {
|
|
|
552
588
|
if ((_a = parameter.undocumentedSynonyms) === null || _a === void 0 ? void 0 : _a.length) {
|
|
553
589
|
argumentGroup.addArgument(parameter.undocumentedSynonyms, Object.assign(Object.assign({}, argparseOptions), { help: argparse.Const.SUPPRESS }));
|
|
554
590
|
}
|
|
591
|
+
// Register the parameter names so that we can detect ambiguous parameters
|
|
592
|
+
for (const name of [...names, ...(parameter.undocumentedSynonyms || [])]) {
|
|
593
|
+
this._registeredParameterParserKeysByName.set(name, parameter._parserKey);
|
|
594
|
+
}
|
|
555
595
|
}
|
|
556
|
-
_registerAmbiguousParameter(name) {
|
|
557
|
-
const parserKey = this._generateKey();
|
|
558
|
-
this._ambiguousParameterNamesByParserKey.set(parserKey, name);
|
|
596
|
+
_registerAmbiguousParameter(name, parserKey) {
|
|
559
597
|
this._getArgumentParser().addArgument(name, {
|
|
560
598
|
dest: parserKey,
|
|
561
599
|
// We don't know if this argument takes parameters or not, so we need to accept any number of args
|
|
@@ -593,6 +631,16 @@ class CommandLineParameterProvider {
|
|
|
593
631
|
}
|
|
594
632
|
return parameter;
|
|
595
633
|
}
|
|
634
|
+
_throwParserExitError(parserOptions, data, errorCode, message) {
|
|
635
|
+
// Write out the usage text to make it easier for the user to find the correct parameter name
|
|
636
|
+
const targetActionName = data.aliasAction || data.action || '';
|
|
637
|
+
const errorPrefix = `Error: ${parserOptions.toolFilename}` +
|
|
638
|
+
// Handle aliases, actions, and actionless parameter providers
|
|
639
|
+
`${targetActionName ? ' ' : ''}${targetActionName}: error: `;
|
|
640
|
+
// eslint-disable-next-line no-console
|
|
641
|
+
console.log(this.renderUsageText());
|
|
642
|
+
throw new CommandLineParserExitError_1.CommandLineParserExitError(errorCode, `${errorPrefix}${message.trimStart().trimEnd()}\n`);
|
|
643
|
+
}
|
|
596
644
|
}
|
|
597
645
|
CommandLineParameterProvider._keyCounter = 0;
|
|
598
646
|
exports.CommandLineParameterProvider = CommandLineParameterProvider;
|