Skip to content

Commit

Permalink
Print crc command to channel before output (#1965)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin [email protected]
  • Loading branch information
dgolovin authored Feb 17, 2021
1 parent 0b8fd9c commit b6a527f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/view/cluster/clusterViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { CliChannel } from '../../cli';

let panel: vscode.WebviewPanel;

const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs');

export default class ClusterViewLoader {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
static get extensionPath() {
Expand All @@ -23,7 +25,6 @@ export default class ClusterViewLoader {

let startProcess: ChildProcess;
let stopProcess: ChildProcess;
const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs');
const localResourceRoot = vscode.Uri.file(path.join(ClusterViewLoader.extensionPath, 'out', 'clusterViewer'));
if (panel) {
// If we already have a panel, show it in the target column
Expand All @@ -42,22 +43,21 @@ export default class ClusterViewLoader {
panel = undefined;
});
panel.webview.onDidReceiveMessage(async (event) => {
const timestamp = Number(new Date());
const date = new Date(timestamp);
if (event.action === 'run') {
const terminal: vscode.Terminal = WindowUtil.createTerminal(`OpenShift: CRC Setup`, undefined);
terminal.sendText(`${event.data} setup`);
terminal.show();
}
if (event.action === 'start') {
channel.show();
channel.append(`\nStarting Red Hat CodeReady Containers from webview at ${date}\n`);
if (event.isSetting) {
const binaryFromSetting= vscode.workspace.getConfiguration("openshiftConnector").get("crcBinaryLocation");
const pullSecretFromSetting= vscode.workspace.getConfiguration("openshiftConnector").get("crcPullSecretPath");
const cpuFromSetting= vscode.workspace.getConfiguration("openshiftConnector").get("crcCpuCores");
const memoryFromSetting= vscode.workspace.getConfiguration("openshiftConnector").get("crcMemoryAllocated");
startProcess = spawn(`${binaryFromSetting}`, ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, '-ojson']);
const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, '-ojson'];
startProcess = spawn(`${binaryFromSetting}`, crcOptions);
channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`);
} else {
const configuration = vscode.workspace.getConfiguration("openshiftConnector");
configuration.update("crcBinaryLocation", event.crcLoc, vscode.ConfigurationTarget.Global);
Expand All @@ -66,6 +66,7 @@ export default class ClusterViewLoader {
configuration.update("crcMemoryAllocated", Number.parseInt(event.memory), vscode.ConfigurationTarget.Global);
const [tool, ...params] = event.data.split(' ');
startProcess = spawn(tool, params);
channel.append(`\n\n${tool} ${params.join(' ')}\n`);
}
startProcess.stdout.setEncoding('utf8');
startProcess.stderr.setEncoding('utf8');
Expand All @@ -88,11 +89,13 @@ export default class ClusterViewLoader {
if (event.action === 'stop') {
let filePath: string;
channel.show();
channel.append(`\nStopping Red Hat CodeReady Containers from webview at ${date}\n`);
if (event.data === '') {
filePath = vscode.workspace.getConfiguration("openshiftConnector").get("crcBinaryLocation");
} else filePath = event.data;
} else {
filePath = event.data;
}
stopProcess = spawn(`${filePath}`, ['stop']);
channel.append(`\n\n$${filePath} stop\n`);
stopProcess.stdout.setEncoding('utf8');
stopProcess.stderr.setEncoding('utf8');
stopProcess.stdout.on('data', (chunk) => {
Expand Down Expand Up @@ -134,7 +137,11 @@ export default class ClusterViewLoader {
private static async checkCrcStatus(filePath: string, postCommand: string, panel: vscode.WebviewPanel | undefined = undefined) {
let crcCredArray = [];
const crcVerInfo = await CliChannel.getInstance().execute(`${filePath} version -ojson`);
channel.append(`\n\n${filePath} version -ojson\n`);
channel.append(crcVerInfo.stdout);
const result = await CliChannel.getInstance().execute(`${filePath} status -ojson`);
channel.append(`\n\n${filePath} status -ojson\n`);
channel.append(result.stdout);
if (result.stderr || crcVerInfo.stderr) {
panel.webview.postMessage({action: postCommand, errorStatus: true});
} else {
Expand Down

0 comments on commit b6a527f

Please sign in to comment.