@rushstack/ts-command-line 4.10.6 → 4.10.9

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 (29) hide show
  1. package/README.md +251 -251
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/lib/CommandLineHelper.js.map +1 -1
  4. package/lib/Constants.js.map +1 -1
  5. package/lib/index.js.map +1 -1
  6. package/lib/parameters/BaseClasses.js.map +1 -1
  7. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -1
  8. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -1
  9. package/lib/parameters/CommandLineDefinition.js.map +1 -1
  10. package/lib/parameters/CommandLineFlagParameter.js.map +1 -1
  11. package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -1
  12. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -1
  13. package/lib/parameters/CommandLineRemainder.js.map +1 -1
  14. package/lib/parameters/CommandLineStringListParameter.js.map +1 -1
  15. package/lib/parameters/CommandLineStringParameter.js.map +1 -1
  16. package/lib/parameters/EnvironmentVariableParser.js.map +1 -1
  17. package/lib/providers/CommandLineAction.js.map +1 -1
  18. package/lib/providers/CommandLineParameterProvider.js.map +1 -1
  19. package/lib/providers/CommandLineParser.js.map +1 -1
  20. package/lib/providers/CommandLineParserExitError.js +1 -1
  21. package/lib/providers/CommandLineParserExitError.js.map +1 -1
  22. package/lib/providers/DynamicCommandLineAction.js.map +1 -1
  23. package/lib/providers/DynamicCommandLineParser.js.map +1 -1
  24. package/lib/providers/TabCompletionAction.d.ts.map +1 -1
  25. package/lib/providers/TabCompletionAction.js +2 -2
  26. package/lib/providers/TabCompletionAction.js.map +1 -1
  27. package/package.json +31 -28
  28. package/CHANGELOG.json +0 -1418
  29. package/CHANGELOG.md +0 -743
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineChoiceListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":";AAAA,4F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,KAAK,CAAC,GAAG,CAAC,EAAE;wBACxC,MAAM,OAAO,GAAW,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;wBACnE,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,gCAAgC;4BACrD,IAAI,IAAI,CAAC,mBAAmB,yBAAyB,OAAO,EAAE,CACjE,CAAC;qBACH;iBACF;gBACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;gBACtB,OAAO;aACR;SACF;QAED,sCAAsC;QAEtC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AA1FD,wEA0FC","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 { ICommandLineChoiceListDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\r\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.\r\n * @public\r\n */\r\nexport class CommandLineChoiceListParameter extends CommandLineParameter {\r\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\r\n public readonly alternatives: ReadonlyArray<string>;\r\n\r\n private _values: string[] = [];\r\n\r\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\r\n public readonly completions: (() => Promise<string[]>) | undefined;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineChoiceListDefinition) {\r\n super(definition);\r\n\r\n if (definition.alternatives.length < 1) {\r\n throw new Error(\r\n `When defining a choice list parameter, the alternatives list must contain at least one value.`\r\n );\r\n }\r\n\r\n this.alternatives = definition.alternatives;\r\n this.completions = definition.completions;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.ChoiceList;\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 // If argparse passed us a value, confirm it is valid\r\n if (data !== null && data !== undefined) {\r\n if (!Array.isArray(data)) {\r\n this.reportInvalidData(data);\r\n }\r\n for (const arrayItem of data) {\r\n if (typeof arrayItem !== 'string') {\r\n this.reportInvalidData(data);\r\n }\r\n }\r\n this._values = data;\r\n return;\r\n }\r\n\r\n if (this.environmentVariable !== undefined) {\r\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\r\n if (values) {\r\n for (const value of values) {\r\n if (this.alternatives.indexOf(value) < 0) {\r\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\r\n throw new Error(\r\n `Invalid value \"${value}\" for the environment variable` +\r\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\r\n );\r\n }\r\n }\r\n this._values = values;\r\n return;\r\n }\r\n }\r\n\r\n // (No default value for choice lists)\r\n\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Returns the string arguments for a choice list parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The array will be empty 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 values(): ReadonlyArray<string> {\r\n return this._values;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.values.length > 0) {\r\n for (const value of this.values) {\r\n argList.push(this.longName);\r\n argList.push(value);\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineChoiceListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAC/E,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAA+B,SAAQ,kCAAoB;IAStE,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,YAAO,GAAa,EAAE,CAAC;QAS7B,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;SACH;QAED,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,UAAU,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;gBAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;iBAC9B;aACF;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;SACR;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,MAAM,MAAM,GAAyB,qDAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE;gBACV,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;oBAC1B,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;wBACxC,MAAM,OAAO,GAAW,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;wBACnE,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,gCAAgC;4BACrD,IAAI,IAAI,CAAC,mBAAmB,yBAAyB,OAAO,EAAE,CACjE,CAAC;qBACH;iBACF;gBACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;gBACtB,OAAO;aACR;SACF;QAED,sCAAsC;QAEtC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AA1FD,wEA0FC","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 { ICommandLineChoiceListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceListParameter}.\n * @public\n */\nexport class CommandLineChoiceListParameter extends CommandLineParameter {\n /** {@inheritDoc ICommandLineChoiceListDefinition.alternatives} */\n public readonly alternatives: ReadonlyArray<string>;\n\n private _values: string[] = [];\n\n /** {@inheritDoc ICommandLineChoiceListDefinition.completions} */\n public readonly completions: (() => Promise<string[]>) | undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineChoiceListDefinition) {\n super(definition);\n\n if (definition.alternatives.length < 1) {\n throw new Error(\n `When defining a choice list parameter, the alternatives list must contain at least one value.`\n );\n }\n\n this.alternatives = definition.alternatives;\n this.completions = definition.completions;\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.ChoiceList;\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 // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'string') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n for (const value of values) {\n if (this.alternatives.indexOf(value) < 0) {\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\n );\n }\n }\n this._values = values;\n return;\n }\n }\n\n // (No default value for choice lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a choice list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty 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 values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value);\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineChoiceParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineChoiceParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAE/E;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,kCAAoB;IAYlE,gBAAgB;IAChB,YAAmB,UAAwC;QACzD,KAAK,CAAC,UAAU,CAAC,CAAC;QAPZ,WAAM,GAAuB,SAAS,CAAC;QAS7C,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAC;SACH;QACD,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE;YAC9F,MAAM,IAAI,KAAK,CACb,gCAAgC,UAAU,CAAC,YAAY,GAAG;gBACxD,yCAAyC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAChF,CAAC;SACH;QAED,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,S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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;AA5GD,gEA4GC","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 { ICommandLineChoiceDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineChoiceParameter}.\r\n * @public\r\n */\r\nexport class CommandLineChoiceParameter extends CommandLineParameter {\r\n /** {@inheritDoc ICommandLineChoiceDefinition.alternatives} */\r\n public readonly alternatives: ReadonlyArray<string>;\r\n\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 /** {@inheritDoc ICommandLineChoiceDefinition.completions} */\r\n public readonly completions: (() => Promise<string[]>) | undefined;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineChoiceDefinition) {\r\n super(definition);\r\n\r\n if (definition.alternatives.length < 1) {\r\n throw new Error(\r\n `When defining a choice parameter, the alternatives list must contain at least one value.`\r\n );\r\n }\r\n if (definition.defaultValue && definition.alternatives.indexOf(definition.defaultValue) === -1) {\r\n throw new Error(\r\n `The specified default value \"${definition.defaultValue}\"` +\r\n ` is not one of the available options: ${definition.alternatives.toString()}`\r\n );\r\n }\r\n\r\n this.alternatives = definition.alternatives;\r\n this.defaultValue = definition.defaultValue;\r\n this.validateDefaultValue(!!this.defaultValue);\r\n this.completions = definition.completions;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.Choice;\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 && environmentValue !== '') {\r\n if (this.alternatives.indexOf(environmentValue) < 0) {\r\n const choices: string = '\"' + this.alternatives.join('\", \"') + '\"';\r\n throw new Error(\r\n `Invalid value \"${environmentValue}\" for the environment variable` +\r\n ` ${this.environmentVariable}. Valid choices are: ${choices}`\r\n );\r\n }\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 supplementaryNotes.push(`The default value is \"${this.defaultValue}\".`);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the argument value for a choice 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"]}
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S,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;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 { 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<string>;\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<string[]>) | 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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineDefinition.js","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 * For use with CommandLineParser, this interface represents a generic command-line parameter\r\n *\r\n * @public\r\n */\r\nexport interface IBaseCommandLineDefinition {\r\n /**\r\n * The long name of the flag including double dashes, e.g. \"--do-something\"\r\n */\r\n parameterLongName: string;\r\n\r\n /**\r\n * An optional short name for the flag including the dash, e.g. \"-d\"\r\n */\r\n parameterShortName?: string;\r\n\r\n /**\r\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\r\n */\r\n description: string;\r\n\r\n /**\r\n * If true, then an error occurs if the parameter was not included on the command-line.\r\n */\r\n required?: boolean;\r\n\r\n /**\r\n * The name of an environment variable that the parameter value will be read from,\r\n * if it was omitted from the command-line. An error will be reported if the\r\n * environment value cannot be parsed.\r\n *\r\n * @remarks\r\n * The environment variable name must consist only of upper-case letters, numbers,\r\n * and underscores. It may not start with a number.\r\n *\r\n * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,\r\n * because in that case the environmentVariable would never be used.\r\n *\r\n * Syntax notes for environment variable values:\r\n *\r\n * - Choice Parameter: The value must match one of the defined choices,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - Integer Parameter: The value must be an integer number,\r\n * otherwise a validation error is reported.\r\n * An empty string causes the environment variable to be ignored.\r\n *\r\n * - String Parameter: Any value is accepted, including an empty string.\r\n *\r\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\r\n * then it will be parsed as a JSON array, whose elements must be strings,\r\n * numbers, or boolean values.\r\n * If the string does not start with `[`, then it behaves like an\r\n * ordinary String Parameter: Any value is accepted, including an empty string.\r\n */\r\n environmentVariable?: string;\r\n\r\n /**\r\n * Specifies additional names for this parameter that are accepted but not displayed\r\n * in the command line help.\r\n *\r\n * @remarks\r\n * This option can be used in cases where a command-line parameter may have been renamed,\r\n * but the developer doesn't want to break backwards compatibility with systems that may\r\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\r\n */\r\n undocumentedSynonyms?: string[];\r\n}\r\n\r\n/**\r\n * The common base interface for parameter types that accept an argument.\r\n *\r\n * @remarks\r\n * An argument is an accompanying command-line token, such as \"123\" in the\r\n * example \"--max-count 123\".\r\n * @public\r\n */\r\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\r\n /**\r\n * The name of the argument, which will be shown in the command-line help.\r\n *\r\n * @remarks\r\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\r\n * then the command-line help would display \"--count NUMBER\". The argument name must\r\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\r\n */\r\n argumentName: string;\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineChoiceParameter},\r\n * this interface defines a command line parameter which is constrained to a list of possible\r\n * options.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {\r\n /**\r\n * A list of strings (which contain no spaces), of possible options which can be selected\r\n */\r\n alternatives: string[];\r\n\r\n /**\r\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\r\n */\r\n defaultValue?: string;\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\r\n * this interface defines a command line parameter which is constrained to a list of possible\r\n * options. The parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {\r\n /**\r\n * A list of strings (which contain no spaces), of possible options which can be selected\r\n */\r\n alternatives: string[];\r\n\r\n /**\r\n * An optional callback that provides a list of custom choices for tab completion.\r\n * @remarks\r\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\r\n * is enabled.\r\n */\r\n completions?: () => Promise<string[]>;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\r\n * this interface defines a command line parameter that is a boolean flag.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineIntegerParameter},\r\n * this interface defines a command line parameter whose argument is an integer value.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\r\n /**\r\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\r\n */\r\n defaultValue?: number;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\r\n * this interface defines a command line parameter whose argument is an integer value. The\r\n * parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineStringParameter},\r\n * this interface defines a command line parameter whose argument is a string value.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\r\n /**\r\n * The default value which will be used if the parameter is omitted from the command line.\r\n *\r\n * @remarks\r\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\r\n * must not be true. Instead, a custom error message should be used to report cases\r\n * where a default value was not available.\r\n */\r\n defaultValue?: string;\r\n}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\r\n * this interface defines a command line parameter whose argument is a single text string.\r\n * The parameter can be specified multiple times to build a list.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\r\n\r\n/**\r\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\r\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\r\n *\r\n * @public\r\n */\r\nexport interface ICommandLineRemainderDefinition {\r\n /**\r\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\r\n * the tool with \"--help\".\r\n */\r\n description: string;\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineDefinition.js","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 * For use with CommandLineParser, this interface represents a generic command-line parameter\n *\n * @public\n */\nexport interface IBaseCommandLineDefinition {\n /**\n * The long name of the flag including double dashes, e.g. \"--do-something\"\n */\n parameterLongName: string;\n\n /**\n * An optional short name for the flag including the dash, e.g. \"-d\"\n */\n parameterShortName?: string;\n\n /**\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\n */\n description: string;\n\n /**\n * If true, then an error occurs if the parameter was not included on the command-line.\n */\n required?: boolean;\n\n /**\n * The name of an environment variable that the parameter value will be read from,\n * if it was omitted from the command-line. An error will be reported if the\n * environment value cannot be parsed.\n *\n * @remarks\n * The environment variable name must consist only of upper-case letters, numbers,\n * and underscores. It may not start with a number.\n *\n * This feature cannot be used when {@link IBaseCommandLineDefinition.required} is true,\n * because in that case the environmentVariable would never be used.\n *\n * Syntax notes for environment variable values:\n *\n * - Choice Parameter: The value must match one of the defined choices,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Integer Parameter: The value must be an integer number,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - String Parameter: Any value is accepted, including an empty string.\n *\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\n * then it will be parsed as a JSON array, whose elements must be strings,\n * numbers, or boolean values.\n * If the string does not start with `[`, then it behaves like an\n * ordinary String Parameter: Any value is accepted, including an empty string.\n */\n environmentVariable?: string;\n\n /**\n * Specifies additional names for this parameter that are accepted but not displayed\n * in the command line help.\n *\n * @remarks\n * This option can be used in cases where a command-line parameter may have been renamed,\n * but the developer doesn't want to break backwards compatibility with systems that may\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\n */\n undocumentedSynonyms?: string[];\n}\n\n/**\n * The common base interface for parameter types that accept 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 interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\n /**\n * The name of the argument, which will be shown in the command-line help.\n *\n * @remarks\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\n * then the command-line help would display \"--count NUMBER\". The argument name must\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\n */\n argumentName: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options. The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineChoiceListDefinition extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: string[];\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\n * this interface defines a command line parameter that is a boolean flag.\n *\n * @public\n */\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerParameter},\n * this interface defines a command line parameter whose argument is an integer value.\n *\n * @public\n */\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: number;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\n * this interface defines a command line parameter whose argument is an integer value. The\n * parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringParameter},\n * this interface defines a command line parameter whose argument is a string value.\n *\n * @public\n */\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * The default value which will be used if the parameter is omitted from the command line.\n *\n * @remarks\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\n * must not be true. Instead, a custom error message should be used to report cases\n * where a default value was not available.\n */\n defaultValue?: string;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\n * this interface defines a command line parameter whose argument is a single text string.\n * The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @public\n */\nexport interface ICommandLineRemainderDefinition {\n /**\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\n * the tool with \"--help\".\n */\n description: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineFlagParameter.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ACtB,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,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;CACF;AArED,4DAqEC","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 { ICommandLineFlagDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.\r\n * @public\r\n */\r\nexport class CommandLineFlagParameter extends CommandLineParameter {\r\n private _value: boolean = false;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineFlagDefinition) {\r\n super(definition);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.Flag;\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 !== 'boolean') {\r\n this.reportInvalidData(data);\r\n }\r\n\r\n // If the flag is omitted, then argparse sets the data to \"false\" instead of \"undefined\".\r\n // This design prevents a syntax such as \"--flag=false\", probably because argparse prefers \"--no-flag\".\r\n // If we switch to a new CLI parser, we should try to add support for \"--flag=false\".\r\n if (data) {\r\n this._value = data;\r\n return;\r\n }\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 && environmentValue !== '') {\r\n if (environmentValue !== '0' && environmentValue !== '1') {\r\n throw new Error(\r\n `Invalid value \"${environmentValue}\" for the environment variable` +\r\n ` ${this.environmentVariable}. Valid choices are 0 or 1.`\r\n );\r\n }\r\n this._value = environmentValue === '1';\r\n return;\r\n }\r\n }\r\n\r\n this._value = false;\r\n }\r\n\r\n /**\r\n * Returns a boolean indicating whether the parameter was included in the command line.\r\n *\r\n * @remarks\r\n * The return value will be false if the command-line has not been parsed yet,\r\n * or if the flag was not used.\r\n */\r\n public get value(): boolean {\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) {\r\n argList.push(this.longName);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineFlagParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineFlagParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA+E;AAE/E;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,kCAAoB;IAGhE,gBAAgB;IAChB,YAAmB,UAAsC;QACvD,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAY,KAAK,CAAC;IAKhC,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,IAAI,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE;gBAC7B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YAED,yFAAyF;YACzF,uGAAuG;YACvG,qFAAqF;YACrF,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,OAAO;aACR;SACF;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACnF,IAAI,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,EAAE,EAAE;gBAC7D,IAAI,gBAAgB,KAAK,GAAG,IAAI,gBAAgB,KAAK,GAAG,EAAE;oBACxD,MAAM,IAAI,KAAK,CACb,kBAAkB,gBAAgB,gCAAgC;wBAChE,IAAI,IAAI,CAAC,mBAAmB,8BAA8B,CAC7D,CAAC;iBACH;gBACD,IAAI,CAAC,MAAM,GAAG,gBAAgB,KAAK,GAAG,CAAC;gBACvC,OAAO;aACR;SACF;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,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,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC7B;IACH,CAAC;CACF;AArED,4DAqEC","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 { ICommandLineFlagDefinition } from './CommandLineDefinition';\nimport { CommandLineParameter, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineFlagParameter}.\n * @public\n */\nexport class CommandLineFlagParameter extends CommandLineParameter {\n private _value: boolean = false;\n\n /** @internal */\n public constructor(definition: ICommandLineFlagDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.Flag;\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 !== 'boolean') {\n this.reportInvalidData(data);\n }\n\n // If the flag is omitted, then argparse sets the data to \"false\" instead of \"undefined\".\n // This design prevents a syntax such as \"--flag=false\", probably because argparse prefers \"--no-flag\".\n // If we switch to a new CLI parser, we should try to add support for \"--flag=false\".\n if (data) {\n this._value = data;\n return;\n }\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 (environmentValue !== '0' && environmentValue !== '1') {\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. Valid choices are 0 or 1.`\n );\n }\n this._value = environmentValue === '1';\n return;\n }\n }\n\n this._value = false;\n }\n\n /**\n * Returns a boolean indicating whether the parameter was included in the command line.\n *\n * @remarks\n * The return value will be false if the command-line has not been parsed yet,\n * or if the flag was not used.\n */\n public get value(): boolean {\n return this._value;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.value) {\n argList.push(this.longName);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineIntegerListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,8CAAgC;IAGnF,gBAAgB;IAChB,YAAmB,UAA6C;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,WAAW,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAA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CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7B;SACF;IACH,CAAC;CACF;AA9ED,0EA8EC","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 { ICommandLineIntegerListDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\r\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.\r\n * @public\r\n */\r\nexport class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {\r\n private _values: number[] = [];\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineIntegerListDefinition) {\r\n super(definition);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.IntegerList;\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 // If argparse passed us a value, confirm it is valid\r\n if (data !== null && data !== undefined) {\r\n if (!Array.isArray(data)) {\r\n this.reportInvalidData(data);\r\n }\r\n for (const arrayItem of data) {\r\n if (typeof arrayItem !== 'number') {\r\n this.reportInvalidData(data);\r\n }\r\n }\r\n this._values = data;\r\n return;\r\n }\r\n\r\n // If an environment variable exists, attempt to parse it as a list\r\n if (this.environmentVariable !== undefined) {\r\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\r\n if (values) {\r\n const parsedValues: number[] = [];\r\n for (const value of values) {\r\n const parsed: number = parseInt(value, 10);\r\n if (isNaN(parsed) || value.indexOf('.') >= 0) {\r\n throw new Error(\r\n `Invalid value \"${value}\" for the environment variable` +\r\n ` ${this.environmentVariable}. It must be an integer value.`\r\n );\r\n }\r\n parsedValues.push(parsed);\r\n }\r\n this._values = parsedValues;\r\n return;\r\n }\r\n }\r\n\r\n // (No default value for integer lists)\r\n\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Returns the integer arguments for an integer list parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The array will be empty 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 values(): ReadonlyArray<number> {\r\n return this._values;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.values.length > 0) {\r\n for (const value of this.values) {\r\n argList.push(this.longName);\r\n argList.push(String(value));\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineIntegerListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,8CAAgC;IAGnF,gBAAgB;IAChB,YAAmB,UAA6C;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,WAAW,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,i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AAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7B;SACF;IACH,CAAC;CACF;AA9ED,0EA8EC","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 { ICommandLineIntegerListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerListParameter}.\n * @public\n */\nexport class CommandLineIntegerListParameter extends CommandLineParameterWithArgument {\n private _values: number[] = [];\n\n /** @internal */\n public constructor(definition: ICommandLineIntegerListDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.IntegerList;\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 // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'number') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n const parsedValues: number[] = [];\n for (const value of values) {\n const parsed: number = parseInt(value, 10);\n if (isNaN(parsed) || value.indexOf('.') >= 0) {\n throw new Error(\n `Invalid value \"${value}\" for the environment variable` +\n ` ${this.environmentVariable}. It must be an integer value.`\n );\n }\n parsedValues.push(parsed);\n }\n this._values = parsedValues;\n return;\n }\n }\n\n // (No default value for integer lists)\n\n this._values = [];\n }\n\n /**\n * Returns the integer arguments for an integer list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty 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 values(): ReadonlyArray<number> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(String(value));\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineIntegerParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAE3F;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,8CAAgC;IAM/E,gBAAgB;IAChB,YAAmB,UAAyC;QAC1D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAuB,SAAS,CAAC;QAK7C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,OAAO,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,OAAO;SACR;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,uCAAuC;YACvC,MAAM,gBAAgB,GAAuB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mB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ation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { ICommandLineIntegerDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.\r\n * @public\r\n */\r\nexport class CommandLineIntegerParameter extends CommandLineParameterWithArgument {\r\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\r\n public readonly defaultValue: number | undefined;\r\n\r\n private _value: number | undefined = undefined;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineIntegerDefinition) {\r\n super(definition);\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.Integer;\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 !== 'number') {\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 && environmentValue !== '') {\r\n const parsed: number = parseInt(environmentValue, 10);\r\n if (isNaN(parsed) || environmentValue.indexOf('.') >= 0) {\r\n throw new Error(\r\n `Invalid value \"${environmentValue}\" for the environment variable` +\r\n ` ${this.environmentVariable}. It must be an integer value.`\r\n );\r\n }\r\n this._value = parsed;\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 supplementaryNotes.push(`The default value is ${this.defaultValue}.`);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the argument value for an integer 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(): number | 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.toString());\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineIntegerParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineIntegerParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAE3F;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,8CAAgC;IAM/E,gBAAgB;IAChB,YAAmB,UAAyC;QAC1D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,WAAM,GAAuB,SAAS,CAAC;QAK7C,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,OAAO,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;gBAC5B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC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C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;SACrC;IACH,CAAC;CACF;AAvFD,kEAuFC","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 { ICommandLineIntegerDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineIntegerParameter}.\n * @public\n */\nexport class CommandLineIntegerParameter extends CommandLineParameterWithArgument {\n /** {@inheritDoc ICommandLineStringDefinition.defaultValue} */\n public readonly defaultValue: number | undefined;\n\n private _value: number | undefined = undefined;\n\n /** @internal */\n public constructor(definition: ICommandLineIntegerDefinition) {\n super(definition);\n this.defaultValue = definition.defaultValue;\n this.validateDefaultValue(!!this.defaultValue);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.Integer;\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 !== 'number') {\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 const parsed: number = parseInt(environmentValue, 10);\n if (isNaN(parsed) || environmentValue.indexOf('.') >= 0) {\n throw new Error(\n `Invalid value \"${environmentValue}\" for the environment variable` +\n ` ${this.environmentVariable}. It must be an integer value.`\n );\n }\n this._value = parsed;\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 an integer 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(): number | 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.toString());\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineRemainder.js","sourceRoot":"","sources":["../../src/parameters/CommandLineRemainder.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D;;;GAGG;AACH,MAAa,oBAAoB;IAM/B,gBAAgB;IAChB,YAAmB,UAA2C;QANtD,YAAO,GAAa,EAAE,CAAC;QAO7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;SAClF;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AA5CD,oDA4CC","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 { ICommandLineRemainderDefinition } from './CommandLineDefinition';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.\r\n * @public\r\n */\r\nexport class CommandLineRemainder {\r\n private _values: string[] = [];\r\n\r\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\r\n public readonly description: string;\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineRemainderDefinition) {\r\n this.description = definition.description;\r\n }\r\n\r\n /**\r\n * Returns any remaining command line arguments after the recognized portion\r\n * that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The array will be empty if the command-line has not been parsed yet.\r\n */\r\n public get values(): ReadonlyArray<string> {\r\n return this._values;\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 (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {\r\n throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));\r\n }\r\n\r\n this._values.push(...data);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.values.length > 0) {\r\n for (const value of this.values) {\r\n argList.push(value);\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineRemainder.js","sourceRoot":"","sources":["../../src/parameters/CommandLineRemainder.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D;;;GAGG;AACH,MAAa,oBAAoB;IAM/B,gBAAgB;IAChB,YAAmB,UAA2C;QANtD,YAAO,GAAa,EAAE,CAAC;QAO7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,WAAW;QACX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;SAClF;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AA5CD,oDA4CC","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 { ICommandLineRemainderDefinition } from './CommandLineDefinition';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineCommandLineRemainder}.\n * @public\n */\nexport class CommandLineRemainder {\n private _values: string[] = [];\n\n /** {@inheritDoc IBaseCommandLineDefinition.description} */\n public readonly description: string;\n\n /** @internal */\n public constructor(definition: ICommandLineRemainderDefinition) {\n this.description = definition.description;\n }\n\n /**\n * Returns any remaining command line arguments after the recognized portion\n * that was parsed from the command line.\n *\n * @remarks\n * The array will be empty if the command-line has not been parsed yet.\n */\n public get values(): ReadonlyArray<string> {\n return this._values;\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 (!Array.isArray(data) || !data.every((x) => typeof x === 'string')) {\n throw new Error(`Unexpected data object for remainder: ` + JSON.stringify(data));\n }\n\n this._values.push(...data);\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(value);\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineStringListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAA+B,SAAQ,8CAAgC;IAGlF,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,CAAC;IAK/B,CAAC;IAED,8CAA8C;IAC9C,IAAW,IAAI;QACb,OAAO,sCAAwB,CAAC,UAAU,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,8DAA8D;IACvD,SAAS,CAAC,IAAS;QACxB,qDAAqD;QACrD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YACvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAC9B;YACD,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;gBAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;iBAC9B;aACF;YACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO;SACR;QAED,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC1C,MAAM,MAAM,GAAyB,qDAAyB,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACrG,IAAI,MAAM,EAAE;gBACV,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;gBACtB,OAAO;aACR;SACF;QAED,sCAAsC;QAEtC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,mEAAmE;IAC5D,eAAe,CAAC,OAAiB;QACtC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC;CACF;AAnED,wEAmEC","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 { ICommandLineStringListDefinition } from './CommandLineDefinition';\r\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\r\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\r\n\r\n/**\r\n * The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.\r\n * @public\r\n */\r\nexport class CommandLineStringListParameter extends CommandLineParameterWithArgument {\r\n private _values: string[] = [];\r\n\r\n /** @internal */\r\n public constructor(definition: ICommandLineStringListDefinition) {\r\n super(definition);\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.kind} */\r\n public get kind(): CommandLineParameterKind {\r\n return CommandLineParameterKind.StringList;\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 // If argparse passed us a value, confirm it is valid\r\n if (data !== null && data !== undefined) {\r\n if (!Array.isArray(data)) {\r\n this.reportInvalidData(data);\r\n }\r\n for (const arrayItem of data) {\r\n if (typeof arrayItem !== 'string') {\r\n this.reportInvalidData(data);\r\n }\r\n }\r\n this._values = data;\r\n return;\r\n }\r\n\r\n // If an environment variable exists, attempt to parse it as a list\r\n if (this.environmentVariable !== undefined) {\r\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\r\n if (values) {\r\n this._values = values;\r\n return;\r\n }\r\n }\r\n\r\n // (No default value for string lists)\r\n\r\n this._values = [];\r\n }\r\n\r\n /**\r\n * Returns the string arguments for a string list parameter that was parsed from the command line.\r\n *\r\n * @remarks\r\n * The array will be empty 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 values(): ReadonlyArray<string> {\r\n return this._values;\r\n }\r\n\r\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\r\n public appendToArgList(argList: string[]): void {\r\n if (this.values.length > 0) {\r\n for (const value of this.values) {\r\n argList.push(this.longName);\r\n argList.push(value);\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineStringListParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringListParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2F;AAC3F,2EAAwE;AAExE;;;GAGG;AACH,MAAa,8BAA+B,SAAQ,8CAAgC;IAGlF,gBAAgB;IAChB,YAAmB,UAA4C;QAC7D,KAAK,CAAC,UAAU,CAAC,CAAC;QAJZ,YAAO,GAAa,EAAE,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C;CACF;AAnED,wEAmEC","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 { ICommandLineStringListDefinition } from './CommandLineDefinition';\nimport { CommandLineParameterWithArgument, CommandLineParameterKind } from './BaseClasses';\nimport { EnvironmentVariableParser } from './EnvironmentVariableParser';\n\n/**\n * The data type returned by {@link CommandLineParameterProvider.defineStringListParameter}.\n * @public\n */\nexport class CommandLineStringListParameter extends CommandLineParameterWithArgument {\n private _values: string[] = [];\n\n /** @internal */\n public constructor(definition: ICommandLineStringListDefinition) {\n super(definition);\n }\n\n /** {@inheritDoc CommandLineParameter.kind} */\n public get kind(): CommandLineParameterKind {\n return CommandLineParameterKind.StringList;\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 // If argparse passed us a value, confirm it is valid\n if (data !== null && data !== undefined) {\n if (!Array.isArray(data)) {\n this.reportInvalidData(data);\n }\n for (const arrayItem of data) {\n if (typeof arrayItem !== 'string') {\n this.reportInvalidData(data);\n }\n }\n this._values = data;\n return;\n }\n\n // If an environment variable exists, attempt to parse it as a list\n if (this.environmentVariable !== undefined) {\n const values: string[] | undefined = EnvironmentVariableParser.parseAsList(this.environmentVariable);\n if (values) {\n this._values = values;\n return;\n }\n }\n\n // (No default value for string lists)\n\n this._values = [];\n }\n\n /**\n * Returns the string arguments for a string list parameter that was parsed from the command line.\n *\n * @remarks\n * The array will be empty 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 values(): ReadonlyArray<string> {\n return this._values;\n }\n\n /** {@inheritDoc CommandLineParameter.appendToArgList} @override */\n public appendToArgList(argList: string[]): void {\n if (this.values.length > 0) {\n for (const value of this.values) {\n argList.push(this.longName);\n argList.push(value);\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineStringParameter.js","sourceRoot":"","s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ACI,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.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { 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
+ {"version":3,"file":"CommandLineStringParameter.js","sourceRoot":"","sources":["../../src/parameters/CommandLineStringParameter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,+CAA2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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 +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.\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
+ {"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 +1 @@
1
- {"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,iFAAsG;AA0BtG;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAe1E,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YACjE,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,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,IAA4B;QACpD,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACjC,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;;AAzEH,8CAoFC;AAnFC,0BAA0B;AACX,mCAAiB,GAAW,kCAAkC,CAAC","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\nimport { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';\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 * 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 // Example: \"do-something\"\r\n private static _actionNameRegExp: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\r\n\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 (!CommandLineAction._actionNameRegExp.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 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(data: ICommandLineParserData): void {\r\n super._processParsedData(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 * {@inheritDoc CommandLineParameterProvider.onDefineParameters}\r\n */\r\n protected abstract onDefineParameters(): void;\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
+ {"version":3,"file":"CommandLineAction.js","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,iFAAsG;AA0BtG;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAe1E,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YACjE,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,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,IAA4B;QACpD,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACjC,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;;AAzEH,8CAoFC;AAnFC,0BAA0B;AACX,mCAAiB,GAAW,kCAAkC,CAAC","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';\nimport { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';\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 * 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 // Example: \"do-something\"\n private static _actionNameRegExp: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\n\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 (!CommandLineAction._actionNameRegExp.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(data: ICommandLineParserData): void {\n super._processParsedData(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 * {@inheritDoc CommandLineParameterProvider.onDefineParameters}\n */\n protected abstract onDefineParameters(): void;\n\n /**\n * Your subclass should implement this hook to perform the operation.\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAWrC,2DAImC;AACnC,yFAAsF;AACtF,iGAA8F;AAC9F,2FAAwF;AACxF,mGAAgG;AAChG,qFAAkF;AAClF,yFAAsF;AACtF,iGAA8F;AAC9F,6EAA0E;AAW1E;;;;;GAKG;AACH,MAAsB,4BAA4B;IAQhD,gBAAgB;IAChB,0EAA0E;IAC1E;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAgC,CAAC;QACrE,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;;;;;;OASG;IACI,qBAAqB,CAAC,UAAwC;QACnE,MAAM,SAAS,GAA+B,IAAI,uDAA0B,CAAC,UAAU,CAAC,CAAC;QACzF,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CAAC,iBAAyB;QACjD,OAAO,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,sCAAwB,CAAC,MAAM,CAAC,CAAC;IAChF,CAAC;IAED;;;;;;;;;;OAUG;IACI,yBAAyB,CAC9B,UAA4C;QAE5C,MAAM,SAAS,GAAmC,IAAI,+DAA8B,CAAC,UAAU,CAAC,CAAC;QACj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C,MAAM,GAAG,QAAQ,CAAC;gBAClC,MAAM;YACR,KAAK,sCAAwB,CAAC,MAAM;gBAClC,MAAM;YACR,KAAK,sCAAwB,CAAC,UAAU;gBACtC,eAAe,CAAC,MAAM,GAAG,QAAQ,CAAC;gBAClC,MAAM;SACT;QAED,MAAM,cAAc,GAA4B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1E,cAAc,CAAC,WAAW,CAAC,KAAK,oBAAO,eAAe,EAAG,CAAC;QAC1D,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/E,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC,oBAAoB,kCACpD,eAAe,KAClB,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAC7B,CAAC;SACJ;QAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;;AAzaH,oEA0aC;AAzagB,wCAAW,GAAW,CAAC,CAAC","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\nimport {\r\n ICommandLineChoiceDefinition,\r\n ICommandLineChoiceListDefinition,\r\n ICommandLineIntegerDefinition,\r\n ICommandLineIntegerListDefinition,\r\n ICommandLineFlagDefinition,\r\n ICommandLineStringDefinition,\r\n ICommandLineStringListDefinition,\r\n ICommandLineRemainderDefinition\r\n} from '../parameters/CommandLineDefinition';\r\nimport {\r\n CommandLineParameter,\r\n CommandLineParameterWithArgument,\r\n CommandLineParameterKind\r\n} from '../parameters/BaseClasses';\r\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\r\nimport { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\r\nimport { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\r\nimport { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\r\nimport { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\r\nimport { CommandLineStringParameter } from '../parameters/CommandLineStringParameter';\r\nimport { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';\r\nimport { CommandLineRemainder } from '../parameters/CommandLineRemainder';\r\n\r\n/**\r\n * This is the argparse result data object\r\n * @internal\r\n */\r\nexport interface ICommandLineParserData {\r\n action: string;\r\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\r\n}\r\n\r\n/**\r\n * This is the common base class for CommandLineAction and CommandLineParser\r\n * that provides functionality for defining command-line parameters.\r\n *\r\n * @public\r\n */\r\nexport abstract class CommandLineParameterProvider {\r\n private static _keyCounter: number = 0;\r\n\r\n private _parameters: CommandLineParameter[];\r\n private _parametersByLongName: Map<string, CommandLineParameter>;\r\n private _parametersProcessed: boolean;\r\n private _remainder: CommandLineRemainder | undefined;\r\n\r\n /** @internal */\r\n // Third party code should not inherit subclasses or call this constructor\r\n public constructor() {\r\n this._parameters = [];\r\n this._parametersByLongName = new Map<string, CommandLineParameter>();\r\n this._parametersProcessed = false;\r\n }\r\n\r\n /**\r\n * Returns a collection of the parameters that were defined for this object.\r\n */\r\n public get parameters(): ReadonlyArray<CommandLineParameter> {\r\n return this._parameters;\r\n }\r\n\r\n /**\r\n * Informs the caller if the argparse data has been processed into parameters.\r\n */\r\n public get parametersProcessed(): boolean {\r\n return this._parametersProcessed;\r\n }\r\n\r\n /**\r\n * If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,\r\n * this object captures any remaining command line arguments after the recognized portion.\r\n */\r\n public get remainder(): CommandLineRemainder | undefined {\r\n return this._remainder;\r\n }\r\n\r\n /**\r\n * Defines a command-line parameter whose value must be a string from a fixed set of\r\n * allowable choices (similar to an enum).\r\n *\r\n * @remarks\r\n * Example of a choice parameter:\r\n * ```\r\n * example-tool --log-level warn\r\n * ```\r\n */\r\n public defineChoiceParameter(definition: ICommandLineChoiceDefinition): CommandLineChoiceParameter {\r\n const parameter: CommandLineChoiceParameter = new CommandLineChoiceParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineChoiceParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.Choice);\r\n }\r\n\r\n /**\r\n * Defines a command-line parameter whose value must be a string from a fixed set of\r\n * allowable choices (similar to an enum). The parameter can be specified multiple times to\r\n * build a list.\r\n *\r\n * @remarks\r\n * Example of a choice list parameter:\r\n * ```\r\n * example-tool --allow-color red --allow-color green\r\n * ```\r\n */\r\n public defineChoiceListParameter(\r\n definition: ICommandLineChoiceListDefinition\r\n ): CommandLineChoiceListParameter {\r\n const parameter: CommandLineChoiceListParameter = new CommandLineChoiceListParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineChoiceListParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getChoiceListParameter(parameterLongName: string): CommandLineChoiceListParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.ChoiceList);\r\n }\r\n\r\n /**\r\n * Defines a command-line switch whose boolean value is true if the switch is provided,\r\n * and false otherwise.\r\n *\r\n * @remarks\r\n * Example usage of a flag parameter:\r\n * ```\r\n * example-tool --debug\r\n * ```\r\n */\r\n public defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter {\r\n const parameter: CommandLineFlagParameter = new CommandLineFlagParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineFlagParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getFlagParameter(parameterLongName: string): CommandLineFlagParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.Flag);\r\n }\r\n\r\n /**\r\n * Defines a command-line parameter whose argument is an integer.\r\n *\r\n * @remarks\r\n * Example usage of an integer parameter:\r\n * ```\r\n * example-tool --max-attempts 5\r\n * ```\r\n */\r\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter {\r\n const parameter: CommandLineIntegerParameter = new CommandLineIntegerParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineIntegerParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.Integer);\r\n }\r\n\r\n /**\r\n * Defines a command-line parameter whose argument is an integer. The parameter can be specified\r\n * multiple times to build a list.\r\n *\r\n * @remarks\r\n * Example usage of an integer list parameter:\r\n * ```\r\n * example-tool --avoid 4 --avoid 13\r\n * ```\r\n */\r\n public defineIntegerListParameter(\r\n definition: ICommandLineIntegerListDefinition\r\n ): CommandLineIntegerListParameter {\r\n const parameter: CommandLineIntegerListParameter = new CommandLineIntegerListParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineIntegerParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getIntegerListParameter(parameterLongName: string): CommandLineIntegerListParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.IntegerList);\r\n }\r\n /**\r\n * Defines a command-line parameter whose argument is a single text string.\r\n *\r\n * @remarks\r\n * Example usage of a string parameter:\r\n * ```\r\n * example-tool --message \"Hello, world!\"\r\n * ```\r\n */\r\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter {\r\n const parameter: CommandLineStringParameter = new CommandLineStringParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineStringParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getStringParameter(parameterLongName: string): CommandLineStringParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.String);\r\n }\r\n\r\n /**\r\n * Defines a command-line parameter whose argument is a single text string. The parameter can be\r\n * specified multiple times to build a list.\r\n *\r\n * @remarks\r\n * Example usage of a string list parameter:\r\n * ```\r\n * example-tool --add file1.txt --add file2.txt --add file3.txt\r\n * ```\r\n */\r\n public defineStringListParameter(\r\n definition: ICommandLineStringListDefinition\r\n ): CommandLineStringListParameter {\r\n const parameter: CommandLineStringListParameter = new CommandLineStringListParameter(definition);\r\n this._defineParameter(parameter);\r\n return parameter;\r\n }\r\n\r\n /**\r\n * Defines a rule that captures any remaining command line arguments after the recognized portion.\r\n *\r\n * @remarks\r\n * This feature is useful for commands that pass their arguments along to an external tool, relying on\r\n * that tool to perform validation. (It could also be used to parse parameters without any validation\r\n * or documentation, but that is not recommended.)\r\n *\r\n * Example of capturing the remainder after an optional flag parameter.\r\n * ```\r\n * example-tool --my-flag this is the remainder\r\n * ```\r\n *\r\n * In the \"--help\" documentation, the remainder rule will be represented as \"...\".\r\n */\r\n public defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder {\r\n if (this._remainder) {\r\n throw new Error('defineRemainingArguments() has already been called for this provider');\r\n }\r\n this._remainder = new CommandLineRemainder(definition);\r\n\r\n const argparseOptions: argparse.ArgumentOptions = {\r\n help: this._remainder.description,\r\n nargs: argparse.Const.REMAINDER,\r\n metavar: '\"...\"'\r\n };\r\n\r\n this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);\r\n\r\n return this._remainder;\r\n }\r\n\r\n /**\r\n * Returns the CommandLineStringListParameter with the specified long name.\r\n * @remarks\r\n * This method throws an exception if the parameter is not defined.\r\n */\r\n public getStringListParameter(parameterLongName: string): CommandLineStringListParameter {\r\n return this._getParameter(parameterLongName, CommandLineParameterKind.StringList);\r\n }\r\n\r\n /**\r\n * Generates the command-line help text.\r\n */\r\n public renderHelpText(): string {\r\n return this._getArgumentParser().formatHelp();\r\n }\r\n\r\n /**\r\n * Returns a object which maps the long name of each parameter in this.parameters\r\n * to the stringified form of its value. This is useful for logging telemetry, but\r\n * it is not the proper way of accessing parameters or their values.\r\n */\r\n public getParameterStringMap(): Record<string, string> {\r\n const parameterMap: Record<string, string> = {};\r\n for (const parameter of this.parameters) {\r\n switch (parameter.kind) {\r\n case CommandLineParameterKind.Flag:\r\n case CommandLineParameterKind.Choice:\r\n case CommandLineParameterKind.String:\r\n case CommandLineParameterKind.Integer:\r\n parameterMap[parameter.longName] = JSON.stringify(\r\n (\r\n parameter as\r\n | CommandLineFlagParameter\r\n | CommandLineIntegerParameter\r\n | CommandLineChoiceParameter\r\n | CommandLineStringParameter\r\n ).value\r\n );\r\n break;\r\n case CommandLineParameterKind.StringList:\r\n case CommandLineParameterKind.IntegerList:\r\n case CommandLineParameterKind.ChoiceList:\r\n const arrayValue: ReadonlyArray<string | number> | undefined = (\r\n parameter as\r\n | CommandLineIntegerListParameter\r\n | CommandLineStringListParameter\r\n | CommandLineChoiceListParameter\r\n ).values;\r\n parameterMap[parameter.longName] = arrayValue ? arrayValue.join(',') : '';\r\n break;\r\n }\r\n }\r\n return parameterMap;\r\n }\r\n\r\n /**\r\n * The child class should implement this hook to define its command-line parameters,\r\n * e.g. by calling defineFlagParameter().\r\n */\r\n protected abstract onDefineParameters(): void;\r\n\r\n /**\r\n * Retrieves the argparse object.\r\n * @internal\r\n */\r\n protected abstract _getArgumentParser(): argparse.ArgumentParser;\r\n\r\n /** @internal */\r\n protected _processParsedData(data: ICommandLineParserData): void {\r\n if (this._parametersProcessed) {\r\n throw new Error('Command Line Parser Data was already processed');\r\n }\r\n\r\n // Fill in the values for the parameters\r\n for (const parameter of this._parameters) {\r\n const value: any = data[parameter._parserKey!]; // eslint-disable-line @typescript-eslint/no-explicit-any\r\n parameter._setValue(value);\r\n }\r\n\r\n if (this.remainder) {\r\n this.remainder._setValue(data[argparse.Const.REMAINDER]);\r\n }\r\n\r\n this._parametersProcessed = true;\r\n }\r\n\r\n private _generateKey(): string {\r\n return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();\r\n }\r\n\r\n private _getParameter<T extends CommandLineParameter>(\r\n parameterLongName: string,\r\n expectedKind: CommandLineParameterKind\r\n ): T {\r\n const parameter: CommandLineParameter | undefined = this._parametersByLongName.get(parameterLongName);\r\n if (!parameter) {\r\n throw new Error(`The parameter \"${parameterLongName}\" is not defined`);\r\n }\r\n if (parameter.kind !== expectedKind) {\r\n throw new Error(\r\n `The parameter \"${parameterLongName}\" is of type \"${CommandLineParameterKind[parameter.kind]}\"` +\r\n ` whereas the caller was expecting \"${CommandLineParameterKind[expectedKind]}\".`\r\n );\r\n }\r\n return parameter as T;\r\n }\r\n\r\n private _defineParameter(parameter: CommandLineParameter): void {\r\n if (this._remainder) {\r\n throw new Error(\r\n 'defineCommandLineRemainder() was already called for this provider;' +\r\n ' no further parameters can be defined'\r\n );\r\n }\r\n\r\n const names: string[] = [];\r\n if (parameter.shortName) {\r\n names.push(parameter.shortName);\r\n }\r\n names.push(parameter.longName);\r\n\r\n parameter._parserKey = this._generateKey();\r\n\r\n let finalDescription: string = parameter.description;\r\n\r\n const supplementaryNotes: string[] = [];\r\n parameter._getSupplementaryNotes(supplementaryNotes);\r\n if (supplementaryNotes.length > 0) {\r\n // If they left the period off the end of their sentence, then add one.\r\n if (finalDescription.match(/[a-z0-9]\"?\\s*$/i)) {\r\n finalDescription = finalDescription.trimRight() + '.';\r\n }\r\n // Append the supplementary text\r\n finalDescription += ' ' + supplementaryNotes.join(' ');\r\n }\r\n\r\n // NOTE: Our \"environmentVariable\" feature takes precedence over argparse's \"defaultValue\",\r\n // so we have to reimplement that feature.\r\n const argparseOptions: argparse.ArgumentOptions = {\r\n help: finalDescription,\r\n dest: parameter._parserKey,\r\n metavar: (parameter as CommandLineParameterWithArgument).argumentName || undefined,\r\n required: parameter.required\r\n };\r\n\r\n switch (parameter.kind) {\r\n case CommandLineParameterKind.Choice: {\r\n const choiceParameter: CommandLineChoiceParameter = parameter as CommandLineChoiceParameter;\r\n argparseOptions.choices = choiceParameter.alternatives as string[];\r\n break;\r\n }\r\n case CommandLineParameterKind.ChoiceList: {\r\n const choiceParameter: CommandLineChoiceListParameter = parameter as CommandLineChoiceListParameter;\r\n argparseOptions.choices = choiceParameter.alternatives as string[];\r\n argparseOptions.action = 'append';\r\n break;\r\n }\r\n case CommandLineParameterKind.Flag:\r\n argparseOptions.action = 'storeTrue';\r\n break;\r\n case CommandLineParameterKind.Integer:\r\n argparseOptions.type = 'int';\r\n break;\r\n case CommandLineParameterKind.IntegerList:\r\n argparseOptions.type = 'int';\r\n argparseOptions.action = 'append';\r\n break;\r\n case CommandLineParameterKind.String:\r\n break;\r\n case CommandLineParameterKind.StringList:\r\n argparseOptions.action = 'append';\r\n break;\r\n }\r\n\r\n const argumentParser: argparse.ArgumentParser = this._getArgumentParser();\r\n argumentParser.addArgument(names, { ...argparseOptions });\r\n if (parameter.undocumentedSynonyms && parameter.undocumentedSynonyms.length > 0) {\r\n argumentParser.addArgument(parameter.undocumentedSynonyms, {\r\n ...argparseOptions,\r\n help: argparse.Const.SUPPRESS\r\n });\r\n }\r\n\r\n this._parameters.push(parameter);\r\n this._parametersByLongName.set(parameter.longName, parameter);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAWrC,2DAImC;AACnC,yFAAsF;AACtF,iGAA8F;AAC9F,2FAAwF;AACxF,mGAAgG;AAChG,qFAAkF;AAClF,yFAAsF;AACtF,iGAA8F;AAC9F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C1D,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/E,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC,oBAAoB,kCACpD,eAAe,KAClB,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,IAC7B,CAAC;SACJ;QAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;;AAzaH,oEA0aC;AAzagB,wCAAW,GAAW,CAAC,CAAC","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';\nimport {\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineRemainderDefinition\n} from '../parameters/CommandLineDefinition';\nimport {\n CommandLineParameter,\n CommandLineParameterWithArgument,\n CommandLineParameterKind\n} from '../parameters/BaseClasses';\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\nimport { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\nimport { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\nimport { CommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';\nimport { CommandLineRemainder } from '../parameters/CommandLineRemainder';\n\n/**\n * This is the argparse result data object\n * @internal\n */\nexport interface ICommandLineParserData {\n action: string;\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\n/**\n * This is the common base class for CommandLineAction and CommandLineParser\n * that provides functionality for defining command-line parameters.\n *\n * @public\n */\nexport abstract class CommandLineParameterProvider {\n private static _keyCounter: number = 0;\n\n private _parameters: CommandLineParameter[];\n private _parametersByLongName: Map<string, CommandLineParameter>;\n private _parametersProcessed: boolean;\n private _remainder: CommandLineRemainder | undefined;\n\n /** @internal */\n // Third party code should not inherit subclasses or call this constructor\n public constructor() {\n this._parameters = [];\n this._parametersByLongName = new Map<string, CommandLineParameter>();\n this._parametersProcessed = false;\n }\n\n /**\n * Returns a collection of the parameters that were defined for this object.\n */\n public get parameters(): ReadonlyArray<CommandLineParameter> {\n return this._parameters;\n }\n\n /**\n * Informs the caller if the argparse data has been processed into parameters.\n */\n public get parametersProcessed(): boolean {\n return this._parametersProcessed;\n }\n\n /**\n * If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called,\n * this object captures any remaining command line arguments after the recognized portion.\n */\n public get remainder(): CommandLineRemainder | undefined {\n return this._remainder;\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum).\n *\n * @remarks\n * Example of a choice parameter:\n * ```\n * example-tool --log-level warn\n * ```\n */\n public defineChoiceParameter(definition: ICommandLineChoiceDefinition): CommandLineChoiceParameter {\n const parameter: CommandLineChoiceParameter = new CommandLineChoiceParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Choice);\n }\n\n /**\n * Defines a command-line parameter whose value must be a string from a fixed set of\n * allowable choices (similar to an enum). The parameter can be specified multiple times to\n * build a list.\n *\n * @remarks\n * Example of a choice list parameter:\n * ```\n * example-tool --allow-color red --allow-color green\n * ```\n */\n public defineChoiceListParameter(\n definition: ICommandLineChoiceListDefinition\n ): CommandLineChoiceListParameter {\n const parameter: CommandLineChoiceListParameter = new CommandLineChoiceListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineChoiceListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getChoiceListParameter(parameterLongName: string): CommandLineChoiceListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.ChoiceList);\n }\n\n /**\n * Defines a command-line switch whose boolean value is true if the switch is provided,\n * and false otherwise.\n *\n * @remarks\n * Example usage of a flag parameter:\n * ```\n * example-tool --debug\n * ```\n */\n public defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter {\n const parameter: CommandLineFlagParameter = new CommandLineFlagParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineFlagParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getFlagParameter(parameterLongName: string): CommandLineFlagParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Flag);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer.\n *\n * @remarks\n * Example usage of an integer parameter:\n * ```\n * example-tool --max-attempts 5\n * ```\n */\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter {\n const parameter: CommandLineIntegerParameter = new CommandLineIntegerParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Integer);\n }\n\n /**\n * Defines a command-line parameter whose argument is an integer. The parameter can be specified\n * multiple times to build a list.\n *\n * @remarks\n * Example usage of an integer list parameter:\n * ```\n * example-tool --avoid 4 --avoid 13\n * ```\n */\n public defineIntegerListParameter(\n definition: ICommandLineIntegerListDefinition\n ): CommandLineIntegerListParameter {\n const parameter: CommandLineIntegerListParameter = new CommandLineIntegerListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineIntegerParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getIntegerListParameter(parameterLongName: string): CommandLineIntegerListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.IntegerList);\n }\n /**\n * Defines a command-line parameter whose argument is a single text string.\n *\n * @remarks\n * Example usage of a string parameter:\n * ```\n * example-tool --message \"Hello, world!\"\n * ```\n */\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter {\n const parameter: CommandLineStringParameter = new CommandLineStringParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Returns the CommandLineStringParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringParameter(parameterLongName: string): CommandLineStringParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.String);\n }\n\n /**\n * Defines a command-line parameter whose argument is a single text string. The parameter can be\n * specified multiple times to build a list.\n *\n * @remarks\n * Example usage of a string list parameter:\n * ```\n * example-tool --add file1.txt --add file2.txt --add file3.txt\n * ```\n */\n public defineStringListParameter(\n definition: ICommandLineStringListDefinition\n ): CommandLineStringListParameter {\n const parameter: CommandLineStringListParameter = new CommandLineStringListParameter(definition);\n this._defineParameter(parameter);\n return parameter;\n }\n\n /**\n * Defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @remarks\n * This feature is useful for commands that pass their arguments along to an external tool, relying on\n * that tool to perform validation. (It could also be used to parse parameters without any validation\n * or documentation, but that is not recommended.)\n *\n * Example of capturing the remainder after an optional flag parameter.\n * ```\n * example-tool --my-flag this is the remainder\n * ```\n *\n * In the \"--help\" documentation, the remainder rule will be represented as \"...\".\n */\n public defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder {\n if (this._remainder) {\n throw new Error('defineRemainingArguments() has already been called for this provider');\n }\n this._remainder = new CommandLineRemainder(definition);\n\n const argparseOptions: argparse.ArgumentOptions = {\n help: this._remainder.description,\n nargs: argparse.Const.REMAINDER,\n metavar: '\"...\"'\n };\n\n this._getArgumentParser().addArgument(argparse.Const.REMAINDER, argparseOptions);\n\n return this._remainder;\n }\n\n /**\n * Returns the CommandLineStringListParameter with the specified long name.\n * @remarks\n * This method throws an exception if the parameter is not defined.\n */\n public getStringListParameter(parameterLongName: string): CommandLineStringListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.StringList);\n }\n\n /**\n * Generates the command-line help text.\n */\n public renderHelpText(): string {\n return this._getArgumentParser().formatHelp();\n }\n\n /**\n * Returns a object which maps the long name of each parameter in this.parameters\n * to the stringified form of its value. This is useful for logging telemetry, but\n * it is not the proper way of accessing parameters or their values.\n */\n public getParameterStringMap(): Record<string, string> {\n const parameterMap: Record<string, string> = {};\n for (const parameter of this.parameters) {\n switch (parameter.kind) {\n case CommandLineParameterKind.Flag:\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.String:\n case CommandLineParameterKind.Integer:\n parameterMap[parameter.longName] = JSON.stringify(\n (\n parameter as\n | CommandLineFlagParameter\n | CommandLineIntegerParameter\n | CommandLineChoiceParameter\n | CommandLineStringParameter\n ).value\n );\n break;\n case CommandLineParameterKind.StringList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.ChoiceList:\n const arrayValue: ReadonlyArray<string | number> | undefined = (\n parameter as\n | CommandLineIntegerListParameter\n | CommandLineStringListParameter\n | CommandLineChoiceListParameter\n ).values;\n parameterMap[parameter.longName] = arrayValue ? arrayValue.join(',') : '';\n break;\n }\n }\n return parameterMap;\n }\n\n /**\n * The child class should implement this hook to define its command-line parameters,\n * e.g. by calling defineFlagParameter().\n */\n protected abstract onDefineParameters(): void;\n\n /**\n * Retrieves the argparse object.\n * @internal\n */\n protected abstract _getArgumentParser(): argparse.ArgumentParser;\n\n /** @internal */\n protected _processParsedData(data: ICommandLineParserData): void {\n if (this._parametersProcessed) {\n throw new Error('Command Line Parser Data was already processed');\n }\n\n // Fill in the values for the parameters\n for (const parameter of this._parameters) {\n const value: any = data[parameter._parserKey!]; // eslint-disable-line @typescript-eslint/no-explicit-any\n parameter._setValue(value);\n }\n\n if (this.remainder) {\n this.remainder._setValue(data[argparse.Const.REMAINDER]);\n }\n\n this._parametersProcessed = true;\n }\n\n private _generateKey(): string {\n return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();\n }\n\n private _getParameter<T extends CommandLineParameter>(\n parameterLongName: string,\n expectedKind: CommandLineParameterKind\n ): T {\n const parameter: CommandLineParameter | undefined = this._parametersByLongName.get(parameterLongName);\n if (!parameter) {\n throw new Error(`The parameter \"${parameterLongName}\" is not defined`);\n }\n if (parameter.kind !== expectedKind) {\n throw new Error(\n `The parameter \"${parameterLongName}\" is of type \"${CommandLineParameterKind[parameter.kind]}\"` +\n ` whereas the caller was expecting \"${CommandLineParameterKind[expectedKind]}\".`\n );\n }\n return parameter as T;\n }\n\n private _defineParameter(parameter: CommandLineParameter): void {\n if (this._remainder) {\n throw new Error(\n 'defineCommandLineRemainder() was already called for this provider;' +\n ' no further parameters can be defined'\n );\n }\n\n const names: string[] = [];\n if (parameter.shortName) {\n names.push(parameter.shortName);\n }\n names.push(parameter.longName);\n\n parameter._parserKey = this._generateKey();\n\n let finalDescription: string = parameter.description;\n\n const supplementaryNotes: string[] = [];\n parameter._getSupplementaryNotes(supplementaryNotes);\n if (supplementaryNotes.length > 0) {\n // If they left the period off the end of their sentence, then add one.\n if (finalDescription.match(/[a-z0-9]\"?\\s*$/i)) {\n finalDescription = finalDescription.trimRight() + '.';\n }\n // Append the supplementary text\n finalDescription += ' ' + supplementaryNotes.join(' ');\n }\n\n // NOTE: Our \"environmentVariable\" feature takes precedence over argparse's \"defaultValue\",\n // so we have to reimplement that feature.\n const argparseOptions: argparse.ArgumentOptions = {\n help: finalDescription,\n dest: parameter._parserKey,\n metavar: (parameter as CommandLineParameterWithArgument).argumentName || undefined,\n required: parameter.required\n };\n\n switch (parameter.kind) {\n case CommandLineParameterKind.Choice: {\n const choiceParameter: CommandLineChoiceParameter = parameter as CommandLineChoiceParameter;\n argparseOptions.choices = choiceParameter.alternatives as string[];\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n const choiceParameter: CommandLineChoiceListParameter = parameter as CommandLineChoiceListParameter;\n argparseOptions.choices = choiceParameter.alternatives as string[];\n argparseOptions.action = 'append';\n break;\n }\n case CommandLineParameterKind.Flag:\n argparseOptions.action = 'storeTrue';\n break;\n case CommandLineParameterKind.Integer:\n argparseOptions.type = 'int';\n break;\n case CommandLineParameterKind.IntegerList:\n argparseOptions.type = 'int';\n argparseOptions.action = 'append';\n break;\n case CommandLineParameterKind.String:\n break;\n case CommandLineParameterKind.StringList:\n argparseOptions.action = 'append';\n break;\n }\n\n const argumentParser: argparse.ArgumentParser = this._getArgumentParser();\n argumentParser.addArgument(names, { ...argparseOptions });\n if (parameter.undocumentedSynonyms && parameter.undocumentedSynonyms.length > 0) {\n argumentParser.addArgument(parameter.undocumentedSynonyms, {\n ...argparseOptions,\n help: argparse.Const.SUPPRESS\n });\n }\n\n this._parameters.push(parameter);\n this._parametersByLongName.set(parameter.longName, parameter);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAG3D,oDAA4B;AAG5B,iFAAsG;AACtG,6EAAgG;AAChG,+DAA0D;AAuB1D;;;;;;;;;GASG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAgB1E,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAJF,cAAS,GAAY,KAAK,CAAC;QAC3B,+BAA0B,GAAY,KAAK,CAAC;QAKlD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,IAAI,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CAAC;SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,uDAA0B,EAAE;gBAC7C,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;oBACjB,kDAAkD;oBAClD,IAAI,GAAG,CAAC,OAAO,EAAE;wBACf,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;qBAC1B;oBAED,OAAO;iBACR;aACF;YAED,MAAM,GAAG,CAAC;SACX;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7C,+CAA+C;YAC/C,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;SACvG;IACH,CAAC;IAED;;;OAGG;IACO,kBAAkB;QAC1B,WAAW;QACX,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;SACtC;IACH,CAAC;CACF;AAzND,8CAyNC","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\nimport colors from 'colors';\r\n\r\nimport { CommandLineAction } from './CommandLineAction';\r\nimport { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';\r\nimport { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError';\r\nimport { TabCompleteAction } from './TabCompletionAction';\r\n\r\n/**\r\n * Options for the {@link CommandLineParser} constructor.\r\n * @public\r\n */\r\nexport interface ICommandLineParserOptions {\r\n /**\r\n * The name of your tool when invoked from the command line\r\n */\r\n toolFilename: string;\r\n\r\n /**\r\n * General documentation that is included in the \"--help\" main page\r\n */\r\n toolDescription: string;\r\n\r\n /**\r\n * Set to true to auto-define a tab completion action. False by default.\r\n */\r\n enableTabCompletionAction?: boolean;\r\n}\r\n\r\n/**\r\n * The \"argparse\" library is a relatively advanced command-line parser with features such\r\n * as word-wrapping and intelligible error messages (that are lacking in other similar\r\n * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API\r\n * is awkward to use. The abstract base classes CommandLineParser and CommandLineAction\r\n * provide a wrapper for \"argparse\" that makes defining and consuming arguments quick\r\n * and simple, and enforces that appropriate documentation is provided for each parameter.\r\n *\r\n * @public\r\n */\r\nexport abstract class CommandLineParser extends CommandLineParameterProvider {\r\n /**\r\n * Reports which CommandLineAction was specified on the command line.\r\n * @remarks\r\n * The value will be assigned before onExecute() is invoked.\r\n */\r\n public selectedAction: CommandLineAction | undefined;\r\n\r\n private _argumentParser: argparse.ArgumentParser;\r\n private _actionsSubParser: argparse.SubParser | undefined;\r\n private _options: ICommandLineParserOptions;\r\n private _actions: CommandLineAction[];\r\n private _actionsByName: Map<string, CommandLineAction>;\r\n private _executed: boolean = false;\r\n private _tabCompleteActionWasAdded: boolean = false;\r\n\r\n public constructor(options: ICommandLineParserOptions) {\r\n super();\r\n\r\n this._options = options;\r\n this._actions = [];\r\n this._actionsByName = new Map<string, CommandLineAction>();\r\n\r\n this._argumentParser = new CustomArgumentParser({\r\n addHelp: true,\r\n prog: this._options.toolFilename,\r\n description: this._options.toolDescription,\r\n epilog: colors.bold(\r\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\r\n )\r\n });\r\n\r\n this.onDefineParameters();\r\n }\r\n\r\n /**\r\n * Returns the list of actions that were defined for this CommandLineParser object.\r\n */\r\n public get actions(): ReadonlyArray<CommandLineAction> {\r\n return this._actions;\r\n }\r\n\r\n /**\r\n * Defines a new action that can be used with the CommandLineParser instance.\r\n */\r\n public addAction(action: CommandLineAction): void {\r\n if (!this._actionsSubParser) {\r\n this._actionsSubParser = this._argumentParser.addSubparsers({\r\n metavar: '<command>',\r\n dest: 'action'\r\n });\r\n }\r\n\r\n action._buildParser(this._actionsSubParser);\r\n this._actions.push(action);\r\n this._actionsByName.set(action.actionName, action);\r\n }\r\n\r\n /**\r\n * Retrieves the action with the specified name. If no matching action is found,\r\n * an exception is thrown.\r\n */\r\n public getAction(actionName: string): CommandLineAction {\r\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\r\n if (!action) {\r\n throw new Error(`The action \"${actionName}\" was not defined`);\r\n }\r\n return action;\r\n }\r\n\r\n /**\r\n * Retrieves the action with the specified name. If no matching action is found,\r\n * undefined is returned.\r\n */\r\n public tryGetAction(actionName: string): CommandLineAction | undefined {\r\n return this._actionsByName.get(actionName);\r\n }\r\n\r\n /**\r\n * The program entry point will call this method to begin parsing command-line arguments\r\n * and executing the corresponding action.\r\n *\r\n * @remarks\r\n * The returned promise will never reject: If an error occurs, it will be printed\r\n * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.\r\n * This simplifies the most common usage scenario where the program entry point doesn't\r\n * want to be involved with the command-line logic, and will discard the promise without\r\n * a then() or catch() block.\r\n *\r\n * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}\r\n * instead.\r\n *\r\n * @param args - the command-line arguments to be parsed; if omitted, then\r\n * the process.argv will be used\r\n */\r\n public async execute(args?: string[]): Promise<boolean> {\r\n if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {\r\n this.addAction(new TabCompleteAction(this.actions, this.parameters));\r\n this._tabCompleteActionWasAdded = true;\r\n }\r\n\r\n try {\r\n await this.executeWithoutErrorHandling(args);\r\n return true;\r\n } catch (err) {\r\n if (err instanceof CommandLineParserExitError) {\r\n // executeWithoutErrorHandling() handles the successful cases,\r\n // so here we can assume err has a nonzero exit code\r\n if (err.message) {\r\n console.error(err.message);\r\n }\r\n if (!process.exitCode) {\r\n process.exitCode = err.exitCode;\r\n }\r\n } else {\r\n let message: string = ((err as Error).message || 'An unknown error occurred').trim();\r\n\r\n // If the message doesn't already start with \"Error:\" then add a prefix\r\n if (!/^(error|internal error|warning)\\b/i.test(message)) {\r\n message = 'Error: ' + message;\r\n }\r\n\r\n console.error();\r\n console.error(colors.red(message));\r\n\r\n if (!process.exitCode) {\r\n process.exitCode = 1;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * This is similar to {@link CommandLineParser.execute}, except that execution errors\r\n * simply cause the promise to reject. It is the caller's responsibility to trap\r\n */\r\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\r\n try {\r\n if (this._executed) {\r\n // In the future we could allow the same parser to be invoked multiple times\r\n // with different arguments. We'll do that work as soon as someone encounters\r\n // a real world need for it.\r\n throw new Error('execute() was already called for this parser instance');\r\n }\r\n this._executed = true;\r\n\r\n this._validateDefinitions();\r\n\r\n if (!args) {\r\n // 0=node.exe, 1=script name\r\n args = process.argv.slice(2);\r\n }\r\n if (args.length === 0) {\r\n this._argumentParser.printHelp();\r\n return;\r\n }\r\n\r\n const data: ICommandLineParserData = this._argumentParser.parseArgs(args);\r\n\r\n this._processParsedData(data);\r\n\r\n for (const action of this._actions) {\r\n if (action.actionName === data.action) {\r\n this.selectedAction = action;\r\n action._processParsedData(data);\r\n break;\r\n }\r\n }\r\n if (this.actions.length > 0 && !this.selectedAction) {\r\n const actions: string[] = this.actions.map((x) => x.actionName);\r\n throw new Error(`An action must be specified (${actions.join(', ')})`);\r\n }\r\n\r\n return this.onExecute();\r\n } catch (err) {\r\n if (err instanceof CommandLineParserExitError) {\r\n if (!err.exitCode) {\r\n // non-error exit modeled using exception handling\r\n if (err.message) {\r\n console.log(err.message);\r\n }\r\n\r\n return;\r\n }\r\n }\r\n\r\n throw err;\r\n }\r\n }\r\n\r\n private _validateDefinitions(): void {\r\n if (this.remainder && this.actions.length > 0) {\r\n // This is apparently not supported by argparse\r\n throw new Error('defineCommandLineRemainder() cannot be called for a CommandLineParser with actions');\r\n }\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 return this._argumentParser;\r\n }\r\n\r\n /**\r\n * This hook allows the subclass to perform additional operations before or after\r\n * the chosen action is executed.\r\n */\r\n protected async onExecute(): Promise<void> {\r\n if (this.selectedAction) {\r\n await this.selectedAction._execute();\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAG3D,oDAA4B;AAG5B,iFAAsG;AACtG,6EAAgG;AAChG,+DAA0D;AAuB1D;;;;;;;;;GASG;AACH,MAAsB,iBAAkB,SAAQ,2DAA4B;IAgB1E,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QAJF,cAAS,GAAY,KAAK,CAAC;QAC3B,+BAA0B,GAAY,KAAK,CAAC;QAKlD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;QAE3D,IAAI,CAAC,eAAe,GAAG,IAAI,iDAAoB,CAAC;YAC9C,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;YAChC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe;YAC1C,MAAM,EAAE,gBAAM,CAAC,IAAI,CACjB,oDAAoD,IAAI,CAAC,QAAQ,CAAC,YAAY,eAAe,CAC9F;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,MAAyB;QACxC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC3B,IAAI,CAAC,iBAAiB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AAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;SACtC;IACH,CAAC;CACF;AAzND,8CAyNC","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';\nimport colors from 'colors';\n\nimport { CommandLineAction } from './CommandLineAction';\nimport { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider';\nimport { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError';\nimport { TabCompleteAction } from './TabCompletionAction';\n\n/**\n * Options for the {@link CommandLineParser} constructor.\n * @public\n */\nexport interface ICommandLineParserOptions {\n /**\n * The name of your tool when invoked from the command line\n */\n toolFilename: string;\n\n /**\n * General documentation that is included in the \"--help\" main page\n */\n toolDescription: string;\n\n /**\n * Set to true to auto-define a tab completion action. False by default.\n */\n enableTabCompletionAction?: boolean;\n}\n\n/**\n * The \"argparse\" library is a relatively advanced command-line parser with features such\n * as word-wrapping and intelligible error messages (that are lacking in other similar\n * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API\n * is awkward to use. The abstract base classes CommandLineParser and CommandLineAction\n * provide a wrapper for \"argparse\" that makes defining and consuming arguments quick\n * and simple, and enforces that appropriate documentation is provided for each parameter.\n *\n * @public\n */\nexport abstract class CommandLineParser extends CommandLineParameterProvider {\n /**\n * Reports which CommandLineAction was specified on the command line.\n * @remarks\n * The value will be assigned before onExecute() is invoked.\n */\n public selectedAction: CommandLineAction | undefined;\n\n private _argumentParser: argparse.ArgumentParser;\n private _actionsSubParser: argparse.SubParser | undefined;\n private _options: ICommandLineParserOptions;\n private _actions: CommandLineAction[];\n private _actionsByName: Map<string, CommandLineAction>;\n private _executed: boolean = false;\n private _tabCompleteActionWasAdded: boolean = false;\n\n public constructor(options: ICommandLineParserOptions) {\n super();\n\n this._options = options;\n this._actions = [];\n this._actionsByName = new Map<string, CommandLineAction>();\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: this._options.toolFilename,\n description: this._options.toolDescription,\n epilog: colors.bold(\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\n )\n });\n\n this.onDefineParameters();\n }\n\n /**\n * Returns the list of actions that were defined for this CommandLineParser object.\n */\n public get actions(): ReadonlyArray<CommandLineAction> {\n return this._actions;\n }\n\n /**\n * Defines a new action that can be used with the CommandLineParser instance.\n */\n public addAction(action: CommandLineAction): void {\n if (!this._actionsSubParser) {\n this._actionsSubParser = this._argumentParser.addSubparsers({\n metavar: '<command>',\n dest: 'action'\n });\n }\n\n action._buildParser(this._actionsSubParser);\n this._actions.push(action);\n this._actionsByName.set(action.actionName, action);\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * an exception is thrown.\n */\n public getAction(actionName: string): CommandLineAction {\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n if (!action) {\n throw new Error(`The action \"${actionName}\" was not defined`);\n }\n return action;\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * undefined is returned.\n */\n public tryGetAction(actionName: string): CommandLineAction | undefined {\n return this._actionsByName.get(actionName);\n }\n\n /**\n * The program entry point will call this method to begin parsing command-line arguments\n * and executing the corresponding action.\n *\n * @remarks\n * The returned promise will never reject: If an error occurs, it will be printed\n * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.\n * This simplifies the most common usage scenario where the program entry point doesn't\n * want to be involved with the command-line logic, and will discard the promise without\n * a then() or catch() block.\n *\n * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}\n * instead.\n *\n * @param args - the command-line arguments to be parsed; if omitted, then\n * the process.argv will be used\n */\n public async execute(args?: string[]): Promise<boolean> {\n if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {\n this.addAction(new TabCompleteAction(this.actions, this.parameters));\n this._tabCompleteActionWasAdded = true;\n }\n\n try {\n await this.executeWithoutErrorHandling(args);\n return true;\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n // executeWithoutErrorHandling() handles the successful cases,\n // so here we can assume err has a nonzero exit code\n if (err.message) {\n console.error(err.message);\n }\n if (!process.exitCode) {\n process.exitCode = err.exitCode;\n }\n } else {\n let message: string = ((err as Error).message || 'An unknown error occurred').trim();\n\n // If the message doesn't already start with \"Error:\" then add a prefix\n if (!/^(error|internal error|warning)\\b/i.test(message)) {\n message = 'Error: ' + message;\n }\n\n console.error();\n console.error(colors.red(message));\n\n if (!process.exitCode) {\n process.exitCode = 1;\n }\n }\n\n return false;\n }\n }\n\n /**\n * This is similar to {@link CommandLineParser.execute}, except that execution errors\n * simply cause the promise to reject. It is the caller's responsibility to trap\n */\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\n try {\n if (this._executed) {\n // In the future we could allow the same parser to be invoked multiple times\n // with different arguments. We'll do that work as soon as someone encounters\n // a real world need for it.\n throw new Error('execute() was already called for this parser instance');\n }\n this._executed = true;\n\n this._validateDefinitions();\n\n if (!args) {\n // 0=node.exe, 1=script name\n args = process.argv.slice(2);\n }\n if (args.length === 0) {\n this._argumentParser.printHelp();\n return;\n }\n\n const data: ICommandLineParserData = this._argumentParser.parseArgs(args);\n\n this._processParsedData(data);\n\n for (const action of this._actions) {\n if (action.actionName === data.action) {\n this.selectedAction = action;\n action._processParsedData(data);\n break;\n }\n }\n if (this.actions.length > 0 && !this.selectedAction) {\n const actions: string[] = this.actions.map((x) => x.actionName);\n throw new Error(`An action must be specified (${actions.join(', ')})`);\n }\n\n return this.onExecute();\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n if (!err.exitCode) {\n // non-error exit modeled using exception handling\n if (err.message) {\n console.log(err.message);\n }\n\n return;\n }\n }\n\n throw err;\n }\n }\n\n private _validateDefinitions(): void {\n if (this.remainder && this.actions.length > 0) {\n // This is apparently not supported by argparse\n throw new Error('defineCommandLineRemainder() cannot be called for a CommandLineParser with actions');\n }\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider._getArgumentParser}\n * @internal\n */\n protected _getArgumentParser(): argparse.ArgumentParser {\n // override\n return this._argumentParser;\n }\n\n /**\n * This hook allows the subclass to perform additional operations before or after\n * the chosen action is executed.\n */\n protected async onExecute(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._execute();\n }\n }\n}\n"]}
@@ -27,7 +27,7 @@ class CommandLineParserExitError extends Error {
27
27
  constructor(exitCode, message) {
28
28
  super(message);
29
29
  // Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc
30
- // https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
30
+ // https://github.com/microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
31
31
  //
32
32
  // Note: the prototype must also be set on any classes which extend this one
33
33
  this.__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -1 +1 @@
1
- {"version":3,"file":"CommandLineParserExitError.js","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,MAAa,0BAA2B,SAAQ,KAAK;IAGnD,YAAmB,QAAgB,EAAE,OAAe;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,sGAAsG;QACtG,+IAA+I;QAC/I,EAAE;QACF,4EAA4E;QAC3E,IAAY,CAAC,SAAS,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC,yDAAyD;QAEzH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAdD,gEAcC;AAED,MAAa,oBAAqB,SAAQ,QAAQ,CAAC,cAAc;IACxD,IAAI,CAAC,MAAc,EAAE,OAAe;QACzC,WAAW;QACX,MAAM,IAAI,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,GAAmB;QAC9B,WAAW;QACX,kFAAkF;QAClF,IAAI,GAAG,YAAY,0BAA0B,EAAE;YAC7C,MAAM,GAAG,CAAC;SACX;QAED,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AAfD,oDAeC","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\nexport class CommandLineParserExitError extends Error {\r\n public readonly exitCode: number;\r\n\r\n public constructor(exitCode: number, message: string) {\r\n super(message);\r\n\r\n // Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc\r\n // https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\r\n //\r\n // Note: the prototype must also be set on any classes which extend this one\r\n (this as any).__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any\r\n\r\n this.exitCode = exitCode;\r\n }\r\n}\r\n\r\nexport class CustomArgumentParser extends argparse.ArgumentParser {\r\n public exit(status: number, message: string): void {\r\n // override\r\n throw new CommandLineParserExitError(status, message);\r\n }\r\n\r\n public error(err: Error | string): void {\r\n // override\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\r\n super.error(err);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"CommandLineParserExitError.js","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,MAAa,0BAA2B,SAAQ,KAAK;IAGnD,YAAmB,QAAgB,EAAE,OAAe;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,sGAAsG;QACtG,6IAA6I;QAC7I,EAAE;QACF,4EAA4E;QAC3E,IAAY,CAAC,SAAS,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC,yDAAyD;QAEzH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAdD,gEAcC;AAED,MAAa,oBAAqB,SAAQ,QAAQ,CAAC,cAAc;IACxD,IAAI,CAAC,MAAc,EAAE,OAAe;QACzC,WAAW;QACX,MAAM,IAAI,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,GAAmB;QAC9B,WAAW;QACX,kFAAkF;QAClF,IAAI,GAAG,YAAY,0BAA0B,EAAE;YAC7C,MAAM,GAAG,CAAC;SACX;QAED,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF;AAfD,oDAeC","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\nexport class CommandLineParserExitError extends Error {\n public readonly exitCode: number;\n\n public constructor(exitCode: number, message: string) {\n super(message);\n\n // Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc\n // https://github.com/microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n //\n // Note: the prototype must also be set on any classes which extend this one\n (this as any).__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n this.exitCode = exitCode;\n }\n}\n\nexport class CustomArgumentParser extends argparse.ArgumentParser {\n public exit(status: number, message: string): void {\n // override\n throw new CommandLineParserExitError(status, message);\n }\n\n public error(err: Error | string): void {\n // override\n // Ensure the ParserExitError bubbles up to the top without any special processing\n if (err instanceof CommandLineParserExitError) {\n throw err;\n }\n\n super.error(err);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAAwD;AAExD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,qCAAiB;IACnD,kBAAkB;QAC1B,WAAW;QACX,iCAAiC;IACnC,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,WAAW;QACX,iCAAiC;IACnC,CAAC;CACF;AAVD,4DAUC","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 { CommandLineAction } from './CommandLineAction';\r\n\r\n/**\r\n * @public\r\n */\r\nexport class DynamicCommandLineAction extends CommandLineAction {\r\n protected onDefineParameters(): void {\r\n // abstract\r\n // (handled by the external code)\r\n }\r\n\r\n protected async onExecute(): Promise<void> {\r\n // abstract\r\n // (handled by the external code)\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"DynamicCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAAwD;AAExD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,qCAAiB;IACnD,kBAAkB;QAC1B,WAAW;QACX,iCAAiC;IACnC,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,WAAW;QACX,iCAAiC;IACnC,CAAC;CACF;AAVD,4DAUC","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 { CommandLineAction } from './CommandLineAction';\n\n/**\n * @public\n */\nexport class DynamicCommandLineAction extends CommandLineAction {\n protected onDefineParameters(): void {\n // abstract\n // (handled by the external code)\n }\n\n protected async onExecute(): Promise<void> {\n // abstract\n // (handled by the external code)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicCommandLineParser.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAAwD;AAExD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,qCAAiB;IACnD,kBAAkB;QAC1B,WAAW;IACb,CAAC;CACF;AAJD,4DAIC","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 { CommandLineParser } from './CommandLineParser';\r\n\r\n/**\r\n * @public\r\n */\r\nexport class DynamicCommandLineParser extends CommandLineParser {\r\n protected onDefineParameters(): void {\r\n // abstract\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"DynamicCommandLineParser.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAAwD;AAExD;;GAEG;AACH,MAAa,wBAAyB,SAAQ,qCAAiB;IACnD,kBAAkB;QAC1B,WAAW;IACb,CAAC;CACF;AAJD,4DAIC","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 { CommandLineParser } from './CommandLineParser';\n\n/**\n * @public\n */\nexport class DynamicCommandLineParser extends CommandLineParser {\n protected onDefineParameters(): void {\n // abstract\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"TabCompletionAction.d.ts","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,oBAAoB,EAErB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAOxD,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,wBAAwB,CAA8B;IAC9D,OAAO,CAAC,kBAAkB,CAA+B;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiD;IAC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