Skip to content

Commit

Permalink
Prettify json in OpenShift Output Channel (#888)
Browse files Browse the repository at this point in the history
* Prettify json in OpenShift Output Channel
* Filter update message from output
  • Loading branch information
sudhirverma authored and dgolovin committed Jun 11, 2019
1 parent 770e40c commit de457dd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export class Cli implements ICli {
opts.maxBuffer = 2*1024*1024;
}
childProcess.exec(cmd, opts, (error: ExecException, stdout: string, stderr: string) => {
this.odoChannel.print(stdout);
const stdoutFiltered = stdout.replace(/---[\s\S]*$/g, '').trim()
this.odoChannel.print(stdoutFiltered);
this.odoChannel.print(stderr);
// do not reject it here, because caller in some cases need the error and the streams
// to make a decision
// Filter update message text which starts with `---`
resolve({ error, stdout: stdout.replace(/---[\s\S]*$/g, '').trim(), stderr });
resolve({ error, stdout: stdoutFiltered, stderr });
});
});
}
Expand All @@ -64,9 +65,20 @@ class OdoChannelImpl implements OdoChannel {
this.channel.show();
}

prettifyJson(str: string) {
let jsonData: string;
try {
jsonData = JSON.stringify(JSON.parse(str), null, 2);
} catch (ignore) {
return str;
}
return jsonData;
}

print(text: string): void {
this.channel.append(text);
if (text.charAt(text.length - 1) !== '\n') {
const textData = this.prettifyJson(text);
this.channel.append(textData);
if (textData.charAt(textData.length - 1) !== '\n') {
this.channel.append('\n');
}
if (vscode.workspace.getConfiguration('openshiftConnector').get<boolean>('showChannelOnOutput')) {
Expand Down

0 comments on commit de457dd

Please sign in to comment.