Skip to content

Commit 5f287a4

Browse files
authored
Use full path to cli tool when running in terminal (#1381)
* Use full path to cli tool when running in terminal Signed-off-by: Denis Golovin <dgolovin@redhat.com> * Fix build errors Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 6b3a233 commit 5f287a4

File tree

5 files changed

+13
-39
lines changed

5 files changed

+13
-39
lines changed

src/odo.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export interface Odo {
473473
getServiceTemplatePlans(svc: string): Promise<string[]>;
474474
getServices(application: OpenShiftObject): Promise<OpenShiftObject[]>;
475475
execute(command: string, cwd?: string, fail?: boolean): Promise<CliExitData>;
476-
executeInTerminal(command: string, cwd?: string): void;
476+
executeInTerminal(command: string, cwd?: string): Promise<void>;
477477
requireLogin(): Promise<boolean>;
478478
clearCache?(): void;
479479
createProject(name: string): Promise<OpenShiftObject>;
@@ -891,12 +891,13 @@ export class OdoImpl implements Odo {
891891

892892
public async executeInTerminal(command: string, cwd: string = process.cwd(), name = 'OpenShift'): Promise<void> {
893893
const cmd = command.split(' ')[0];
894-
let toolLocation = await ToolsConfig.detectOrDownload(cmd);
894+
const toolLocation = await ToolsConfig.detectOrDownload(cmd);
895+
let toolDirLocation: string;
895896
if (toolLocation) {
896-
toolLocation = path.dirname(toolLocation);
897+
toolDirLocation = path.dirname(toolLocation);
897898
}
898-
const terminal: Terminal = WindowUtil.createTerminal(name, cwd, toolLocation);
899-
terminal.sendText(command, true);
899+
const terminal: Terminal = WindowUtil.createTerminal(name, cwd);
900+
terminal.sendText(toolDirLocation ? command.replace(cmd, `"${toolLocation}"`).replace(new RegExp(`&& ${cmd}`, 'g'), `&& "${toolLocation}"`) : command, true);
900901
terminal.show();
901902
}
902903

src/openshift/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class Component extends OpenShiftItem {
296296
const choice = await Component.handleMigratedComponent(component);
297297
if (!choice) return null;
298298
Component.setPushCmd(component.contextPath.fsPath);
299-
Component.odo.executeInTerminal(Command.pushComponent(), component.contextPath.fsPath);
299+
await Component.odo.executeInTerminal(Command.pushComponent(), component.contextPath.fsPath);
300300
component.contextValue = ContextType.COMPONENT_PUSHED;
301301
Component.explorer.refresh(component);
302302
}

src/util/windowUtils.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,15 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import { window, Terminal, TerminalOptions } from 'vscode';
7-
import * as path from 'path';
87

98
export class WindowUtil {
109

11-
static createTerminal(name: string, cwd: string, toolLocation?: string, env: NodeJS.ProcessEnv = process.env): Terminal {
12-
const finalEnv: NodeJS.ProcessEnv = {};
13-
Object.assign(finalEnv, env);
14-
const key = process.platform === 'win32' ? 'Path' : 'PATH';
15-
16-
if (toolLocation && env[key] && !env[key].includes(toolLocation)) {
17-
finalEnv[key] = `${toolLocation}${path.delimiter}${env[key]}`;
18-
}
10+
static createTerminal(name: string, cwd: string): Terminal {
1911
const options: TerminalOptions = {
2012
cwd,
2113
name,
22-
env: finalEnv,
23-
shellPath: process.platform === 'win32' ? undefined : '/bin/bash'
14+
shellPath: process.platform === 'win32' ? process.env.ComSpec : '/bin/bash'
2415
};
2516
return window.createTerminal(options);
2617
}
27-
}
18+
}

test/unit/odo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ suite("odo", () => {
126126
await odoCli.executeInTerminal('cmd');
127127
expect(termFake.sendText).calledOnce;
128128
expect(termFake.show).calledOnce;
129-
expect(ctStub).calledWith('OpenShift', process.cwd(), 'segment1');
129+
expect(ctStub).calledWith('OpenShift', process.cwd());
130130
});
131131
});
132132

test/unit/util/window.test.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import * as chai from 'chai';
77
import * as sinonChai from 'sinon-chai';
88
import * as sinon from 'sinon';
9-
import * as path from 'path';
10-
import { window, TerminalOptions } from 'vscode';
9+
import { window } from 'vscode';
1110
import { WindowUtil } from '../../../src/util/windowUtils';
1211

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

34-
test('createTerminal adds tools location and shell path to the environment', () => {
35-
const toolLocationDir = path.dirname(path.join("dir", "where", "tool", "is", "located", "tool"));
36-
const env: NodeJS.ProcessEnv = {};
37-
const key = process.platform === 'win32' ? 'Path' : 'PATH';
38-
Object.assign(env, process.env);
39-
env[key] = `${toolLocationDir}${path.delimiter}${process.env[key]}`;
40-
41-
const options: TerminalOptions = {
42-
cwd: process.cwd(),
43-
name: 'terminal',
44-
shellPath: process.platform === 'win32' ? undefined : '/bin/bash',
45-
env
46-
};
47-
WindowUtil.createTerminal('terminal', process.cwd(), toolLocationDir);
48-
49-
expect(termStub).calledOnceWith(options);
50-
});
51-
});
33+
});

0 commit comments

Comments
 (0)