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BAAgB;IAChB,YAAmB,UAAkD;QACnE,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,UAAU,CAAC,YAAY,KAAK,EAAE,EAAE;YAClC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;SACH;QACD,IAAI,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,YAAY,EAAE;YACrE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,CAAC,YAAY,8CAA8C,CACxF,CAAC;SACH;QACD,MAAM,KAAK,GAA4B,UAAU,CAAC,YAAY,CAAC,KAAK,CAClE,gCAAgC,CAAC,0BAA0B,CAC5D,CAAC;QACF,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,CAAC,YAAY,oCAAoC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC3F,iEAAiE,CACpE,CAAC;SACH;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;;AAlCD,oGAAoG;AACrF,2DAA0B,GAAW,YAAY,CAAC;AAF7C,4EAAgC","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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport type {\n IBaseCommandLineDefinition,\n IBaseCommandLineDefinitionWithArgument\n} from './CommandLineDefinition';\n\n/**\n * Identifies the kind of a CommandLineParameter.\n * @public\n */\nexport enum CommandLineParameterKind {\n /** Indicates a CommandLineChoiceParameter */\n Choice,\n /** Indicates a CommandLineFlagParameter */\n Flag,\n /** Indicates a CommandLineIntegerParameter */\n Integer,\n /** Indicates a CommandLineStringParameter */\n String,\n /** Indicates a CommandLineStringListParameter */\n StringList,\n /** Indicates a CommandLineChoiceListParameter */\n ChoiceList,\n /** Indicates a CommandLineIntegerListParameter */\n IntegerList\n}\n\n/**\n * Matches kebab-case formatted strings prefixed with double dashes.\n * Example: \"--do-something\"\n */\nconst LONG_NAME_REGEXP: RegExp = /^-(-[a-z0-9]+)+$/;\n\n/**\n * Matches a single upper-case or lower-case letter prefixed with a dash.\n * Example: \"-d\"\n */\nconst SHORT_NAME_REGEXP: RegExp = /^-[a-zA-Z]$/;\n\n/**\n * Matches kebab-case formatted strings\n * Example: \"my-scope\"\n */\nconst SCOPE_REGEXP: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/;\n\n/**\n * \"Environment variable names used by the utilities in the Shell and Utilities volume of\n * IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore)\n * from the characters defined in Portable Character Set and do not begin with a digit.\"\n * Example: \"THE_SETTING\"\n */\nconst ENVIRONMENT_VARIABLE_NAME_REGEXP: RegExp = /^[A-Z_][A-Z0-9_]*$/;\n\n/**\n * The base class for the various command-line parameter types.\n * @public\n */\nexport abstract class CommandLineParameter {\n private _shortNameValue: string | undefined;\n\n /**\n * A unique internal key used to retrieve the value from the parser's dictionary.\n * @internal\n */\n public _parserKey: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterLongName} */\n public readonly longName: string;\n\n /**\n * If a parameterScope is provided, returns the scope-prefixed long name of the flag,\n * including double dashes, eg. \"--scope:do-something\". Otherwise undefined.\n */\n public readonly scopedLongName: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterGroup} */\n public readonly parameterGroup: string | typeof SCOPING_PARAMETER_GROUP | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterScope} */\n public readonly parameterScope: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** {@inheritDoc IBaseCommandLineDefinition.required} */\n public readonly required: boolean;\n\n /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */\n public readonly environmentVariable: string | undefined;\n\n /** {@inheritDoc IBaseCommandLineDefinition.undocumentedSynonyms } */\n public readonly undocumentedSynonyms: string[] | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinition) {\n this.longName = definition.parameterLongName;\n this._shortNameValue = definition.parameterShortName;\n this.parameterGroup = definition.parameterGroup;\n this.parameterScope = definition.parameterScope;\n this.description = definition.description;\n this.required = !!definition.required;\n this.environmentVariable = definition.environmentVariable;\n this.undocumentedSynonyms = definition.undocumentedSynonyms;\n\n if (!LONG_NAME_REGEXP.test(this.longName)) {\n throw new Error(\n `Invalid name: \"${this.longName}\". The parameter long name must be` +\n ` lower-case and use dash delimiters (e.g. \"--do-a-thing\")`\n );\n }\n\n if (this.shortName) {\n if (!SHORT_NAME_REGEXP.test(this.shortName)) {\n throw new Error(\n `Invalid name: \"${this.shortName}\". The parameter short name must be` +\n ` a dash followed by a single upper-case or lower-case letter (e.g. \"-a\")`\n );\n }\n }\n\n if (this.parameterScope) {\n if (!SCOPE_REGEXP.test(this.parameterScope)) {\n throw new Error(\n `Invalid scope: \"${this.parameterScope}\". The parameter scope name must be` +\n ` lower-case and use dash delimiters (e.g. \"my-scope\")`\n );\n }\n // Parameter long name is guaranteed to start with '--' since this is validated above\n const unprefixedLongName: string = this.longName.slice(2);\n this.scopedLongName = `--${this.parameterScope}:${unprefixedLongName}`;\n }\n\n if (this.environmentVariable) {\n if (this.required) {\n // TODO: This constraint is imposed only because argparse enforces \"required\" parameters, but\n // it does not know about ts-command-line environment variable mappings. We should fix this.\n throw new Error(\n `An \"environmentVariable\" cannot be specified for \"${this.longName}\"` +\n ` because it is a required parameter`\n );\n }\n\n if (!ENVIRONMENT_VARIABLE_NAME_REGEXP.test(this.environmentVariable)) {\n throw new Error(\n `Invalid environment variable name: \"${this.environmentVariable}\". The name must` +\n ` consist only of upper-case letters, numbers, and underscores. It may not start with a number.`\n );\n }\n }\n\n if (this.undocumentedSynonyms && this.undocumentedSynonyms.length > 0) {\n for (const undocumentedSynonym of this.undocumentedSynonyms) {\n if (this.longName === undocumentedSynonym) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". Undocumented synonyms must not be the same` +\n ` as the the long name.`\n );\n } else if (!LONG_NAME_REGEXP.test(undocumentedSynonym)) {\n throw new Error(\n `Invalid name: \"${undocumentedSynonym}\". All undocumented synonyms name must be lower-case and ` +\n 'use dash delimiters (e.g. \"--do-a-thing\")'\n );\n }\n }\n }\n }\n\n /** {@inheritDoc IBaseCommandLineDefinition.parameterShortName} */\n public get shortName(): string | undefined {\n return this._shortNameValue;\n }\n\n /**\n * Called internally by CommandLineParameterProvider._processParsedData()\n * @internal\n */\n public abstract _setValue(data: any): void; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Returns additional text used by the help formatter.\n * @internal\n */\n public _getSupplementaryNotes(supplementaryNotes: string[]): void {\n // virtual\n if (this.environmentVariable !== undefined) {\n supplementaryNotes.push(\n 'This parameter may alternatively be specified via the ' +\n this.environmentVariable +\n ' environment variable.'\n );\n }\n }\n\n /**\n * Indicates the type of parameter.\n */\n public abstract get kind(): CommandLineParameterKind;\n\n /**\n * Append the parsed values to the provided string array.\n * @remarks\n * Sometimes a command line parameter is not used directly, but instead gets passed through to another\n * tool that will use it. For example if our parameter comes in as \"--max-count 3\", then we might want to\n * call `child_process.spawn()` and append [\"--max-count\", \"3\"] to the args array for that tool.\n * appendToArgList() appends zero or more strings to the provided array, based on the input command-line\n * that we parsed.\n *\n * If the parameter was omitted from our command-line and has no default value, then\n * nothing will be appended. If the short name was used, the long name will be appended instead.\n * @param argList - the parsed strings will be appended to this string array\n */\n public abstract appendToArgList(argList: string[]): void;\n\n /**\n * Internal usage only. Used to report unexpected output from the argparse library.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected reportInvalidData(data: any): never {\n throw new Error(`Unexpected data object for parameter \"${this.longName}\": ` + JSON.stringify(data));\n }\n\n protected validateDefaultValue(hasDefaultValue: boolean): void {\n if (this.required && hasDefaultValue) {\n // If a parameter is \"required\", then the user understands that they always need to\n // specify a value for this parameter (either via the command line or via an environment variable).\n // It would be confusing to allow a default value that sometimes allows the \"required\" parameter\n // to be omitted. If you sometimes don't have a suitable default value, then the better approach\n // is to throw a custom error explaining why the parameter is required in that case.\n throw new Error(\n `A default value cannot be specified for \"${this.longName}\" because it is a \"required\" parameter`\n );\n }\n }\n}\n\n/**\n * The common base class for parameters types that receive an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport abstract class CommandLineParameterWithArgument extends CommandLineParameter {\n // Matches the first character that *isn't* part of a valid upper-case argument name such as \"URL_2\"\n private static _invalidArgumentNameRegExp: RegExp = /[^A-Z_0-9]/;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */\n public readonly argumentName: string;\n\n /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: IBaseCommandLineDefinitionWithArgument) {\n super(definition);\n\n if (definition.argumentName === '') {\n throw new Error(\n 'The argument name cannot be an empty string. (For the default name, specify undefined.)'\n );\n }\n if (definition.argumentName.toUpperCase() !== definition.argumentName) {\n throw new Error(\n `Invalid name: \"${definition.argumentName}\". The argument name must be all upper case.`\n );\n }\n const match: RegExpMatchArray | null = definition.argumentName.match(\n CommandLineParameterWithArgument._invalidArgumentNameRegExp\n );\n if (match) {\n throw new Error(\n `The argument name \"${definition.argumentName}\" contains an invalid character \"${match[0]}\".` +\n ` Only upper-case letters, numbers, and underscores are allowed.`\n );\n }\n this.argumentName = definition.argumentName;\n this.completions = definition.completions;\n }\n}\n"]} |