diff --git a/package.json b/package.json index 03d330a35..c99774731 100644 --- a/package.json +++ b/package.json @@ -813,6 +813,46 @@ "command": "openshift.Serverless.stopRun", "title": "Stop", "category": "OpenShift" + }, + { + "command": "openshift.Serverless.addEnv", + "title": "Environment Variables", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.addLabel", + "title": "Labels", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.addVolume", + "title": "Volumes", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.addGit", + "title": "Git", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.removeEnv", + "title": "Environment Variables", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.removeLabel", + "title": "Labels", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.removeVolume", + "title": "Volumes", + "category": "OpenShift" + }, + { + "command": "openshift.Serverless.removeGit", + "title": "Git", + "category": "OpenShift" } ], "keybindings": [ @@ -827,6 +867,16 @@ "mac": "ctrl+shift+p" } ], + "submenus": [ + { + "id": "serverlessfunction/addConfig", + "label": "Add" + }, + { + "id": "serverlessfunction/removeConfig", + "label": "Remove" + } + ], "viewsContainers": { "activitybar": [ { @@ -1135,6 +1185,38 @@ { "command": "openshift.Serverless.stopRun", "when": "false" + }, + { + "command": "openshift.Serverless.addEnv", + "when": "false" + }, + { + "command": "openshift.Serverless.addLabel", + "when": "false" + }, + { + "command": "openshift.Serverless.addVolume", + "when": "false" + }, + { + "command": "openshift.Serverless.addGit", + "when": "false" + }, + { + "command": "openshift.Serverless.removeEnv", + "when": "false" + }, + { + "command": "openshift.Serverless.removeLabel", + "when": "false" + }, + { + "command": "openshift.Serverless.removeVolume", + "when": "false" + }, + { + "command": "openshift.Serverless.removeGit", + "when": "false" } ], "view/title": [ @@ -1204,6 +1286,50 @@ "group": "navigation" } ], + "serverlessfunction/addConfig": [ + { + "command": "openshift.Serverless.addEnv", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@0" + }, + { + "command": "openshift.Serverless.addGit", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@1" + }, + { + "command": "openshift.Serverless.addLabel", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@2" + }, + { + "command": "openshift.Serverless.addVolume", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@3" + } + ], + "serverlessfunction/removeConfig": [ + { + "command": "openshift.Serverless.removeEnv", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@0" + }, + { + "command": "openshift.Serverless.removeGit", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@1" + }, + { + "command": "openshift.Serverless.removeLabel", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@2" + }, + { + "command": "openshift.Serverless.removeVolume", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@3" + } + ], "view/item/context": [ { "command": "openshift.sandbox.signup", @@ -1486,6 +1612,16 @@ { "command": "openshift.Serverless.stopRun", "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(running)$/" + }, + { + "submenu": "serverlessfunction/addConfig", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@1" + }, + { + "submenu": "serverlessfunction/removeConfig", + "when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/", + "group": "c1@2" } ] }, diff --git a/src/cli.ts b/src/cli.ts index dc2801294..28c9e6cb2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -152,12 +152,14 @@ export class CliChannel implements Cli { return result; } - async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env): Promise { - const [cmd, ...params] = command.toString().split(' '); + async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env, isFuncionCLI = false): Promise { + const commandStr = command.toString(); + const [cmd, ...params] = commandStr.split(' '); const toolLocation = await ToolsConfig.detect(cmd); const envWithTelemetry = {...env, ...CliChannel.createTelemetryEnv()}; const terminal: vscode.Terminal = WindowUtil.createTerminal(name, cwd, envWithTelemetry); - terminal.sendText(toolLocation === cmd ? command.toString() : toolLocation.concat(' ', ...params), true); + terminal.sendText(toolLocation === cmd ? commandStr : + isFuncionCLI ? toolLocation.concat(' ', ...params.join(' ')) : toolLocation.concat(' ', ...params), true); terminal.show(); } diff --git a/src/serverlessFunction/build-run-deploy.ts b/src/serverlessFunction/build-run-deploy.ts index c6885a719..add0de624 100644 --- a/src/serverlessFunction/build-run-deploy.ts +++ b/src/serverlessFunction/build-run-deploy.ts @@ -19,6 +19,8 @@ export class BuildAndDeploy { private static instance: BuildAndDeploy; + protected static readonly cli = CliChannel.getInstance(); + private buildTerminalMap: Map = new Map(); public runTerminalMap: Map = new Map(); private buildEmiterMap: Map> = new Map>(); @@ -315,6 +317,11 @@ export class BuildAndDeploy { }); } + public async config(title: string, context: FunctionObject, mode: string, isAdd = true) { + await BuildAndDeploy.cli.executeInTerminal(ServerlessCommand.config(context.folderURI.fsPath, mode, isAdd), + context.folderURI.fsPath, title, process.env, true); + } + private async provideUserNameAndPassword( process: ChildProcess, message: string, diff --git a/src/serverlessFunction/commands.ts b/src/serverlessFunction/commands.ts index 6cf5d09d7..a7656c35f 100644 --- a/src/serverlessFunction/commands.ts +++ b/src/serverlessFunction/commands.ts @@ -79,4 +79,21 @@ export class ServerlessCommand { new CommandOption('-o', 'josn') ]); } + + static config(functionPath: string, mode: string, isAdd: boolean): CommandText { + const commandText = new CommandText('func', 'config', [ + new CommandOption(mode), + new CommandOption('-p', functionPath) + ]); + if (isAdd) { + if (mode === 'git') { + commandText.addOption(new CommandOption('set')); + } else { + commandText.addOption(new CommandOption('add')); + } + } else { + commandText.addOption(new CommandOption('remove')); + } + return commandText; + } } diff --git a/src/serverlessFunction/view.ts b/src/serverlessFunction/view.ts index c82fe8974..49cab79c1 100644 --- a/src/serverlessFunction/view.ts +++ b/src/serverlessFunction/view.ts @@ -255,4 +255,44 @@ export class ServerlessFunctionView implements TreeDataProvider, D (err) => window.showErrorMessage(`Error loading document: ${err}`), ); } + + @vsCommand('openshift.Serverless.addEnv') + static async addEnv(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Add environment variables '${context.name}'`, context, 'envs'); + } + + @vsCommand('openshift.Serverless.addLabel') + static async addLabel(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Add Labels '${context.name}'`, context, 'labels'); + } + + @vsCommand('openshift.Serverless.addVolume') + static async addVolume(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Add Volumes '${context.name}'`, context, 'volumes'); + } + + @vsCommand('openshift.Serverless.addGit') + static async addGit(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Add Git '${context.name}'`, context, 'git'); + } + + @vsCommand('openshift.Serverless.removeEnv') + static removeEnv(context: FunctionObject) { + void BuildAndDeploy.getInstance().config(`Remove environment variables '${context.name}'`, context, 'envs', false); + } + + @vsCommand('openshift.Serverless.removeLabel') + static removeLabel(context: FunctionObject) { + void BuildAndDeploy.getInstance().config(`Remove Labels '${context.name}'`, context, 'labels', false); + } + + @vsCommand('openshift.Serverless.removeVolume') + static async removeVolume(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Remove Volumes '${context.name}'`, context, 'volumes', false); + } + + @vsCommand('openshift.Serverless.removeGit') + static async removeGit(context: FunctionObject) { + await BuildAndDeploy.getInstance().config(`Remove Git '${context.name}'`, context, 'git', false); + } }