forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecCommand.ts
More file actions
47 lines (39 loc) · 1.92 KB
/
Copy pathexecCommand.ts
File metadata and controls
47 lines (39 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { CommandOption, CommandText } from '../base/command';
import { Oc } from '../oc/ocWrapper';
import { Exec } from '../odo/componentTypeDescription';
import { ComponentWorkspaceFolder } from '../odo/workspace';
import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
import { DevfileResolver } from './devfileResolver';
import { VariableResolver } from './variableResolver';
export class ExecCommandExecutor {
public static async execute(
componentFolder: ComponentWorkspaceFolder,
commandId: string,
exec: Exec,
): Promise<void> {
const rawDevfile = componentFolder.component.devfileData.devfile;
const resolver = new DevfileResolver();
const devfile = await resolver.resolve(rawDevfile);
const resolvedExec = VariableResolver.resolveExec(devfile, exec);
const componentName = devfile.metadata.name;
const podName = await Oc.Instance.getComponentPod(componentName);
const command = new CommandText('oc', 'exec', [
new CommandOption(podName),
new CommandOption('-c'),
new CommandOption(resolvedExec.component),
new CommandOption('--'),
new CommandOption('sh'),
new CommandOption('-c'),
new CommandOption(`cd ${resolvedExec.workingDir} && ${resolvedExec.commandLine}`),
]);
void OpenShiftTerminalManager.getInstance().createTerminal(
command,
`Component ${componentName}: Run '${commandId}' Command`,
componentFolder.contextPath,
);
}
}