Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ module github.com/hugoh/tmhi-cli
go 1.25.0

require (
github.com/go-playground/validator/v10 v10.30.2
github.com/go-playground/validator/v10 v10.30.3
github.com/hugoh/cellular-signal v1.1.3
github.com/hugoh/tmhi-gateway v1.1.1
github.com/hugoh/tmhi-gateway v1.2.0
github.com/pterm/pterm v0.12.83
github.com/stretchr/testify v1.11.1
github.com/urfave/cli-altsrc/v3 v3.1.0
github.com/urfave/cli-validation v0.0.0-20230629031421-92802a7fd6e9
github.com/urfave/cli/v3 v3.8.0
github.com/urfave/cli/v3 v3.9.0
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04
golang.org/x/term v0.42.0
golang.org/x/term v0.43.0
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/keyboard v0.2.10 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
Expand All @@ -27,18 +27,18 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-resty/resty/v2 v2.17.2 // indirect
github.com/gookit/color v1.6.0 // indirect
github.com/gookit/color v1.6.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.23 // indirect
github.com/mattn/go-runewidth v0.0.24 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
93 changes: 26 additions & 67 deletions go.sum

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions internal/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ func login(_ context.Context, _ *cli.Command) error {
return err
}

_, err = fetchWithFeedback("Checking logging in...", gateway.Login, displayLoginResult)
_, err = fetchWithFeedback(
"Logging in...",
func() (*tmhi.StatusResult, error) {
return nil, gateway.Login()
},
nil,
"Successfully logged in",
)

return err
}
Expand All @@ -164,7 +171,7 @@ func req(_ context.Context, cmd *cli.Command) error {
loginFirst := cmd.Bool("login")

if loginFirst {
if _, err := gateway.Login(); err != nil {
if err := gateway.Login(); err != nil {
return fmt.Errorf("request failed: %w", err)
}
}
Expand Down
7 changes: 2 additions & 5 deletions internal/cmd_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ type mockGateway struct {
signalErr error
}

func (m *mockGateway) Login() (*tmhi.LoginResult, error) {
func (m *mockGateway) Login() error {
m.loginCalled = true
if m.loginErr != nil {
return nil, m.loginErr
}

return &tmhi.LoginResult{Success: true}, nil
return m.loginErr
}

func (m *mockGateway) Reboot() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLoginIntegration_FullFlow(t *testing.T) {

err := login(context.Background(), nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "Checking logging in...")
assert.Contains(t, err.Error(), "Logging in...")
assert.True(t, mg.loginCalled, "login should still be attempted")
})
}
Expand Down
6 changes: 0 additions & 6 deletions internal/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
"github.com/pterm/pterm"
)

func displayLoginResult(result *tmhi.LoginResult) {
if result.Success {
pterm.Success.Println("Successfully logged in")
}
}

func displayStatusResult(result *tmhi.StatusResult) {
switch {
case result.WebInterfaceUp:
Expand Down
18 changes: 0 additions & 18 deletions internal/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDisplayLoginResult(t *testing.T) {
pterm.DisableStyling()

defer pterm.EnableStyling()

t.Run("success", func(t *testing.T) {
result := &tmhi.LoginResult{Success: true}

assert.NotPanics(t, func() { displayLoginResult(result) })
})

t.Run("failure", func(t *testing.T) {
result := &tmhi.LoginResult{Success: false}

assert.NotPanics(t, func() { displayLoginResult(result) })
})
}

func TestDisplayStatusResult(t *testing.T) {
pterm.DisableStyling()

Expand Down
8 changes: 4 additions & 4 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ golangci-lint = "2.12.2"
goreleaser = "2.16.0"
gotestsum = "1.13.0"
cocogitto = "7.0.0"
hk = "1.45.0"
rumdl = "0.1.91"
zizmor = "1.24.1"
hk = "1.46.0"
rumdl = "0.2.4"
zizmor = "1.25.2"
dprint = "0.54.0"
ghalint = "1.5.6"
gitleaks = "8.30.1"
actionlint = "1.7.12"
"npm:jscpd" = "4.2.3"
"npm:jscpd" = "4.2.4"
"go:golang.org/x/tools/cmd/deadcode" = "0.45.0"

[env]
Expand Down
Loading