@rushstack/ts-command-line 4.19.5 → 4.20.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.
- package/dist/ts-command-line.d.ts +17 -4
- package/lib/parameters/CommandLineDefinition.d.ts +2 -0
- package/lib/parameters/CommandLineDefinition.d.ts.map +1 -1
- package/lib/parameters/CommandLineDefinition.js.map +1 -1
- package/lib/providers/AliasCommandLineAction.js +1 -1
- package/lib/providers/AliasCommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineAction.d.ts +4 -1
- package/lib/providers/CommandLineAction.d.ts.map +1 -1
- package/lib/providers/CommandLineAction.js +1 -1
- package/lib/providers/CommandLineAction.js.map +1 -1
- package/lib/providers/CommandLineParameterProvider.d.ts +3 -3
- package/lib/providers/CommandLineParameterProvider.js +3 -3
- package/lib/providers/CommandLineParameterProvider.js.map +1 -1
- package/lib/providers/CommandLineParser.d.ts +10 -2
- package/lib/providers/CommandLineParser.d.ts.map +1 -1
- package/lib/providers/CommandLineParser.js +22 -8
- package/lib/providers/CommandLineParser.js.map +1 -1
- package/lib/providers/ScopedCommandLineAction.d.ts +2 -2
- package/lib/providers/ScopedCommandLineAction.d.ts.map +1 -1
- package/lib/providers/ScopedCommandLineAction.js +4 -4
- package/lib/providers/ScopedCommandLineAction.js.map +1 -1
- package/lib/providers/TabCompletionAction.d.ts +2 -2
- package/lib/providers/TabCompletionAction.d.ts.map +1 -1
- package/lib/providers/TabCompletionAction.js +6 -6
- package/lib/providers/TabCompletionAction.js.map +1 -1
- package/package.json +2 -2
|
@@ -58,10 +58,13 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
|
|
|
58
58
|
private _argumentParser;
|
|
59
59
|
constructor(options: ICommandLineActionOptions);
|
|
60
60
|
/* Excluded from this release type: _buildParser */
|
|
61
|
-
/* Excluded from this release type:
|
|
61
|
+
/* Excluded from this release type: _executeAsync */
|
|
62
62
|
/* Excluded from this release type: _getArgumentParser */
|
|
63
63
|
/**
|
|
64
64
|
* Your subclass should implement this hook to perform the operation.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* In a future release, this function will be renamed to onExecuteAsync
|
|
65
68
|
*/
|
|
66
69
|
protected abstract onExecute(): Promise<void>;
|
|
67
70
|
}
|
|
@@ -630,17 +633,25 @@ export declare abstract class CommandLineParser extends CommandLineParameterProv
|
|
|
630
633
|
* want to be involved with the command-line logic, and will discard the promise without
|
|
631
634
|
* a then() or catch() block.
|
|
632
635
|
*
|
|
633
|
-
* If your caller wants to trap and handle errors, use {@link CommandLineParser.
|
|
636
|
+
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandlingAsync}
|
|
634
637
|
* instead.
|
|
635
638
|
*
|
|
636
639
|
* @param args - the command-line arguments to be parsed; if omitted, then
|
|
637
640
|
* the process.argv will be used
|
|
638
641
|
*/
|
|
642
|
+
executeAsync(args?: string[]): Promise<boolean>;
|
|
643
|
+
/**
|
|
644
|
+
* @deprecated Use {@link CommandLineParser.executeAsync} instead.
|
|
645
|
+
*/
|
|
639
646
|
execute(args?: string[]): Promise<boolean>;
|
|
640
647
|
/**
|
|
641
|
-
* This is similar to {@link CommandLineParser.
|
|
648
|
+
* This is similar to {@link CommandLineParser.executeAsync}, except that execution errors
|
|
642
649
|
* simply cause the promise to reject. It is the caller's responsibility to trap
|
|
643
650
|
*/
|
|
651
|
+
executeWithoutErrorHandlingAsync(args?: string[]): Promise<void>;
|
|
652
|
+
/**
|
|
653
|
+
* @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.
|
|
654
|
+
*/
|
|
644
655
|
executeWithoutErrorHandling(args?: string[]): Promise<void>;
|
|
645
656
|
/* Excluded from this release type: _registerDefinedParameters */
|
|
646
657
|
private _validateDefinitions;
|
|
@@ -873,6 +884,8 @@ export declare interface IBaseCommandLineDefinitionWithArgument extends IBaseCom
|
|
|
873
884
|
* @remarks
|
|
874
885
|
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
|
|
875
886
|
* is enabled.
|
|
887
|
+
*
|
|
888
|
+
* In a future release, this will be renamed to `getCompletionsAsync`
|
|
876
889
|
*/
|
|
877
890
|
completions?: () => Promise<string[]>;
|
|
878
891
|
}
|
|
@@ -1133,7 +1146,7 @@ export declare abstract class ScopedCommandLineAction extends CommandLineAction
|
|
|
1133
1146
|
*/
|
|
1134
1147
|
get parameters(): ReadonlyArray<CommandLineParameter>;
|
|
1135
1148
|
/* Excluded from this release type: _processParsedData */
|
|
1136
|
-
/* Excluded from this release type:
|
|
1149
|
+
/* Excluded from this release type: _executeAsync */
|
|
1137
1150
|
/* Excluded from this release type: _registerDefinedParameters */
|
|
1138
1151
|
/**
|
|
1139
1152
|
* {@inheritdoc CommandLineParameterProvider.onDefineParameters}
|
|
@@ -113,6 +113,8 @@ export interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLine
|
|
|
113
113
|
* @remarks
|
|
114
114
|
* This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`
|
|
115
115
|
* is enabled.
|
|
116
|
+
*
|
|
117
|
+
* In a future release, this will be renamed to `getCompletionsAsync`
|
|
116
118
|
*/
|
|
117
119
|
completions?: () => Promise<string[]>;
|
|
118
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineDefinition.d.ts","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,uBAAuB,CAAC;IAEzD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,WAAW,EAA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andLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { SCOPING_PARAMETER_GROUP } from '../Constants';\n\n/**\n * For use with CommandLineParser, this interface represents a generic command-line parameter\n *\n * @public\n */\nexport interface IBaseCommandLineDefinition {\n /**\n * The long name of the flag including double dashes, e.g. \"--do-something\"\n */\n parameterLongName: string;\n\n /**\n * An optional short name for the flag including the dash, e.g. \"-d\"\n */\n parameterShortName?: string;\n\n /**\n * An optional parameter group name, shown when invoking the tool with \"--help\"\n */\n parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;\n\n /**\n * An optional parameter scope name, used to add a scope-prefixed parameter synonym,\n * e.g. \"--scope:do-something\". Scopes provide additional flexibility for parameters\n * in conflict resolution since when a scope is specified, parameters that have\n * conflicting long names will be defined using only the scope-prefixed name.\n */\n parameterScope?: string;\n\n /**\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\n */\n description: string;\n\n /**\n * If true, then an error occurs if the parameter was not included on the command-line.\n */\n required?: boolean;\n\n /**\n * The name of an environment variable that the parameter value will be read from,\n * if it was omitted from the command-line. An error will be reported if the\n * environment value cannot be parsed.\n *\n * @remarks\n * The environment variable name must consist only of upper-case letters, numbers,\n * and underscores. It may not start with a number. To disable this validation, set\n * `{@link IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames}`\n * to `true`.\n *\n * Syntax notes for environment variable values:\n *\n * - Choice Parameter: The value must match one of the defined choices,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Integer Parameter: The value must be an integer number,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - String Parameter: Any value is accepted, including an empty string.\n *\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\n * then it will be parsed as a JSON array, whose elements must be strings,\n * numbers, or boolean values.\n * If the string does not start with `[`, then it behaves like an\n * ordinary String Parameter: Any value is accepted, including an empty string.\n */\n environmentVariable?: string;\n\n /**\n * Allows for the use of environment variable names that do not conform to the standard\n * described by the Shell and Utilities volume of IEEE Std 1003.1-2001. This disables\n * the validation that is performed on the provided\n * {@link IBaseCommandLineDefinition.environmentVariable} value by default.\n *\n * @remarks\n * if this is set to `true`, environment variable discovery will vary based on the\n * platform in use. For example, Windows environment variable names are case-insensitive,\n * while on Linux, environment variable names are case-sensitive. It is recommended that\n * this option be used only when necessary based on environmental constraints.\n */\n allowNonStandardEnvironmentVariableNames?: boolean;\n\n /**\n * Specifies additional names for this parameter that are accepted but not displayed\n * in the command line help.\n *\n * @remarks\n * This option can be used in cases where a command-line parameter may have been renamed,\n * but the developer doesn't want to break backwards compatibility with systems that may\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\n */\n undocumentedSynonyms?: string[];\n}\n\n/**\n * The common base interface for parameter types that accept an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\n /**\n * The name of the argument, which will be shown in the command-line help.\n *\n * @remarks\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\n * then the command-line help would display \"--count NUMBER\". The argument name must\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\n */\n argumentName: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineChoiceParameter:1)} and\n * {@link CommandLineParameterProvider.(defineChoiceParameter:2)}, this interface\n * defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: TChoice[];\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: TChoice;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<TChoice[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options. The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineChoiceListDefinition<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: TChoice[];\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<TChoice[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\n * this interface defines a command line parameter that is a boolean flag.\n *\n * @public\n */\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineIntegerParameter:1)},\n * {@link CommandLineParameterProvider.(defineIntegerParameter:2)}, this interface\n * defines a command line parameter whose argument is an integer value.\n *\n * @public\n */\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: number;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\n * this interface defines a command line parameter whose argument is an integer value. The\n * parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineStringParameter:1)} and\n * {@link CommandLineParameterProvider.(defineStringParameter:2)}, this interface\n * defines a command line parameter whose argument is a string value.\n *\n * @public\n */\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * The default value which will be used if the parameter is omitted from the command line.\n *\n * @remarks\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\n * must not be true. Instead, a custom error message should be used to report cases\n * where a default value was not available.\n */\n defaultValue?: string;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\n * this interface defines a command line parameter whose argument is a single text string.\n * The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @public\n */\nexport interface ICommandLineRemainderDefinition {\n /**\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\n * the tool with \"--help\".\n */\n description: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineDefinition.js","sourceRoot":"","sources":["../../src/parameters/CommandLineDefinition.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { SCOPING_PARAMETER_GROUP } from '../Constants';\n\n/**\n * For use with CommandLineParser, this interface represents a generic command-line parameter\n *\n * @public\n */\nexport interface IBaseCommandLineDefinition {\n /**\n * The long name of the flag including double dashes, e.g. \"--do-something\"\n */\n parameterLongName: string;\n\n /**\n * An optional short name for the flag including the dash, e.g. \"-d\"\n */\n parameterShortName?: string;\n\n /**\n * An optional parameter group name, shown when invoking the tool with \"--help\"\n */\n parameterGroup?: string | typeof SCOPING_PARAMETER_GROUP;\n\n /**\n * An optional parameter scope name, used to add a scope-prefixed parameter synonym,\n * e.g. \"--scope:do-something\". Scopes provide additional flexibility for parameters\n * in conflict resolution since when a scope is specified, parameters that have\n * conflicting long names will be defined using only the scope-prefixed name.\n */\n parameterScope?: string;\n\n /**\n * Documentation for the parameter that will be shown when invoking the tool with \"--help\"\n */\n description: string;\n\n /**\n * If true, then an error occurs if the parameter was not included on the command-line.\n */\n required?: boolean;\n\n /**\n * The name of an environment variable that the parameter value will be read from,\n * if it was omitted from the command-line. An error will be reported if the\n * environment value cannot be parsed.\n *\n * @remarks\n * The environment variable name must consist only of upper-case letters, numbers,\n * and underscores. It may not start with a number. To disable this validation, set\n * `{@link IBaseCommandLineDefinition.allowNonStandardEnvironmentVariableNames}`\n * to `true`.\n *\n * Syntax notes for environment variable values:\n *\n * - Choice Parameter: The value must match one of the defined choices,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Flag Parameter: The value must be `1` for true, or `0` for false,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - Integer Parameter: The value must be an integer number,\n * otherwise a validation error is reported.\n * An empty string causes the environment variable to be ignored.\n *\n * - String Parameter: Any value is accepted, including an empty string.\n *\n * - String List Parameter: If the string starts with `[` (ignoring whitespace)\n * then it will be parsed as a JSON array, whose elements must be strings,\n * numbers, or boolean values.\n * If the string does not start with `[`, then it behaves like an\n * ordinary String Parameter: Any value is accepted, including an empty string.\n */\n environmentVariable?: string;\n\n /**\n * Allows for the use of environment variable names that do not conform to the standard\n * described by the Shell and Utilities volume of IEEE Std 1003.1-2001. This disables\n * the validation that is performed on the provided\n * {@link IBaseCommandLineDefinition.environmentVariable} value by default.\n *\n * @remarks\n * if this is set to `true`, environment variable discovery will vary based on the\n * platform in use. For example, Windows environment variable names are case-insensitive,\n * while on Linux, environment variable names are case-sensitive. It is recommended that\n * this option be used only when necessary based on environmental constraints.\n */\n allowNonStandardEnvironmentVariableNames?: boolean;\n\n /**\n * Specifies additional names for this parameter that are accepted but not displayed\n * in the command line help.\n *\n * @remarks\n * This option can be used in cases where a command-line parameter may have been renamed,\n * but the developer doesn't want to break backwards compatibility with systems that may\n * still be using the old name. Only the `parameterLongName` syntax is currently allowed.\n */\n undocumentedSynonyms?: string[];\n}\n\n/**\n * The common base interface for parameter types that accept an argument.\n *\n * @remarks\n * An argument is an accompanying command-line token, such as \"123\" in the\n * example \"--max-count 123\".\n * @public\n */\nexport interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition {\n /**\n * The name of the argument, which will be shown in the command-line help.\n *\n * @remarks\n * For example, if the parameter name is '--count\" and the argument name is \"NUMBER\",\n * then the command-line help would display \"--count NUMBER\". The argument name must\n * be comprised of upper-case letters, numbers, and underscores. It should be kept short.\n */\n argumentName: string;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n *\n * In a future release, this will be renamed to `getCompletionsAsync`\n */\n completions?: () => Promise<string[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineChoiceParameter:1)} and\n * {@link CommandLineParameterProvider.(defineChoiceParameter:2)}, this interface\n * defines a command line parameter which is constrained to a list of possible\n * options.\n *\n * @public\n */\nexport interface ICommandLineChoiceDefinition<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: TChoice[];\n\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: TChoice;\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<TChoice[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineChoiceListParameter},\n * this interface defines a command line parameter which is constrained to a list of possible\n * options. The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineChoiceListDefinition<TChoice extends string = string>\n extends IBaseCommandLineDefinition {\n /**\n * A list of strings (which contain no spaces), of possible options which can be selected\n */\n alternatives: TChoice[];\n\n /**\n * An optional callback that provides a list of custom choices for tab completion.\n * @remarks\n * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction`\n * is enabled.\n */\n completions?: () => Promise<TChoice[]>;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineFlagParameter},\n * this interface defines a command line parameter that is a boolean flag.\n *\n * @public\n */\nexport interface ICommandLineFlagDefinition extends IBaseCommandLineDefinition {}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineIntegerParameter:1)},\n * {@link CommandLineParameterProvider.(defineIntegerParameter:2)}, this interface\n * defines a command line parameter whose argument is an integer value.\n *\n * @public\n */\nexport interface ICommandLineIntegerDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * {@inheritDoc ICommandLineStringDefinition.defaultValue}\n */\n defaultValue?: number;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineIntegerListParameter},\n * this interface defines a command line parameter whose argument is an integer value. The\n * parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineIntegerListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.(defineStringParameter:1)} and\n * {@link CommandLineParameterProvider.(defineStringParameter:2)}, this interface\n * defines a command line parameter whose argument is a string value.\n *\n * @public\n */\nexport interface ICommandLineStringDefinition extends IBaseCommandLineDefinitionWithArgument {\n /**\n * The default value which will be used if the parameter is omitted from the command line.\n *\n * @remarks\n * If a default value is specified, then {@link IBaseCommandLineDefinition.required}\n * must not be true. Instead, a custom error message should be used to report cases\n * where a default value was not available.\n */\n defaultValue?: string;\n}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineStringListParameter},\n * this interface defines a command line parameter whose argument is a single text string.\n * The parameter can be specified multiple times to build a list.\n *\n * @public\n */\nexport interface ICommandLineStringListDefinition extends IBaseCommandLineDefinitionWithArgument {}\n\n/**\n * For use with {@link CommandLineParameterProvider.defineCommandLineRemainder},\n * this interface defines a rule that captures any remaining command line arguments after the recognized portion.\n *\n * @public\n */\nexport interface ICommandLineRemainderDefinition {\n /**\n * Documentation for how the remaining arguments will be used. This will be shown when invoking\n * the tool with \"--help\".\n */\n description: string;\n}\n"]}
|
|
@@ -143,7 +143,7 @@ class AliasCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
143
143
|
* Executes the target action.
|
|
144
144
|
*/
|
|
145
145
|
async onExecute() {
|
|
146
|
-
await this.targetAction.
|
|
146
|
+
await this.targetAction._executeAsync();
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
exports.AliasCommandLineAction = AliasCommandLineAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAImC;AA+BnC;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC,CAAC,EAC5D,IAAI,CAAC;QAEL,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7B,OAAO;YACP,aAAa,EACX,GAAG,OAAO,oDAAoD;gBAC9D,IAAI,YAAY,IAAI,gBAAgB,WAAW;SAClD,CAAC,CAAC;QAhBG,qBAAgB,GAAwB,IAAI,GAAG,EAAE,CAAC;QAkBxD,IAAI,C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,eAAe,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAwC,EAAE,IAA4B;QAC9F,oGAAoG;QACpG,MAAM,UAAU,GAA2B;YACzC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;YACpC,WAAW,EAAE,IAAI,CAAC,MAAM;YACxB,kBAAkB,EAAE,IAAI,CAAC,aAAa;SACvC,CAAC;QACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,yFAAyF;YACzF,qFAAqF;YACrF,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAuB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrE,UAAU,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,GAAG,CAAC,GAAG,KAAK,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,SAAS;QACvB,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;CACF;AA3ID,wDA2IC","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 { CommandLineAction } from './CommandLineAction';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\n\n/**\n * Options for the AliasCommandLineAction constructor.\n * @public\n */\nexport interface IAliasCommandLineActionOptions {\n /**\n * The name of your tool when invoked from the command line. Used for generating help text.\n */\n toolFilename: string;\n\n /**\n * The name of the alias. For example, if the tool is called \"example\",\n * then the \"build\" alias might be invoked as: \"example build -q --some-other-option\"\n */\n aliasName: string;\n\n /**\n * A list of default parameters to pass to the target action.\n */\n defaultParameters?: string[];\n\n /**\n * The action that this alias invokes.\n */\n targetAction: CommandLineAction;\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * The sub-command is an alias for another existing action.\n *\n * The alias name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\").\n *\n * @public\n */\nexport class AliasCommandLineAction extends CommandLineAction {\n /**\n * The action that this alias invokes.\n */\n public readonly targetAction: CommandLineAction;\n\n /**\n * A list of default arguments to pass to the target action.\n */\n public readonly defaultParameters: ReadonlyArray<string>;\n\n private _parameterKeyMap: Map<string, string> = new Map();\n\n public constructor(options: IAliasCommandLineActionOptions) {\n const toolFilename: string = options.toolFilename;\n const targetActionName: string = options.targetAction.actionName;\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\n defaultParametersString ? ` ${defaultParametersString}` : ''\n }\".`;\n\n super({\n actionName: options.aliasName,\n summary,\n documentation:\n `${summary} For more information on the aliased command, use ` +\n `\"${toolFilename} ${targetActionName} --help\".`\n });\n\n this.targetAction = options.targetAction;\n this.defaultParameters = options.defaultParameters || [];\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n /* override */\n // All parameters are going to be defined by the target action. Re-use the target action parameters\n // for this action.\n for (const parameter of this.targetAction.parameters as CommandLineParameter[]) {\n const { kind, longName, shortName } = parameter;\n let aliasParameter: CommandLineParameterBase;\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\n parameterLongName: longName,\n parameterShortName: shortName\n };\n switch (kind) {\n case CommandLineParameterKind.Choice:\n aliasParameter = this.defineChoiceParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.ChoiceList:\n aliasParameter = this.defineChoiceListParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.Flag:\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.Integer:\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.IntegerList:\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.String:\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.StringList:\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...parameter });\n break;\n default:\n throw new Error(`Unsupported parameter kind: ${kind}`);\n }\n\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\n // and all parameters that we have access to have already been defined.\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\n }\n\n // We also need to register the remainder parameter if the target action has one. The parser\n // key for this parameter is constant.\n if (this.targetAction.remainder) {\n this.defineCommandLineRemainder(this.targetAction.remainder);\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\n }\n\n // Finally, register the parameters with the parser. We need to make sure that the target action\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\n // during registration. This will no-op if the target action is already registered.\n this.targetAction._registerDefinedParameters(state);\n super._registerDefinedParameters(state);\n\n // We need to re-map the ambiguous parameters after they are defined by calling\n // super._registerDefinedParameters()\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n const targetParserKey: string | undefined =\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\n\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n if (targetParserKey) {\n this._parameterKeyMap.set(parserKey, targetParserKey);\n }\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // Re-map the parsed data to the target action's parameters and execute the target action processor.\n const targetData: ICommandLineParserData = {\n action: this.targetAction.actionName,\n aliasAction: data.action,\n aliasDocumentation: this.documentation\n };\n for (const [key, value] of Object.entries(data)) {\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n // Skip over the action key though, since we've already re-mapped it to \"aliasAction\"\n if (key === 'action') {\n continue;\n }\n const targetKey: string | undefined = this._parameterKeyMap.get(key);\n targetData[targetKey ?? key] = value;\n }\n this.targetAction._processParsedData(parserOptions, targetData);\n }\n\n /**\n * Executes the target action.\n */\n protected async onExecute(): Promise<void> {\n await this.targetAction._execute();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AliasCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/AliasCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAErC,2DAAwD;AACxD,2DAImC;AA+BnC;;;;;;;;;GASG;AACH,MAAa,sBAAuB,SAAQ,qCAAiB;IAa3D,YAAmB,OAAuC;QACxD,MAAM,YAAY,GAAW,OAAO,CAAC,YAAY,CAAC;QAClD,MAAM,gBAAgB,GAAW,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC;QACjE,MAAM,uBAAuB,GAAW,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpF,MAAM,OAAO,GAAW,iBAAiB,YAAY,IAAI,gBAAgB,GACvE,uBAAuB,CAAC,CAAC,CAAC,IAAI,uBAAuB,EAAE,CAAC,CAAC,CAAC,EAC5D,IAAI,CAAC;QAEL,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7B,OAAO;YACP,aAAa,EACX,GAAG,OAAO,oDAAoD;gB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AsB,CAAC,CAAC;YAEpF,yFAAyF;YACzF,IAAI,eAAe,EAAE,CAAC;gBACpB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAwC,EAAE,IAA4B;QAC9F,oGAAoG;QACpG,MAAM,UAAU,GAA2B;YACzC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU;YACpC,WAAW,EAAE,IAAI,CAAC,MAAM;YACxB,kBAAkB,EAAE,IAAI,CAAC,aAAa;SACvC,CAAC;QACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,yFAAyF;YACzF,qFAAqF;YACrF,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAuB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACrE,UAAU,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,GAAG,CAAC,GAAG,KAAK,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,SAAS;QACvB,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;IAC1C,CAAC;CACF;AA3ID,wDA2IC","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 { CommandLineAction } from './CommandLineAction';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport type { ICommandLineParserData, IRegisterDefinedParametersState } from './CommandLineParameterProvider';\nimport type { ICommandLineParserOptions } from './CommandLineParser';\n\n/**\n * Options for the AliasCommandLineAction constructor.\n * @public\n */\nexport interface IAliasCommandLineActionOptions {\n /**\n * The name of your tool when invoked from the command line. Used for generating help text.\n */\n toolFilename: string;\n\n /**\n * The name of the alias. For example, if the tool is called \"example\",\n * then the \"build\" alias might be invoked as: \"example build -q --some-other-option\"\n */\n aliasName: string;\n\n /**\n * A list of default parameters to pass to the target action.\n */\n defaultParameters?: string[];\n\n /**\n * The action that this alias invokes.\n */\n targetAction: CommandLineAction;\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * The sub-command is an alias for another existing action.\n *\n * The alias name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\").\n *\n * @public\n */\nexport class AliasCommandLineAction extends CommandLineAction {\n /**\n * The action that this alias invokes.\n */\n public readonly targetAction: CommandLineAction;\n\n /**\n * A list of default arguments to pass to the target action.\n */\n public readonly defaultParameters: ReadonlyArray<string>;\n\n private _parameterKeyMap: Map<string, string> = new Map();\n\n public constructor(options: IAliasCommandLineActionOptions) {\n const toolFilename: string = options.toolFilename;\n const targetActionName: string = options.targetAction.actionName;\n const defaultParametersString: string = (options.defaultParameters || []).join(' ');\n const summary: string = `An alias for \"${toolFilename} ${targetActionName}${\n defaultParametersString ? ` ${defaultParametersString}` : ''\n }\".`;\n\n super({\n actionName: options.aliasName,\n summary,\n documentation:\n `${summary} For more information on the aliased command, use ` +\n `\"${toolFilename} ${targetActionName} --help\".`\n });\n\n this.targetAction = options.targetAction;\n this.defaultParameters = options.defaultParameters || [];\n }\n\n /** @internal */\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n /* override */\n // All parameters are going to be defined by the target action. Re-use the target action parameters\n // for this action.\n for (const parameter of this.targetAction.parameters as CommandLineParameter[]) {\n const { kind, longName, shortName } = parameter;\n let aliasParameter: CommandLineParameterBase;\n const nameOptions: { parameterLongName: string; parameterShortName: string | undefined } = {\n parameterLongName: longName,\n parameterShortName: shortName\n };\n switch (kind) {\n case CommandLineParameterKind.Choice:\n aliasParameter = this.defineChoiceParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.ChoiceList:\n aliasParameter = this.defineChoiceListParameter({\n ...nameOptions,\n ...parameter,\n alternatives: [...parameter.alternatives]\n });\n break;\n case CommandLineParameterKind.Flag:\n aliasParameter = this.defineFlagParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.Integer:\n aliasParameter = this.defineIntegerParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.IntegerList:\n aliasParameter = this.defineIntegerListParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.String:\n aliasParameter = this.defineStringParameter({ ...nameOptions, ...parameter });\n break;\n case CommandLineParameterKind.StringList:\n aliasParameter = this.defineStringListParameter({ ...nameOptions, ...parameter });\n break;\n default:\n throw new Error(`Unsupported parameter kind: ${kind}`);\n }\n\n // We know the parserKey is defined because the underlying _defineParameter method sets it,\n // and all parameters that we have access to have already been defined.\n this._parameterKeyMap.set(aliasParameter._parserKey!, parameter._parserKey!);\n }\n\n // We also need to register the remainder parameter if the target action has one. The parser\n // key for this parameter is constant.\n if (this.targetAction.remainder) {\n this.defineCommandLineRemainder(this.targetAction.remainder);\n this._parameterKeyMap.set(argparse.Const.REMAINDER, argparse.Const.REMAINDER);\n }\n\n // Finally, register the parameters with the parser. We need to make sure that the target action\n // is registered, since we need to re-use its parameters, and ambiguous parameters are discovered\n // during registration. This will no-op if the target action is already registered.\n this.targetAction._registerDefinedParameters(state);\n super._registerDefinedParameters(state);\n\n // We need to re-map the ambiguous parameters after they are defined by calling\n // super._registerDefinedParameters()\n for (const [ambiguousParameterName, parserKey] of this._ambiguousParameterParserKeysByName) {\n const targetParserKey: string | undefined =\n this.targetAction._ambiguousParameterParserKeysByName.get(ambiguousParameterName);\n\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n if (targetParserKey) {\n this._parameterKeyMap.set(parserKey, targetParserKey);\n }\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // Re-map the parsed data to the target action's parameters and execute the target action processor.\n const targetData: ICommandLineParserData = {\n action: this.targetAction.actionName,\n aliasAction: data.action,\n aliasDocumentation: this.documentation\n };\n for (const [key, value] of Object.entries(data)) {\n // If we have a mapping for the specified key, then use it. Otherwise, use the key as-is.\n // Skip over the action key though, since we've already re-mapped it to \"aliasAction\"\n if (key === 'action') {\n continue;\n }\n const targetKey: string | undefined = this._parameterKeyMap.get(key);\n targetData[targetKey ?? key] = value;\n }\n this.targetAction._processParsedData(parserOptions, targetData);\n }\n\n /**\n * Executes the target action.\n */\n protected async onExecute(): Promise<void> {\n await this.targetAction._executeAsync();\n }\n}\n"]}
|
|
@@ -52,7 +52,7 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
|
|
|
52
52
|
* Invoked by CommandLineParser.onExecute().
|
|
53
53
|
* @internal
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
_executeAsync(): Promise<void>;
|
|
56
56
|
/**
|
|
57
57
|
* {@inheritDoc CommandLineParameterProvider._getArgumentParser}
|
|
58
58
|
* @internal
|
|
@@ -60,6 +60,9 @@ export declare abstract class CommandLineAction extends CommandLineParameterProv
|
|
|
60
60
|
_getArgumentParser(): argparse.ArgumentParser;
|
|
61
61
|
/**
|
|
62
62
|
* Your subclass should implement this hook to perform the operation.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* In a future release, this function will be renamed to onExecuteAsync
|
|
63
66
|
*/
|
|
64
67
|
protected abstract onExecute(): Promise<void>;
|
|
65
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAG9E;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAOD;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAkB,SAAQ,4BAA4B;IAC1E,yDAAyD;IACzD,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,sDAAsD;IACtD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,4DAA4D;IAC5D,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,eAAe,CAAsC;gBAE1C,OAAO,EAAE,yBAAyB;IAiBrD;;;OAGG;IACI,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI;IAwB/D;;;OAGG;IACI,
|
|
1
|
+
{"version":3,"file":"CommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAG9E;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAOD;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAkB,SAAQ,4BAA4B;IAC1E,yDAAyD;IACzD,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,sDAAsD;IACtD,SAAgB,OAAO,EAAE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AC;IAC9B,CAAC;CASF;AAtFD,8CAsFC","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 { CommandLineParameterProvider } from './CommandLineParameterProvider';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\n\n/**\n * Options for the CommandLineAction constructor.\n * @public\n */\nexport interface ICommandLineActionOptions {\n /**\n * The name of the action. For example, if the tool is called \"example\",\n * then the \"build\" action might be invoked as: \"example build -q --some-other-option\"\n */\n actionName: string;\n\n /**\n * A quick summary that is shown on the main help page, which is displayed\n * by the command \"example --help\"\n */\n summary: string;\n\n /**\n * A detailed description that is shown on the action help page, which is displayed\n * by the command \"example build --help\", e.g. for actionName=\"build\".\n */\n documentation: string;\n}\n\n/**\n * Example: \"do-something\"\n */\nconst ACTION_NAME_REGEXP: RegExp = /^[a-z][a-z0-9]*([-:][a-z0-9]+)*$/;\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command line.\n * Applications should create subclasses of CommandLineAction corresponding to\n * each action that they want to expose.\n *\n * The action name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\n * \"docs:serve\", etc).\n *\n * @public\n */\nexport abstract class CommandLineAction extends CommandLineParameterProvider {\n /** {@inheritDoc ICommandLineActionOptions.actionName} */\n public readonly actionName: string;\n\n /** {@inheritDoc ICommandLineActionOptions.summary} */\n public readonly summary: string;\n\n /** {@inheritDoc ICommandLineActionOptions.documentation} */\n public readonly documentation: string;\n\n private _argumentParser: argparse.ArgumentParser | undefined;\n\n public constructor(options: ICommandLineActionOptions) {\n super();\n\n if (!ACTION_NAME_REGEXP.test(options.actionName)) {\n throw new Error(\n `Invalid action name \"${options.actionName}\". ` +\n `The name must be comprised of lower-case words optionally separated by hyphens or colons.`\n );\n }\n\n this.actionName = options.actionName;\n this.summary = options.summary;\n this.documentation = options.documentation;\n\n this._argumentParser = undefined;\n }\n\n /**\n * This is called internally by CommandLineParser.addAction()\n * @internal\n */\n public _buildParser(actionsSubParser: argparse.SubParser): void {\n this._argumentParser = actionsSubParser.addParser(this.actionName, {\n help: this.summary,\n description: this.documentation\n });\n\n // Monkey-patch the error handling for the action parser\n this._argumentParser.exit = (status: number, message: string) => {\n throw new CommandLineParserExitError(status, message);\n };\n const originalArgumentParserErrorFn: (err: Error | string) => void = this._argumentParser.error.bind(\n this._argumentParser\n );\n this._argumentParser.error = (err: Error | string) => {\n // Ensure the ParserExitError bubbles up to the top without any special processing\n if (err instanceof CommandLineParserExitError) {\n throw err;\n }\n originalArgumentParserErrorFn(err);\n };\n\n this.onDefineParameters?.();\n }\n\n /**\n * Invoked by CommandLineParser.onExecute().\n * @internal\n */\n public _executeAsync(): Promise<void> {\n return this.onExecute();\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider._getArgumentParser}\n * @internal\n */\n public _getArgumentParser(): argparse.ArgumentParser {\n // override\n if (!this._argumentParser) {\n // We will improve this in the future\n throw new Error('The CommandLineAction must be added to a CommandLineParser before it can be used');\n }\n\n return this._argumentParser;\n }\n\n /**\n * Your subclass should implement this hook to perform the operation.\n *\n * @remarks\n * In a future release, this function will be renamed to onExecuteAsync\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
@@ -305,17 +305,17 @@ export declare abstract class CommandLineParameterProvider {
|
|
|
305
305
|
*/
|
|
306
306
|
protected abstract _getArgumentParser(): argparse.ArgumentParser;
|
|
307
307
|
/**
|
|
308
|
-
* This is called internally by {@link CommandLineParser.
|
|
308
|
+
* This is called internally by {@link CommandLineParser.executeAsync}
|
|
309
309
|
* @internal
|
|
310
310
|
*/
|
|
311
311
|
_preParse(): void;
|
|
312
312
|
/**
|
|
313
|
-
* This is called internally by {@link CommandLineParser.
|
|
313
|
+
* This is called internally by {@link CommandLineParser.executeAsync} before `printUsage` is called
|
|
314
314
|
* @internal
|
|
315
315
|
*/
|
|
316
316
|
_postParse(): void;
|
|
317
317
|
/**
|
|
318
|
-
* This is called internally by {@link CommandLineParser.
|
|
318
|
+
* This is called internally by {@link CommandLineParser.executeAsync}
|
|
319
319
|
* @internal
|
|
320
320
|
*/
|
|
321
321
|
_processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void;
|
|
@@ -356,7 +356,7 @@ class CommandLineParameterProvider {
|
|
|
356
356
|
this._parametersHaveBeenRegistered = true;
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
|
-
* This is called internally by {@link CommandLineParser.
|
|
359
|
+
* This is called internally by {@link CommandLineParser.executeAsync}
|
|
360
360
|
* @internal
|
|
361
361
|
*/
|
|
362
362
|
_preParse() {
|
|
@@ -366,7 +366,7 @@ class CommandLineParameterProvider {
|
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
|
-
* This is called internally by {@link CommandLineParser.
|
|
369
|
+
* This is called internally by {@link CommandLineParser.executeAsync} before `printUsage` is called
|
|
370
370
|
* @internal
|
|
371
371
|
*/
|
|
372
372
|
_postParse() {
|
|
@@ -376,7 +376,7 @@ class CommandLineParameterProvider {
|
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
/**
|
|
379
|
-
* This is called internally by {@link CommandLineParser.
|
|
379
|
+
* This is called internally by {@link CommandLineParser.executeAsync}
|
|
380
380
|
* @internal
|
|
381
381
|
*/
|
|
382
382
|
_processParsedData(parserOptions, data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAarC,2DAKmC;AACnC,yFAGkD;AAClD,iGAA8F;AAC9F,2FAGmD;AACnD,mGAAgG;AAChG,qFAA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gBACjC,MAAM,IAAI,KAAK,CACb,kBAAkB,iBAAiB,iBAAiB,cAAc,mBAAmB,CACtF,CAAC;YACJ,CAAC;YACD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,kBAAkB,iBAAiB,2CAA2C,CAAC,CAAC;YAClG,CAAC;YACD,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,SAAS,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,kBAAkB,iBAAiB,iBAAiB,sCAAwB,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;gBAC7F,sCAAsC,sCAAwB,CAAC,YAAY,CAAC,IAAI,CACnF,CAAC;QACJ,CAAC;QAED,OAAO,SAAc,CAAC;IACxB,CAAC;IAEO,qBAAqB,CAC3B,aAAwC,EACxC,IAA4B,EAC5B,SAAiB,EACjB,OAAe;QAEf,6FAA6F;QAC7F,MAAM,gBAAgB,GAAW,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QACvE,MAAM,WAAW,GACf,UAAU,aAAa,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,uDAA0B,CAAC,SAAS,EAAE,GAAG,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;;AAn6BH,oEAo6BC;AAn6BgB,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';\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<CommandLineParameterBase> {\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 * The child class should implement this hook to define its command-line parameters,\n * e.g. by calling defineFlagParameter().\n */\n protected onDefineParameters?(): void;\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.execute}\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.execute} 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.execute}\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 = parameter.alternatives as string[];\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n choices = parameter.alternatives as string[];\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: 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"]}
|
|
1
|
+
{"version":3,"file":"CommandLineParameterProvider.js","sourceRoot":"","sources":["../../src/providers/CommandLineParameterProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mDAAqC;AAarC,2DAKmC;AACnC,yFAGkD;AAClD,iGAA8F;AAC9F,2FAGmD;AACnD,mGAAgG;AAChG,qFAAkF;AAClF,yFAGkD;AAClD,iGAA8F;AAC9F,6EAA0E;AAC1E,4CAAuD;AACvD,6EAA0E;AA6C1E,MAAM,gBAAgB,GAAW,OAAO,CAAC;AACzC,MAAM,oBAAoB,GAAW,UAAU,CAAC;AAChD,MAAM,gCAAgC,GACpC,gFAAgF,CAAC;AAanF;;;;;GAKG;AACH,MAAsB,4BAA4B;IAmBhD,gBAAgB;IAChB,0EAA0E;IAC1E;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;QACvC,IAAI,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAE,CAAC;QACxC,IAAI,CAAC,mCAAmC,GAAG,IAAI,GAAG,EAAE,CAAC;QACrD,IAAI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O,qBAAqB,CAC3B,aAAwC,EACxC,IAA4B,EAC5B,SAAiB,EACjB,OAAe;QAEf,6FAA6F;QAC7F,MAAM,gBAAgB,GAAW,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QACvE,MAAM,WAAW,GACf,UAAU,aAAa,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,uDAA0B,CAAC,SAAS,EAAE,GAAG,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;;AAn6BH,oEAo6BC;AAn6BgB,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';\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<CommandLineParameterBase> {\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 * The child class should implement this hook to define its command-line parameters,\n * e.g. by calling defineFlagParameter().\n */\n protected onDefineParameters?(): void;\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 = parameter.alternatives as string[];\n break;\n }\n case CommandLineParameterKind.ChoiceList: {\n choices = parameter.alternatives as string[];\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: 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"]}
|
|
@@ -78,17 +78,25 @@ export declare abstract class CommandLineParser extends CommandLineParameterProv
|
|
|
78
78
|
* want to be involved with the command-line logic, and will discard the promise without
|
|
79
79
|
* a then() or catch() block.
|
|
80
80
|
*
|
|
81
|
-
* If your caller wants to trap and handle errors, use {@link CommandLineParser.
|
|
81
|
+
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandlingAsync}
|
|
82
82
|
* instead.
|
|
83
83
|
*
|
|
84
84
|
* @param args - the command-line arguments to be parsed; if omitted, then
|
|
85
85
|
* the process.argv will be used
|
|
86
86
|
*/
|
|
87
|
+
executeAsync(args?: string[]): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use {@link CommandLineParser.executeAsync} instead.
|
|
90
|
+
*/
|
|
87
91
|
execute(args?: string[]): Promise<boolean>;
|
|
88
92
|
/**
|
|
89
|
-
* This is similar to {@link CommandLineParser.
|
|
93
|
+
* This is similar to {@link CommandLineParser.executeAsync}, except that execution errors
|
|
90
94
|
* simply cause the promise to reject. It is the caller's responsibility to trap
|
|
91
95
|
*/
|
|
96
|
+
executeWithoutErrorHandlingAsync(args?: string[]): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.
|
|
99
|
+
*/
|
|
92
100
|
executeWithoutErrorHandling(args?: string[]): Promise<void>;
|
|
93
101
|
/** @internal */
|
|
94
102
|
_registerDefinedParameters(state: IRegisterDefinedParametersState): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParser.d.ts","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAG1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EACL,4BAA4B,EAC5B,KAAK,+BAA+B,EAErC,MAAM,gCAAgC,CAAC;AAIxC;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,EAAE,MAAM,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C,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxE,gBAAgB;IACT,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,IAAI;IAkB/E,OAAO,CAAC,oBAAoB;IAO5B;;;OAGG;IACH,SAAS,CAAC,kBAAkB,IAAI,QAAQ,CAAC,cAAc;IAKvD;;;OAGG;cACa,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAK3C"}
|
|
@@ -83,24 +83,24 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
83
83
|
* want to be involved with the command-line logic, and will discard the promise without
|
|
84
84
|
* a then() or catch() block.
|
|
85
85
|
*
|
|
86
|
-
* If your caller wants to trap and handle errors, use {@link CommandLineParser.
|
|
86
|
+
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandlingAsync}
|
|
87
87
|
* instead.
|
|
88
88
|
*
|
|
89
89
|
* @param args - the command-line arguments to be parsed; if omitted, then
|
|
90
90
|
* the process.argv will be used
|
|
91
91
|
*/
|
|
92
|
-
async
|
|
92
|
+
async executeAsync(args) {
|
|
93
93
|
if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {
|
|
94
94
|
this.addAction(new TabCompletionAction_1.TabCompleteAction(this.actions, this.parameters));
|
|
95
95
|
this._tabCompleteActionWasAdded = true;
|
|
96
96
|
}
|
|
97
97
|
try {
|
|
98
|
-
await this.
|
|
98
|
+
await this.executeWithoutErrorHandlingAsync(args);
|
|
99
99
|
return true;
|
|
100
100
|
}
|
|
101
101
|
catch (err) {
|
|
102
102
|
if (err instanceof CommandLineParserExitError_1.CommandLineParserExitError) {
|
|
103
|
-
//
|
|
103
|
+
// executeWithoutErrorHandlingAsync() handles the successful cases,
|
|
104
104
|
// so here we can assume err has a nonzero exit code
|
|
105
105
|
if (err.message) {
|
|
106
106
|
// eslint-disable-next-line no-console
|
|
@@ -128,17 +128,24 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
131
|
+
* @deprecated Use {@link CommandLineParser.executeAsync} instead.
|
|
132
|
+
*/
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
134
|
+
async execute(args) {
|
|
135
|
+
return await this.executeAsync(args);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* This is similar to {@link CommandLineParser.executeAsync}, except that execution errors
|
|
132
139
|
* simply cause the promise to reject. It is the caller's responsibility to trap
|
|
133
140
|
*/
|
|
134
|
-
async
|
|
141
|
+
async executeWithoutErrorHandlingAsync(args) {
|
|
135
142
|
var _a, _b;
|
|
136
143
|
try {
|
|
137
144
|
if (this._executed) {
|
|
138
145
|
// In the future we could allow the same parser to be invoked multiple times
|
|
139
146
|
// with different arguments. We'll do that work as soon as someone encounters
|
|
140
147
|
// a real world need for it.
|
|
141
|
-
throw new Error('
|
|
148
|
+
throw new Error('executeAsync() was already called for this parser instance');
|
|
142
149
|
}
|
|
143
150
|
this._executed = true;
|
|
144
151
|
this._validateDefinitions();
|
|
@@ -218,6 +225,13 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
218
225
|
throw err;
|
|
219
226
|
}
|
|
220
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.
|
|
230
|
+
*/
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
232
|
+
async executeWithoutErrorHandling(args) {
|
|
233
|
+
await this.executeWithoutErrorHandlingAsync(args);
|
|
234
|
+
}
|
|
221
235
|
/** @internal */
|
|
222
236
|
_registerDefinedParameters(state) {
|
|
223
237
|
super._registerDefinedParameters(state);
|
|
@@ -251,7 +265,7 @@ class CommandLineParser extends CommandLineParameterProvider_1.CommandLineParame
|
|
|
251
265
|
*/
|
|
252
266
|
async onExecute() {
|
|
253
267
|
if (this.selectedAction) {
|
|
254
|
-
await this.selectedAction.
|
|
268
|
+
await this.selectedAction._executeAsync();
|
|
255
269
|
}
|
|
256
270
|
}
|
|
257
271
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAA+C;AAI/C,iFAIwC;AACxC,6EAAgG;AAChG,+DAA0D;AA6B1D;;;;;;;;;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,mBAAQ,CAAC,IAAI,CACnB,MAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,mCACtB,oDAAoD,IAAI,CAAC,QAAQ,CAAC,YAAY,eAAe,CAChG;SACF,CAAC,CAAC;QAEH,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,MAAyB;QACxC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,IAAI,CAAC,iBAAiB,GAAG,IAAI,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X,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AA5RD,8CA4RC","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';\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';\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 abstract base classes CommandLineParser and CommandLineAction\n * provide a wrapper for \"argparse\" that makes defining and consuming arguments quick\n * and simple, and enforces that appropriate documentation is provided for each parameter.\n *\n * @public\n */\nexport abstract class CommandLineParser extends CommandLineParameterProvider {\n /**\n * Reports which CommandLineAction was specified on the command line.\n * @remarks\n * The value will be assigned before onExecute() is invoked.\n */\n public selectedAction: CommandLineAction | undefined;\n\n private readonly _argumentParser: argparse.ArgumentParser;\n private _actionsSubParser: argparse.SubParser | undefined;\n private readonly _options: ICommandLineParserOptions;\n private readonly _actions: CommandLineAction[];\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._actions = [];\n this._actionsByName = new Map<string, CommandLineAction>();\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: this._options.toolFilename,\n description: this._options.toolDescription,\n epilog: Colorize.bold(\n this._options.toolEpilog ??\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\n )\n });\n\n this.onDefineParameters?.();\n }\n\n /**\n * Returns the list of actions that were defined for this CommandLineParser object.\n */\n public get actions(): ReadonlyArray<CommandLineAction> {\n return this._actions;\n }\n\n /**\n * Defines a new action that can be used with the CommandLineParser instance.\n */\n public addAction(action: CommandLineAction): void {\n if (!this._actionsSubParser) {\n this._actionsSubParser = this._argumentParser.addSubparsers({\n metavar: '<command>',\n dest: 'action'\n });\n }\n\n action._buildParser(this._actionsSubParser);\n this._actions.push(action);\n this._actionsByName.set(action.actionName, action);\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * an exception is thrown.\n */\n public getAction(actionName: string): CommandLineAction {\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n if (!action) {\n throw new Error(`The action \"${actionName}\" was not defined`);\n }\n return action;\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * undefined is returned.\n */\n public tryGetAction(actionName: string): CommandLineAction | undefined {\n return this._actionsByName.get(actionName);\n }\n\n /**\n * The program entry point will call this method to begin parsing command-line arguments\n * and executing the corresponding action.\n *\n * @remarks\n * The returned promise will never reject: If an error occurs, it will be printed\n * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.\n * This simplifies the most common usage scenario where the program entry point doesn't\n * want to be involved with the command-line logic, and will discard the promise without\n * a then() or catch() block.\n *\n * If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}\n * instead.\n *\n * @param args - the command-line arguments to be parsed; if omitted, then\n * the process.argv will be used\n */\n public async execute(args?: string[]): Promise<boolean> {\n if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) {\n this.addAction(new TabCompleteAction(this.actions, this.parameters));\n this._tabCompleteActionWasAdded = true;\n }\n\n try {\n await this.executeWithoutErrorHandling(args);\n return true;\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n // executeWithoutErrorHandling() handles the successful cases,\n // so here we can assume err has a nonzero exit code\n if (err.message) {\n // eslint-disable-next-line no-console\n console.error(err.message);\n }\n if (!process.exitCode) {\n process.exitCode = err.exitCode;\n }\n } else {\n let message: string = ((err as Error).message || 'An unknown error occurred').trim();\n\n // If the message doesn't already start with \"Error:\" then add a prefix\n if (!/^(error|internal error|warning)\\b/i.test(message)) {\n message = 'Error: ' + message;\n }\n\n // 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.execute}, except that execution errors\n * simply cause the promise to reject. It is the caller's responsibility to trap\n */\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\n try {\n if (this._executed) {\n // In the future we could allow the same parser to be invoked multiple times\n // with different arguments. We'll do that work as soon as someone encounters\n // a real world need for it.\n throw new Error('execute() was already called for this parser instance');\n }\n this._executed = true;\n\n this._validateDefinitions();\n\n // 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.onExecute();\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n if (!err.exitCode) {\n // non-error exit modeled using exception handling\n if (err.message) {\n // 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._actions) {\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 _getArgumentParser(): argparse.ArgumentParser {\n // override\n return this._argumentParser;\n }\n\n /**\n * This hook allows the subclass to perform additional operations before or after\n * the chosen action is executed.\n */\n protected async onExecute(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._execute();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CommandLineParser.js","sourceRoot":"","sources":["../../src/providers/CommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAA+C;AAI/C,iFAIwC;AACxC,6EAAgG;AAChG,+DAA0D;AA6B1D;;;;;;;;;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,mBAAQ,CAAC,IAAI,CACnB,MAAA,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CAAC;QAExC,MAAM,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC;QACvC,MAAM,2BAA2B,GAAgB,IAAI,GAAG,CAAC;YACvD,GAAG,oBAAoB;YACvB,GAAG,IAAI,CAAC,oCAAoC,CAAC,IAAI,EAAE;SACpD,CAAC,CAAC;QAEH,MAAM,WAAW,mCACZ,KAAK,KACR,oBAAoB,EAAE,2BAA2B,GAClD,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,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;IACO,kBAAkB;QAC1B,WAAW;QACX,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AA5SD,8CA4SC","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';\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';\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 abstract base classes CommandLineParser and CommandLineAction\n * provide a wrapper for \"argparse\" that makes defining and consuming arguments quick\n * and simple, and enforces that appropriate documentation is provided for each parameter.\n *\n * @public\n */\nexport abstract class CommandLineParser extends CommandLineParameterProvider {\n /**\n * Reports which CommandLineAction was specified on the command line.\n * @remarks\n * The value will be assigned before onExecute() is invoked.\n */\n public selectedAction: CommandLineAction | undefined;\n\n private readonly _argumentParser: argparse.ArgumentParser;\n private _actionsSubParser: argparse.SubParser | undefined;\n private readonly _options: ICommandLineParserOptions;\n private readonly _actions: CommandLineAction[];\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._actions = [];\n this._actionsByName = new Map<string, CommandLineAction>();\n\n this._argumentParser = new CustomArgumentParser({\n addHelp: true,\n prog: this._options.toolFilename,\n description: this._options.toolDescription,\n epilog: Colorize.bold(\n this._options.toolEpilog ??\n `For detailed help about a specific command, use: ${this._options.toolFilename} <command> -h`\n )\n });\n\n this.onDefineParameters?.();\n }\n\n /**\n * Returns the list of actions that were defined for this CommandLineParser object.\n */\n public get actions(): ReadonlyArray<CommandLineAction> {\n return this._actions;\n }\n\n /**\n * Defines a new action that can be used with the CommandLineParser instance.\n */\n public addAction(action: CommandLineAction): void {\n if (!this._actionsSubParser) {\n this._actionsSubParser = this._argumentParser.addSubparsers({\n metavar: '<command>',\n dest: 'action'\n });\n }\n\n action._buildParser(this._actionsSubParser);\n this._actions.push(action);\n this._actionsByName.set(action.actionName, action);\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * an exception is thrown.\n */\n public getAction(actionName: string): CommandLineAction {\n const action: CommandLineAction | undefined = this.tryGetAction(actionName);\n if (!action) {\n throw new Error(`The action \"${actionName}\" was not defined`);\n }\n return action;\n }\n\n /**\n * Retrieves the action with the specified name. If no matching action is found,\n * undefined is returned.\n */\n public tryGetAction(actionName: string): CommandLineAction | undefined {\n return this._actionsByName.get(actionName);\n }\n\n /**\n * The program entry point will call this method to begin parsing command-line arguments\n * and executing the corresponding action.\n *\n * @remarks\n * The returned promise will never reject: If an error occurs, it will be printed\n * to stderr, process.exitCode will be set to 1, and the promise will resolve to false.\n * This simplifies the most common usage scenario where the program entry point doesn't\n * want to be involved with the command-line logic, and will discard the promise without\n * a then() or catch() block.\n *\n * If your caller wants to trap and handle errors, use {@link CommandLineParser.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 {\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 * @deprecated Use {@link CommandLineParser.executeAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async execute(args?: string[]): Promise<boolean> {\n return await this.executeAsync(args);\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.onExecute();\n } catch (err) {\n if (err instanceof CommandLineParserExitError) {\n if (!err.exitCode) {\n // non-error exit modeled using exception handling\n if (err.message) {\n // 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 /**\n * @deprecated Use {@link CommandLineParser.executeWithoutErrorHandlingAsync} instead.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async executeWithoutErrorHandling(args?: string[]): Promise<void> {\n await this.executeWithoutErrorHandlingAsync(args);\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._actions) {\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 _getArgumentParser(): argparse.ArgumentParser {\n // override\n return this._argumentParser;\n }\n\n /**\n * This hook allows the subclass to perform additional operations before or after\n * the chosen action is executed.\n */\n protected async onExecute(): Promise<void> {\n if (this.selectedAction) {\n await this.selectedAction._executeAsync();\n }\n }\n}\n"]}
|
|
@@ -49,10 +49,10 @@ export declare abstract class ScopedCommandLineAction extends CommandLineAction
|
|
|
49
49
|
*/
|
|
50
50
|
_processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void;
|
|
51
51
|
/**
|
|
52
|
-
* {@inheritdoc CommandLineAction.
|
|
52
|
+
* {@inheritdoc CommandLineAction._executeAsync}
|
|
53
53
|
* @internal
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
_executeAsync(): Promise<void>;
|
|
56
56
|
/** @internal */
|
|
57
57
|
_registerDefinedParameters(state: IRegisterDefinedParametersState): void;
|
|
58
58
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopedCommandLineAction.d.ts","sourceRoot":"","sources":["../../src/providers/ScopedCommandLineAction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAExF,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,KAAK,EACV,4BAA4B,EAC5B,sBAAsB,EACtB,+BAA+B,EAChC,MAAM,gCAAgC,CAAC;AAmExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8BAAsB,uBAAwB,SAAQ,iBAAiB;IACrE,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,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aAAa,CAAC,wBAAwB,CAAC,CAM/D;IAED;;;OAGG;IACI,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,EAAE,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAyBvG;;;OAGG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAuC3C,gBAAgB;IACT,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,IAAI;IAe/E;;OAEG;IACH,SAAS,CAAC,kBAAkB,IAAI,IAAI;IA2BpC;;;OAGG;IACH,SAAS,CAAC,2BAA2B,IAAI,iBAAiB;IAO1D,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAOjE;;;;;OAKG;IACH,SAAS,CAAC,0BAA0B,CAAC,IAAI,IAAI;IAE7C;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,wBAAwB,CAAC,uBAAuB,EAAE,4BAA4B,GAAG,IAAI;IAExG;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAC9C"}
|
|
@@ -111,10 +111,10 @@ class ScopedCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
111
111
|
this._scopedCommandLineParser = new InternalScopedCommandLineParser(Object.assign(Object.assign({}, parserOptions), { actionOptions: this._options, aliasAction: data.aliasAction, aliasDocumentation: data.aliasDocumentation, unscopedActionParameters: this.parameters, registerDefinedParametersState: this._subparserState, onDefineScopedParameters: this.onDefineScopedParameters.bind(this) }));
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* {@inheritdoc CommandLineAction.
|
|
114
|
+
* {@inheritdoc CommandLineAction._executeAsync}
|
|
115
115
|
* @internal
|
|
116
116
|
*/
|
|
117
|
-
async
|
|
117
|
+
async _executeAsync() {
|
|
118
118
|
// override
|
|
119
119
|
if (!this._unscopedParserOptions || !this._scopedCommandLineParser) {
|
|
120
120
|
throw new Error('The CommandLineAction parameters must be processed before execution.');
|
|
@@ -139,11 +139,11 @@ class ScopedCommandLineAction extends CommandLineAction_1.CommandLineAction {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
// Call the scoped parser using only the scoped args to handle parsing
|
|
142
|
-
await this._scopedCommandLineParser.
|
|
142
|
+
await this._scopedCommandLineParser.executeWithoutErrorHandlingAsync(scopedArgs);
|
|
143
143
|
// Only call execute if the parser reached the execute stage. This may not be true if
|
|
144
144
|
// the parser exited early due to a specified '--help' parameter.
|
|
145
145
|
if (this._scopedCommandLineParser.canExecute) {
|
|
146
|
-
await super.
|
|
146
|
+
await super._executeAsync();
|
|
147
147
|
}
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopedCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/ScopedCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,4CAAuD;AACvD,2DAAwF;AACxF,2DAAwF;AACxF,6EAA0E;AAiB1E;;;GAGG;AACH,MAAM,+BAAgC,SAAQ,qCAAiB;IAI7D,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,YAAmB,OAAgD;QACjE,MAAM,EAAE,aAAa,EAAE,wBAAwB,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAC9F,OAAO,CAAC;QAEV,MAAM,WAAW,GAAW,GAAG,YAAY,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QAC1E,6FAA6F;QAC7F,MAAM,qBAAqB,GAAW,GAAG,YAAY,IAAI,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QACnG,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,KAAK,MAAM,SAAS,IAAI,wBAAwB,EAAE,CAAC;YACjD,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAC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AED;;OAEG;IACO,kBAAkB;;QAC1B,MAAA,IAAI,CAAC,0BAA0B,oDAAI,CAAC;QAEpC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,iFAAiF;gBAC/E,sEAAsE;gBACtE,oDAAoD,CACvD,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,6FAA6F;gBAC3F,8DAA8D,CACjE,CAAC;QACJ,CAAC;QAED,2FAA2F;QAC3F,4FAA4F;QAC5F,mCAAmC;QACnC,IAAI,CAAC,0BAA0B,CAAC;YAC9B,WAAW,EACT,4EAA4E;gBAC5E,2FAA2F;SAC9F,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACO,2BAA2B;QACnC,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;QAClG,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,SAA+B;QACxD,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,SAAS,CAAC,cAAc,KAAK,uBAAuB,CAAC,qBAAqB,EAAE,CAAC;YAC/E,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;;AAzKH,0DAkMC;AA3LC;;;GAGG;AACoB,6CAAqB,GAAmC,mCAAuB,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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineAction, type ICommandLineActionOptions } from './CommandLineAction';\nimport { CommandLineParser, type ICommandLineParserOptions } from './CommandLineParser';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\nimport type { CommandLineParameter, CommandLineParameterBase } from '../parameters/BaseClasses';\nimport type {\n CommandLineParameterProvider,\n ICommandLineParserData,\n IRegisterDefinedParametersState\n} from './CommandLineParameterProvider';\n\ninterface IInternalScopedCommandLineParserOptions extends ICommandLineParserOptions {\n readonly actionOptions: ICommandLineActionOptions;\n readonly unscopedActionParameters: ReadonlyArray<CommandLineParameter>;\n readonly onDefineScopedParameters: (commandLineParameterProvider: CommandLineParameterProvider) => void;\n readonly aliasAction?: string;\n readonly aliasDocumentation?: string;\n readonly registerDefinedParametersState: IRegisterDefinedParametersState;\n}\n\n/**\n * A CommandLineParser used exclusively to parse the scoped command-line parameters\n * for a ScopedCommandLineAction.\n */\nclass InternalScopedCommandLineParser extends CommandLineParser {\n private _canExecute: boolean;\n private readonly _internalOptions: IInternalScopedCommandLineParserOptions;\n\n public get canExecute(): boolean {\n return this._canExecute;\n }\n\n public constructor(options: IInternalScopedCommandLineParserOptions) {\n const { actionOptions, unscopedActionParameters, toolFilename, aliasAction, aliasDocumentation } =\n options;\n\n const toolCommand: string = `${toolFilename} ${actionOptions.actionName}`;\n // When coming from an alias command, we want to show the alias command name in the help text\n const toolCommandForLogging: string = `${toolFilename} ${aliasAction ?? actionOptions.actionName}`;\n const scopingArgs: string[] = [];\n for (const parameter of unscopedActionParameters) {\n parameter.appendToArgList(scopingArgs);\n }\n const scope: string = scopingArgs.join(' ');\n\n // We can run the parser directly because we are not going to use it for any other actions,\n // so construct a special options object to make the \"--help\" text more useful.\n const scopedCommandLineParserOptions: ICommandLineParserOptions = {\n // Strip the scoping args if coming from an alias command, since they are not applicable\n // to the alias command itself\n toolFilename: `${toolCommandForLogging}${scope && !aliasAction ? ` ${scope} --` : ''}`,\n toolDescription: aliasDocumentation ?? actionOptions.documentation,\n toolEpilog: `For more information on available unscoped parameters, use \"${toolCommand} --help\"`,\n enableTabCompletionAction: false\n };\n\n super(scopedCommandLineParserOptions);\n this._canExecute = false;\n this._internalOptions = options;\n this._internalOptions.onDefineScopedParameters(this);\n }\n\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n // Since we are in a separate parser, we need to register the parameters using the state\n // from the parent parser.\n super._registerDefinedParameters(this._internalOptions.registerDefinedParametersState);\n }\n\n protected async onExecute(): Promise<void> {\n // override\n // Only set if we made it this far, which may not be the case if an error occurred or\n // if '--help' was specified.\n this._canExecute = true;\n }\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command-line.\n * Applications should create subclasses of ScopedCommandLineAction corresponding to\n * each action that they want to expose.\n *\n * The action name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\n * \"docs:serve\", etc).\n *\n * Scoped commands allow for different parameters to be specified for different\n * provided scoping values. For example, the \"scoped-action --scope A\" command\n * may allow for different scoped arguments to be specified than the \"scoped-action\n * --scope B\" command.\n *\n * Scoped arguments are specified after the \"--\" pseudo-argument. For example,\n * \"scoped-action --scope A -- --scopedFoo --scopedBar\".\n *\n * @public\n */\nexport abstract class ScopedCommandLineAction extends CommandLineAction {\n private _options: ICommandLineActionOptions;\n private _scopingParameters: CommandLineParameter[];\n private _unscopedParserOptions: ICommandLineParserOptions | undefined;\n private _scopedCommandLineParser: InternalScopedCommandLineParser | undefined;\n private _subparserState: IRegisterDefinedParametersState | undefined;\n\n /**\n * The required group name to apply to all scoping parameters. At least one parameter\n * must be defined with this group name.\n */\n public static readonly ScopingParameterGroup: typeof SCOPING_PARAMETER_GROUP = SCOPING_PARAMETER_GROUP;\n\n public constructor(options: ICommandLineActionOptions) {\n super(options);\n\n this._options = options;\n this._scopingParameters = [];\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider.parameters}\n *\n * @internalremarks\n * TODO: Replace this type with `CommandLineParameter` in the next major bump.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n if (this._scopedCommandLineParser) {\n return [...super.parameters, ...this._scopedCommandLineParser.parameters];\n } else {\n return super.parameters;\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // override\n super._processParsedData(parserOptions, data);\n\n // This should never happen because the super method should throw if parameters haven't been registered,\n // but guard against this just in-case.\n if (this._subparserState === undefined) {\n throw new Error('Parameters have not been registered');\n }\n\n this._unscopedParserOptions = parserOptions;\n\n // Generate the scoped parser using the parent parser information. We can only create this after we\n // have parsed the data, since the parameter values are used during construction.\n this._scopedCommandLineParser = new InternalScopedCommandLineParser({\n ...parserOptions,\n actionOptions: this._options,\n aliasAction: data.aliasAction,\n aliasDocumentation: data.aliasDocumentation,\n unscopedActionParameters: this.parameters as CommandLineParameter[],\n registerDefinedParametersState: this._subparserState,\n onDefineScopedParameters: this.onDefineScopedParameters.bind(this)\n });\n }\n\n /**\n * {@inheritdoc CommandLineAction._execute}\n * @internal\n */\n public async _execute(): Promise<void> {\n // override\n if (!this._unscopedParserOptions || !this._scopedCommandLineParser) {\n throw new Error('The CommandLineAction parameters must be processed before execution.');\n }\n if (!this.remainder) {\n throw new Error('CommandLineAction.onDefineParameters must be called before execution.');\n }\n\n // The '--' argument is required to separate the action parameters from the scoped parameters,\n // so it needs to be trimmed. If remainder values are provided but no '--' is found, then throw.\n const scopedArgs: string[] = [];\n if (this.remainder.values.length) {\n if (this.remainder.values[0] !== '--') {\n throw new CommandLineParserExitError(\n // argparse sets exit code 2 for invalid arguments\n 2,\n // model the message off of the built-in \"unrecognized arguments\" message\n `${this.renderUsageText()}\\n${this._unscopedParserOptions.toolFilename} ${this.actionName}: ` +\n `error: Unrecognized arguments: ${this.remainder.values[0]}.\\n`\n );\n }\n for (const scopedArg of this.remainder.values.slice(1)) {\n scopedArgs.push(scopedArg);\n }\n }\n\n // Call the scoped parser using only the scoped args to handle parsing\n await this._scopedCommandLineParser.executeWithoutErrorHandling(scopedArgs);\n\n // Only call execute if the parser reached the execute stage. This may not be true if\n // the parser exited early due to a specified '--help' parameter.\n if (this._scopedCommandLineParser.canExecute) {\n await super._execute();\n }\n\n return;\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 this._subparserState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider.onDefineParameters}\n */\n protected onDefineParameters(): void {\n this.onDefineUnscopedParameters?.();\n\n if (!this._scopingParameters.length) {\n throw new Error(\n 'No scoping parameters defined. At least one scoping parameter must be defined. ' +\n 'Scoping parameters are defined by setting the parameterGroupName to ' +\n 'ScopedCommandLineAction.ScopingParameterGroupName.'\n );\n }\n if (this.remainder) {\n throw new Error(\n 'Unscoped remainder parameters are not allowed. Remainder parameters can only be defined on ' +\n 'the scoped parameter provider in onDefineScopedParameters().'\n );\n }\n\n // Consume the remainder of the command-line, which will later be passed the scoped parser.\n // This will also prevent developers from calling this.defineCommandLineRemainder(...) since\n // we will have already defined it.\n this.defineCommandLineRemainder({\n description:\n 'Scoped parameters. Must be prefixed with \"--\", ex. \"-- --scopedParameter ' +\n 'foo --scopedFlag\". For more information on available scoped parameters, use \"-- --help\".'\n });\n }\n\n /**\n * Retrieves the scoped CommandLineParser, which is populated after the ScopedCommandLineAction is executed.\n * @internal\n */\n protected _getScopedCommandLineParser(): CommandLineParser {\n if (!this._scopedCommandLineParser) {\n throw new Error('The scoped CommandLineParser is only populated after the action is executed.');\n }\n return this._scopedCommandLineParser;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n super._defineParameter(parameter);\n if (parameter.parameterGroup === ScopedCommandLineAction.ScopingParameterGroup) {\n this._scopingParameters.push(parameter);\n }\n }\n\n /**\n * The child class should implement this hook to define its unscoped command-line parameters,\n * e.g. by calling defineFlagParameter(). At least one scoping parameter must be defined.\n * Scoping parameters are defined by setting the parameterGroupName to\n * ScopedCommandLineAction.ScopingParameterGroupName.\n */\n protected onDefineUnscopedParameters?(): void;\n\n /**\n * The child class should implement this hook to define its scoped command-line\n * parameters, e.g. by calling scopedParameterProvider.defineFlagParameter(). These\n * parameters will only be available if the action is invoked with a scope.\n *\n * @remarks\n * onDefineScopedParameters is called after the unscoped parameters have been parsed.\n * The values they provide can be used to vary the defined scope parameters.\n */\n protected abstract onDefineScopedParameters(scopedParameterProvider: CommandLineParameterProvider): void;\n\n /**\n * {@inheritDoc CommandLineAction.onExecute}\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ScopedCommandLineAction.js","sourceRoot":"","sources":["../../src/providers/ScopedCommandLineAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,4CAAuD;AACvD,2DAAwF;AACxF,2DAAwF;AACxF,6EAA0E;AAiB1E;;;GAGG;AACH,MAAM,+BAAgC,SAAQ,qCAAiB;IAI7D,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,YAAmB,OAAgD;QACjE,MAAM,EAAE,aAAa,EAAE,wBAAwB,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAC9F,OAAO,CAAC;QAEV,MAAM,WAAW,GAAW,GAAG,YAAY,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QAC1E,6FAA6F;QAC7F,MAAM,qBAAqB,GAAW,GAAG,YAAY,IAAI,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,aAAa,CAAC,UAAU,EAAE,CAAC;QACnG,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,KAAK,MAAM,SAAS,IAAI,wBAAwB,EAAE,CAAC;YACjD,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC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;IAED;;OAEG;IACO,kBAAkB;;QAC1B,MAAA,IAAI,CAAC,0BAA0B,oDAAI,CAAC;QAEpC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,iFAAiF;gBAC/E,sEAAsE;gBACtE,oDAAoD,CACvD,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,6FAA6F;gBAC3F,8DAA8D,CACjE,CAAC;QACJ,CAAC;QAED,2FAA2F;QAC3F,4FAA4F;QAC5F,mCAAmC;QACnC,IAAI,CAAC,0BAA0B,CAAC;YAC9B,WAAW,EACT,4EAA4E;gBAC5E,2FAA2F;SAC9F,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACO,2BAA2B;QACnC,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;QAClG,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,SAA+B;QACxD,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,SAAS,CAAC,cAAc,KAAK,uBAAuB,CAAC,qBAAqB,EAAE,CAAC;YAC/E,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;;AAzKH,0DAkMC;AA3LC;;;GAGG;AACoB,6CAAqB,GAAmC,mCAAuB,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 { SCOPING_PARAMETER_GROUP } from '../Constants';\nimport { CommandLineAction, type ICommandLineActionOptions } from './CommandLineAction';\nimport { CommandLineParser, type ICommandLineParserOptions } from './CommandLineParser';\nimport { CommandLineParserExitError } from './CommandLineParserExitError';\nimport type { CommandLineParameter, CommandLineParameterBase } from '../parameters/BaseClasses';\nimport type {\n CommandLineParameterProvider,\n ICommandLineParserData,\n IRegisterDefinedParametersState\n} from './CommandLineParameterProvider';\n\ninterface IInternalScopedCommandLineParserOptions extends ICommandLineParserOptions {\n readonly actionOptions: ICommandLineActionOptions;\n readonly unscopedActionParameters: ReadonlyArray<CommandLineParameter>;\n readonly onDefineScopedParameters: (commandLineParameterProvider: CommandLineParameterProvider) => void;\n readonly aliasAction?: string;\n readonly aliasDocumentation?: string;\n readonly registerDefinedParametersState: IRegisterDefinedParametersState;\n}\n\n/**\n * A CommandLineParser used exclusively to parse the scoped command-line parameters\n * for a ScopedCommandLineAction.\n */\nclass InternalScopedCommandLineParser extends CommandLineParser {\n private _canExecute: boolean;\n private readonly _internalOptions: IInternalScopedCommandLineParserOptions;\n\n public get canExecute(): boolean {\n return this._canExecute;\n }\n\n public constructor(options: IInternalScopedCommandLineParserOptions) {\n const { actionOptions, unscopedActionParameters, toolFilename, aliasAction, aliasDocumentation } =\n options;\n\n const toolCommand: string = `${toolFilename} ${actionOptions.actionName}`;\n // When coming from an alias command, we want to show the alias command name in the help text\n const toolCommandForLogging: string = `${toolFilename} ${aliasAction ?? actionOptions.actionName}`;\n const scopingArgs: string[] = [];\n for (const parameter of unscopedActionParameters) {\n parameter.appendToArgList(scopingArgs);\n }\n const scope: string = scopingArgs.join(' ');\n\n // We can run the parser directly because we are not going to use it for any other actions,\n // so construct a special options object to make the \"--help\" text more useful.\n const scopedCommandLineParserOptions: ICommandLineParserOptions = {\n // Strip the scoping args if coming from an alias command, since they are not applicable\n // to the alias command itself\n toolFilename: `${toolCommandForLogging}${scope && !aliasAction ? ` ${scope} --` : ''}`,\n toolDescription: aliasDocumentation ?? actionOptions.documentation,\n toolEpilog: `For more information on available unscoped parameters, use \"${toolCommand} --help\"`,\n enableTabCompletionAction: false\n };\n\n super(scopedCommandLineParserOptions);\n this._canExecute = false;\n this._internalOptions = options;\n this._internalOptions.onDefineScopedParameters(this);\n }\n\n public _registerDefinedParameters(state: IRegisterDefinedParametersState): void {\n // Since we are in a separate parser, we need to register the parameters using the state\n // from the parent parser.\n super._registerDefinedParameters(this._internalOptions.registerDefinedParametersState);\n }\n\n protected async onExecute(): Promise<void> {\n // override\n // Only set if we made it this far, which may not be the case if an error occurred or\n // if '--help' was specified.\n this._canExecute = true;\n }\n}\n\n/**\n * Represents a sub-command that is part of the CommandLineParser command-line.\n * Applications should create subclasses of ScopedCommandLineAction corresponding to\n * each action that they want to expose.\n *\n * The action name should be comprised of lower case words separated by hyphens\n * or colons. The name should include an English verb (e.g. \"deploy\"). Use a\n * hyphen to separate words (e.g. \"upload-docs\"). A group of related commands\n * can be prefixed with a colon (e.g. \"docs:generate\", \"docs:deploy\",\n * \"docs:serve\", etc).\n *\n * Scoped commands allow for different parameters to be specified for different\n * provided scoping values. For example, the \"scoped-action --scope A\" command\n * may allow for different scoped arguments to be specified than the \"scoped-action\n * --scope B\" command.\n *\n * Scoped arguments are specified after the \"--\" pseudo-argument. For example,\n * \"scoped-action --scope A -- --scopedFoo --scopedBar\".\n *\n * @public\n */\nexport abstract class ScopedCommandLineAction extends CommandLineAction {\n private _options: ICommandLineActionOptions;\n private _scopingParameters: CommandLineParameter[];\n private _unscopedParserOptions: ICommandLineParserOptions | undefined;\n private _scopedCommandLineParser: InternalScopedCommandLineParser | undefined;\n private _subparserState: IRegisterDefinedParametersState | undefined;\n\n /**\n * The required group name to apply to all scoping parameters. At least one parameter\n * must be defined with this group name.\n */\n public static readonly ScopingParameterGroup: typeof SCOPING_PARAMETER_GROUP = SCOPING_PARAMETER_GROUP;\n\n public constructor(options: ICommandLineActionOptions) {\n super(options);\n\n this._options = options;\n this._scopingParameters = [];\n }\n\n /**\n * {@inheritDoc CommandLineParameterProvider.parameters}\n *\n * @internalremarks\n * TODO: Replace this type with `CommandLineParameter` in the next major bump.\n */\n public get parameters(): ReadonlyArray<CommandLineParameterBase> {\n if (this._scopedCommandLineParser) {\n return [...super.parameters, ...this._scopedCommandLineParser.parameters];\n } else {\n return super.parameters;\n }\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider._processParsedData}\n * @internal\n */\n public _processParsedData(parserOptions: ICommandLineParserOptions, data: ICommandLineParserData): void {\n // override\n super._processParsedData(parserOptions, data);\n\n // This should never happen because the super method should throw if parameters haven't been registered,\n // but guard against this just in-case.\n if (this._subparserState === undefined) {\n throw new Error('Parameters have not been registered');\n }\n\n this._unscopedParserOptions = parserOptions;\n\n // Generate the scoped parser using the parent parser information. We can only create this after we\n // have parsed the data, since the parameter values are used during construction.\n this._scopedCommandLineParser = new InternalScopedCommandLineParser({\n ...parserOptions,\n actionOptions: this._options,\n aliasAction: data.aliasAction,\n aliasDocumentation: data.aliasDocumentation,\n unscopedActionParameters: this.parameters as CommandLineParameter[],\n registerDefinedParametersState: this._subparserState,\n onDefineScopedParameters: this.onDefineScopedParameters.bind(this)\n });\n }\n\n /**\n * {@inheritdoc CommandLineAction._executeAsync}\n * @internal\n */\n public async _executeAsync(): Promise<void> {\n // override\n if (!this._unscopedParserOptions || !this._scopedCommandLineParser) {\n throw new Error('The CommandLineAction parameters must be processed before execution.');\n }\n if (!this.remainder) {\n throw new Error('CommandLineAction.onDefineParameters must be called before execution.');\n }\n\n // The '--' argument is required to separate the action parameters from the scoped parameters,\n // so it needs to be trimmed. If remainder values are provided but no '--' is found, then throw.\n const scopedArgs: string[] = [];\n if (this.remainder.values.length) {\n if (this.remainder.values[0] !== '--') {\n throw new CommandLineParserExitError(\n // argparse sets exit code 2 for invalid arguments\n 2,\n // model the message off of the built-in \"unrecognized arguments\" message\n `${this.renderUsageText()}\\n${this._unscopedParserOptions.toolFilename} ${this.actionName}: ` +\n `error: Unrecognized arguments: ${this.remainder.values[0]}.\\n`\n );\n }\n for (const scopedArg of this.remainder.values.slice(1)) {\n scopedArgs.push(scopedArg);\n }\n }\n\n // Call the scoped parser using only the scoped args to handle parsing\n await this._scopedCommandLineParser.executeWithoutErrorHandlingAsync(scopedArgs);\n\n // Only call execute if the parser reached the execute stage. This may not be true if\n // the parser exited early due to a specified '--help' parameter.\n if (this._scopedCommandLineParser.canExecute) {\n await super._executeAsync();\n }\n\n return;\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 this._subparserState = {\n ...state,\n parentParameterNames: updatedParentParameterNames\n };\n }\n\n /**\n * {@inheritdoc CommandLineParameterProvider.onDefineParameters}\n */\n protected onDefineParameters(): void {\n this.onDefineUnscopedParameters?.();\n\n if (!this._scopingParameters.length) {\n throw new Error(\n 'No scoping parameters defined. At least one scoping parameter must be defined. ' +\n 'Scoping parameters are defined by setting the parameterGroupName to ' +\n 'ScopedCommandLineAction.ScopingParameterGroupName.'\n );\n }\n if (this.remainder) {\n throw new Error(\n 'Unscoped remainder parameters are not allowed. Remainder parameters can only be defined on ' +\n 'the scoped parameter provider in onDefineScopedParameters().'\n );\n }\n\n // Consume the remainder of the command-line, which will later be passed the scoped parser.\n // This will also prevent developers from calling this.defineCommandLineRemainder(...) since\n // we will have already defined it.\n this.defineCommandLineRemainder({\n description:\n 'Scoped parameters. Must be prefixed with \"--\", ex. \"-- --scopedParameter ' +\n 'foo --scopedFlag\". For more information on available scoped parameters, use \"-- --help\".'\n });\n }\n\n /**\n * Retrieves the scoped CommandLineParser, which is populated after the ScopedCommandLineAction is executed.\n * @internal\n */\n protected _getScopedCommandLineParser(): CommandLineParser {\n if (!this._scopedCommandLineParser) {\n throw new Error('The scoped CommandLineParser is only populated after the action is executed.');\n }\n return this._scopedCommandLineParser;\n }\n\n /** @internal */\n protected _defineParameter(parameter: CommandLineParameter): void {\n super._defineParameter(parameter);\n if (parameter.parameterGroup === ScopedCommandLineAction.ScopingParameterGroup) {\n this._scopingParameters.push(parameter);\n }\n }\n\n /**\n * The child class should implement this hook to define its unscoped command-line parameters,\n * e.g. by calling defineFlagParameter(). At least one scoping parameter must be defined.\n * Scoping parameters are defined by setting the parameterGroupName to\n * ScopedCommandLineAction.ScopingParameterGroupName.\n */\n protected onDefineUnscopedParameters?(): void;\n\n /**\n * The child class should implement this hook to define its scoped command-line\n * parameters, e.g. by calling scopedParameterProvider.defineFlagParameter(). These\n * parameters will only be available if the action is invoked with a scope.\n *\n * @remarks\n * onDefineScopedParameters is called after the unscoped parameters have been parsed.\n * The values they provide can be used to vary the defined scope parameters.\n */\n protected abstract onDefineScopedParameters(scopedParameterProvider: CommandLineParameterProvider): void;\n\n /**\n * {@inheritDoc CommandLineAction.onExecute}\n */\n protected abstract onExecute(): Promise<void>;\n}\n"]}
|
|
@@ -7,10 +7,10 @@ export declare class TabCompleteAction extends CommandLineAction {
|
|
|
7
7
|
private readonly _globalParameters;
|
|
8
8
|
constructor(actions: ReadonlyArray<CommandLineAction>, globalParameters: ReadonlyArray<CommandLineParameterBase>);
|
|
9
9
|
protected onExecute(): Promise<void>;
|
|
10
|
-
|
|
10
|
+
getCompletionsAsync(commandLine: string, caretPosition?: number): AsyncIterable<string>;
|
|
11
11
|
private _getAllActions;
|
|
12
12
|
tokenizeCommandLine(commandLine: string): string[];
|
|
13
|
-
private
|
|
13
|
+
private _getParameterValueCompletionsAsync;
|
|
14
14
|
private _getGlobalParameterOffset;
|
|
15
15
|
private _completeParameterValues;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabCompletionAction.d.ts","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMxD,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAsC;IAC/E,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAC1E,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,wBAAwB,CAAC;cA2C3C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,
|
|
1
|
+
{"version":3,"file":"TabCompletionAction.d.ts","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMxD,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAsC;IAC/E,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAC1E,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,wBAAwB,CAAC;cA2C3C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,mBAAmB,CAC/B,WAAW,EAAE,MAAM,EACnB,aAAa,GAAE,MAA2B,GACzC,aAAa,CAAC,MAAM,CAAC;IAiFxB,OAAO,CAAE,cAAc;IAKhB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE;YAI3C,kCAAkC;IA0BhD,OAAO,CAAC,yBAAyB;IAgBjC,OAAO,CAAE,wBAAwB;CAUlC"}
|
|
@@ -80,7 +80,7 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
80
80
|
const commandLine = this._wordToCompleteParameter.value;
|
|
81
81
|
const caretPosition = this._positionParameter.value || commandLine.length;
|
|
82
82
|
try {
|
|
83
|
-
for (var _d = true, _e = __asyncValues(this.
|
|
83
|
+
for (var _d = true, _e = __asyncValues(this.getCompletionsAsync(commandLine, caretPosition)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
|
|
84
84
|
_c = _f.value;
|
|
85
85
|
_d = false;
|
|
86
86
|
const value = _c;
|
|
@@ -96,8 +96,8 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
96
96
|
finally { if (e_1) throw e_1.error; }
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
return __asyncGenerator(this, arguments, function*
|
|
99
|
+
getCompletionsAsync(commandLine, caretPosition = commandLine.length) {
|
|
100
|
+
return __asyncGenerator(this, arguments, function* getCompletionsAsync_1() {
|
|
101
101
|
const actions = this._actions;
|
|
102
102
|
if (!commandLine || !caretPosition) {
|
|
103
103
|
yield __await(yield* __asyncDelegator(__asyncValues(this._getAllActions())));
|
|
@@ -129,7 +129,7 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
129
129
|
if (completePartialWord) {
|
|
130
130
|
for (const parameterName of parameterNames) {
|
|
131
131
|
if (parameterName === secondLastToken) {
|
|
132
|
-
const values = yield __await(this.
|
|
132
|
+
const values = yield __await(this._getParameterValueCompletionsAsync(parameterNameMap.get(parameterName)));
|
|
133
133
|
if (values.length > 0) {
|
|
134
134
|
yield __await(yield* __asyncDelegator(__asyncValues(this._completeParameterValues(values, lastToken))));
|
|
135
135
|
return yield __await(void 0);
|
|
@@ -141,7 +141,7 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
141
141
|
else {
|
|
142
142
|
for (const parameterName of parameterNames) {
|
|
143
143
|
if (parameterName === lastToken) {
|
|
144
|
-
const values = yield __await(this.
|
|
144
|
+
const values = yield __await(this._getParameterValueCompletionsAsync(parameterNameMap.get(parameterName)));
|
|
145
145
|
if (values.length > 0) {
|
|
146
146
|
yield __await(yield* __asyncDelegator(__asyncValues(values)));
|
|
147
147
|
return yield __await(void 0);
|
|
@@ -170,7 +170,7 @@ class TabCompleteAction extends CommandLineAction_1.CommandLineAction {
|
|
|
170
170
|
tokenizeCommandLine(commandLine) {
|
|
171
171
|
return (0, string_argv_1.default)(commandLine);
|
|
172
172
|
}
|
|
173
|
-
async
|
|
173
|
+
async _getParameterValueCompletionsAsync(parameter) {
|
|
174
174
|
let choiceParameterValues = [];
|
|
175
175
|
if (parameter.kind === BaseClasses_1.CommandLineParameterKind.Choice) {
|
|
176
176
|
choiceParameterValues = parameter.alternatives;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabCompletionAction.js","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,8DAAqC;AAIrC,2DAKmC;AACnC,yFAAsF;AACtF,2DAAwD;AAGxD,MAAM,4BAA4B,GAAW,EAAE,CAAC;AAChD,MAAM,gBAAgB,GAAW,CAAC,CAAC;AAEnC,MAAa,iBAAkB,SAAQ,qCAAiB;IAMtD,YACE,OAAyC,EACzC,gBAAyD;QAEzD,KAAK,CAAC;YACJ,UAAU,mEAA8C;YACxD,OAAO,EAAE,0BAA0B;YACnC,aAAa,EAAE,0BAA0B;SAC1C,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,+BAA+B,GAAsC,IAAI,GAAG,EAAE,CAAC;YACrF,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBAC1C,+BAA+B,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAiC,CAAC,CAAC;gBAC3F,IAAI,SAAS,CAAC,SAAS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ICENSE in the project root for license information.\n\nimport stringArgv from 'string-argv';\n\nimport type { IRequiredCommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport type { IRequiredCommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n CommandLineParameterWithArgument,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineAction } from './CommandLineAction';\nimport { CommandLineConstants } from '../Constants';\n\nconst DEFAULT_WORD_TO_AUTOCOMPLETE: string = '';\nconst DEFAULT_POSITION: number = 0;\n\nexport class TabCompleteAction extends CommandLineAction {\n private readonly _wordToCompleteParameter: IRequiredCommandLineStringParameter;\n private readonly _positionParameter: IRequiredCommandLineIntegerParameter;\n private readonly _actions: Map<string, Map<string, CommandLineParameter>>;\n private readonly _globalParameters: Map<string, CommandLineParameter>;\n\n public constructor(\n actions: ReadonlyArray<CommandLineAction>,\n globalParameters: ReadonlyArray<CommandLineParameterBase>\n ) {\n super({\n actionName: CommandLineConstants.TabCompletionActionName,\n summary: 'Provides tab completion.',\n documentation: 'Provides tab completion.'\n });\n\n this._actions = new Map();\n for (const action of actions) {\n const parameterNameToParameterInfoMap: Map<string, CommandLineParameter> = new Map();\n for (const parameter of action.parameters) {\n parameterNameToParameterInfoMap.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n parameterNameToParameterInfoMap.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n this._actions.set(action.actionName, parameterNameToParameterInfoMap);\n }\n\n this._globalParameters = new Map<string, CommandLineParameter>();\n for (const parameter of globalParameters) {\n this._globalParameters.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n this._globalParameters.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n\n this._wordToCompleteParameter = this.defineStringParameter({\n parameterLongName: '--word',\n argumentName: 'WORD',\n description: `The word to complete.`,\n defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE\n });\n\n this._positionParameter = this.defineIntegerParameter({\n parameterLongName: '--position',\n argumentName: 'INDEX',\n description: `The position in the word to be completed.`,\n defaultValue: DEFAULT_POSITION\n });\n }\n\n protected async onExecute(): Promise<void> {\n const commandLine: string = this._wordToCompleteParameter.value;\n const caretPosition: number = this._positionParameter.value || commandLine.length;\n\n for await (const value of this.getCompletions(commandLine, caretPosition)) {\n // eslint-disable-next-line no-console\n console.log(value);\n }\n }\n\n public async *getCompletions(\n commandLine: string,\n caretPosition: number = commandLine.length\n ): AsyncIterable<string> {\n const actions: Map<string, Map<string, CommandLineParameter>> = this._actions;\n\n if (!commandLine || !caretPosition) {\n yield* this._getAllActions();\n return;\n }\n\n const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine));\n\n // offset arguments by the number of global params in the input\n const globalParameterOffset: number = this._getGlobalParameterOffset(tokens);\n\n if (tokens.length < 2 + globalParameterOffset) {\n yield* this._getAllActions();\n return;\n }\n\n const lastToken: string = tokens[tokens.length - 1];\n const secondLastToken: string = tokens[tokens.length - 2];\n\n const lastCharacterIsWhitespace: boolean = !commandLine.slice(-1).trim();\n const completePartialWord: boolean = caretPosition === commandLine.length && !lastCharacterIsWhitespace;\n\n if (completePartialWord && tokens.length === 2 + globalParameterOffset) {\n for (const actionName of actions.keys()) {\n if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) {\n yield actionName;\n }\n }\n } else {\n for (const actionName of actions.keys()) {\n if (actionName === tokens[1 + globalParameterOffset]) {\n const parameterNameMap: Map<string, CommandLineParameter> = actions.get(actionName)!;\n\n const parameterNames: string[] = Array.from(parameterNameMap.keys());\n\n if (completePartialWord) {\n for (const parameterName of parameterNames) {\n if (parameterName === secondLastToken) {\n const values: ReadonlyArray<string> = await this._getParameterValueCompletions(\n parameterNameMap.get(parameterName)!\n );\n if (values.length > 0) {\n yield* this._completeParameterValues(values, lastToken);\n return;\n }\n }\n }\n yield* this._completeParameterValues(parameterNames, lastToken);\n } else {\n for (const parameterName of parameterNames) {\n if (parameterName === lastToken) {\n const values: ReadonlyArray<string> = await this._getParameterValueCompletions(\n parameterNameMap.get(parameterName)!\n );\n if (values.length > 0) {\n yield* values;\n return;\n }\n }\n }\n for (const parameterName of parameterNames) {\n if (\n parameterName === lastToken &&\n parameterNameMap.get(parameterName)!.kind !== CommandLineParameterKind.Flag\n ) {\n // The parameter is expecting a value, so don't suggest parameter names again\n return;\n }\n }\n\n yield* parameterNames;\n }\n\n break;\n }\n }\n }\n }\n\n private *_getAllActions(): IterableIterator<string> {\n yield* this._actions.keys();\n yield* this._globalParameters.keys();\n }\n\n public tokenizeCommandLine(commandLine: string): string[] {\n return stringArgv(commandLine);\n }\n\n private async _getParameterValueCompletions(\n parameter: CommandLineParameter\n ): Promise<ReadonlyArray<string>> {\n let choiceParameterValues: ReadonlyArray<string> = [];\n if (parameter.kind === CommandLineParameterKind.Choice) {\n choiceParameterValues = parameter.alternatives;\n } else if (parameter.kind !== CommandLineParameterKind.Flag) {\n let parameterWithArgumentOrChoices:\n | CommandLineParameterWithArgument\n | CommandLineChoiceParameter\n | undefined = undefined;\n if (\n parameter instanceof CommandLineParameterWithArgument ||\n parameter instanceof CommandLineChoiceParameter\n ) {\n parameterWithArgumentOrChoices = parameter;\n }\n\n if (parameterWithArgumentOrChoices?.completions) {\n choiceParameterValues = await parameterWithArgumentOrChoices.completions();\n }\n }\n\n return choiceParameterValues;\n }\n\n private _getGlobalParameterOffset(tokens: string[]): number {\n const globalParameters: Map<string, CommandLineParameter> = this._globalParameters;\n let count: number = 0;\n\n outer: for (let i: number = 1; i < tokens.length; i++) {\n for (const globalParameter of globalParameters.values()) {\n if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) {\n break outer;\n }\n }\n count++;\n }\n\n return count;\n }\n\n private *_completeParameterValues(\n choiceParameterValues: ReadonlyArray<string>,\n lastToken: string\n ): IterableIterator<string> {\n for (const choiceParameterValue of choiceParameterValues) {\n if (choiceParameterValue.indexOf(lastToken) === 0) {\n yield choiceParameterValue;\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TabCompletionAction.js","sourceRoot":"","sources":["../../src/providers/TabCompletionAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,8DAAqC;AAIrC,2DAKmC;AACnC,yFAAsF;AACtF,2DAAwD;AAGxD,MAAM,4BAA4B,GAAW,EAAE,CAAC;AAChD,MAAM,gBAAgB,GAAW,CAAC,CAAC;AAEnC,MAAa,iBAAkB,SAAQ,qCAAiB;IAMtD,YACE,OAAyC,EACzC,gBAAyD;QAEzD,KAAK,CAAC;YACJ,UAAU,mEAA8C;YACxD,OAAO,EAAE,0BAA0B;YACnC,aAAa,EAAE,0BAA0B;SAC1C,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,+BAA+B,GAAsC,IAAI,GAAG,EAAE,CAAC;YACrF,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBAC1C,+BAA+B,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAiC,CAAC,CAAC;gBAC3F,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;oBACxB,+BAA+B,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,SAAiC,CAAC,CAAC;gBAC9F,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,+BAA+B,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAgC,CAAC;QACjE,KAAK,MAAM,SAAS,IAAI,gBAAgB,EAAE,CAAC;YACzC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAA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AC;IAEO,yBAAyB,CAAC,MAAgB;QAChD,MAAM,gBAAgB,GAAsC,IAAI,CAAC,iBAAiB,CAAC;QACnF,IAAI,KAAK,GAAW,CAAC,CAAC;QAEtB,KAAK,EAAE,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtD,KAAK,MAAM,eAAe,IAAI,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC;gBACxD,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,SAAS,EAAE,CAAC;oBACtF,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,CAAC,wBAAwB,CAC/B,qBAA4C,EAC5C,SAAiB;QAEjB,KAAK,MAAM,oBAAoB,IAAI,qBAAqB,EAAE,CAAC;YACzD,IAAI,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,MAAM,oBAAoB,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9MD,8CA8MC","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 stringArgv from 'string-argv';\n\nimport type { IRequiredCommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter';\nimport type { IRequiredCommandLineStringParameter } from '../parameters/CommandLineStringParameter';\nimport {\n CommandLineParameterKind,\n type CommandLineParameterBase,\n CommandLineParameterWithArgument,\n type CommandLineParameter\n} from '../parameters/BaseClasses';\nimport { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter';\nimport { CommandLineAction } from './CommandLineAction';\nimport { CommandLineConstants } from '../Constants';\n\nconst DEFAULT_WORD_TO_AUTOCOMPLETE: string = '';\nconst DEFAULT_POSITION: number = 0;\n\nexport class TabCompleteAction extends CommandLineAction {\n private readonly _wordToCompleteParameter: IRequiredCommandLineStringParameter;\n private readonly _positionParameter: IRequiredCommandLineIntegerParameter;\n private readonly _actions: Map<string, Map<string, CommandLineParameter>>;\n private readonly _globalParameters: Map<string, CommandLineParameter>;\n\n public constructor(\n actions: ReadonlyArray<CommandLineAction>,\n globalParameters: ReadonlyArray<CommandLineParameterBase>\n ) {\n super({\n actionName: CommandLineConstants.TabCompletionActionName,\n summary: 'Provides tab completion.',\n documentation: 'Provides tab completion.'\n });\n\n this._actions = new Map();\n for (const action of actions) {\n const parameterNameToParameterInfoMap: Map<string, CommandLineParameter> = new Map();\n for (const parameter of action.parameters) {\n parameterNameToParameterInfoMap.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n parameterNameToParameterInfoMap.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n this._actions.set(action.actionName, parameterNameToParameterInfoMap);\n }\n\n this._globalParameters = new Map<string, CommandLineParameter>();\n for (const parameter of globalParameters) {\n this._globalParameters.set(parameter.longName, parameter as CommandLineParameter);\n if (parameter.shortName) {\n this._globalParameters.set(parameter.shortName, parameter as CommandLineParameter);\n }\n }\n\n this._wordToCompleteParameter = this.defineStringParameter({\n parameterLongName: '--word',\n argumentName: 'WORD',\n description: `The word to complete.`,\n defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE\n });\n\n this._positionParameter = this.defineIntegerParameter({\n parameterLongName: '--position',\n argumentName: 'INDEX',\n description: `The position in the word to be completed.`,\n defaultValue: DEFAULT_POSITION\n });\n }\n\n protected async onExecute(): Promise<void> {\n const commandLine: string = this._wordToCompleteParameter.value;\n const caretPosition: number = this._positionParameter.value || commandLine.length;\n\n for await (const value of this.getCompletionsAsync(commandLine, caretPosition)) {\n // eslint-disable-next-line no-console\n console.log(value);\n }\n }\n\n public async *getCompletionsAsync(\n commandLine: string,\n caretPosition: number = commandLine.length\n ): AsyncIterable<string> {\n const actions: Map<string, Map<string, CommandLineParameter>> = this._actions;\n\n if (!commandLine || !caretPosition) {\n yield* this._getAllActions();\n return;\n }\n\n const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine));\n\n // offset arguments by the number of global params in the input\n const globalParameterOffset: number = this._getGlobalParameterOffset(tokens);\n\n if (tokens.length < 2 + globalParameterOffset) {\n yield* this._getAllActions();\n return;\n }\n\n const lastToken: string = tokens[tokens.length - 1];\n const secondLastToken: string = tokens[tokens.length - 2];\n\n const lastCharacterIsWhitespace: boolean = !commandLine.slice(-1).trim();\n const completePartialWord: boolean = caretPosition === commandLine.length && !lastCharacterIsWhitespace;\n\n if (completePartialWord && tokens.length === 2 + globalParameterOffset) {\n for (const actionName of actions.keys()) {\n if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) {\n yield actionName;\n }\n }\n } else {\n for (const actionName of actions.keys()) {\n if (actionName === tokens[1 + globalParameterOffset]) {\n const parameterNameMap: Map<string, CommandLineParameter> = actions.get(actionName)!;\n\n const parameterNames: string[] = Array.from(parameterNameMap.keys());\n\n if (completePartialWord) {\n for (const parameterName of parameterNames) {\n if (parameterName === secondLastToken) {\n const values: ReadonlyArray<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.length > 0) {\n yield* this._completeParameterValues(values, lastToken);\n return;\n }\n }\n }\n yield* this._completeParameterValues(parameterNames, lastToken);\n } else {\n for (const parameterName of parameterNames) {\n if (parameterName === lastToken) {\n const values: ReadonlyArray<string> = await this._getParameterValueCompletionsAsync(\n parameterNameMap.get(parameterName)!\n );\n if (values.length > 0) {\n yield* values;\n return;\n }\n }\n }\n for (const parameterName of parameterNames) {\n if (\n parameterName === lastToken &&\n parameterNameMap.get(parameterName)!.kind !== CommandLineParameterKind.Flag\n ) {\n // The parameter is expecting a value, so don't suggest parameter names again\n return;\n }\n }\n\n yield* parameterNames;\n }\n\n break;\n }\n }\n }\n }\n\n private *_getAllActions(): IterableIterator<string> {\n yield* this._actions.keys();\n yield* this._globalParameters.keys();\n }\n\n public tokenizeCommandLine(commandLine: string): string[] {\n return stringArgv(commandLine);\n }\n\n private async _getParameterValueCompletionsAsync(\n parameter: CommandLineParameter\n ): Promise<ReadonlyArray<string>> {\n let choiceParameterValues: ReadonlyArray<string> = [];\n if (parameter.kind === CommandLineParameterKind.Choice) {\n choiceParameterValues = parameter.alternatives;\n } else if (parameter.kind !== CommandLineParameterKind.Flag) {\n let parameterWithArgumentOrChoices:\n | CommandLineParameterWithArgument\n | CommandLineChoiceParameter\n | undefined = undefined;\n if (\n parameter instanceof CommandLineParameterWithArgument ||\n parameter instanceof CommandLineChoiceParameter\n ) {\n parameterWithArgumentOrChoices = parameter;\n }\n\n if (parameterWithArgumentOrChoices?.completions) {\n choiceParameterValues = await parameterWithArgumentOrChoices.completions();\n }\n }\n\n return choiceParameterValues;\n }\n\n private _getGlobalParameterOffset(tokens: string[]): number {\n const globalParameters: Map<string, CommandLineParameter> = this._globalParameters;\n let count: number = 0;\n\n outer: for (let i: number = 1; i < tokens.length; i++) {\n for (const globalParameter of globalParameters.values()) {\n if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) {\n break outer;\n }\n }\n count++;\n }\n\n return count;\n }\n\n private *_completeParameterValues(\n choiceParameterValues: ReadonlyArray<string>,\n lastToken: string\n ): IterableIterator<string> {\n for (const choiceParameterValue of choiceParameterValues) {\n if (choiceParameterValue.indexOf(lastToken) === 0) {\n yield choiceParameterValue;\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/ts-command-line",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.1",
|
|
4
4
|
"description": "An object-oriented command-line parser for TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@types/argparse": "1.0.38",
|
|
15
15
|
"argparse": "~1.0.9",
|
|
16
16
|
"string-argv": "~0.3.1",
|
|
17
|
-
"@rushstack/terminal": "0.
|
|
17
|
+
"@rushstack/terminal": "0.11.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@rushstack/heft": "0.65.5",
|