Skip to content

Commit be8c61a

Browse files
msivasubramaniaandatho7561
authored andcommitted
config functionality added
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 43a4ec3 commit be8c61a

File tree

5 files changed

+163
-3
lines changed

5 files changed

+163
-3
lines changed

package.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,36 @@
813813
"command": "openshift.Serverless.stopRun",
814814
"title": "Stop",
815815
"category": "OpenShift"
816+
},
817+
{
818+
"command": "openshift.Serverless.addEnv",
819+
"title": "Environment Variables",
820+
"category": "OpenShift"
821+
},
822+
{
823+
"command": "openshift.Serverless.addLabel",
824+
"title": "Labels",
825+
"category": "OpenShift"
826+
},
827+
{
828+
"command": "openshift.Serverless.addVolume",
829+
"title": "Volumes",
830+
"category": "OpenShift"
831+
},
832+
{
833+
"command": "openshift.Serverless.removeEnv",
834+
"title": "Environment Variables",
835+
"category": "OpenShift"
836+
},
837+
{
838+
"command": "openshift.Serverless.removeLabel",
839+
"title": "Labels",
840+
"category": "OpenShift"
841+
},
842+
{
843+
"command": "openshift.Serverless.removeVolume",
844+
"title": "Volumes",
845+
"category": "OpenShift"
816846
}
817847
],
818848
"keybindings": [
@@ -827,6 +857,16 @@
827857
"mac": "ctrl+shift+p"
828858
}
829859
],
860+
"submenus": [
861+
{
862+
"id": "serverlessfunction/addConfig",
863+
"label": "Add"
864+
},
865+
{
866+
"id": "serverlessfunction/removeConfig",
867+
"label": "Remove"
868+
}
869+
],
830870
"viewsContainers": {
831871
"activitybar": [
832872
{
@@ -1135,6 +1175,30 @@
11351175
{
11361176
"command": "openshift.Serverless.stopRun",
11371177
"when": "false"
1178+
},
1179+
{
1180+
"command": "openshift.Serverless.addEnv",
1181+
"when": "false"
1182+
},
1183+
{
1184+
"command": "openshift.Serverless.addLabel",
1185+
"when": "false"
1186+
},
1187+
{
1188+
"command": "openshift.Serverless.addVolume",
1189+
"when": "false"
1190+
},
1191+
{
1192+
"command": "openshift.Serverless.removeEnv",
1193+
"when": "false"
1194+
},
1195+
{
1196+
"command": "openshift.Serverless.removeLabel",
1197+
"when": "false"
1198+
},
1199+
{
1200+
"command": "openshift.Serverless.removeVolume",
1201+
"when": "false"
11381202
}
11391203
],
11401204
"view/title": [
@@ -1204,6 +1268,40 @@
12041268
"group": "navigation"
12051269
}
12061270
],
1271+
"serverlessfunction/addConfig": [
1272+
{
1273+
"command": "openshift.Serverless.addLabel",
1274+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1275+
"group": "c1@1"
1276+
},
1277+
{
1278+
"command": "openshift.Serverless.addVolume",
1279+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1280+
"group": "c1@2"
1281+
},
1282+
{
1283+
"command": "openshift.Serverless.addEnv",
1284+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1285+
"group": "c1@3"
1286+
}
1287+
],
1288+
"serverlessfunction/removeConfig": [
1289+
{
1290+
"command": "openshift.Serverless.removeLabel",
1291+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1292+
"group": "c1@1"
1293+
},
1294+
{
1295+
"command": "openshift.Serverless.removeVolume",
1296+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1297+
"group": "c1@2"
1298+
},
1299+
{
1300+
"command": "openshift.Serverless.removeEnv",
1301+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1302+
"group": "c1@3"
1303+
}
1304+
],
12071305
"view/item/context": [
12081306
{
12091307
"command": "openshift.sandbox.signup",
@@ -1486,6 +1584,16 @@
14861584
{
14871585
"command": "openshift.Serverless.stopRun",
14881586
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(running)$/"
1587+
},
1588+
{
1589+
"submenu": "serverlessfunction/addConfig",
1590+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1591+
"group": "c1@1"
1592+
},
1593+
{
1594+
"submenu": "serverlessfunction/removeConfig",
1595+
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
1596+
"group": "c1@2"
14891597
}
14901598
]
14911599
},

src/cli.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ export class CliChannel implements Cli {
152152
return result;
153153
}
154154

155-
async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env): Promise<void> {
156-
const [cmd, ...params] = command.toString().split(' ');
155+
async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env, isFuncionCLI = false): Promise<void> {
156+
const commandStr = command.toString();
157+
const [cmd, ...params] = commandStr.split(' ');
157158
const toolLocation = await ToolsConfig.detect(cmd);
158159
const envWithTelemetry = {...env, ...CliChannel.createTelemetryEnv()};
159160
const terminal: vscode.Terminal = WindowUtil.createTerminal(name, cwd, envWithTelemetry);
160-
terminal.sendText(toolLocation === cmd ? command.toString() : toolLocation.concat(' ', ...params), true);
161+
terminal.sendText(toolLocation === cmd ? commandStr :
162+
isFuncionCLI ? toolLocation.concat(' ', ...params.join(' ')) : toolLocation.concat(' ', ...params), true);
161163
terminal.show();
162164
}
163165

