Skip to content

Commit

Permalink
fix/send normal output to stderr (#194)
Browse files Browse the repository at this point in the history
* feat: fix bug

Signed-off-by: Kasper J. Hermansen <[email protected]>

* fix: set all output to stderr from ui

Signed-off-by: Kasper J. Hermansen <[email protected]>

* feat: send git plan to out

Signed-off-by: Kasper J. Hermansen <[email protected]>

* feat: with stderr instead

Signed-off-by: Kasper J. Hermansen <[email protected]>

---------

Signed-off-by: Kasper J. Hermansen <[email protected]>
  • Loading branch information
kjuulh authored Dec 5, 2023
1 parent 0d20dfa commit d2da666
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestConfig(t *testing.T) {
name: "git plan",
input: args("-p", "testdata/project-git", "config"),
stdoutput: "Version <dev-version>\nPlan:\nhttps://github.com/lunarway/shuttle-example-go-plan.git master\nEnvironment:\nVAR1=TEST1\nVAR2=TEST2\nVAR3=TEST3\n",
erroutput: "",
erroutput: "Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n",
err: nil,
},
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ func TestPlan(t *testing.T) {
err: nil,
},
{
name: "git plan",
input: args("-p", "testdata/project-git", "plan"),
stdoutput: `Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git
https://github.com/lunarway/shuttle-example-go-plan.git`,
erroutput: "",
name: "git plan",
input: args("-p", "testdata/project-git", "plan"),
stdoutput: "https://github.com/lunarway/shuttle-example-go-plan.git",
erroutput: "Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n",
err: nil,
},
{
Expand Down
30 changes: 13 additions & 17 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Global Flags:
name: "std err echo",
input: args("-p", "testdata/project", "run", "hello_stderr"),
stdoutput: "",
erroutput: "\x1b[31;1mHello stderr\x1b[0m\n",
erroutput: "Hello stderr\n",
err: nil,
},
{
Expand Down Expand Up @@ -154,28 +154,24 @@ Make sure you are in a project using shuttle and that a 'shuttle.yaml' file is a
err: errors.New(`unknown flag: --a b`),
},
{
name: "branched git plan",
input: args("-p", "testdata/project-git-branched", "run", "say"),
stdoutput: `Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git
something clever
`,
erroutput: "",
name: "branched git plan",
input: args("-p", "testdata/project-git-branched", "run", "say"),
stdoutput: "something clever\n",
erroutput: "Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n",
err: nil,
},
{
name: "git plan",
input: args("-p", "testdata/project-git", "run", "say"),
stdoutput: `Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git
something masterly
`,
erroutput: "",
name: "git plan",
input: args("-p", "testdata/project-git", "run", "say"),
stdoutput: "something masterly\n",
erroutput: "Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n",
initErr: errors.New("something"),
},
{
name: "tagged git plan",
input: args("-p", "testdata/project-git", "--plan", "#tagged", "run", "say"),
stdoutput: "\x1b[032;1mOverload git plan branch/tag/sha with tagged\x1b[0m\nCloning plan https://github.com/lunarway/shuttle-example-go-plan.git\nsomething tagged\n",
erroutput: "",
stdoutput: "something tagged\n",
erroutput: "\x1b[032;1mOverload git plan branch/tag/sha with tagged\x1b[0m\nCloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n",
err: nil,
},
{
Expand All @@ -188,8 +184,8 @@ something masterly
"run",
"hello-plan",
),
stdoutput: "Using overloaded plan ./testdata/project-local/plan\nHello from plan\n",
erroutput: "",
stdoutput: "Hello from plan\n",
erroutput: "Using overloaded plan ./testdata/project-local/plan\n",
err: nil,
},
// FIXME: This case actually hits a bug as we do not support fetching specific commits
Expand Down
4 changes: 2 additions & 2 deletions pkg/executors/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func executeShell(ctx context.Context, ui *ui.UI, context ActionExecutionContext
execCmd.Stdout = nil
continue
}
context.ScriptContext.Project.UI.Infoln("%s", line)
context.ScriptContext.Project.UI.Output("%s", line)
case line, open := <-execCmd.Stderr:
if !open {
execCmd.Stderr = nil
continue
}
context.ScriptContext.Project.UI.Errorln("%s", line)
context.ScriptContext.Project.UI.Infoln("%s", line)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func RunGitPlanCommand(command string, plan string, uii *ui.UI) {
execCmd.Stdout = nil
continue
}
uii.Infoln("%s", line)
fmt.Printf("%s", line)
case line, open := <-execCmd.Stderr:
if !open {
execCmd.Stderr = nil
Expand Down
11 changes: 8 additions & 3 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,28 @@ func (ui *UI) SetContext(level Level) *UI {
return ui
}

// Output.
func (ui *UI) Output(format string, args ...interface{}) {
fmt.Fprintln(ui.Out, fmt.Sprintf(format, args...))
}

// Verboseln prints a formatted verbose message line.
func (ui *UI) Verboseln(format string, args ...interface{}) {
if ui.EffectiveLevel.OutputIsIncluded(LevelVerbose) {
fmt.Fprintln(ui.Out, fmt.Sprintf(format, args...))
fmt.Fprintln(ui.Err, fmt.Sprintf(format, args...))
}
}

// Infoln prints a formatted info message line.
func (ui *UI) Infoln(format string, args ...interface{}) {
if ui.EffectiveLevel.OutputIsIncluded(LevelInfo) {
fmt.Fprintln(ui.Out, fmt.Sprintf(format, args...))
fmt.Fprintln(ui.Err, fmt.Sprintf(format, args...))
}
}

func (ui *UI) EmphasizeInfoln(format string, args ...interface{}) {
if ui.EffectiveLevel.OutputIsIncluded(LevelInfo) {
fmt.Fprintf(ui.Out, "\x1b[032;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
fmt.Fprintf(ui.Err, "\x1b[032;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
}
}

Expand Down

0 comments on commit d2da666

Please sign in to comment.