Skip to content

Commit 8a58ee6

Browse files
clean up more cruft
1 parent 3363371 commit 8a58ee6

7 files changed

Lines changed: 26 additions & 58 deletions

File tree

checks/runner.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, send func(tea.Msg))
3232
}
3333

3434
for i, step := range cliData.Steps {
35-
// This is the magic of the initial message sent before executing the test
36-
if step.CLICommand != nil {
35+
switch {
36+
case step.CLICommand != nil:
3737
send(messages.StartStepMsg{
3838
Description: step.Description,
3939
CMD: step.CLICommand.Command,
4040
TmdlQuery: step.CLICommand.StdoutFilterTmdl,
4141
NoPenaltyOnFail: step.NoPenaltyOnFail,
4242
})
43-
} else if step.HTTPRequest != nil {
43+
44+
result := runCLICommand(*step.CLICommand, variables)
45+
result.JqOutputs = collectStdoutJqOutputs(*step.CLICommand, result)
46+
results[i].CLICommandResult = &result
47+
48+
sendCLICommandResults(send, *step.CLICommand, result, i)
49+
handleSleep(step.CLICommand.SleepAfterMs, send)
50+
51+
case step.HTTPRequest != nil:
4452
fullURL := strings.Replace(step.HTTPRequest.Request.FullURL, api.BaseURLPlaceholder, baseURL, 1)
4553
interpolatedURL := InterpolateVariables(fullURL, variables)
4654

@@ -50,18 +58,7 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, send func(tea.Msg))
5058
Method: step.HTTPRequest.Request.Method,
5159
NoPenaltyOnFail: step.NoPenaltyOnFail,
5260
})
53-
}
54-
55-
switch {
56-
case step.CLICommand != nil:
57-
result := runCLICommand(*step.CLICommand, variables)
58-
result.JqOutputs = collectStdoutJqOutputs(*step.CLICommand, result)
59-
results[i].CLICommandResult = &result
60-
61-
sendCLICommandResults(send, *step.CLICommand, result, i)
62-
handleSleep(step.CLICommand.SleepAfterMs, send)
6361

64-
case step.HTTPRequest != nil:
6562
result := runHTTPRequest(client, baseURL, variables, *step.HTTPRequest)
6663
results[i].HTTPRequestResult = &result
6764
sendHTTPRequestResults(send, *step.HTTPRequest, result, i)

checks/runner_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,6 @@ func TestApplySubmissionResultsStopsAfterFailedCLITest(t *testing.T) {
169169
assertMessages(t, got, want)
170170
}
171171

172-
func TestApplySubmissionResultsStopsAfterFailedHTTPTest(t *testing.T) {
173-
cliData := api.CLIData{Steps: []api.CLIStep{
174-
{CLICommand: &api.CLIStepCLICommand{Tests: []api.CLICommandTest{{}}}},
175-
{HTTPRequest: &api.CLIStepHTTPRequest{Tests: []api.HTTPRequestTest{{}, {}, {}}}},
176-
}}
177-
failure := &api.StructuredErrCLI{FailedStepIndex: 1, FailedTestIndex: 1}
178-
179-
got := applySubmissionResultsMessages(cliData, failure)
180-
want := []tea.Msg{
181-
messages.ResolveStepMsg{Index: 0, Passed: boolPtr(true)},
182-
messages.ResolveTestMsg{StepIndex: 0, TestIndex: 0, Passed: boolPtr(true)},
183-
messages.ResolveStepMsg{Index: 1, Passed: boolPtr(false)},
184-
messages.ResolveTestMsg{StepIndex: 1, TestIndex: 0, Passed: boolPtr(true)},
185-
messages.ResolveTestMsg{StepIndex: 1, TestIndex: 1, Passed: boolPtr(false)},
186-
}
187-
188-
assertMessages(t, got, want)
189-
}
190-
191172
func applySubmissionResultsMessages(cliData api.CLIData, failure *api.StructuredErrCLI) []tea.Msg {
192173
var msgs []tea.Msg
193174
ApplySubmissionResults(cliData, failure, func(msg tea.Msg) {

cmd/configure.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ var configureColorsCmd = &cobra.Command{
4040
viper.Set("color."+color, defaultVal)
4141
}
4242

43-
err := viper.WriteConfig()
44-
if err != nil {
43+
if err := viper.WriteConfig(); err != nil {
4544
return fmt.Errorf("failed to write config: %v", err)
4645
}
4746

4847
fmt.Println("Colors reset!")
49-
return err
48+
return nil
5049
}
5150

5251
configColors := map[string]string{}
@@ -81,11 +80,10 @@ var configureColorsCmd = &cobra.Command{
8180
return nil
8281
}
8382

84-
err = viper.WriteConfig()
85-
if err != nil {
83+
if err := viper.WriteConfig(); err != nil {
8684
return fmt.Errorf("failed to write config: %v", err)
8785
}
88-
return err
86+
return nil
8987
},
9088
}
9189

@@ -102,12 +100,11 @@ var configureBaseURLCmd = &cobra.Command{
102100

103101
if resetOverrideBaseURL {
104102
viper.Set("override_base_url", "")
105-
err := viper.WriteConfig()
106-
if err != nil {
103+
if err := viper.WriteConfig(); err != nil {
107104
return fmt.Errorf("failed to write config: %v", err)
108105
}
109106
fmt.Println("Base URL reset!")
110-
return err
107+
return nil
111108
}
112109

113110
if len(args) == 0 {
@@ -135,12 +132,11 @@ var configureBaseURLCmd = &cobra.Command{
135132
}
136133

137134
viper.Set("override_base_url", overrideBaseURL.String())
138-
err = viper.WriteConfig()
139-
if err != nil {
135+
if err := viper.WriteConfig(); err != nil {
140136
return fmt.Errorf("failed to write config: %v", err)
141137
}
142138
fmt.Printf("Base URL set to %v\n", overrideBaseURL.String())
143-
return err
139+
return nil
144140
},
145141
}
146142

cmd/login.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import (
2323
"golang.org/x/term"
2424
)
2525

26-
func logoRenderer() string {
27-
return logo
28-
}
29-
3026
//go:embed boots.txt
3127
var logo string
3228

@@ -42,10 +38,10 @@ var loginCmd = &cobra.Command{
4238
w = 0
4339
}
4440
// Pad the logo with whitespace
45-
welcome := lipgloss.PlaceHorizontal(lipgloss.Width(logoRenderer()), lipgloss.Center, "Welcome to the Boot.dev CLI!")
41+
welcome := lipgloss.PlaceHorizontal(lipgloss.Width(logo), lipgloss.Center, "Welcome to the Boot.dev CLI!")
4642

4743
if w >= lipgloss.Width(welcome) {
48-
fmt.Print(logoRenderer())
44+
fmt.Print(logo)
4945
fmt.Print(welcome, "\n\n")
5046
} else {
5147
fmt.Print("Welcome to the Boot.dev CLI!\n\n")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/charmbracelet/lipgloss v1.1.0
99
github.com/goccy/go-json v0.10.5
1010
github.com/itchyny/gojq v0.12.18
11-
github.com/muesli/termenv v0.16.0
1211
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1312
github.com/spf13/cobra v1.10.2
1413
github.com/spf13/viper v1.21.0
@@ -37,6 +36,7 @@ require (
3736
github.com/mattn/go-runewidth v0.0.19 // indirect
3837
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
3938
github.com/muesli/cancelreader v0.2.2 // indirect
39+
github.com/muesli/termenv v0.16.0 // indirect
4040
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
4141
github.com/rivo/uniseg v0.4.7 // indirect
4242
github.com/rogpeppe/go-internal v1.14.1 // indirect

render/render.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/bootdotdev/bootdev/messages"
1010
tea "github.com/charmbracelet/bubbletea"
1111
"github.com/charmbracelet/lipgloss"
12-
"github.com/muesli/termenv"
1312
"github.com/spf13/viper"
1413
)
1514

@@ -114,8 +113,7 @@ func StartRenderer(isSubmit bool, verbose bool) (func(tea.Msg), func(api.LessonS
114113
} else if r, ok := model.(rootModel); ok {
115114
r.clear = false
116115
r.finalized = true
117-
output := termenv.NewOutput(os.Stdout)
118-
output.WriteString(r.View())
116+
fmt.Fprint(os.Stdout, r.View())
119117
}
120118
}()
121119

version/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package version
22

33
import "context"
44

5-
var ContextKey = struct{ string }{"version"}
5+
var contextKey = struct{ string }{"version"}
66

77
func WithContext(ctx context.Context, version *VersionInfo) context.Context {
8-
return context.WithValue(ctx, ContextKey, version)
8+
return context.WithValue(ctx, contextKey, version)
99
}
1010

1111
func FromContext(ctx context.Context) *VersionInfo {
12-
if c, ok := ctx.Value(ContextKey).(*VersionInfo); ok {
12+
if c, ok := ctx.Value(contextKey).(*VersionInfo); ok {
1313
return c
1414
}
1515

0 commit comments

Comments
 (0)