src/serverlessFunction/build-run-deploy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class BuildAndDeploy {
1919

2020
private static instance: BuildAndDeploy;
2121

22+
protected static readonly cli = CliChannel.getInstance();
23+
2224
private buildTerminalMap: Map<string, Terminal> = new Map<string, Terminal>();
2325
public runTerminalMap: Map<string, Terminal> = new Map<string, Terminal>();
2426
private buildEmiterMap: Map<string, EventEmitter<string>> = new Map<string, EventEmitter<string>>();
@@ -315,6 +317,11 @@ export class BuildAndDeploy {
315317
});
316318
}
317319

320+
public async config(title: string, context: FunctionObject, mode: string, isAdd = true) {
321+
await BuildAndDeploy.cli.executeInTerminal(ServerlessCommand.config(context.folderURI.fsPath, mode, isAdd),
322+
context.folderURI.fsPath, title, process.env, true);
323+
}
324+
318325
private async provideUserNameAndPassword(
319326
process: ChildProcess,
320327
message: string,

src/serverlessFunction/commands.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,17 @@ export class ServerlessCommand {
7979
new CommandOption('-o', 'josn')
8080
]);
8181
}
82+
83+
static config(functionPath: string, mode: string, isAdd: boolean): CommandText {
84+
const commandText = new CommandText('func', 'config', [
85+
new CommandOption(mode),
86+
new CommandOption('-p', functionPath)
87+
]);
88+
if (isAdd) {
89+
commandText.addOption(new CommandOption('add'));
90+
} else {
91+
commandText.addOption(new CommandOption('remove'));
92+
}
93+
return commandText;
94+
}
8295
}

src/serverlessFunction/view.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,34 @@ export class ServerlessFunctionView implements TreeDataProvider<ExplorerItem>, D
255255
(err) => window.showErrorMessage(`Error loading document: ${err}`),
256256
);
257257
}
258+
259+
@vsCommand('openshift.Serverless.addEnv')
260+
static async addEnv(context: FunctionObject) {
261+
await BuildAndDeploy.getInstance().config(`Add environment variables '${context.name}'`, context, 'envs');
262+
}
263+
264+
@vsCommand('openshift.Serverless.addLabel')
265+
static async addLabel(context: FunctionObject) {
266+
await BuildAndDeploy.getInstance().config(`Add Labels '${context.name}'`, context, 'labels');
267+
}
268+
269+
@vsCommand('openshift.Serverless.addVolume')
270+
static async addVolume(context: FunctionObject) {
271+
await BuildAndDeploy.getInstance().config(`Add Volumes '${context.name}'`, context, 'volumes');
272+
}
273+
274+
@vsCommand('openshift.Serverless.removeEnv')
275+
static removeEnv(context: FunctionObject) {
276+
void BuildAndDeploy.getInstance().config(`Remove environment variables '${context.name}'`, context, 'envs', false);
277+
}
278+
279+
@vsCommand('openshift.Serverless.removeLabel')
280+
static removeLabel(context: FunctionObject) {
281+
void BuildAndDeploy.getInstance().config(`Remove Labels '${context.name}'`, context, 'labels', false);
282+
}
283+
284+
@vsCommand('openshift.Serverless.removeVolume')
285+
static async removeVolume(context: FunctionObject) {
286+
await BuildAndDeploy.getInstance().config(`Remove Volumes '${context.name}'`, context, 'volumes', false);
287+
}
258288
}

0 commit comments

Comments
 (0)