@rushstack/ts-command-line 4.9.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 (91) hide show
  1. package/CHANGELOG.json +1329 -0
  2. package/CHANGELOG.md +704 -0
  3. package/LICENSE +24 -0
  4. package/README.md +251 -0
  5. package/dist/ts-command-line.d.ts +878 -0
  6. package/dist/tsdoc-metadata.json +11 -0
  7. package/lib/CommandLineHelper.d.ts +14 -0
  8. package/lib/CommandLineHelper.d.ts.map +1 -0
  9. package/lib/CommandLineHelper.js +22 -0
  10. package/lib/CommandLineHelper.js.map +1 -0
  11. package/lib/Constants.d.ts +12 -0
  12. package/lib/Constants.d.ts.map +1 -0
  13. package/lib/Constants.js +5 -0
  14. package/lib/Constants.js.map +1 -0
  15. package/lib/index.d.ts +23 -0
  16. package/lib/index.d.ts.map +1 -0
  17. package/lib/index.js +42 -0
  18. package/lib/index.js.map +1 -0
  19. package/lib/parameters/BaseClasses.d.ts +100 -0
  20. package/lib/parameters/BaseClasses.d.ts.map +1 -0
  21. package/lib/parameters/BaseClasses.js +148 -0
  22. package/lib/parameters/BaseClasses.js.map +1 -0
  23. package/lib/parameters/CommandLineChoiceListParameter.d.ts +33 -0
  24. package/lib/parameters/CommandLineChoiceListParameter.d.ts.map +1 -0
  25. package/lib/parameters/CommandLineChoiceListParameter.js +84 -0
  26. package/lib/parameters/CommandLineChoiceListParameter.js.map +1 -0
  27. package/lib/parameters/CommandLineChoiceParameter.d.ts +40 -0
  28. package/lib/parameters/CommandLineChoiceParameter.d.ts.map +1 -0
  29. package/lib/parameters/CommandLineChoiceParameter.js +95 -0
  30. package/lib/parameters/CommandLineChoiceParameter.js.map +1 -0
  31. package/lib/parameters/CommandLineDefinition.d.ts +207 -0
  32. package/lib/parameters/CommandLineDefinition.d.ts.map +1 -0
  33. package/lib/parameters/CommandLineDefinition.js +5 -0
  34. package/lib/parameters/CommandLineDefinition.js.map +1 -0
  35. package/lib/parameters/CommandLineFlagParameter.d.ts +29 -0
  36. package/lib/parameters/CommandLineFlagParameter.d.ts.map +1 -0
  37. package/lib/parameters/CommandLineFlagParameter.js +72 -0
  38. package/lib/parameters/CommandLineFlagParameter.js.map +1 -0
  39. package/lib/parameters/CommandLineIntegerListParameter.d.ts +29 -0
  40. package/lib/parameters/CommandLineIntegerListParameter.d.ts.map +1 -0
  41. package/lib/parameters/CommandLineIntegerListParameter.js +82 -0
  42. package/lib/parameters/CommandLineIntegerListParameter.js.map +1 -0
  43. package/lib/parameters/CommandLineIntegerParameter.d.ts +36 -0
  44. package/lib/parameters/CommandLineIntegerParameter.d.ts.map +1 -0
  45. package/lib/parameters/CommandLineIntegerParameter.js +86 -0
  46. package/lib/parameters/CommandLineIntegerParameter.js.map +1 -0
  47. package/lib/parameters/CommandLineRemainder.d.ts +28 -0
  48. package/lib/parameters/CommandLineRemainder.d.ts.map +1 -0
  49. package/lib/parameters/CommandLineRemainder.js +48 -0
  50. package/lib/parameters/CommandLineRemainder.js.map +1 -0
  51. package/lib/parameters/CommandLineStringListParameter.d.ts +29 -0
  52. package/lib/parameters/CommandLineStringListParameter.d.ts.map +1 -0
  53. package/lib/parameters/CommandLineStringListParameter.js +73 -0
  54. package/lib/parameters/CommandLineStringListParameter.js.map +1 -0
  55. package/lib/parameters/CommandLineStringParameter.d.ts +36 -0
  56. package/lib/parameters/CommandLineStringParameter.d.ts.map +1 -0
  57. package/lib/parameters/CommandLineStringParameter.js +85 -0
  58. package/lib/parameters/CommandLineStringParameter.js.map +1 -0
  59. package/lib/parameters/EnvironmentVariableParser.d.ts +10 -0
  60. package/lib/parameters/EnvironmentVariableParser.d.ts.map +1 -0
  61. package/lib/parameters/EnvironmentVariableParser.js +51 -0
  62. package/lib/parameters/EnvironmentVariableParser.js.map +1 -0
  63. package/lib/providers/CommandLineAction.d.ts +76 -0
  64. package/lib/providers/CommandLineAction.d.ts.map +1 -0
  65. package/lib/providers/CommandLineAction.js +73 -0
  66. package/lib/providers/CommandLineAction.js.map +1 -0
  67. package/lib/providers/CommandLineParameterProvider.d.ts +202 -0
  68. package/lib/providers/CommandLineParameterProvider.d.ts.map +1 -0
  69. package/lib/providers/CommandLineParameterProvider.js +374 -0
  70. package/lib/providers/CommandLineParameterProvider.js.map +1 -0
  71. package/lib/providers/CommandLineParser.d.ts +100 -0
  72. package/lib/providers/CommandLineParser.d.ts.map +1 -0
  73. package/lib/providers/CommandLineParser.js +204 -0
  74. package/lib/providers/CommandLineParser.js.map +1 -0
  75. package/lib/providers/CommandLineParserExitError.d.ts +10 -0
  76. package/lib/providers/CommandLineParserExitError.d.ts.map +1 -0
  77. package/lib/providers/CommandLineParserExitError.js +53 -0
  78. package/lib/providers/CommandLineParserExitError.js.map +1 -0
  79. package/lib/providers/DynamicCommandLineAction.d.ts +9 -0
  80. package/lib/providers/DynamicCommandLineAction.d.ts.map +1 -0
  81. package/lib/providers/DynamicCommandLineAction.js +21 -0
  82. package/lib/providers/DynamicCommandLineAction.js.map +1 -0
  83. package/lib/providers/DynamicCommandLineParser.d.ts +8 -0
  84. package/lib/providers/DynamicCommandLineParser.d.ts.map +1 -0
  85. package/lib/providers/DynamicCommandLineParser.js +16 -0
  86. package/lib/providers/DynamicCommandLineParser.js.map +1 -0
  87. package/lib/providers/TabCompletionAction.d.ts +18 -0
  88. package/lib/providers/TabCompletionAction.d.ts.map +1 -0
  89. package/lib/providers/TabCompletionAction.js +211 -0
  90. package/lib/providers/TabCompletionAction.js.map +1 -0
  91. package/package.json +28 -0
