|
16 | 16 | package compile
|
17 | 17 |
|
18 | 18 | import (
|
19 |
| - "bytes" |
20 | 19 | "context"
|
21 | 20 | "encoding/json"
|
22 | 21 | "errors"
|
@@ -218,16 +217,9 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
|
218 | 217 | EncryptKey: encryptKey,
|
219 | 218 | SkipLibrariesDiscovery: skipLibrariesDiscovery,
|
220 | 219 | }
|
221 |
| - compileStdOut := new(bytes.Buffer) |
222 |
| - compileStdErr := new(bytes.Buffer) |
| 220 | + stdOut, stdErr, stdIORes := feedback.OutputStreams() |
223 | 221 | verboseCompile := configuration.Settings.GetString("logging.level") == "debug"
|
224 |
| - var compileRes *rpc.CompileResponse |
225 |
| - var compileError error |
226 |
| - if feedback.GetFormat() == feedback.JSON { |
227 |
| - compileRes, compileError = compile.Compile(context.Background(), compileRequest, compileStdOut, compileStdErr, nil, verboseCompile) |
228 |
| - } else { |
229 |
| - compileRes, compileError = compile.Compile(context.Background(), compileRequest, os.Stdout, os.Stderr, nil, verboseCompile) |
230 |
| - } |
| 222 | + compileRes, compileError := compile.Compile(context.Background(), compileRequest, stdOut, stdErr, nil, verboseCompile) |
231 | 223 |
|
232 | 224 | if compileError == nil && uploadAfterCompile {
|
233 | 225 | userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
|
@@ -261,17 +253,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
|
261 | 253 | UserFields: fields,
|
262 | 254 | }
|
263 | 255 |
|
264 |
| - var uploadError error |
265 |
| - if feedback.GetFormat() == feedback.JSON { |
266 |
| - // TODO: do not print upload output in json mode |
267 |
| - uploadStdOut := new(bytes.Buffer) |
268 |
| - uploadStdErr := new(bytes.Buffer) |
269 |
| - uploadError = upload.Upload(context.Background(), uploadRequest, uploadStdOut, uploadStdErr) |
270 |
| - } else { |
271 |
| - uploadError = upload.Upload(context.Background(), uploadRequest, os.Stdout, os.Stderr) |
272 |
| - } |
273 |
| - if uploadError != nil { |
274 |
| - feedback.Fatal(tr("Error during Upload: %v", uploadError), errorcodes.ErrGeneric) |
| 256 | + if err := upload.Upload(context.Background(), uploadRequest, stdOut, stdErr); err != nil { |
| 257 | + feedback.Fatal(tr("Error during Upload: %v", err), errorcodes.ErrGeneric) |
275 | 258 | }
|
276 | 259 | }
|
277 | 260 |
|
@@ -323,9 +306,10 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
|
323 | 306 | }
|
324 | 307 | }
|
325 | 308 |
|
| 309 | + stdIO := stdIORes() |
326 | 310 | feedback.PrintResult(&compileResult{
|
327 |
| - CompileOut: compileStdOut.String(), |
328 |
| - CompileErr: compileStdErr.String(), |
| 311 | + CompilerOut: stdIO.Stdout, |
| 312 | + CompilerErr: stdIO.Stderr, |
329 | 313 | BuilderResult: compileRes,
|
330 | 314 | Success: compileError == nil,
|
331 | 315 | })
|
@@ -364,8 +348,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
|
364 | 348 | }
|
365 | 349 |
|
366 | 350 | type compileResult struct {
|
367 |
| - CompileOut string `json:"compiler_out"` |
368 |
| - CompileErr string `json:"compiler_err"` |
| 351 | + CompilerOut string `json:"compiler_out"` |
| 352 | + CompilerErr string `json:"compiler_err"` |
369 | 353 | BuilderResult *rpc.CompileResponse `json:"builder_result"`
|
370 | 354 | Success bool `json:"success"`
|
371 | 355 | }
|
|
0 commit comments