Skip to content

Commit

Permalink
Merge pull request #1190 from dotnetjunky/kinhln/string-param
Browse files Browse the repository at this point in the history
[rush] Add support for string parameter in custom commands
  • Loading branch information
octogonz authored Mar 29, 2019
2 parents 55290d3 + 2344a56 commit ecb9676
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
9 changes: 7 additions & 2 deletions apps/rush-lib/src/api/CommandLineJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions apps/rush-lib/src/cli/scriptActions/BaseScriptAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`);
Expand Down
42 changes: 39 additions & 3 deletions apps/rush-lib/src/schemas/command-line.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -287,7 +322,8 @@
"type": "object",
"oneOf": [
{ "$ref": "#/definitions/flagParameter" },
{ "$ref": "#/definitions/choiceParameter" }
{ "$ref": "#/definitions/choiceParameter" },
{ "$ref": "#/definitions/stringParameter" }
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "Add support for string parameter for custom commands.",
"packageName": "@microsoft/rush",
"type": "none"
}
],
"packageName": "@microsoft/rush",
"email": "[email protected]"
}

0 comments on commit ecb9676

Please sign in to comment.