Skip to content

Commit de457dd

Browse files
sudhirvermadgolovin
authored andcommitted
Prettify json in OpenShift Output Channel (#888)
* Prettify json in OpenShift Output Channel * Filter update message from output
1 parent 770e40c commit de457dd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/cli.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ export class Cli implements ICli {
3737
opts.maxBuffer = 2*1024*1024;
3838
}
3939
childProcess.exec(cmd, opts, (error: ExecException, stdout: string, stderr: string) => {
40-
this.odoChannel.print(stdout);
40+
const stdoutFiltered = stdout.replace(/---[\s\S]*$/g, '').trim()
41+
this.odoChannel.print(stdoutFiltered);
4142
this.odoChannel.print(stderr);
4243
// do not reject it here, because caller in some cases need the error and the streams
4344
// to make a decision
4445
// Filter update message text which starts with `---`
45-
resolve({ error, stdout: stdout.replace(/---[\s\S]*$/g, '').trim(), stderr });
46+
resolve({ error, stdout: stdoutFiltered, stderr });
4647
});
4748
});
4849
}
@@ -64,9 +65,20 @@ class OdoChannelImpl implements OdoChannel {
6465
this.channel.show();
6566
}
6667

68+
prettifyJson(str: string) {
69+
let jsonData: string;
70+
try {
71+
jsonData = JSON.stringify(JSON.parse(str), null, 2);
72+
} catch (ignore) {
73+
return str;
74+
}
75+
return jsonData;
76+
}
77+
6778
print(text: string): void {
68-
this.channel.append(text);
69-
if (text.charAt(text.length - 1) !== '\n') {
79+
const textData = this.prettifyJson(text);
80+
this.channel.append(textData);
81+
if (textData.charAt(textData.length - 1) !== '\n') {
7082
this.channel.append('\n');
7183
}
7284
if (vscode.workspace.getConfiguration('openshiftConnector').get<boolean>('showChannelOnOutput')) {

0 commit comments

Comments
 (0)