(response: Response, exitImmediately = false)
| 22 | constructor(protected serviceContainer: ServiceContainer) {} |
| 23 | |
| 24 | protected processResponse(response: Response, exitImmediately = false) { |
| 25 | if (!response.success) { |
| 26 | if (process.env.BW_QUIET !== "true") { |
| 27 | if (process.env.BW_RESPONSE === "true") { |
| 28 | writeLn(this.getJson(response), true, false); |
| 29 | } else { |
| 30 | writeLn(chalk.redBright(response.message), true, true); |
| 31 | } |
| 32 | } |
| 33 | const exitCode = process.env.BW_CLEANEXIT ? 0 : 1; |
| 34 | if (exitImmediately) { |
| 35 | process.exit(exitCode); |
| 36 | } else { |
| 37 | process.exitCode = exitCode; |
| 38 | } |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (process.env.BW_RESPONSE === "true") { |
| 43 | writeLn(this.getJson(response), true, false); |
| 44 | } else if (response.data != null) { |
| 45 | let out: string = null; |
| 46 | |
| 47 | if (response.data.object === "template") { |
| 48 | out = this.getJson((response.data as TemplateResponse).template); |
| 49 | } |
| 50 | |
| 51 | if (out == null) { |
| 52 | if (response.data.object === "string") { |
| 53 | const data = (response.data as StringResponse).data; |
| 54 | if (data != null) { |
| 55 | out = data; |
| 56 | } |
| 57 | } else if (response.data.object === "list") { |
| 58 | out = this.getJson((response.data as ListResponse).data); |
| 59 | } else if (response.data.object === "message") { |
| 60 | out = this.getMessage(response); |
| 61 | } else { |
| 62 | out = this.getJson(response.data); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (out != null && process.env.BW_QUIET !== "true") { |
| 67 | writeLn(out, true, false); |
| 68 | } |
| 69 | } |
| 70 | if (exitImmediately) { |
| 71 | process.exit(0); |
| 72 | } else { |
| 73 | process.exitCode = 0; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private getJson(obj: any): string { |
| 78 | if (process.env.BW_PRETTY === "true") { |
nothing calls this directly
no test coverage detected