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