Skip to content

Commit a393900

Browse files
committed
Removed direct access to stdio streams in compile command
1 parent 36d9999 commit a393900

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

cli/compile/compile.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package compile
1717

1818
import (
19-
"bytes"
2019
"context"
2120
"encoding/json"
2221
"errors"
@@ -218,16 +217,9 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
218217
EncryptKey: encryptKey,
219218
SkipLibrariesDiscovery: skipLibrariesDiscovery,
220219
}
221-
compileStdOut := new(bytes.Buffer)
222-
compileStdErr := new(bytes.Buffer)
220+
stdOut, stdErr, stdIORes := feedback.OutputStreams()
223221
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)
231223

232224
if compileError == nil && uploadAfterCompile {
233225
userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
@@ -261,17 +253,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
261253
UserFields: fields,
262254
}
263255

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)
275258
}
276259
}
277260

@@ -323,9 +306,10 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
323306
}
324307
}
325308

309+
stdIO := stdIORes()
326310
feedback.PrintResult(&compileResult{
327-
CompileOut: compileStdOut.String(),
328-
CompileErr: compileStdErr.String(),
311+
CompilerOut: stdIO.Stdout,
312+
CompilerErr: stdIO.Stderr,
329313
BuilderResult: compileRes,
330314
Success: compileError == nil,
331315
})
@@ -364,8 +348,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
364348
}
365349

366350
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"`
369353
BuilderResult *rpc.CompileResponse `json:"builder_result"`
370354
Success bool `json:"success"`
371355
}

0 commit comments

Comments
 (0)