Skip to content

Commit f24790a

Browse files
authored
[QT-330] Only render event diagnostics once (#72)
* Only render event diagnostics once * Dynamically update the event responses header based on success or failure Signed-off-by: Ryan Cragun <[email protected]> Co-authored-by: Rebecca Willett [email protected]
1 parent cac032f commit f24790a

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

command/enos/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package main
22

3-
import "github.com/hashicorp/enos/internal/command/enos/cmd"
3+
import (
4+
"math/rand"
5+
"time"
6+
7+
"github.com/hashicorp/enos/internal/command/enos/cmd"
8+
)
49

510
func main() {
11+
rand.Seed(time.Now().UnixNano())
612
cmd.Execute()
713
}

internal/ui/basic/show_op_event.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ func (v *View) ShowOperationEvent(event *pb.Operation_Event) {
5353
)...)
5454
}
5555

56-
v.writeDiags(event.GetDiagnostics(), msg)
5756
v.writeMsg(event.GetStatus(), msg.String())
5857
}

internal/ui/basic/show_op_response.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,49 @@ package basic
22

33
import (
44
"fmt"
5+
"math/rand"
56

67
"github.com/hashicorp/enos/internal/diagnostics"
78
"github.com/hashicorp/enos/internal/flightplan"
89
"github.com/hashicorp/enos/internal/ui/status"
910
"github.com/hashicorp/enos/proto/hashicorp/enos/v1/pb"
1011
)
1112

13+
var failedIcons = []string{"🙈", "🙉", "🙊"}
14+
1215
// ShowOperationResponses shows an operation responses
1316
func (v *View) ShowOperationResponses(res *pb.OperationResponses) error {
14-
// Check for request level diagnostics and fail early if they exist
17+
// Determine if anything failed so we can create the correct display header
1518
diags := diagnostics.Concat(res.GetDecode().GetDiagnostics(), res.GetDiagnostics())
19+
failed := diagnostics.HasFailed(v.Settings().GetFailOnWarnings(), diags)
20+
if !failed {
21+
for _, r := range res.GetResponses() {
22+
if diagnostics.OpResFailed(v.Settings().GetFailOnWarnings(), r) {
23+
failed = true
24+
break
25+
}
26+
}
27+
}
28+
29+
header := "\nEnos operations"
30+
if failed {
31+
if v.settings.IsTty {
32+
header = fmt.Sprintf("%s failed! %s\n", header, failedIcons[rand.Intn(len(failedIcons))])
33+
} else {
34+
header += " failed!\n"
35+
}
36+
} else {
37+
if v.settings.IsTty {
38+
header += " finished! 🐵\n"
39+
} else {
40+
header += " finished!\n"
41+
}
42+
}
43+
1644
if diagnostics.HasFailed(v.Settings().GetFailOnWarnings(), diags) {
45+
// Our request failed so show our header and request diagnostics
46+
v.ui.Error(header)
47+
1748
err := v.ShowDiagnostics(diags)
1849
if err != nil {
1950
return err
@@ -22,8 +53,12 @@ func (v *View) ShowOperationResponses(res *pb.OperationResponses) error {
2253
return status.OperationResponses(v.Settings().GetFailOnWarnings(), res)
2354
}
2455

25-
// Our request didn't fail so we'll show each operations status
26-
v.ui.Info("\nEnos operations finished!\n")
56+
if failed {
57+
// One or more sub-requests failed
58+
v.ui.Error(header)
59+
} else {
60+
v.ui.Info(header)
61+
}
2762

2863
err := v.ShowDecode(res.GetDecode(), true)
2964
if err != nil {

internal/ui/basic/tf_responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (v *View) writePlainTextResponse(cmd string, stderr string, res status.ResW
169169
if status.HasFailed(v.settings.FailOnWarnings, res) {
170170
msg := fmt.Sprintf(" %s: failed!", cmd)
171171
if v.settings.IsTty {
172-
msg = fmt.Sprintf(" %s: ❌", cmd)
172+
msg = fmt.Sprintf(" %s: ❌", cmd)
173173
}
174174
v.ui.Error(msg)
175175
if stderr != "" {

0 commit comments

Comments
 (0)