@rushstack/ts-command-line 5.2.0 → 5.3.1

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 (154) hide show
  1. package/CHANGELOG.json +40 -0
  2. package/CHANGELOG.md +15 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/lib-esm/CommandLineHelper.js +19 -0
  5. package/lib-esm/CommandLineHelper.js.map +1 -0
  6. package/lib-esm/Constants.js +16 -0
  7. package/lib-esm/Constants.js.map +1 -0
  8. package/lib-esm/TypeUuidLite.js +28 -0
  9. package/lib-esm/TypeUuidLite.js.map +1 -0
  10. package/lib-esm/escapeSprintf.js +9 -0
  11. package/lib-esm/escapeSprintf.js.map +1 -0
  12. package/lib-esm/index.js +26 -0
  13. package/lib-esm/index.js.map +1 -0
  14. package/lib-esm/parameters/BaseClasses.js +163 -0
  15. package/lib-esm/parameters/BaseClasses.js.map +1 -0
  16. package/lib-esm/parameters/CommandLineChoiceListParameter.js +79 -0
  17. package/lib-esm/parameters/CommandLineChoiceListParameter.js.map +1 -0
  18. package/lib-esm/parameters/CommandLineChoiceParameter.js +90 -0
  19. package/lib-esm/parameters/CommandLineChoiceParameter.js.map +1 -0
  20. package/lib-esm/parameters/CommandLineDefinition.js +4 -0
  21. package/lib-esm/parameters/CommandLineDefinition.js.map +1 -0
  22. package/lib-esm/parameters/CommandLineFlagParameter.js +65 -0
  23. package/lib-esm/parameters/CommandLineFlagParameter.js.map +1 -0
  24. package/lib-esm/parameters/CommandLineIntegerListParameter.js +75 -0
  25. package/lib-esm/parameters/CommandLineIntegerListParameter.js.map +1 -0
  26. package/lib-esm/parameters/CommandLineIntegerParameter.js +79 -0
  27. package/lib-esm/parameters/CommandLineIntegerParameter.js.map +1 -0
  28. package/lib-esm/parameters/CommandLineRemainder.js +43 -0
  29. package/lib-esm/parameters/CommandLineRemainder.js.map +1 -0
  30. package/lib-esm/parameters/CommandLineStringListParameter.js +66 -0
  31. package/lib-esm/parameters/CommandLineStringListParameter.js.map +1 -0
  32. package/lib-esm/parameters/CommandLineStringParameter.js +78 -0
  33. package/lib-esm/parameters/CommandLineStringParameter.js.map +1 -0
  34. package/lib-esm/parameters/EnvironmentVariableParser.js +47 -0
  35. package/lib-esm/parameters/EnvironmentVariableParser.js.map +1 -0
  36. package/lib-esm/providers/AliasCommandLineAction.js +131 -0
  37. package/lib-esm/providers/AliasCommandLineAction.js.map +1 -0
  38. package/lib-esm/providers/CommandLineAction.js +76 -0
  39. package/lib-esm/providers/CommandLineAction.js.map +1 -0
  40. package/lib-esm/providers/CommandLineParameterProvider.js +671 -0
  41. package/lib-esm/providers/CommandLineParameterProvider.js.map +1 -0
  42. package/lib-esm/providers/CommandLineParser.js +262 -0
  43. package/lib-esm/providers/CommandLineParser.js.map +1 -0
  44. package/lib-esm/providers/CommandLineParserExitError.js +27 -0
  45. package/lib-esm/providers/CommandLineParserExitError.js.map +1 -0
  46. package/lib-esm/providers/DynamicCommandLineAction.js +13 -0
  47. package/lib-esm/providers/DynamicCommandLineAction.js.map +1 -0
  48. package/lib-esm/providers/DynamicCommandLineParser.js +9 -0
  49. package/lib-esm/providers/DynamicCommandLineParser.js.map +1 -0
  50. package/lib-esm/providers/ScopedCommandLineAction.js +197 -0
  51. package/lib-esm/providers/ScopedCommandLineAction.js.map +1 -0
  52. package/lib-esm/providers/TabCompletionAction.js +166 -0
  53. package/lib-esm/providers/TabCompletionAction.js.map +1 -0
  54. package/package.json +31 -7
  55. /package/{lib → lib-commonjs}/CommandLineHelper.js +0 -0
  56. /package/{lib → lib-commonjs}/CommandLineHelper.js.map +0 -0
  57. /package/{lib → lib-commonjs}/Constants.js +0 -0
  58. /package/{lib → lib-commonjs}/Constants.js.map +0 -0
  59. /package/{lib → lib-commonjs}/TypeUuidLite.js +0 -0
  60. /package/{lib → lib-commonjs}/TypeUuidLite.js.map +0 -0
  61. /package/{lib → lib-commonjs}/escapeSprintf.js +0 -0
  62. /package/{lib → lib-commonjs}/escapeSprintf.js.map +0 -0
  63. /package/{lib → lib-commonjs}/index.js +0 -0
  64. /package/{lib → lib-commonjs}/index.js.map +0 -0
  65. /package/{lib → lib-commonjs}/parameters/BaseClasses.js +0 -0
  66. /package/{lib → lib-commonjs}/parameters/BaseClasses.js.map +0 -0
  67. /package/{lib → lib-commonjs}/parameters/CommandLineChoiceListParameter.js +0 -0
  68. /package/{lib → lib-commonjs}/parameters/CommandLineChoiceListParameter.js.map +0 -0
  69. /package/{lib → lib-commonjs}/parameters/CommandLineChoiceParameter.js +0 -0
  70. /package/{lib → lib-commonjs}/parameters/CommandLineChoiceParameter.js.map +0 -0
  71. /package/{lib → lib-commonjs}/parameters/CommandLineDefinition.js +0 -0
  72. /package/{lib → lib-commonjs}/parameters/CommandLineDefinition.js.map +0 -0
  73. /package/{lib → lib-commonjs}/parameters/CommandLineFlagParameter.js +0 -0
  74. /package/{lib → lib-commonjs}/parameters/CommandLineFlagParameter.js.map +0 -0
  75. /package/{lib → lib-commonjs}/parameters/CommandLineIntegerListParameter.js +0 -0
  76. /package/{lib → lib-commonjs}/parameters/CommandLineIntegerListParameter.js.map +0 -0
  77. /package/{lib → lib-commonjs}/parameters/CommandLineIntegerParameter.js +0 -0
  78. /package/{lib → lib-commonjs}/parameters/CommandLineIntegerParameter.js.map +0 -0
  79. /package/{lib → lib-commonjs}/parameters/CommandLineRemainder.js +0 -0
  80. /package/{lib → lib-commonjs}/parameters/CommandLineRemainder.js.map +0 -0
  81. /package/{lib → lib-commonjs}/parameters/CommandLineStringListParameter.js +0 -0
  82. /package/{lib → lib-commonjs}/parameters/CommandLineStringListParameter.js.map +0 -0
  83. /package/{lib → lib-commonjs}/parameters/CommandLineStringParameter.js +0 -0
  84. /package/{lib → lib-commonjs}/parameters/CommandLineStringParameter.js.map +0 -0
  85. /package/{lib → lib-commonjs}/parameters/EnvironmentVariableParser.js +0 -0
  86. /package/{lib → lib-commonjs}/parameters/EnvironmentVariableParser.js.map +0 -0
  87. /package/{lib → lib-commonjs}/providers/AliasCommandLineAction.js +0 -0
  88. /package/{lib → lib-commonjs}/providers/AliasCommandLineAction.js.map +0 -0
  89. /package/{lib → lib-commonjs}/providers/CommandLineAction.js +0 -0
  90. /package/{lib → lib-commonjs}/providers/CommandLineAction.js.map +0 -0
  91. /package/{lib → lib-commonjs}/providers/CommandLineParameterProvider.js +0 -0
  92. /package/{lib → lib-commonjs}/providers/CommandLineParameterProvider.js.map +0 -0
  93. /package/{lib → lib-commonjs}/providers/CommandLineParser.js +0 -0
  94. /package/{lib → lib-commonjs}/providers/CommandLineParser.js.map +0 -0
  95. /package/{lib → lib-commonjs}/providers/CommandLineParserExitError.js +0 -0
  96. /package/{lib → lib-commonjs}/providers/CommandLineParserExitError.js.map +0 -0
  97. /package/{lib → lib-commonjs}/providers/DynamicCommandLineAction.js +0 -0
  98. /package/{lib → lib-commonjs}/providers/DynamicCommandLineAction.js.map +0 -0
  99. /package/{lib → lib-commonjs}/providers/DynamicCommandLineParser.js +0 -0
  100. /package/{lib → lib-commonjs}/providers/DynamicCommandLineParser.js.map +0 -0
  101. /package/{lib → lib-commonjs}/providers/ScopedCommandLineAction.js +0 -0
  102. /package/{lib → lib-commonjs}/providers/ScopedCommandLineAction.js.map +0 -0
  103. /package/{lib → lib-commonjs}/providers/TabCompletionAction.js +0 -0
  104. /package/{lib → lib-commonjs}/providers/TabCompletionAction.js.map +0 -0
  105. /package/{lib → lib-dts}/CommandLineHelper.d.ts +0 -0
  106. /package/{lib → lib-dts}/CommandLineHelper.d.ts.map +0 -0
  107. /package/{lib → lib-dts}/Constants.d.ts +0 -0
  108. /package/{lib → lib-dts}/Constants.d.ts.map +0 -0
  109. /package/{lib → lib-dts}/TypeUuidLite.d.ts +0 -0
  110. /package/{lib → lib-dts}/TypeUuidLite.d.ts.map +0 -0
  111. /package/{lib → lib-dts}/escapeSprintf.d.ts +0 -0
  112. /package/{lib → lib-dts}/escapeSprintf.d.ts.map +0 -0
  113. /package/{lib → lib-dts}/index.d.ts +0 -0
  114. /package/{lib → lib-dts}/index.d.ts.map +0 -0
  115. /package/{lib → lib-dts}/parameters/BaseClasses.d.ts +0 -0
  116. /package/{lib → lib-dts}/parameters/BaseClasses.d.ts.map +0 -0
  117. /package/{lib → lib-dts}/parameters/CommandLineChoiceListParameter.d.ts +0 -0
  118. /package/{lib → lib-dts}/parameters/CommandLineChoiceListParameter.d.ts.map +0 -0
  119. /package/{lib → lib-dts}/parameters/CommandLineChoiceParameter.d.ts +0 -0
  120. /package/{lib → lib-dts}/parameters/CommandLineChoiceParameter.d.ts.map +0 -0
  121. /package/{lib → lib-dts}/parameters/CommandLineDefinition.d.ts +0 -0
  122. /package/{lib → lib-dts}/parameters/CommandLineDefinition.d.ts.map +0 -0
  123. /package/{lib → lib-dts}/parameters/CommandLineFlagParameter.d.ts +0 -0
  124. /package/{lib → lib-dts}/parameters/CommandLineFlagParameter.d.ts.map +0 -0
  125. /package/{lib → lib-dts}/parameters/CommandLineIntegerListParameter.d.ts +0 -0
  126. /package/{lib → lib-dts}/parameters/CommandLineIntegerListParameter.d.ts.map +0 -0
  127. /package/{lib → lib-dts}/parameters/CommandLineIntegerParameter.d.ts +0 -0
  128. /package/{lib → lib-dts}/parameters/CommandLineIntegerParameter.d.ts.map +0 -0
  129. /package/{lib → lib-dts}/parameters/CommandLineRemainder.d.ts +0 -0
  130. /package/{lib → lib-dts}/parameters/CommandLineRemainder.d.ts.map +0 -0
  131. /package/{lib → lib-dts}/parameters/CommandLineStringListParameter.d.ts +0 -0
  132. /package/{lib → lib-dts}/parameters/CommandLineStringListParameter.d.ts.map +0 -0
  133. /package/{lib → lib-dts}/parameters/CommandLineStringParameter.d.ts +0 -0
  134. /package/{lib → lib-dts}/parameters/CommandLineStringParameter.d.ts.map +0 -0
  135. /package/{lib → lib-dts}/parameters/EnvironmentVariableParser.d.ts +0 -0
  136. /package/{lib → lib-dts}/parameters/EnvironmentVariableParser.d.ts.map +0 -0
  137. /package/{lib → lib-dts}/providers/AliasCommandLineAction.d.ts +0 -0
  138. /package/{lib → lib-dts}/providers/AliasCommandLineAction.d.ts.map +0 -0
  139. /package/{lib → lib-dts}/providers/CommandLineAction.d.ts +0 -0
  140. /package/{lib → lib-dts}/providers/CommandLineAction.d.ts.map +0 -0
  141. /package/{lib → lib-dts}/providers/CommandLineParameterProvider.d.ts +0 -0
  142. /package/{lib → lib-dts}/providers/CommandLineParameterProvider.d.ts.map +0 -0
  143. /package/{lib → lib-dts}/providers/CommandLineParser.d.ts +0 -0
  144. /package/{lib → lib-dts}/providers/CommandLineParser.d.ts.map +0 -0
  145. /package/{lib → lib-dts}/providers/CommandLineParserExitError.d.ts +0 -0
  146. /package/{lib → lib-dts}/providers/CommandLineParserExitError.d.ts.map +0 -0
  147. /package/{lib → lib-dts}/providers/DynamicCommandLineAction.d.ts +0 -0
  148. /package/{lib → lib-dts}/providers/DynamicCommandLineAction.d.ts.map +0 -0
  149. /package/{lib → lib-dts}/providers/DynamicCommandLineParser.d.ts +0 -0
  150. /package/{lib → lib-dts}/providers/DynamicCommandLineParser.d.ts.map +0 -0
  151. /package/{lib → lib-dts}/providers/ScopedCommandLineAction.d.ts +0 -0
  152. /package/{lib → lib-dts}/providers/ScopedCommandLineAction.d.ts.map +0 -0
  153. /package/{lib → lib-dts}/providers/TabCompletionAction.d.ts +0 -0
  154. /package/{lib → lib-dts}/providers/TabCompletionAction.d.ts.map +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAarC,OAAO,EAGL,wBAAwB,EAEzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAE3B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,8CAA8C,CAAC;AAC9F,OAAO,EACL,2BA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,CAAC,YAAY,EAAE;YACtC,8DAA8D;YAC9D,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,gBAAgB,WAAW,CAAC;QAE/D,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QACpC,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,GAAG,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;;AA55Bc,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';\n\nimport type {\n ICommandLineChoiceDefinition,\n ICommandLineChoiceListDefinition,\n ICommandLineIntegerDefinition,\n ICommandLineIntegerListDefinition,\n ICommandLineFlagDefinition,\n ICommandLineStringDefinition,\n ICommandLineStringListDefinition,\n ICommandLineRemainderDefinition\n} from '../parameters/CommandLineDefinition';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\nimport {\n type CommandLineParameterBase,\n type CommandLineParameterWithArgument,\n CommandLineParameterKind,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport {\n CommandLineChoiceParameter,\n type IRequiredCommandLineChoiceParameter\n} from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineChoiceListParameter } from '../parameters/CommandLineChoiceListParameter';\nimport {\n CommandLineIntegerParameter,\n type IRequiredCommandLineIntegerParameter\n} from '../parameters/CommandLineIntegerParameter';\nimport { CommandLineIntegerListParameter } from '../parameters/CommandLineIntegerListParameter';\nimport { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter';\nimport {\n CommandLineStringParameter,\n type IRequiredCommandLineStringParameter\n} from '../parameters/CommandLineStringParameter';\nimport { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter';\nimport { CommandLineRemainder } from '../parameters/CommandLineRemainder';\nimport { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\nimport { escapeSprintf } from '../escapeSprintf';\n\n/**\n * The result containing the parsed parameter long name and scope. Returned when calling\n * {@link CommandLineParameterProvider.parseScopedLongName}.\n *\n * @public\n */\nexport interface IScopedLongNameParseResult {\n /**\n * The long name parsed from the scoped long name, e.g. \"--my-scope:my-parameter\" -\\> \"--my-parameter\"\n */\n longName: string;\n\n /**\n * The scope parsed from the scoped long name or undefined if no scope was found,\n * e.g. \"--my-scope:my-parameter\" -\\> \"my-scope\"\n */\n scope: string | undefined;\n}\n\n/**\n * An object containing the state of the\n *\n * @internal\n */\nexport interface IRegisterDefinedParametersState {\n /**\n * A set of all defined parameter names registered by parent {@link CommandLineParameterProvider}\n * objects.\n */\n parentParameterNames: Set<string>;\n}\n\n/**\n * This is the argparse result data object\n * @internal\n */\nexport interface ICommandLineParserData {\n action: string;\n aliasAction?: string;\n aliasDocumentation?: string;\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nconst SCOPE_GROUP_NAME: string = 'scope';\nconst LONG_NAME_GROUP_NAME: string = 'longName';\nconst POSSIBLY_SCOPED_LONG_NAME_REGEXP: RegExp =\n /^--((?<scope>[a-z0-9]+(-[a-z0-9]+)*):)?(?<longName>[a-z0-9]+((-[a-z0-9]+)+)?)$/;\n\ninterface IExtendedArgumentGroup extends argparse.ArgumentGroup {\n // The types are incorrect - this function returns the constructed argument\n // object, which looks like the argument options type.\n addArgument(nameOrFlags: string | string[], options: argparse.ArgumentOptions): argparse.ArgumentOptions;\n}\n\ninterface IExtendedArgumentParser extends argparse.ArgumentParser {\n // This function throws\n error(message: string): never;\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 /** @internal */\n public readonly _ambiguousParameterParserKeysByName: Map<string, string>;\n /** @internal */\n protected readonly _registeredParameterParserKeysByName: Map<string, string>;\n\n private readonly _parameters: CommandLineParameter[];\n private readonly _parametersByLongName: Map<string, CommandLineParameter[]>;\n private readonly _parametersByShortName: Map<string, CommandLineParameter[]>;\n private readonly _parameterGroupsByName: Map<\n string | typeof SCOPING_PARAMETER_GROUP,\n argparse.ArgumentGroup\n >;\n private _parametersHaveBeenRegistered: boolean;\n private _parametersHaveBeenProcessed: 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();\n this._parametersByShortName = new Map();\n this._parameterGroupsByName = new Map();\n this._ambiguousParameterParserKeysByName = new Map();\n this._registeredParameterParserKeysByName = new Map();\n this._parametersHaveBeenRegistered = false;\n this._parametersHaveBeenProcessed = 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._parametersHaveBeenProcessed;\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<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & {\n required: false | undefined;\n defaultValue: undefined;\n }\n ): CommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { required: true }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice> & { defaultValue: TChoice }\n ): IRequiredCommandLineChoiceParameter<TChoice>;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineChoiceParameter:1)}\n */\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice>;\n public defineChoiceParameter<TChoice extends string = string>(\n definition: ICommandLineChoiceDefinition<TChoice>\n ): CommandLineChoiceParameter<TChoice> {\n const parameter: CommandLineChoiceParameter<TChoice> = 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, parameterScope?: string): CommandLineChoiceParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Choice, parameterScope);\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<TChoice extends string = string>(\n definition: ICommandLineChoiceListDefinition<TChoice>\n ): CommandLineChoiceListParameter<TChoice> {\n const parameter: CommandLineChoiceListParameter<TChoice> = 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(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineChoiceListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.ChoiceList, parameterScope);\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, parameterScope?: string): CommandLineFlagParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Flag, parameterScope);\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(\n definition: ICommandLineIntegerDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { required: true }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(\n definition: ICommandLineIntegerDefinition & { defaultValue: number }\n ): IRequiredCommandLineIntegerParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineIntegerParameter:1)}\n */\n public defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter;\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(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.Integer, parameterScope);\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(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineIntegerListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.IntegerList, parameterScope);\n }\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(\n definition: ICommandLineStringDefinition & { required: false | undefined; defaultValue: undefined }\n ): CommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { required: true }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(\n definition: ICommandLineStringDefinition & { defaultValue: string }\n ): IRequiredCommandLineStringParameter;\n /**\n * {@inheritdoc CommandLineParameterProvider.(defineStringParameter:1)}\n */\n public defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter;\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, parameterScope?: string): CommandLineStringParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.String, parameterScope);\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 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(\n parameterLongName: string,\n parameterScope?: string\n ): CommandLineStringListParameter {\n return this._getParameter(parameterLongName, CommandLineParameterKind.StringList, parameterScope);\n }\n\n /**\n * Generates the command-line help text.\n */\n public renderHelpText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatHelp();\n }\n\n /**\n * Generates the command-line usage text.\n */\n public renderUsageText(): string {\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n return this._getArgumentParser().formatUsage();\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 const parameterName: string = parameter.scopedLongName || parameter.longName;\n switch (parameter.kind) {\n case CommandLineParameterKind.Flag:\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.String:\n case CommandLineParameterKind.Integer:\n parameterMap[parameterName] = 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[parameterName] = arrayValue ? arrayValue.join(',') : '';\n break;\n }\n }\n return parameterMap;\n }\n\n /**\n * Returns an object with the parsed scope (if present) and the long name of the parameter.\n */\n public parseScopedLongName(scopedLongName: string): IScopedLongNameParseResult {\n const result: RegExpExecArray | null = POSSIBLY_SCOPED_LONG_NAME_REGEXP.exec(scopedLongName);\n if (!result || !result.groups) {\n throw new Error(`The parameter long name \"${scopedLongName}\" is not valid.`);\n }\n return {\n longName: `--${result.groups[LONG_NAME_GROUP_NAME]}`,\n scope: result.groups[SCOPE_GROUP_NAME]\n };\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n if (this._parametersHaveBeenRegistered) {\n // We prevent new parameters from being defined after the first call to _registerDefinedParameters,\n // so we can already ensure that all parameters were registered.\n return;\n }\n\n // First, loop through all parameters with short names. If there are any duplicates, disable the short names\n // since we can't prefix scopes to short names in order to deduplicate them. The duplicate short names will\n // be reported as errors if the user attempts to use them.\n const parametersWithDuplicateShortNames: Set<CommandLineParameterBase> = new Set();\n for (const [shortName, shortNameParameters] of this._parametersByShortName.entries()) {\n if (shortNameParameters.length > 1) {\n for (const parameter of shortNameParameters) {\n this._defineAmbiguousParameter(shortName);\n parametersWithDuplicateShortNames.add(parameter);\n }\n }\n }\n\n // Then, loop through all parameters and register them. If there are any duplicates, ensure that they have\n // provided a scope and register them with the scope. The duplicate long names will be reported as an error\n // if the user attempts to use them.\n for (const longNameParameters of this._parametersByLongName.values()) {\n const useScopedLongName: boolean = longNameParameters.length > 1;\n for (const parameter of longNameParameters) {\n if (useScopedLongName) {\n if (!parameter.parameterScope) {\n throw new Error(\n `The parameter \"${parameter.longName}\" is defined multiple times with the same long name. ` +\n 'Parameters with the same long name must define a scope.'\n );\n }\n this._defineAmbiguousParameter(parameter.longName);\n }\n\n const ignoreShortName: boolean = parametersWithDuplicateShortNames.has(parameter);\n this._registerParameter(parameter, useScopedLongName, ignoreShortName);\n }\n }\n\n // Register the existing parameters as ambiguous parameters. These are generally provided by the\n // parent action.\n const { parentParameterNames } = state;\n for (const parentParameterName of parentParameterNames) {\n this._defineAmbiguousParameter(parentParameterName);\n }\n\n // We also need to loop through the defined ambiguous parameters and register them. These will be reported\n // as errors if the user attempts to use them.\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n // Only register the ambiguous parameter if it hasn't already been registered. We will still handle these\n // already-registered parameters as ambiguous, but by avoiding registering again, we will defer errors\n // until the user actually attempts to use the parameter.\n if (!this._registeredParameterParserKeysByName.has(ambiguousParameterName)) {\n this._registerAmbiguousParameter(ambiguousParameterName, parserKey);\n }\n }\n\n // Need to add the remainder parameter last\n if (this._remainder) {\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\n this._parametersHaveBeenRegistered = true;\n }\n\n /**\n * Retrieves the argparse object.\n * @internal\n */\n protected abstract _getArgumentParser(): argparse.ArgumentParser;\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _preParse(): void {\n for (const parameter of this._parameters) {\n parameter._preParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync} before `printUsage` is called\n * @internal\n */\n public _postParse(): void {\n for (const parameter of this._parameters) {\n parameter._postParse?.();\n }\n }\n\n /**\n * This is called internally by {@link CommandLineParser.executeAsync}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n if (!this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have not been registered');\n }\n\n if (this._parametersHaveBeenProcessed) {\n throw new Error('Command Line Parser Data was already processed');\n }\n\n // Search for any ambiguous parameters and throw an error if any are found\n for (const [parameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n if (data[parserKey]) {\n // When the parser key matches the actually registered parameter, we know that this is an ambiguous\n // parameter sourced from the parent action or tool\n if (this._registeredParameterParserKeysByName.get(parameterName) === parserKey) {\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n\n // Determine if the ambiguous parameter is a short name or a long name, since the process of finding\n // the non-ambiguous name is different for each.\n const duplicateShortNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByShortName.get(parameterName);\n if (duplicateShortNameParameters) {\n // We also need to make sure we get the non-ambiguous long name for the parameter, since it is\n // possible for that the long name is ambiguous as well.\n const nonAmbiguousLongNames: string[] = [];\n for (const parameter of duplicateShortNameParameters) {\n const matchingLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameter.longName);\n if (!matchingLongNameParameters?.length) {\n // This should never happen\n throw new Error(\n `Unable to find long name parameters for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n // If there is more than one matching long name parameter, then we know that we need to use the\n // scoped long name for the parameter. The scoped long name should always be provided.\n if (matchingLongNameParameters.length > 1) {\n if (!parameter.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous short name parameter \"${parameterName}\".`\n );\n }\n nonAmbiguousLongNames.push(parameter.scopedLongName);\n } else {\n nonAmbiguousLongNames.push(parameter.longName);\n }\n }\n\n // Throw an error including the non-ambiguous long names for the parameters that have the ambiguous\n // short name, ex.\n // Error: Ambiguous option \"-p\" could match \"--param1\", \"--param2\"\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n const duplicateLongNameParameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterName);\n if (duplicateLongNameParameters) {\n const nonAmbiguousLongNames: string[] = duplicateLongNameParameters.map(\n (p: CommandLineParameterBase) => {\n // The scoped long name should always be provided\n if (!p.scopedLongName) {\n // This should never happen\n throw new Error(\n `Unable to find scoped long name for ambiguous long name parameter \"${parameterName}\".`\n );\n }\n return p.scopedLongName;\n }\n );\n\n // Throw an error including the non-ambiguous scoped long names for the parameters that have the\n // ambiguous long name, ex.\n // Error: Ambiguous option: \"--param\" could match --scope1:param, --scope2:param\n this._throwParserExitError(\n parserOptions,\n data,\n 1,\n `Ambiguous option: \"${parameterName}\" could match ${nonAmbiguousLongNames.join(', ')}.`\n );\n }\n\n // This shouldn't happen, but we also shouldn't allow the user to use the ambiguous parameter\n this._throwParserExitError(parserOptions, data, 1, `Ambiguous option: \"${parameterName}\".`);\n }\n }\n\n // Fill in the values for the parameters\n for (const parameter of this._parameters) {\n const value: unknown = data[parameter._parserKey!];\n parameter._setValue(value);\n parameter._validateValue?.();\n }\n\n if (this.remainder) {\n this.remainder._setValue(data[argparse.Const.REMAINDER]);\n }\n\n this._parametersHaveBeenProcessed = true;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Generate and set the parser key at definition time\n parameter._parserKey = this._generateKey();\n\n this._parameters.push(parameter);\n\n // Collect all parameters with the same long name. We will perform conflict resolution at registration.\n let longNameParameters: CommandLineParameter[] | undefined = this._parametersByLongName.get(\n parameter.longName\n );\n if (!longNameParameters) {\n longNameParameters = [];\n this._parametersByLongName.set(parameter.longName, longNameParameters);\n }\n longNameParameters.push(parameter);\n\n // Collect all parameters with the same short name. We will perform conflict resolution at registration.\n if (parameter.shortName) {\n let shortNameParameters: CommandLineParameter[] | undefined = this._parametersByShortName.get(\n parameter.shortName\n );\n if (!shortNameParameters) {\n shortNameParameters = [];\n this._parametersByShortName.set(parameter.shortName, shortNameParameters);\n }\n shortNameParameters.push(parameter);\n }\n }\n\n /** @internal */\n protected _defineAmbiguousParameter(name: string): string {\n if (this._parametersHaveBeenRegistered) {\n throw new Error('Parameters have already been registered for this provider');\n }\n\n // Only generate a new parser key if the ambiguous parameter hasn't been defined yet,\n // either as an existing parameter or as another ambiguous parameter\n let existingParserKey: string | undefined =\n this._registeredParameterParserKeysByName.get(name) ||\n this._ambiguousParameterParserKeysByName.get(name);\n if (!existingParserKey) {\n existingParserKey = this._generateKey();\n }\n\n this._ambiguousParameterParserKeysByName.set(name, existingParserKey);\n return existingParserKey;\n }\n\n /** @internal */\n protected _registerParameter(\n parameter: CommandLineParameter,\n useScopedLongName: boolean,\n ignoreShortName: boolean\n ): void {\n const {\n shortName,\n longName,\n scopedLongName,\n description,\n kind,\n required,\n environmentVariable,\n parameterGroup,\n undocumentedSynonyms,\n _parserKey: parserKey\n } = parameter;\n\n const names: string[] = [];\n if (shortName && !ignoreShortName) {\n names.push(shortName);\n }\n\n // Use the original long name unless otherwise requested\n if (!useScopedLongName) {\n names.push(longName);\n }\n\n // Add the scoped long name if it exists\n if (scopedLongName) {\n names.push(scopedLongName);\n }\n\n let finalDescription: string = 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.trimEnd() + '.';\n }\n // Append the supplementary text\n finalDescription += ' ' + supplementaryNotes.join(' ');\n }\n\n let choices: string[] | undefined;\n let action: string | undefined;\n let type: string | undefined;\n switch (kind) {\n case CommandLineParameterKind.Choice: {\n choices = Array.from(parameter.alternatives);\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n choices = Array.from(parameter.alternatives);\n action = 'append';\n break;\n }\n case CommandLineParameterKind.Flag:\n action = 'storeTrue';\n break;\n case CommandLineParameterKind.Integer:\n type = 'int';\n break;\n case CommandLineParameterKind.IntegerList:\n type = 'int';\n action = 'append';\n break;\n case CommandLineParameterKind.String:\n break;\n case CommandLineParameterKind.StringList:\n action = 'append';\n break;\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: escapeSprintf(finalDescription),\n dest: parserKey,\n metavar: (parameter as CommandLineParameterWithArgument).argumentName,\n required,\n choices,\n action,\n type\n };\n\n const argumentParser: IExtendedArgumentParser = this._getArgumentParser() as IExtendedArgumentParser;\n let argumentGroup: argparse.ArgumentGroup | undefined;\n if (parameterGroup) {\n argumentGroup = this._parameterGroupsByName.get(parameterGroup);\n if (!argumentGroup) {\n let parameterGroupName: string;\n if (typeof parameterGroup === 'string') {\n parameterGroupName = parameterGroup;\n } else if (parameterGroup === SCOPING_PARAMETER_GROUP) {\n parameterGroupName = 'scoping';\n } else {\n throw new Error('Unexpected parameter group: ' + parameterGroup);\n }\n\n argumentGroup = argumentParser.addArgumentGroup({\n title: `Optional ${parameterGroupName} arguments`\n });\n this._parameterGroupsByName.set(parameterGroup, argumentGroup);\n }\n } else {\n argumentGroup = argumentParser;\n }\n\n const argparseArgument: argparse.ArgumentOptions = (argumentGroup as IExtendedArgumentGroup).addArgument(\n names,\n argparseOptions\n );\n if (required && environmentVariable) {\n // Add some special-cased logic to handle required parameters with environment variables\n\n const originalPreParse: (() => void) | undefined = parameter._preParse?.bind(parameter);\n parameter._preParse = () => {\n originalPreParse?.();\n // Set the value as non-required before parsing. We'll validate it explicitly\n argparseArgument.required = false;\n };\n\n const originalPostParse: (() => void) | undefined = parameter._postParse?.bind(parameter);\n parameter._postParse = () => {\n // Reset the required value to make the usage text correct\n argparseArgument.required = true;\n originalPostParse?.();\n };\n\n function throwMissingParameterError(): never {\n argumentParser.error(`Argument \"${longName}\" is required`);\n }\n\n const originalValidateValue: (() => void) | undefined = parameter._validateValue?.bind(parameter);\n // For these values, we have to perform explicit validation because they're requested\n // as required, but we disabled argparse's required flag to allow the environment variable\n // to potentially fill the value.\n switch (kind) {\n case CommandLineParameterKind.Choice:\n case CommandLineParameterKind.Integer:\n case CommandLineParameterKind.String:\n parameter._validateValue = function () {\n if (this.value === undefined || this.value === null) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n case CommandLineParameterKind.ChoiceList:\n case CommandLineParameterKind.IntegerList:\n case CommandLineParameterKind.StringList:\n parameter._validateValue = function () {\n if (this.values.length === 0) {\n throwMissingParameterError();\n }\n\n originalValidateValue?.();\n };\n break;\n }\n }\n\n if (undocumentedSynonyms?.length) {\n argumentGroup.addArgument(undocumentedSynonyms, {\n ...argparseOptions,\n help: argparse.Const.SUPPRESS\n });\n }\n\n // Register the parameter names so that we can detect ambiguous parameters\n for (const name of [...names, ...(undocumentedSynonyms || [])]) {\n this._registeredParameterParserKeysByName.set(name, parserKey!);\n }\n }\n\n protected _registerAmbiguousParameter(name: string, parserKey: string): void {\n this._getArgumentParser().addArgument(name, {\n dest: parserKey,\n // We don't know if this argument takes parameters or not, so we need to accept any number of args\n nargs: '*',\n // Ensure that the argument is not shown in the help text, since these parameters are only included\n // to inform the user that ambiguous parameters are present\n help: argparse.Const.SUPPRESS\n });\n }\n\n private _generateKey(): string {\n return 'key_' + (CommandLineParameterProvider._keyCounter++).toString();\n }\n\n private _getParameter<T extends CommandLineParameterBase>(\n parameterLongName: string,\n expectedKind: CommandLineParameterKind,\n parameterScope?: string\n ): T {\n // Support the parameter long name being prefixed with the scope\n const { scope, longName } = this.parseScopedLongName(parameterLongName);\n parameterLongName = longName;\n parameterScope = scope || parameterScope;\n\n const parameters: CommandLineParameterBase[] | undefined =\n this._parametersByLongName.get(parameterLongName);\n if (!parameters) {\n throw new Error(`The parameter \"${parameterLongName}\" is not defined`);\n }\n\n let parameter: CommandLineParameterBase | undefined = parameters.find(\n (p) => p.parameterScope === parameterScope\n );\n if (!parameter) {\n if (parameterScope !== undefined) {\n throw new Error(\n `The parameter \"${parameterLongName}\" with scope \"${parameterScope}\" is not defined.`\n );\n }\n if (parameters.length !== 1) {\n throw new Error(`The parameter \"${parameterLongName}\" is ambiguous. You must specify a scope.`);\n }\n parameter = parameters[0];\n }\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\n return parameter as T;\n }\n\n private _throwParserExitError(\n parserOptions: ICommandLineParserOptions,\n data: ICommandLineParserData,\n errorCode: number,\n message: string\n ): never {\n // Write out the usage text to make it easier for the user to find the correct parameter name\n const targetActionName: string = data.aliasAction || data.action || '';\n const errorPrefix: string =\n `Error: ${parserOptions.toolFilename}` +\n // Handle aliases, actions, and actionless parameter providers\n `${targetActionName ? ' ' : ''}${targetActionName}: error: `;\n\n // eslint-disable-next-line no-console\n console.log(this.renderUsageText());\n throw new CommandLineParserExitError(errorCode, `${errorPrefix}${message.trimStart().trimEnd()}\\n`);\n }\n}\n"]}
@@ -0,0 +1,262 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import { Colorize } from '@rushstack/terminal';
4
+ import { CommandLineParameterProvider } from './CommandLineParameterProvider';
5
+ import { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError';
6
+ import { TabCompleteAction } from './TabCompletionAction';
7
+ import { TypeUuid, uuidAlreadyReportedError } from '../TypeUuidLite';
8
+ import { escapeSprintf } from '../escapeSprintf';
9
+ /**
10
+ * The "argparse" library is a relatively advanced command-line parser with features such
11
+ * as word-wrapping and intelligible error messages (that are lacking in other similar
12
+ * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
13
+ * is awkward to use. The base classes CommandLineParser and CommandLineAction
14
+ * provide a wrapper for "argparse" that makes defining and consuming arguments quick
15
+ * and simple, and enforces that appropriate documentation is provided for each parameter.
16
+ *
17
+ * @public
18
+ */
19
+ export class CommandLineParser extends CommandLineParameterProvider {
20
+ constructor(options) {
21
+ super();
22
+ this._executed = false;
23
+ this._tabCompleteActionWasAdded = false;
24
+ this._options = options;
25
+ this._actionsByName = new Map();
26
+ const { toolFilename, toolDescription, toolEpilog } = options;
27
+ this._argumentParser = new CustomArgumentParser({
28
+ addHelp: true,
29
+ prog: toolFilename,
30
+ description: escapeSprintf(toolDescription),
31
+ epilog: Colorize.bold(escapeSprintf(toolEpilog !== null && toolEpilog !== void 0 ? toolEpilog : `For detailed help about a specific command, use: ${toolFilename} <command> -h`))
32
+ });
33
+ }
34
+ /**
35
+ * Returns the list of actions that were defined for this CommandLineParser object.
36
+ */
37
+ get actions() {
38
+ return Array.from(this._actionsByName.values());
39
+ }
40
+ /**
41
+ * Defines a new action that can be used with the CommandLineParser instance.
42
+ */
43
+ addAction(action) {
44
+ if (!this._actionsSubParser) {
45
+ this._actionsSubParser = this._argumentParser.addSubparsers({
46
+ metavar: '<command>',
47
+ dest: 'action'
48
+ });
49
+ }
50
+ action._buildParser(this._actionsSubParser);
51
+ this._actionsByName.set(action.actionName, action);
52
+ }
53
+ /**
54
+ * Retrieves the action with the specified name. If no matching action is found,
55
+ * an exception is thrown.
56
+ */
57
+ getAction(actionName) {
58
+ const action = this.tryGetAction(actionName);
59
+ if (!action) {
60
+ throw new Error(`The action "${actionName}" was not defined`);
61
+ }
62
+ return action;
63
+ }
64
+ /**
65
+ * Retrieves the action with the specified name. If no matching action is found,
66
+ * undefined is returned.
67
+ */
68
+ tryGetAction(actionName) {
69
+ return this._actionsByName.get(actionName);
70
+ }
71
+ /**
72
+ * The program entry point will call this method to begin parsing command-line arguments
73
+ * and executing the corresponding action.
74
+ *
75
+ * @remarks
76
+ * The returned promise will never reject: If an error occurs, it will be printed
77
+ * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
78
+ * This simplifies the most common usage scenario where the program entry point doesn't
79
+ * want to be involved with the command-line logic, and will discard the promise without
80
+ * a then() or catch() block.
81
+ *
82
+ * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandlingAsync}
83
+ * instead.
84
+ *
85
+ * @param args - the command-line arguments to be parsed; if omitted, then
86
+ * the process.argv will be used
87
+ */
88
+ async executeAsync(args) {
89
+ if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {
90
+ this.addAction(new TabCompleteAction(this.actions, this.parameters));
91
+ this._tabCompleteActionWasAdded = true;
92
+ }
93
+ try {
94
+ await this.executeWithoutErrorHandlingAsync(args);
95
+ return true;
96
+ }
97
+ catch (err) {
98
+ if (err instanceof CommandLineParserExitError) {
99
+ // executeWithoutErrorHandlingAsync() handles the successful cases,
100
+ // so here we can assume err has a nonzero exit code
101
+ if (err.message) {
102
+ // eslint-disable-next-line no-console
103
+ console.error(err.message);
104
+ }
105
+ if (!process.exitCode) {
106
+ process.exitCode = err.exitCode;
107
+ }
108
+ }
109
+ else if (TypeUuid.isInstanceOf(err, uuidAlreadyReportedError)) {
110
+ // AlreadyReportedError
111
+ if (!process.exitCode) {
112
+ process.exitCode = 1;
113
+ }
114
+ }
115
+ else {
116
+ let message = (err.message || 'An unknown error occurred').trim();
117
+ // If the message doesn't already start with "Error:" then add a prefix
118
+ if (!/^(error|internal error|warning)\b/i.test(message)) {
119
+ message = 'Error: ' + message;
120
+ }
121
+ // eslint-disable-next-line no-console
122
+ console.error();
123
+ // eslint-disable-next-line no-console
124
+ console.error(Colorize.red(message));
125
+ if (!process.exitCode) {
126
+ process.exitCode = 1;
127
+ }
128
+ }
129
+ return false;
130
+ }
131
+ }
132
+ /**
133
+ * This is similar to {@link CommandLineParser.executeAsync}, except that execution errors
134
+ * simply cause the promise to reject. It is the caller's responsibility to trap
135
+ */
136
+ async executeWithoutErrorHandlingAsync(args) {
137
+ var _a, _b;
138
+ try {
139
+ if (this._executed) {
140
+ // In the future we could allow the same parser to be invoked multiple times
141
+ // with different arguments. We'll do that work as soon as someone encounters
142
+ // a real world need for it.
143
+ throw new Error('executeAsync() was already called for this parser instance');
144
+ }
145
+ this._executed = true;
146
+ this._validateDefinitions();
147
+ // Register the parameters before we print help or parse the CLI
148
+ const initialState = {
149
+ parentParameterNames: new Set()
150
+ };
151
+ this._registerDefinedParameters(initialState);
152
+ if (!args) {
153
+ // 0=node.exe, 1=script name
154
+ args = process.argv.slice(2);
155
+ }
156
+ if (this.actions.length > 0) {
157
+ if (args.length === 0) {
158
+ // Parsers that use actions should print help when 0 args are provided. Allow
159
+ // actionless parsers to continue on zero args.
160
+ this._argumentParser.printHelp();
161
+ return;
162
+ }
163
+ // Alias actions may provide a list of default params to add after the action name.
164
+ // Since we don't know which params are required and which are optional, perform a
165
+ // manual search for the action name to obtain the default params and insert them if
166
+ // any are found. We will guess that the action name is the first arg that doesn't
167
+ // start with a hyphen.
168
+ const actionNameIndex = args.findIndex((x) => !x.startsWith('-'));
169
+ if (actionNameIndex !== undefined) {
170
+ const actionName = args[actionNameIndex];
171
+ const action = this.tryGetAction(actionName);
172
+ const aliasAction = action;
173
+ if ((_a = aliasAction === null || aliasAction === void 0 ? void 0 : aliasAction.defaultParameters) === null || _a === void 0 ? void 0 : _a.length) {
174
+ const insertIndex = actionNameIndex + 1;
175
+ args = args.slice(0, insertIndex).concat(aliasAction.defaultParameters, args.slice(insertIndex));
176
+ }
177
+ }
178
+ }
179
+ const postParse = () => {
180
+ this._postParse();
181
+ for (const action of this.actions) {
182
+ action._postParse();
183
+ }
184
+ };
185
+ function patchFormatUsageForArgumentParser(argumentParser) {
186
+ const originalFormatUsage = argumentParser.formatUsage.bind(argumentParser);
187
+ argumentParser.formatUsage = () => {
188
+ postParse();
189
+ return originalFormatUsage();
190
+ };
191
+ }
192
+ this._preParse();
193
+ patchFormatUsageForArgumentParser(this._argumentParser);
194
+ for (const action of this.actions) {
195
+ action._preParse();
196
+ patchFormatUsageForArgumentParser(action._getArgumentParser());
197
+ }
198
+ const data = this._argumentParser.parseArgs(args);
199
+ postParse();
200
+ this._processParsedData(this._options, data);
201
+ this.selectedAction = this.tryGetAction(data.action);
202
+ if (this.actions.length > 0 && !this.selectedAction) {
203
+ const actions = this.actions.map((x) => x.actionName);
204
+ throw new Error(`An action must be specified (${actions.join(', ')})`);
205
+ }
206
+ (_b = this.selectedAction) === null || _b === void 0 ? void 0 : _b._processParsedData(this._options, data);
207
+ await this.onExecuteAsync();
208
+ }
209
+ catch (err) {
210
+ if (err instanceof CommandLineParserExitError) {
211
+ if (!err.exitCode) {
212
+ // non-error exit modeled using exception handling
213
+ if (err.message) {
214
+ // eslint-disable-next-line no-console
215
+ console.log(err.message);
216
+ }
217
+ return;
218
+ }
219
+ }
220
+ throw err;
221
+ }
222
+ }
223
+ /** @internal */
224
+ _registerDefinedParameters(state) {
225
+ super._registerDefinedParameters(state);
226
+ const { parentParameterNames } = state;
227
+ const updatedParentParameterNames = new Set([
228
+ ...parentParameterNames,
229
+ ...this._registeredParameterParserKeysByName.keys()
230
+ ]);
231
+ const parentState = {
232
+ ...state,
233
+ parentParameterNames: updatedParentParameterNames
234
+ };
235
+ for (const action of this._actionsByName.values()) {
236
+ action._registerDefinedParameters(parentState);
237
+ }
238
+ }
239
+ _validateDefinitions() {
240
+ if (this.remainder && this.actions.length > 0) {
241
+ // This is apparently not supported by argparse
242
+ throw new Error('defineCommandLineRemainder() cannot be called for a CommandLineParser with actions');
243
+ }
244
+ }
245
+ /**
246
+ * {@inheritDoc CommandLineParameterProvider._getArgumentParser}
247
+ * @internal
248
+ */
249
+ _getArgumentParser() {
250
+ return this._argumentParser;
251
+ }
252
+ /**
253
+ * This hook allows the subclass to perform additional operations before or after
254
+ * the chosen action is executed.
255
+ */
256
+ async onExecuteAsync() {
257
+ if (this.selectedAction) {
258
+ await this.selectedAction._executeAsync();
259
+ }
260
+ }
261
+ }
262
+ //# sourceMappingURL=CommandLineParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAI3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,OAAO,EACL,4BAA4B,EAG7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA6BjD;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAkB,SAAQ,4BAA4B;IAejE,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,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAC;QAE3D,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE9D,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,CAAC;YAC9C,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,aAAa,CAAC,eAAe,CAAC;YAC3C,MAAM,EAAE,QAAQ,CAAC,IAAI,CACnB,aAAa,CACX,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,oDAAoD,YAAY,eAAe,CAC9F,CACF;SACF,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,I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2BAA2B;SAClD,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,MAAM,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9C,+CAA+C;YAC/C,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;QACxG,CAAC;IACH,CAAC;IAED;;;OAGG;IACgB,kBAAkB;QACnC,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,cAAc;QAC5B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as argparse from 'argparse';\n\nimport { Colorize } from '@rushstack/terminal';\n\nimport type { CommandLineAction } from './CommandLineAction';\nimport type { AliasCommandLineAction } from './AliasCommandLineAction';\nimport {\n CommandLineParameterProvider,\n type IRegisterDefinedParametersState,\n type ICommandLineParserData\n} from './CommandLineParameterProvider';\nimport { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError';\nimport { TabCompleteAction } from './TabCompletionAction';\nimport { TypeUuid, uuidAlreadyReportedError } from '../TypeUuidLite';\nimport { escapeSprintf } from '../escapeSprintf';\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 * An optional string to append at the end of the \"--help\" main page. If not provided, an epilog\n * will be automatically generated based on the toolFilename.\n */\n toolEpilog?: 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 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 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 readonly _argumentParser: argparse.ArgumentParser;\n private _actionsSubParser: argparse.SubParser | undefined;\n private readonly _options: ICommandLineParserOptions;\n private readonly _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._actionsByName = new Map<string, CommandLineAction>();\n\n const { toolFilename, toolDescription, toolEpilog } = options;\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: toolFilename,\n description: escapeSprintf(toolDescription),\n epilog: Colorize.bold(\n escapeSprintf(\n toolEpilog ?? `For detailed help about a specific command, use: ${toolFilename} <command> -h`\n )\n )\n });\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 Array.from(this._actionsByName.values());\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._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.executeWithoutErrorHandlingAsync}\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 executeAsync(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.executeWithoutErrorHandlingAsync(args);\n return true;\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n // executeWithoutErrorHandlingAsync() handles the successful cases,\n // so here we can assume err has a nonzero exit code\n if (err.message) {\n // eslint-disable-next-line no-console\n console.error(err.message);\n }\n if (!process.exitCode) {\n process.exitCode = err.exitCode;\n }\n } else if (TypeUuid.isInstanceOf(err, uuidAlreadyReportedError)) {\n // AlreadyReportedError\n if (!process.exitCode) {\n process.exitCode = 1;\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 // eslint-disable-next-line no-console\n console.error();\n // eslint-disable-next-line no-console\n console.error(Colorize.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.executeAsync}, except that execution errors\n * simply cause the promise to reject. It is the caller's responsibility to trap\n */\n public async executeWithoutErrorHandlingAsync(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('executeAsync() was already called for this parser instance');\n }\n this._executed = true;\n\n this._validateDefinitions();\n\n // Register the parameters before we print help or parse the CLI\n const initialState: IRegisterDefinedParametersState = {\n parentParameterNames: new Set()\n };\n this._registerDefinedParameters(initialState);\n\n if (!args) {\n // 0=node.exe, 1=script name\n args = process.argv.slice(2);\n }\n if (this.actions.length > 0) {\n if (args.length === 0) {\n // Parsers that use actions should print help when 0 args are provided. Allow\n // actionless parsers to continue on zero args.\n this._argumentParser.printHelp();\n return;\n }\n // Alias actions may provide a list of default params to add after the action name.\n // Since we don't know which params are required and which are optional, perform a\n // manual search for the action name to obtain the default params and insert them if\n // any are found. We will guess that the action name is the first arg that doesn't\n // start with a hyphen.\n const actionNameIndex: number | undefined = args.findIndex((x) => !x.startsWith('-'));\n if (actionNameIndex !== undefined) {\n const actionName: string = args[actionNameIndex];\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n const aliasAction: AliasCommandLineAction | undefined = action as AliasCommandLineAction;\n if (aliasAction?.defaultParameters?.length) {\n const insertIndex: number = actionNameIndex + 1;\n args = args.slice(0, insertIndex).concat(aliasAction.defaultParameters, args.slice(insertIndex));\n }\n }\n }\n\n const postParse: () => void = () => {\n this._postParse();\n for (const action of this.actions) {\n action._postParse();\n }\n };\n\n function patchFormatUsageForArgumentParser(argumentParser: argparse.ArgumentParser): void {\n const originalFormatUsage: () => string = argumentParser.formatUsage.bind(argumentParser);\n argumentParser.formatUsage = () => {\n postParse();\n return originalFormatUsage();\n };\n }\n\n this._preParse();\n patchFormatUsageForArgumentParser(this._argumentParser);\n for (const action of this.actions) {\n action._preParse();\n patchFormatUsageForArgumentParser(action._getArgumentParser());\n }\n\n const data: ICommandLineParserData = this._argumentParser.parseArgs(args);\n\n postParse();\n this._processParsedData(this._options, data);\n\n this.selectedAction = this.tryGetAction(data.action);\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 this.selectedAction?._processParsedData(this._options, data);\n await this.onExecuteAsync();\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 // eslint-disable-next-line no-console\n console.log(err.message);\n }\n\n return;\n }\n }\n\n throw err;\n }\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n super._registerDefinedParameters(state);\n\n const { parentParameterNames } = state;\n const updatedParentParameterNames: Set<string> = new Set([\n ...parentParameterNames,\n ...this._registeredParameterParserKeysByName.keys()\n ]);\n\n const parentState: IRegisterDefinedParametersState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n for (const action of this._actionsByName.values()) {\n action._registerDefinedParameters(parentState);\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 override _getArgumentParser(): argparse.ArgumentParser {\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 onExecuteAsync(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._executeAsync();\n }\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import * as argparse from 'argparse';
4
+ export class CommandLineParserExitError extends Error {
5
+ constructor(exitCode, message) {
6
+ super(message);
7
+ // Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc
8
+ // https://github.com/microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
9
+ //
10
+ // Note: the prototype must also be set on any classes which extend this one
11
+ this.__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any
12
+ this.exitCode = exitCode;
13
+ }
14
+ }
15
+ export class CustomArgumentParser extends argparse.ArgumentParser {
16
+ exit(status, message) {
17
+ throw new CommandLineParserExitError(status, message);
18
+ }
19
+ error(err) {
20
+ // Ensure the ParserExitError bubbles up to the top without any special processing
21
+ if (err instanceof CommandLineParserExitError) {
22
+ throw err;
23
+ }
24
+ super.error(err);
25
+ }
26
+ }
27
+ //# sourceMappingURL=CommandLineParserExitError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandLineParserExitError.js","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,MAAM,OAAO,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;AAED,MAAM,OAAO,oBAAqB,SAAQ,QAAQ,CAAC,cAAc;IAC/C,IAAI,CAAC,MAAc,EAAE,OAAe;QAClD,MAAM,IAAI,0BAA0B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAEe,KAAK,CAAC,GAAmB;QACvC,kFAAkF;QAClF,IAAI,GAAG,YAAY,0BAA0B,EAAE,CAAC;YAC9C,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","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 override exit(status: number, message: string): void {\n throw new CommandLineParserExitError(status, message);\n }\n\n public override error(err: Error | string): void {\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"]}
@@ -0,0 +1,13 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import { CommandLineAction } from './CommandLineAction';
4
+ /**
5
+ * @public
6
+ */
7
+ export class DynamicCommandLineAction extends CommandLineAction {
8
+ async onExecuteAsync() {
9
+ // abstract
10
+ // (handled by the external code)
11
+ }
12
+ }
13
+ //# sourceMappingURL=DynamicCommandLineAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineAction.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAAiB;IAC1C,KAAK,CAAC,cAAc;QACrC,WAAW;QACX,iCAAiC;IACnC,CAAC;CACF","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 override async onExecuteAsync(): Promise<void> {\n // abstract\n // (handled by the external code)\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import { CommandLineParser } from './CommandLineParser';
4
+ /**
5
+ * @public
6
+ */
7
+ export class DynamicCommandLineParser extends CommandLineParser {
8
+ }
9
+ //# sourceMappingURL=DynamicCommandLineParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicCommandLineParser.js","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineParser.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAAiB;CAAG","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"]}