@rushstack/ts-command-line 4.16.1 → 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.
Files changed (47) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +251 -251
  3. package/dist/ts-command-line.d.ts +11 -5
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/CommandLineHelper.js.map +1 -1
  6. package/lib/Constants.js.map +1 -1
  7. package/lib/index.d.ts +5 -5
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.js.map +1 -1
  10. package/lib/parameters/BaseClasses.d.ts +0 -5
  11. package/lib/parameters/BaseClasses.d.ts.map +1 -1
  12. package/lib/parameters/BaseClasses.js +0 -7
  13. package/lib/parameters/BaseClasses.js.map +1 -1
  14. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -1
  15. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -1
  16. package/lib/parameters/CommandLineDefinition.js.map +1 -1
  17. package/lib/parameters/CommandLineFlagParameter.js.map +1 -1
  18. package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -1
  19. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -1
  20. package/lib/parameters/CommandLineRemainder.js.map +1 -1
  21. package/lib/parameters/CommandLineStringListParameter.js.map +1 -1
  22. package/lib/parameters/CommandLineStringParameter.js.map +1 -1
  23. package/lib/parameters/EnvironmentVariableParser.js.map +1 -1
  24. package/lib/providers/AliasCommandLineAction.d.ts +2 -2
  25. package/lib/providers/AliasCommandLineAction.d.ts.map +1 -1
  26. package/lib/providers/AliasCommandLineAction.js +15 -3
  27. package/lib/providers/AliasCommandLineAction.js.map +1 -1
  28. package/lib/providers/CommandLineAction.d.ts.map +1 -1
  29. package/lib/providers/CommandLineAction.js +13 -0
  30. package/lib/providers/CommandLineAction.js.map +1 -1
  31. package/lib/providers/CommandLineParameterProvider.d.ts +24 -6
  32. package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -1
  33. package/lib/providers/CommandLineParameterProvider.js +85 -37
  34. package/lib/providers/CommandLineParameterProvider.js.map +1 -1
  35. package/lib/providers/CommandLineParser.d.ts +2 -2
  36. package/lib/providers/CommandLineParser.d.ts.map +1 -1
  37. package/lib/providers/CommandLineParser.js +14 -5
  38. package/lib/providers/CommandLineParser.js.map +1 -1
  39. package/lib/providers/CommandLineParserExitError.js.map +1 -1
  40. package/lib/providers/DynamicCommandLineAction.js.map +1 -1
  41. package/lib/providers/DynamicCommandLineParser.js.map +1 -1
  42. package/lib/providers/ScopedCommandLineAction.d.ts +4 -1
  43. package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -1
  44. package/lib/providers/ScopedCommandLineAction.js +23 -6
  45. package/lib/providers/ScopedCommandLineAction.js.map +1 -1
  46. package/lib/providers/TabCompletionAction.js.map +1 -1
  47. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAAgG;AAqChG;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC,CAAC,EAC5D,IAAI,CAAC;QAEL,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7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CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAwC,EAAE,IAA4B;QAC9F,oGAAoG;QACpG,MAAM,UAAU,GAA2B;YACzC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;YACpC,WAAW,EAAE,IAAI,CAAC,MAAM;YACxB,kBAAkB,EAAE,IAAI,CAAC,aAAa;SACvC,CAAC;QACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;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;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":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAAgG;AAqChG;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC,C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,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 +1 @@
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;AAErE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;O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AyD;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,iFAA2G;AA2B3G;;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,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;AA5ED,8CA4EC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as argparse from 'argparse';\n\nimport { CommandLineParameterProvider, type 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 * Example: \"do-something\"\n */\nconst ACTION_NAME_REGEXP: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\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 /** {@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 (!ACTION_NAME_REGEXP.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 * Your subclass should implement this hook to perform the operation.\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
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,UA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AAQ;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"]}
@@ -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 readonly _ambiguousParameterNamesByParserKey;
53
- private _parametersRegistered;
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 _registerParameter(parameter: CommandLineParameter, useScopedLongName: boolean): void;
241
- private _registerAmbiguousParameter;
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,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,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,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;IAW9E,gBAAgB;IACT,0BAA0B,IAAI,IAAI;IA2DzC;;;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;IAkG1G,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAiCjE,gBAAgB;IAChB,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,OAAO,GAAG,IAAI;IAmG/F,OAAO,CAAC,2BAA2B;IAcnC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;CAuCtB"}
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,CA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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._ambiguousParameterNamesByParserKey = new Map();
58
- this._parametersRegistered = false;
59
- this._parametersProcessed = false;
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._parametersProcessed;
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
- this._registerDefinedParameters();
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
- this._registerDefinedParameters();
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._parametersRegistered) {
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
- ambiguousParameterNames.add(shortName);
331
- parameter._disableShortName();
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
- ambiguousParameterNames.add(parameter.longName);
353
+ this._defineAmbiguousParameter(parameter.longName);
347
354
  }
348
- this._registerParameter(parameter, useScopedLongName);
355
+ const ignoreShortName = parametersWithDuplicateShortNames.has(parameter);
356
+ this._registerParameter(parameter, useScopedLongName, ignoreShortName);
349
357
  }
350
358
  }
351
- // Register silent parameters for the ambiguous short names and long names to ensure that users are made
352
- // aware that the provided argument is ambiguous.
353
- for (const ambiguousParameterName of ambiguousParameterNames) {
354
- this._registerAmbiguousParameter(ambiguousParameterName);
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._parametersRegistered) {
388
+ if (!this._parametersHaveBeenRegistered) {
369
389
  throw new Error('Parameters have not been registered');
370
390
  }
371
- if (this._parametersProcessed) {
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 [parserKey, parameterName] of this._ambiguousParameterNamesByParserKey) {
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: The short parameter name "-p" is ambiguous. It could refer to any of the following
406
- // parameters: "--param1", "--param2"
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: The parameter name "--param" is ambiguous. It could refer to any of the following
423
- // parameters: "--scope1:param", "--scope2:param"
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
- throw new Error(`The parameter name "${parameterName}" is ambiguous.`);
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._parametersProcessed = true;
460
+ this._parametersHaveBeenProcessed = true;
440
461
  }
441
462
  /** @internal */
442
463
  _defineParameter(parameter) {
443
- if (this._parametersRegistered) {
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
- _registerParameter(parameter, useScopedLongName) {
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;