Skip to content

Commit

Permalink
exec: forward command output to stderr instead of stdout on --show-ta…
Browse files Browse the repository at this point in the history
…sk-output

When "--show-task-output" is passed to "baur run", the command output is now
written to stderr instead of stdout.
Stderr fits better the output is for diagnostic purposes.
  • Loading branch information
fho committed Jan 5, 2024
1 parent 3c1046a commit 74e0352
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *runCmd) run(_ *cobra.Command, args []string) {
c.taskRunnerRoutinePool = routines.NewPool(c.taskRunnerGoRoutines)
c.taskRunner = baur.NewTaskRunner()
if c.showOutput && !verboseFlag {
c.taskRunner.LogFn = stdout.Printf
c.taskRunner.LogFn = stderr.Printf
}

c.dockerClient, err = docker.NewClient(log.StdLogger.Debugf)
Expand Down
8 changes: 4 additions & 4 deletions internal/command/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ echo "greetings from script.sh"

runCmdTest := newRunCmd()
runCmdTest.SetArgs([]string{"-o"})
stdout, _ := interceptCmdOutput(t)
_, stderr := interceptCmdOutput(t)

err = runCmdTest.Execute()
require.NoError(t, err)

require.Equal(t, 1, strings.Count(stdout.String(), "greetings from script.sh"))
require.Equal(t, 1, strings.Count(stderr.String(), "greetings from script.sh"))
}

func TestRunShowOutputOnErrorOutputIsPrintedOnce(t *testing.T) {
Expand Down Expand Up @@ -194,7 +194,7 @@ exit 1

runCmdTest := newRunCmd()
runCmdTest.SetArgs([]string{"-o"})
stdout, _ := interceptCmdOutput(t)
_, stderr := interceptCmdOutput(t)

oldExitFunc := exitFunc
var exitCode int
Expand All @@ -209,7 +209,7 @@ exit 1
require.NoError(t, err)
require.Equal(t, 1, exitCode)

require.Equal(t, 1, strings.Count(stdout.String(), "I will fail!"))
require.Equal(t, 1, strings.Count(stderr.String(), "I will fail!"))
}

func createEnvVarTestApp(t *testing.T, appName, taskName string, envVarsCfg []cfg.EnvVarsInputs) {
Expand Down

0 comments on commit 74e0352

Please sign in to comment.