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2B;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;AAnJD,wDAmJC","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, IRegisterDefinedParametersState } 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;\n\n private _parameterKeyMap: Map = new Map();\n\n public constructor(options: IAliasCommandLineActionOptions) {\n const toolFilename: string = options.toolFilename;\n const targetActionName: string = options.targetAction.actionName;\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\n defaultParametersString ? ` ${defaultParametersString}` : ''\n }\".`;\n\n super({\n actionName: options.aliasName,\n summary,\n documentation:\n `${summary} For more information on the aliased command, use ` +\n `\"${toolFilename} ${targetActionName} --help\".`\n });\n\n this.targetAction = options.targetAction;\n this.defaultParameters = options.defaultParameters || [];\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n /* override */\n // All parameters are going to be defined by the target action. Re-use the target action parameters\n // for this action.\n for (const parameter of this.targetAction.parameters) {\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\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\n // and all parameters that we have access to have already been defined.\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\n }\n\n // We also need to register the remainder parameter if the target action has one. The parser\n // key for this parameter is constant.\n if (this.targetAction.remainder) {\n this.defineCommandLineRemainder(this.targetAction.remainder);\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\n }\n\n // Finally, register the parameters with the parser. We need to make sure that the target action\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\n // during registration. This will no-op if the target action is already registered.\n this.targetAction._registerDefinedParameters(state);\n super._registerDefinedParameters(state);\n\n // We need to re-map the ambiguous parameters after they are defined by calling\n // super._registerDefinedParameters()\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n const targetParserKey: string | undefined =\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\n\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n if (targetParserKey) {\n this._parameterKeyMap.set(parserKey, targetParserKey);\n }\n }\n }\n\n /**\n * 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 {\n await this.targetAction._execute();\n }\n}\n"]}