diff --git a/apps/rush-lib/src/api/CommandLineJson.ts b/apps/rush-lib/src/api/CommandLineJson.ts index 6946dda647a..c189964a007 100644 --- a/apps/rush-lib/src/api/CommandLineJson.ts +++ b/apps/rush-lib/src/api/CommandLineJson.ts @@ -38,7 +38,7 @@ export type CommandJson = IBulkCommandJson | IGlobalCommandJson; * "baseParameter" from command-line.schema.json */ export interface IBaseParameterJson { - parameterKind: 'flag' | 'choice'; + parameterKind: 'flag' | 'choice' | 'string'; longName: string; shortName?: string; description: string; @@ -69,7 +69,12 @@ export interface IChoiceParameterJson extends IBaseParameterJson { defaultValue?: string; } -export type ParameterJson = IFlagParameterJson | IChoiceParameterJson; +export interface IStringParameterJson extends IBaseParameterJson { + parameterKind: 'string'; + argumentName: string; +} + +export type ParameterJson = IFlagParameterJson | IChoiceParameterJson | IStringParameterJson; /** * Interfaces for the file format described by command-line.schema.json diff --git a/apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts index ba5df017d00..f8fb5a2a5e6 100644 --- a/apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts @@ -68,6 +68,14 @@ export abstract class BaseScriptAction extends BaseRushAction { defaultValue: parameter.defaultValue }); break; + case 'string': + customParameter = this.defineStringParameter({ + parameterLongName: parameter.longName, + parameterShortName: parameter.shortName, + description: parameter.description, + argumentName: parameter.argumentName + }); + break; default: throw new Error(`${RushConstants.commandLineFilename} defines a parameter "${parameter!.longName}"` + ` using an unsupported parameter kind "${parameter!.parameterKind}"`); diff --git a/apps/rush-lib/src/schemas/command-line.schema.json b/apps/rush-lib/src/schemas/command-line.schema.json index a173a87ef44..30375dae20f 100644 --- a/apps/rush-lib/src/schemas/command-line.schema.json +++ b/apps/rush-lib/src/schemas/command-line.schema.json @@ -135,9 +135,9 @@ "properties": { "parameterKind": { "title": "Parameter Kind", - "description": "Indicates the kind of syntax for this command-line parameter: \"flag\" or \"choice\"", + "description": "Indicates the kind of syntax for this command-line parameter: \"flag\" or \"choice\" or \"string\"", "type": "string", - "enum": [ "flag", "choice" ] + "enum": [ "flag", "choice", "string" ] }, "longName": { "title": "Long Name", @@ -195,6 +195,41 @@ } ] }, + "stringParameter": { + "title": "String Parameter", + "description": "A custom command-line parameter whose value is intepreted as a string", + "type": "object", + "allOf": [ + { "$ref": "#/definitions/baseParameter" }, + { + "type": "object", + "additionalProperties": true, + "required": ["argumentName"], + "properties": { + "parameterKind": { + "enum": [ "string" ] + }, + "argumentName": { + "title": "Argument Name", + "description": "The name of the argument for this parameter.", + "type": "string" + } + } + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "parameterKind": { "$ref": "#/definitions/anything" }, + "longName": { "$ref": "#/definitions/anything" }, + "shortName": { "$ref": "#/definitions/anything" }, + "description": { "$ref": "#/definitions/anything" }, + "associatedCommands": { "$ref": "#/definitions/anything" }, + "argumentName": { "$ref": "#/definitions/anything" } + } + } + ] + }, "choiceParameter": { "title": "Choice Parameter", "description": "A custom command-line parameter whose argument must be chosen from a list of allowable alternatives", @@ -287,7 +322,8 @@ "type": "object", "oneOf": [ { "$ref": "#/definitions/flagParameter" }, - { "$ref": "#/definitions/choiceParameter" } + { "$ref": "#/definitions/choiceParameter" }, + { "$ref": "#/definitions/stringParameter" } ] } } diff --git a/common/changes/@microsoft/rush/kinhln-string-param_2019-03-28-00-55.json b/common/changes/@microsoft/rush/kinhln-string-param_2019-03-28-00-55.json new file mode 100644 index 00000000000..a709ea5dd1f --- /dev/null +++ b/common/changes/@microsoft/rush/kinhln-string-param_2019-03-28-00-55.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Add support for string parameter for custom commands.", + "packageName": "@microsoft/rush", + "type": "none" + } + ], + "packageName": "@microsoft/rush", + "email": "kinhln@microsoft.com" +} \ No newline at end of file