diff --git a/src/odo.ts b/src/odo.ts index fe6d56679..b77d62c55 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -473,7 +473,7 @@ export interface Odo { getServiceTemplatePlans(svc: string): Promise; getServices(application: OpenShiftObject): Promise; execute(command: string, cwd?: string, fail?: boolean): Promise; - executeInTerminal(command: string, cwd?: string): void; + executeInTerminal(command: string, cwd?: string): Promise; requireLogin(): Promise; clearCache?(): void; createProject(name: string): Promise; @@ -891,12 +891,13 @@ export class OdoImpl implements Odo { public async executeInTerminal(command: string, cwd: string = process.cwd(), name = 'OpenShift'): Promise { 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(); } diff --git a/src/openshift/component.ts b/src/openshift/component.ts index 3910bfb00..df399acbc 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -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); } diff --git a/src/util/windowUtils.ts b/src/util/windowUtils.ts index d17b34682..1f7a9c8e5 100644 --- a/src/util/windowUtils.ts +++ b/src/util/windowUtils.ts @@ -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); } -} \ No newline at end of file +} diff --git a/test/unit/odo.test.ts b/test/unit/odo.test.ts index 769329d05..f435e86c4 100644 --- a/test/unit/odo.test.ts +++ b/test/unit/odo.test.ts @@ -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()); }); }); diff --git a/test/unit/util/window.test.ts b/test/unit/util/window.test.ts index 97b03ea56..bfb4e0dd8 100644 --- a/test/unit/util/window.test.ts +++ b/test/unit/util/window.test.ts @@ -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; @@ -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); - }); -}); \ No newline at end of file +});