Skip to content

Commit 91e5984

Browse files
committed
improve no penalty on fail ux in cli
1 parent b64870c commit 91e5984

6 files changed

Lines changed: 35 additions & 22 deletions

File tree

checks/runner.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (re
3030
// This is the magic of the initial message sent before executing the test
3131
if step.CLICommand != nil {
3232
ch <- messages.StartStepMsg{
33-
CMD: step.CLICommand.Command,
34-
TmdlQuery: step.CLICommand.StdoutFilterTmdl,
33+
CMD: step.CLICommand.Command,
34+
TmdlQuery: step.CLICommand.StdoutFilterTmdl,
35+
NoPenaltyOnFail: step.NoPenaltyOnFail,
3536
}
3637
} else if step.HTTPRequest != nil {
3738
finalBaseURL := baseURL
@@ -43,8 +44,9 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (re
4344
interpolatedURL := InterpolateVariables(fullURL, variables)
4445

4546
ch <- messages.StartStepMsg{
46-
URL: interpolatedURL,
47-
Method: step.HTTPRequest.Request.Method,
47+
URL: interpolatedURL,
48+
Method: step.HTTPRequest.Request.Method,
49+
NoPenaltyOnFail: step.NoPenaltyOnFail,
4850
}
4951
}
5052

client/lessons.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ const BaseURLOverrideRequired = "override"
2222

2323
type CLIData struct {
2424
// ContainsCompleteDir bool
25-
// NoPenaltyOnFail bool
2625
BaseURLDefault string
2726
Steps []CLIStep
2827
AllowedOperatingSystems []string
2928
}
3029

3130
type CLIStep struct {
32-
CLICommand *CLIStepCLICommand
33-
HTTPRequest *CLIStepHTTPRequest
31+
CLICommand *CLIStepCLICommand
32+
HTTPRequest *CLIStepHTTPRequest
33+
NoPenaltyOnFail bool
3434
}
3535

3636
type CLIStepCLICommand struct {

messages/messages.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package messages
33
import api "github.com/bootdotdev/bootdev/client"
44

55
type StartStepMsg struct {
6-
CMD string
7-
URL string
8-
Method string
9-
TmdlQuery *string
6+
CMD string
7+
URL string
8+
Method string
9+
TmdlQuery *string
10+
NoPenaltyOnFail bool
1011
}
1112

1213
type StartTestMsg struct {

render/models.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ type testModel struct {
1212
}
1313

1414
type stepModel struct {
15-
step string
16-
passed *bool
17-
result *api.CLIStepResult
18-
finished bool
19-
tests []testModel
20-
sleepAfter string
15+
step string
16+
passed *bool
17+
result *api.CLIStepResult
18+
finished bool
19+
tests []testModel
20+
sleepAfter string
21+
noPenaltyOnFail bool
2122
}
2223

2324
type rootModel struct {

render/render.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
red lipgloss.Style
1919
magenta lipgloss.Style
2020
gray lipgloss.Style
21+
white lipgloss.Style
2122
borderBox = lipgloss.NewStyle().Border(lipgloss.RoundedBorder())
2223
)
2324

@@ -26,6 +27,7 @@ func (m rootModel) Init() tea.Cmd {
2627
red = lipgloss.NewStyle().Foreground(lipgloss.Color(viper.GetString("color.red")))
2728
magenta = lipgloss.NewStyle().Foreground(lipgloss.Color(viper.GetString("color.magenta")))
2829
gray = lipgloss.NewStyle().Foreground(lipgloss.Color(viper.GetString("color.gray")))
30+
white = lipgloss.NewStyle().Foreground(lipgloss.Color("15"))
2931
return m.spinner.Tick
3032
}
3133

@@ -46,8 +48,9 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4648
step = fmt.Sprintf("%s %s", msg.Method, msg.URL)
4749
}
4850
m.steps = append(m.steps, stepModel{
49-
step: step,
50-
tests: []testModel{},
51+
step: step,
52+
tests: []testModel{},
53+
noPenaltyOnFail: msg.NoPenaltyOnFail,
5154
})
5255
return m, nil
5356

render/view.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import (
1111
"github.com/charmbracelet/lipgloss"
1212
)
1313

14-
func renderTestHeader(header string, spinner spinner.Model, isFinished bool, isSubmit bool, passed *bool) string {
14+
const safeStepIcon = "🛡︎"
15+
16+
func renderTestHeader(header string, spinner spinner.Model, isFinished bool, isSubmit bool, passed *bool, noPenaltyOnFail bool) string {
17+
if noPenaltyOnFail {
18+
header = fmt.Sprintf("%s %s", header, white.Render(safeStepIcon))
19+
}
1520
cmdStr := renderTest(header, spinner.View(), isFinished, &isSubmit, passed)
1621
box := borderBox.Render(fmt.Sprintf(" %s ", cmdStr))
1722
sliced := strings.Split(box, "\n")
@@ -97,7 +102,7 @@ func (m rootModel) View() string {
97102
s := m.spinner.View()
98103
var str strings.Builder
99104
for _, step := range m.steps {
100-
str.WriteString(renderTestHeader(step.step, m.spinner, step.finished, m.isSubmit, step.passed))
105+
str.WriteString(renderTestHeader(step.step, m.spinner, step.finished, m.isSubmit, step.passed, step.noPenaltyOnFail))
101106
str.WriteString(renderTests(step.tests, s))
102107

103108
if step.sleepAfter != "" && step.finished {
@@ -152,7 +157,8 @@ func (m rootModel) View() string {
152157
str.WriteString("\n\nTests failed! ❌")
153158
fmt.Fprintf(&str, "\n\nFailed Step: %v", m.failure.FailedStepIndex+1)
154159
str.WriteString("\nError: " + m.failure.ErrorMessage + "\n")
155-
str.WriteString("\nYou haven't passed, but you also haven't been penalized.\n\n")
160+
str.WriteString("\n" + white.Render(safeStepIcon) + " This was a safe step.\n")
161+
str.WriteString("You haven't passed, but you also haven't lost armor or Sharpshooter progress.\n\n")
156162
} else if m.result == api.VerificationResultSlugFailure {
157163
str.WriteString("\n\n" + red.Render("Tests failed! ❌"))
158164
if m.failure != nil {

0 commit comments

Comments
 (0)