Skip to content

Commit

Permalink
refactor(installer): linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattevans committed Dec 18, 2024
1 parent 8d2d7ce commit 2e7469a
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cmd/cli/commands/config/config_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (p *NetworkConfigPage) initPage() {
// Grab the available networks and their descriptions.
networks := make([]string, len(tui.AvailableNetworks))
networkDescriptions := make(map[string]string)

for i, network := range tui.AvailableNetworks {
networks[i] = network.Value
networkDescriptions[network.Value] = network.Description
Expand All @@ -90,8 +91,10 @@ func (p *NetworkConfigPage) initPage() {
switch event.Key() {
case tcell.KeyTab, tcell.KeyBacktab:
p.display.app.SetFocus(form)

return nil
}

return event
})

Expand All @@ -105,6 +108,7 @@ func (p *NetworkConfigPage) initPage() {
// If we're on the last form item, move to save button.
if formIndex == form.GetFormItemCount()-1 {
p.display.app.SetFocus(saveButton)

return nil
}

Expand All @@ -113,6 +117,7 @@ func (p *NetworkConfigPage) initPage() {
// If we're on the first form item, move to save button.
if formIndex == 0 {
p.display.app.SetFocus(saveButton)

return nil
}

Expand Down
19 changes: 16 additions & 3 deletions cmd/cli/commands/config/config_output_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (p *OutputServerConfigPage) initPage() {
for i, server := range tui.AvailableOutputServers {
if server.Label == "Custom" {
defaultIndex = i

break
}
}
Expand All @@ -100,6 +101,7 @@ func (p *OutputServerConfigPage) initPage() {
for i, server := range tui.AvailableOutputServers {
if server.Value == currentAddress {
defaultIndex = i

break
}
}
Expand Down Expand Up @@ -160,8 +162,10 @@ func (p *OutputServerConfigPage) initPage() {
switch event.Key() {
case tcell.KeyTab, tcell.KeyBacktab:
p.display.app.SetFocus(form)

return nil
}

return event
})

Expand All @@ -175,6 +179,7 @@ func (p *OutputServerConfigPage) initPage() {
// If we're on the last form item, move to save button
if formIndex == form.GetFormItemCount()-1 {
p.display.app.SetFocus(saveButton)

return nil
}

Expand All @@ -183,6 +188,7 @@ func (p *OutputServerConfigPage) initPage() {
// If we're on the first form item, move to save button
if formIndex == 0 {
p.display.app.SetFocus(saveButton)

return nil
}

Expand Down Expand Up @@ -227,7 +233,7 @@ func (p *OutputServerConfigPage) initPage() {

func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
// Get the currently selected server.
dropdown := p.form.GetFormItem(0).(*tview.DropDown)
dropdown, _ := p.form.GetFormItem(0).(*tview.DropDown)
_, serverLabel := dropdown.GetCurrentOption()

// Find the corresponding URL
Expand All @@ -236,6 +242,7 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
for _, server := range tui.AvailableOutputServers {
if server.Label == serverLabel {
serverAddress = server.Value

break
}
}
Expand All @@ -253,7 +260,9 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

Expand All @@ -267,7 +276,9 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

Expand Down Expand Up @@ -313,8 +324,8 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
} else {
// Get and validate credentials, these are required for ethPandaOps servers.
var (
username = p.form.GetFormItem(1).(*tview.InputField)
password = p.form.GetFormItem(2).(*tview.InputField)
username, _ = p.form.GetFormItem(1).(*tview.InputField)
password, _ = p.form.GetFormItem(2).(*tview.InputField)
usernameText = username.GetText()
passwordText = password.GetText()
)
Expand All @@ -328,7 +339,9 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/commands/config/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ func (d *ConfigDisplay) initPage() {
switch event.Key() {
case tcell.KeyTab, tcell.KeyBacktab:
d.app.SetFocus(d.closeButton)

return nil
}

return event
})

Expand Down Expand Up @@ -181,11 +183,14 @@ func (d *ConfigDisplay) initPage() {
switch event.Key() {
case tcell.KeyTab, tcell.KeyBacktab:
d.app.SetFocus(d.categoryList)

return nil
case tcell.KeyUp, tcell.KeyDown:
d.app.SetFocus(d.categoryList)

return event
}

return event
})

Expand Down
1 change: 1 addition & 0 deletions cmd/cli/commands/install/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (d *InstallDisplay) getCurrentStep() int {
if step, exists := stepMap[currentPage]; exists {
return step
}

return 1
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/commands/install/page_20_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ func (p *NetworkConfigPage) initPage() {
if p.page.Parent != nil {
p.display.setPage(p.page.Parent)
}

return nil
}

return event
})

Expand Down
8 changes: 5 additions & 3 deletions cmd/cli/commands/install/page_30_beacon_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func validateAndUpdate(p *BeaconNodePage) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

Expand All @@ -175,21 +177,21 @@ func validateAndUpdate(p *BeaconNodePage) {
func validateBeaconNode(address string) error {
// Check if URL is valid
if !strings.HasPrefix(address, "http://") && !strings.HasPrefix(address, "https://") {
return fmt.Errorf("Beacon node address must start with http:// or https://")
return fmt.Errorf("beacon node address must start with http:// or https://")
}

// Try to connect to the beacon node
client := &http.Client{Timeout: 5 * time.Second}

resp, err := client.Get(fmt.Sprintf("%s/eth/v1/node/health", address))
if err != nil {
return fmt.Errorf("We're unable to connect to your beacon node: %w", err)
return fmt.Errorf("we're unable to connect to your beacon node: %w", err)
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Beacon node returned status %d", resp.StatusCode)
return fmt.Errorf("beacon node returned status %d", resp.StatusCode)
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions cmd/cli/commands/install/page_40_output_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func (p *OutputServerPage) initPage() {
p.display.app.SetFocus(form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

Expand All @@ -163,7 +165,9 @@ func (p *OutputServerPage) initPage() {
p.display.app.SetFocus(form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/cli/commands/install/page_50_output_server_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (p *OutputServerCredentialsPage) initPage() {
p.display.app.SetFocus(form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}
}
Expand Down Expand Up @@ -173,7 +175,9 @@ func validateAndSaveCredentials(p *OutputServerCredentialsPage) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/cli/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func updateContributoor(c *cli.Context, opts *options.CommandOpts) error {
cfg.Version = currentVersion
}); err != nil {
log.Errorf("Failed to roll back version in config: %v", err)

return
}

Expand Down Expand Up @@ -125,6 +126,7 @@ func updateContributoor(c *cli.Context, opts *options.CommandOpts) error {
// Save the updated config.
if err := configService.Save(); err != nil {
log.Errorf("could not save updated config: %v", err)

return err
}

Expand All @@ -134,20 +136,23 @@ func updateContributoor(c *cli.Context, opts *options.CommandOpts) error {
dockerService, err := service.NewDockerService(log, configService)
if err != nil {
log.Errorf("could not create docker service: %v", err)

return err
}

log.WithField("version", configService.Get().Version).Info("Updating Contributoor")

if e := dockerService.Update(); e != nil {
log.Errorf("could not update service: %v", e)

return e
}

// Check if service is currently running.
running, err := dockerService.IsRunning()
if err != nil {
log.Errorf("could not check service status: %v", err)

return err
}

Expand Down Expand Up @@ -184,6 +189,7 @@ func updateContributoor(c *cli.Context, opts *options.CommandOpts) error {
running, err := binaryService.IsRunning()
if err != nil {
log.Errorf("could not check service status: %v", err)

return err
}

Expand Down
1 change: 1 addition & 0 deletions cmd/cli/options/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewCommandOpts(opts ...CommandOptFunc) *CommandOpts {
for _, opt := range opts {
opt(options)
}

return options
}

Expand Down
2 changes: 2 additions & 0 deletions internal/tui/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ func CreatePageFrame(opts PageFrameOptions) *tview.Frame {
frame.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyEsc {
opts.OnEsc()

return nil
}

return event
})
}
Expand Down

0 comments on commit 2e7469a

Please sign in to comment.