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AE;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AA5GD,gEA4GC","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 { ICommandLineChoiceDefinition } from './CommandLineDefinition';\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.\n * @public\n */\nexport class CommandLineChoiceParameter extends CommandLineParameter {\n /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */\n public readonly alternatives: ReadonlyArray;\n\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: string | undefined;\n\n private _value: string | undefined = undefined;\n\n /** {@inheritDoc ICommandLineChoiceDefinition.completions} */\n public readonly completions: (() => Promise) | undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceDefinition) {\n super(definition);\n\n if (definition.alternatives.length < 1) {\n throw new Error(\n `When defining a choice parameter, the alternatives list must contain at least one value.`\n );\n }\n if (definition.defaultValue && definition.alternatives.indexOf(definition.defaultValue) === -1) {\n throw new Error(\n `The specified default value \"${definition.defaultValue}\"` +\n ` is not one of the available options: ${definition.alternatives.toString()}`\n );\n }\n\n this.alternatives = definition.alternatives;\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n this.completions = definition.completions;\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.Choice;\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 && environmentValue !== '') {\n if (this.alternatives.indexOf(environmentValue) < 0) {\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\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 supplementaryNotes.push(`The default value is \"${this.defaultValue}\".`);\n }\n }\n\n /**\n * Returns the argument value for a choice 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"]}