@@ -0,0 +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;AAC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AAS,CAAC,CAAC;QACjC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;;AA3ZH,oEA4ZC;AA3ZgB,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\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 }\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 * 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 // 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\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"]}
@@ -0,0 +1,100 @@
1
+ import * as argparse from 'argparse';
2
+ import { CommandLineAction } from './CommandLineAction';
3
+ import { CommandLineParameterProvider } from './CommandLineParameterProvider';
4
+ /**
5
+ * Options for the {@link CommandLineParser} constructor.
6
+ * @public
7
+ */
8
+ export interface ICommandLineParserOptions {
9
+ /**
10
+ * The name of your tool when invoked from the command line
11
+ */
12
+ toolFilename: string;
13
+ /**
14
+ * General documentation that is included in the "--help" main page
15
+ */
16
+ toolDescription: string;
17
+ /**
18
+ * Set to true to auto-define a tab completion action. False by default.
19
+ */
20
+ enableTabCompletionAction?: boolean;
21
+ }
22
+ /**
23
+ * The "argparse" library is a relatively advanced command-line parser with features such
24
+ * as word-wrapping and intelligible error messages (that are lacking in other similar
25
+ * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
26
+ * is awkward to use. The abstract base classes CommandLineParser and CommandLineAction
27
+ * provide a wrapper for "argparse" that makes defining and consuming arguments quick
28
+ * and simple, and enforces that appropriate documentation is provided for each parameter.
29
+ *
30
+ * @public
31
+ */
32
+ export declare abstract class CommandLineParser extends CommandLineParameterProvider {
33
+ /**
34
+ * Reports which CommandLineAction was specified on the command line.
35
+ * @remarks
36
+ * The value will be assigned before onExecute() is invoked.
37
+ */
38
+ selectedAction: CommandLineAction | undefined;
39
+ private _argumentParser;
40
+ private _actionsSubParser;
41
+ private _options;
42
+ private _actions;
43
+ private _actionsByName;
44
+ private _executed;
45
+ private _tabCompleteActionWasAdded;
46
+ constructor(options: ICommandLineParserOptions);
47
+ /**
48
+ * Returns the list of actions that were defined for this CommandLineParser object.
49
+ */
50
+ get actions(): ReadonlyArray<CommandLineAction>;
51
+ /**
52
+ * Defines a new action that can be used with the CommandLineParser instance.
53
+ */
54
+ addAction(action: CommandLineAction): void;
55
+ /**
56
+ * Retrieves the action with the specified name. If no matching action is found,
57
+ * an exception is thrown.
58
+ */
59
+ getAction(actionName: string): CommandLineAction;
60
+ /**
61
+ * Retrieves the action with the specified name. If no matching action is found,
62
+ * undefined is returned.
63
+ */
64
+ tryGetAction(actionName: string): CommandLineAction | undefined;
65
+ /**
66
+ * The program entry point will call this method to begin parsing command-line arguments
67
+ * and executing the corresponding action.
68
+ *
69
+ * @remarks
70
+ * The returned promise will never reject: If an error occurs, it will be printed
71
+ * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
72
+ * This simplifies the most common usage scenario where the program entry point doesn't
73
+ * want to be involved with the command-line logic, and will discard the promise without
74
+ * a then() or catch() block.
75
+ *
76
+ * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
77
+ * instead.
78
+ *
79
+ * @param args - the command-line arguments to be parsed; if omitted, then
80
+ * the process.argv will be used
81
+ */
82
+ execute(args?: string[]): Promise<boolean>;
83
+ /**
84
+ * This is similar to {@link CommandLineParser.execute}, except that execution errors
85
+ * simply cause the promise to reject. It is the caller's responsibility to trap
86
+ */
87
+ executeWithoutErrorHandling(args?: string[]): Promise<void>;
88
+ private _validateDefinitions;
89
+ /**
90
+ * {@inheritDoc CommandLineParameterProvider._getArgumentParser}
91
+ * @internal
92
+ */
93
+ protected _getArgumentParser(): argparse.ArgumentParser;
94
+ /**
95
+ * This hook allows the subclass to perform additional operations before or after
96
+ * the chosen action is executed.
97
+ */
98
+ protected onExecute(): Promise<void>;
99
+ }
100
+ //# sourceMappingURL=CommandLineParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandLineParser.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAA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3C"}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.CommandLineParser = void 0;
9
+ const colors_1 = __importDefault(require("colors"));
10
+ const CommandLineParameterProvider_1 = require("./CommandLineParameterProvider");
11
+ const CommandLineParserExitError_1 = require("./CommandLineParserExitError");
12
+ const TabCompletionAction_1 = require("./TabCompletionAction");
13
+ /**
14
+ * The "argparse" library is a relatively advanced command-line parser with features such
15
+ * as word-wrapping and intelligible error messages (that are lacking in other similar
16
+ * libraries such as commander, yargs, and nomnom). Unfortunately, its ruby-inspired API
17
+ * is awkward to use. The abstract base classes CommandLineParser and CommandLineAction
18
+ * provide a wrapper for "argparse" that makes defining and consuming arguments quick
19
+ * and simple, and enforces that appropriate documentation is provided for each parameter.
20
+ *
21
+ * @public
22
+ */
23
+ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParameterProvider {
24
+ constructor(options) {
25
+ super();
26
+ this._executed = false;
27
+ this._tabCompleteActionWasAdded = false;
28
+ this._options = options;
29
+ this._actions = [];
30
+ this._actionsByName = new Map();
31
+ this._argumentParser = new CommandLineParserExitError_1.CustomArgumentParser({
32
+ addHelp: true,
33
+ prog: this._options.toolFilename,
34
+ description: this._options.toolDescription,
35
+ epilog: colors_1.default.bold(`For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`)
36
+ });
37
+ this.onDefineParameters();
38
+ }
39
+ /**
40
+ * Returns the list of actions that were defined for this CommandLineParser object.
41
+ */
42
+ get actions() {
43
+ return this._actions;
44
+ }
45
+ /**
46
+ * Defines a new action that can be used with the CommandLineParser instance.
47
+ */
48
+ addAction(action) {
49
+ if (!this._actionsSubParser) {
50
+ this._actionsSubParser = this._argumentParser.addSubparsers({
51
+ metavar: '<command>',
52
+ dest: 'action'
53
+ });
54
+ }
55
+ action._buildParser(this._actionsSubParser);
56
+ this._actions.push(action);
57
+ this._actionsByName.set(action.actionName, action);
58
+ }
59
+ /**
60
+ * Retrieves the action with the specified name. If no matching action is found,
61
+ * an exception is thrown.
62
+ */
63
+ getAction(actionName) {
64
+ const action = this.tryGetAction(actionName);
65
+ if (!action) {
66
+ throw new Error(`The action "${actionName}" was not defined`);
67
+ }
68
+ return action;
69
+ }
70
+ /**
71
+ * Retrieves the action with the specified name. If no matching action is found,
72
+ * undefined is returned.
73
+ */
74
+ tryGetAction(actionName) {
75
+ return this._actionsByName.get(actionName);
76
+ }
77
+ /**
78
+ * The program entry point will call this method to begin parsing command-line arguments
79
+ * and executing the corresponding action.
80
+ *
81
+ * @remarks
82
+ * The returned promise will never reject: If an error occurs, it will be printed
83
+ * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
84
+ * This simplifies the most common usage scenario where the program entry point doesn't
85
+ * want to be involved with the command-line logic, and will discard the promise without
86
+ * a then() or catch() block.
87
+ *
88
+ * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
89
+ * instead.
90
+ *
91
+ * @param args - the command-line arguments to be parsed; if omitted, then
92
+ * the process.argv will be used
93
+ */
94
+ async execute(args) {
95
+ if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {
96
+ this.addAction(new TabCompletionAction_1.TabCompleteAction(this.actions, this.parameters));
97
+ this._tabCompleteActionWasAdded = true;
98
+ }
99
+ try {
100
+ await this.executeWithoutErrorHandling(args);
101
+ return true;
102
+ }
103
+ catch (err) {
104
+ if (err instanceof CommandLineParserExitError_1.CommandLineParserExitError) {
105
+ // executeWithoutErrorHandling() handles the successful cases,
106
+ // so here we can assume err has a nonzero exit code
107
+ if (err.message) {
108
+ console.error(err.message);
109
+ }
110
+ if (!process.exitCode) {
111
+ process.exitCode = err.exitCode;
112
+ }
113
+ }
114
+ else {
115
+ let message = (err.message || 'An unknown error occurred').trim();
116
+ // If the message doesn't already start with "Error:" then add a prefix
117
+ if (!/^(error|internal error|warning)\b/i.test(message)) {
118
+ message = 'Error: ' + message;
119
+ }
120
+ console.error();
121
+ console.error(colors_1.default.red(message));
122
+ if (!process.exitCode) {
123
+ process.exitCode = 1;
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+ }
129
+ /**
130
+ * This is similar to {@link CommandLineParser.execute}, except that execution errors
131
+ * simply cause the promise to reject. It is the caller's responsibility to trap
132
+ */
133
+ async executeWithoutErrorHandling(args) {
134
+ try {
135
+ if (this._executed) {
136
+ // In the future we could allow the same parser to be invoked multiple times
137
+ // with different arguments. We'll do that work as soon as someone encounters
138
+ // a real world need for it.
139
+ throw new Error('execute() was already called for this parser instance');
140
+ }
141
+ this._executed = true;
142
+ this._validateDefinitions();
143
+ if (!args) {
144
+ // 0=node.exe, 1=script name
145
+ args = process.argv.slice(2);
146
+ }
147
+ if (args.length === 0) {
148
+ this._argumentParser.printHelp();
149
+ return;
150
+ }
151
+ const data = this._argumentParser.parseArgs(args);
152
+ this._processParsedData(data);
153
+ for (const action of this._actions) {
154
+ if (action.actionName === data.action) {
155
+ this.selectedAction = action;
156
+ action._processParsedData(data);
157
+ break;
158
+ }
159
+ }
160
+ if (this.actions.length > 0 && !this.selectedAction) {
161
+ const actions = this.actions.map((x) => x.actionName);
162
+ throw new Error(`An action must be specified (${actions.join(', ')})`);
163
+ }
164
+ return this.onExecute();
165
+ }
166
+ catch (err) {
167
+ if (err instanceof CommandLineParserExitError_1.CommandLineParserExitError) {
168
+ if (!err.exitCode) {
169
+ // non-error exit modeled using exception handling
170
+ if (err.message) {
171
+ console.log(err.message);
172
+ }
173
+ return;
174
+ }
175
+ }
176
+ throw err;
177
+ }
178
+ }
179
+ _validateDefinitions() {
180
+ if (this.remainder && this.actions.length > 0) {
181
+ // This is apparently not supported by argparse
182
+ throw new Error('defineCommandLineRemainder() cannot be called for a CommandLineParser with actions');
183
+ }
184
+ }
185
+ /**
186
+ * {@inheritDoc CommandLineParameterProvider._getArgumentParser}
187
+ * @internal
188
+ */
189
+ _getArgumentParser() {
190
+ // override
191
+ return this._argumentParser;
192
+ }
193
+ /**
194
+ * This hook allows the subclass to perform additional operations before or after
195
+ * the chosen action is executed.
196
+ */
197
+ async onExecute() {
198
+ if (this.selectedAction) {
199
+ await this.selectedAction._execute();
200
+ }
201
+ }
202
+ }
203
+ exports.CommandLineParser = CommandLineParser;
204
+ //# 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;;;;;;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;I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AAM,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"]}
@@ -0,0 +1,10 @@
1
+ import * as argparse from 'argparse';
2
+ export declare class CommandLineParserExitError extends Error {
3
+ readonly exitCode: number;
4
+ constructor(exitCode: number, message: string);
5
+ }
6
+ export declare class CustomArgumentParser extends argparse.ArgumentParser {
7
+ exit(status: number, message: string): void;
8
+ error(err: Error | string): void;
9
+ }
10
+ //# sourceMappingURL=CommandLineParserExitError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandLineParserExitError.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParserExitError.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAWrD;AAED,qBAAa,oBAAqB,SAAQ,QAAQ,CAAC,cAAc;IACxD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAK3C,KAAK,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI;CASxC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
7
+ }) : (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ o[k2] = m[k];
10
+ }));
11
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
12
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
13
+ }) : function(o, v) {
14
+ o["default"] = v;
15
+ });
16
+ var __importStar = (this && this.__importStar) || function (mod) {
17
+ if (mod && mod.__esModule) return mod;
18
+ var result = {};
19
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
20
+ __setModuleDefault(result, mod);
21
+ return result;
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.CustomArgumentParser = exports.CommandLineParserExitError = void 0;
25
+ const argparse = __importStar(require("argparse"));
26
+ class CommandLineParserExitError extends Error {
27
+ constructor(exitCode, message) {
28
+ super(message);
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
31
+ //
32
+ // Note: the prototype must also be set on any classes which extend this one
33
+ this.__proto__ = CommandLineParserExitError.prototype; // eslint-disable-line @typescript-eslint/no-explicit-any
34
+ this.exitCode = exitCode;
35
+ }
36
+ }
37
+ exports.CommandLineParserExitError = CommandLineParserExitError;
38
+ class CustomArgumentParser extends argparse.ArgumentParser {
39
+ exit(status, message) {
40
+ // override
41
+ throw new CommandLineParserExitError(status, message);
42
+ }
43
+ error(err) {
44
+ // override
45
+ // Ensure the ParserExitError bubbles up to the top without any special processing
46
+ if (err instanceof CommandLineParserExitError) {
47
+ throw err;
48
+ }
49
+ super.error(err);
50
+ }
51
+ }
52
+ exports.CustomArgumentParser = CustomArgumentParser;
53
+ //# 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,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"]}
@@ -0,0 +1,9 @@
1
+ import { CommandLineAction } from './CommandLineAction';
2
+ /**
3
+ * @public
4
+ */
5
+ export declare class DynamicCommandLineAction extends CommandLineAction {
6
+ protected onDefineParameters(): void;
7
+ protected onExecute(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=DynamicCommandLineAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicCommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,iBAAiB;IAC7D,SAAS,CAAC,kBAAkB,IAAI,IAAI;cAKpB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAI3C"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DynamicCommandLineAction = void 0;
6
+ const CommandLineAction_1 = require("./CommandLineAction");
7
+ /**
8
+ * @public
9
+ */
10
+ class DynamicCommandLineAction extends CommandLineAction_1.CommandLineAction {
11
+ onDefineParameters() {
12
+ // abstract
13
+ // (handled by the external code)
14
+ }
15
+ async onExecute() {
16
+ // abstract
17
+ // (handled by the external code)
18
+ }
19
+ }
20
+ exports.DynamicCommandLineAction = DynamicCommandLineAction;
21
+ //# 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,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"]}
@@ -0,0 +1,8 @@
1
+ import { CommandLineParser } from './CommandLineParser';
2
+ /**
3
+ * @public
4
+ */
5
+ export declare class DynamicCommandLineParser extends CommandLineParser {
6
+ protected onDefineParameters(): void;
7
+ }
8
+ //# sourceMappingURL=DynamicCommandLineParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicCommandLineParser.d.ts","sourceRoot":"","sources":["../../src/providers/DynamicCommandLineParser.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,iBAAiB;IAC7D,SAAS,CAAC,kBAAkB,IAAI,IAAI;CAGrC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DynamicCommandLineParser = void 0;
6
+ const CommandLineParser_1 = require("./CommandLineParser");
7
+ /**
8
+ * @public
9
+ */
10
+ class DynamicCommandLineParser extends CommandLineParser_1.CommandLineParser {
11
+ onDefineParameters() {
12
+ // abstract
13
+ }
14
+ }
15
+ exports.DynamicCommandLineParser = DynamicCommandLineParser;
16
+ //# 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,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"]}
@@ -0,0 +1,18 @@
1
+ import { CommandLineParameter } from '../parameters/BaseClasses';
2
+ import { CommandLineAction } from './CommandLineAction';
3
+ export declare class TabCompleteAction extends CommandLineAction {
4
+ private _wordToCompleteParameter;
5
+ private _positionParameter;
6
+ private readonly _actions;
7
+ private readonly _globalParameters;
8
+ constructor(actions: ReadonlyArray<CommandLineAction>, globalParameters: ReadonlyArray<CommandLineParameter>);
9
+ protected onDefineParameters(): void;
10
+ protected onExecute(): Promise<void>;
11
+ getCompletions(commandLine: string, caretPosition?: number): AsyncIterable<string>;
12
+ private _getAllActions;
13
+ tokenizeCommandLine(commandLine: string): string[];
14
+ private _getParameterValueCompletions;
15
+ private _getGlobalParameterOffset;
16
+ private _completeParameterValues;
17
+ }
18
+ //# sourceMappingURL=TabCompletionAction.d.ts.map
@@ -0,0 +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;IAC1E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoC;gBAGpE,OAAO,EAAE,aAAa,CAAC,iBAAiB,CAAC,EACzC,gBAAgB,EAAE,aAAa,CAAC,oBAAoB,CAAC;IAgCvD,SAAS,CAAC,kBAAkB,IAAI,IAAI;cAgBpB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,cAAc,CAC1B,WAAW,EAAE,MAAM,EACnB,aAAa,GAAE,MAA2B,GACzC,aAAa,CAAC,MAAM,CAAC;IAgFxB,OAAO,CAAE,cAAc;IAKhB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE;YAI3C,6BAA6B;IAsB3C,OAAO,CAAC,yBAAyB;IAgBjC,OAAO,CAAE,wBAAwB;CAUlC"}