Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -827,6 +867,16 @@
"mac": "ctrl+shift+p"
}
],
"submenus": [
{
"id": "serverlessfunction/addConfig",
"label": "Add"
},
{
"id": "serverlessfunction/removeConfig",
"label": "Remove"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
8 changes: 5 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ export class CliChannel implements Cli {
return result;
}

async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env): Promise<void> {
const [cmd, ...params] = command.toString().split(' ');
async executeInTerminal(command: CommandText, cwd: string, name: string, env = process.env, isFuncionCLI = false): Promise<void> {
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();
}

Expand Down
7 changes: 7 additions & 0 deletions src/serverlessFunction/build-run-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class BuildAndDeploy {

private static instance: BuildAndDeploy;

protected static readonly cli = CliChannel.getInstance();

private buildTerminalMap: Map<string, Terminal> = new Map<string, Terminal>();
public runTerminalMap: Map<string, Terminal> = new Map<string, Terminal>();
private buildEmiterMap: Map<string, EventEmitter<string>> = new Map<string, EventEmitter<string>>();
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/serverlessFunction/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
40 changes: 40 additions & 0 deletions src/serverlessFunction/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,44 @@ export class ServerlessFunctionView implements TreeDataProvider<ExplorerItem>, 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);
}
}