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
11 changes: 6 additions & 5 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export interface Odo {
getServiceTemplatePlans(svc: string): Promise<string[]>;
getServices(application: OpenShiftObject): Promise<OpenShiftObject[]>;
execute(command: string, cwd?: string, fail?: boolean): Promise<CliExitData>;
executeInTerminal(command: string, cwd?: string): void;
executeInTerminal(command: string, cwd?: string): Promise<void>;
requireLogin(): Promise<boolean>;
clearCache?(): void;
createProject(name: string): Promise<OpenShiftObject>;
Expand Down Expand Up @@ -891,12 +891,13 @@ export class OdoImpl implements Odo {

public async executeInTerminal(command: string, cwd: string = process.cwd(), name = 'OpenShift'): Promise<void> {
const cmd = command.split(' ')[0];
let toolLocation = await ToolsConfig.detectOrDownload(cmd);
const toolLocation = await ToolsConfig.detectOrDownload(cmd);
let toolDirLocation: string;
if (toolLocation) {
toolLocation = path.dirname(toolLocation);
toolDirLocation = path.dirname(toolLocation);
}
const terminal: Terminal = WindowUtil.createTerminal(name, cwd, toolLocation);
terminal.sendText(command, true);
const terminal: Terminal = WindowUtil.createTerminal(name, cwd);
terminal.sendText(toolDirLocation ? command.replace(cmd, `"${toolLocation}"`).replace(new RegExp(`&& ${cmd}`, 'g'), `&& "${toolLocation}"`) : command, true);
terminal.show();
}

Expand Down
2 changes: 1 addition & 1 deletion src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class Component extends OpenShiftItem {
const choice = await Component.handleMigratedComponent(component);
if (!choice) return null;
Component.setPushCmd(component.contextPath.fsPath);
Component.odo.executeInTerminal(Command.pushComponent(), component.contextPath.fsPath);
await Component.odo.executeInTerminal(Command.pushComponent(), component.contextPath.fsPath);
component.contextValue = ContextType.COMPONENT_PUSHED;
Component.explorer.refresh(component);
}
Expand Down
15 changes: 3 additions & 12 deletions src/util/windowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
*-----------------------------------------------------------------------------------------------*/

import { window, Terminal, TerminalOptions } from 'vscode';
import * as path from 'path';

export class WindowUtil {

static createTerminal(name: string, cwd: string, toolLocation?: string, env: NodeJS.ProcessEnv = process.env): Terminal {
const finalEnv: NodeJS.ProcessEnv = {};
Object.assign(finalEnv, env);
const key = process.platform === 'win32' ? 'Path' : 'PATH';

if (toolLocation && env[key] && !env[key].includes(toolLocation)) {
finalEnv[key] = `${toolLocation}${path.delimiter}${env[key]}`;
}
static createTerminal(name: string, cwd: string): Terminal {
const options: TerminalOptions = {
cwd,
name,
env: finalEnv,
shellPath: process.platform === 'win32' ? undefined : '/bin/bash'
shellPath: process.platform === 'win32' ? process.env.ComSpec : '/bin/bash'
};
return window.createTerminal(options);
}
}
}
2 changes: 1 addition & 1 deletion test/unit/odo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ suite("odo", () => {
await odoCli.executeInTerminal('cmd');
expect(termFake.sendText).calledOnce;
expect(termFake.show).calledOnce;
expect(ctStub).calledWith('OpenShift', process.cwd(), 'segment1');
expect(ctStub).calledWith('OpenShift', process.cwd());
});
});

Expand Down
22 changes: 2 additions & 20 deletions test/unit/util/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
import * as sinon from 'sinon';
import * as path from 'path';
import { window, TerminalOptions } from 'vscode';
import { window } from 'vscode';
import { WindowUtil } from '../../../src/util/windowUtils';

const {expect} = chai;
Expand All @@ -31,21 +30,4 @@ suite('Window Utility', () => {
expect(termStub).calledOnce;
});

test('createTerminal adds tools location and shell path to the environment', () => {
const toolLocationDir = path.dirname(path.join("dir", "where", "tool", "is", "located", "tool"));
const env: NodeJS.ProcessEnv = {};
const key = process.platform === 'win32' ? 'Path' : 'PATH';
Object.assign(env, process.env);
env[key] = `${toolLocationDir}${path.delimiter}${process.env[key]}`;

const options: TerminalOptions = {
cwd: process.cwd(),
name: 'terminal',
shellPath: process.platform === 'win32' ? undefined : '/bin/bash',
env
};
WindowUtil.createTerminal('terminal', process.cwd(), toolLocationDir);

expect(termStub).calledOnceWith(options);
});
});
});