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
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module github.com/hugoh/tmhi-cli

go 1.25.0
go 1.26.0

require (
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/hugoh/cellular-signal v1.1.3
github.com/hugoh/tmhi-gateway v1.2.0
github.com/hugoh/tmhi-gateway v1.3.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.9.0
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04
golang.org/x/term v0.43.0
golang.org/x/term v0.44.0
)

require (
Expand All @@ -33,8 +33,8 @@ require (
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // 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
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ github.com/gookit/color v1.6.1 h1:KoTnDxJPRgrL0SoX0f8rCFg2zI0t4E3GZZBMo2nN8LU=
github.com/gookit/color v1.6.1/go.mod h1:9ACFc7/1IpHGBW8RwuDm/0YEnhg3dwwXpoMsmtyHfjs=
github.com/hugoh/cellular-signal v1.1.3 h1:RBreCLAgY5zoeYbmUPVxMKVZVSuiirnrRHo6a6Dqgz4=
github.com/hugoh/cellular-signal v1.1.3/go.mod h1:UX0FKsxcPzK7YFM6Glu7LjZQA8m8TxXcRV64/N1rgZk=
github.com/hugoh/tmhi-gateway v1.2.0 h1:vsEi1mVIAYduYsuC3L/ZjKiZdiT8MARjXykl/haESh8=
github.com/hugoh/tmhi-gateway v1.2.0/go.mod h1:3UhUbdTePuQi/sX2T3ElzZOUEF98hXp/Dh0j71rGM6g=
github.com/hugoh/tmhi-gateway v1.3.0 h1:4t8xy29fpGpj/Q8fold63Bg0DlAIngV5Egkad+8+nVE=
github.com/hugoh/tmhi-gateway v1.3.0/go.mod h1:sGfaAFa6xlOVAmyinmWCSuP/zlIr6nZUju6rQjged5g=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down Expand Up @@ -93,20 +93,20 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
41 changes: 25 additions & 16 deletions internal/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ var initGatewayFunc = initGateway
//
//nolint:ireturn
func fetchWithFeedback[T any](
ctx context.Context,
message string,
fetch func() (T, error),
fetch func(context.Context) (T, error),
display func(T),
successMessage ...any,
) (T, error) {
Expand All @@ -105,7 +106,7 @@ func fetchWithFeedback[T any](
return *new(T), err
}

result, opErr := fetch()
result, opErr := fetch(ctx)
if opErr != nil {
spinnerInstance.Fail(fmt.Sprintf("%s: %v", message, opErr))

Expand Down Expand Up @@ -137,16 +138,17 @@ func initGateway(_ *Config) (tmhi.Gateway, error) {
return gateway, nil
}

func login(_ context.Context, _ *cli.Command) error {
func login(ctx context.Context, _ *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
}

_, err = fetchWithFeedback(
ctx,
"Logging in...",
func() (*tmhi.StatusResult, error) {
return nil, gateway.Login()
func(ctx context.Context) (*tmhi.StatusResult, error) {
return nil, gateway.Login(ctx)
},
nil,
"Successfully logged in",
Expand All @@ -155,7 +157,7 @@ func login(_ context.Context, _ *cli.Command) error {
return err
}

func req(_ context.Context, cmd *cli.Command) error {
func req(ctx context.Context, cmd *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
Expand All @@ -171,12 +173,12 @@ func req(_ context.Context, cmd *cli.Command) error {
loginFirst := cmd.Bool("login")

if loginFirst {
if err := gateway.Login(); err != nil {
if err := gateway.Login(ctx); err != nil {
return fmt.Errorf("request failed: %w", err)
}
}

result, err := gateway.Request(method, path)
result, err := gateway.Request(ctx, method, path)
if err != nil {
return fmt.Errorf("request failed: %w", err)
}
Expand All @@ -186,35 +188,41 @@ func req(_ context.Context, cmd *cli.Command) error {
return nil
}

func info(_ context.Context, _ *cli.Command) error {
func info(ctx context.Context, _ *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
}

_, err = fetchWithFeedback("Fetching gateway info...", gateway.Info, displayInfoResult)
_, err = fetchWithFeedback(ctx, "Fetching gateway info...", gateway.Info, displayInfoResult)

return err
}

func status(_ context.Context, _ *cli.Command) error {
func status(ctx context.Context, _ *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
}

_, err = fetchWithFeedback("Checking gateway status...", gateway.Status, displayStatusResult)
_, err = fetchWithFeedback(
ctx,
"Checking gateway status...",
gateway.Status,
displayStatusResult,
)

return err
}

func signalCmd(_ context.Context, _ *cli.Command) error {
func signalCmd(ctx context.Context, _ *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
}

_, err = fetchWithFeedback(
ctx,
"Fetching signal information...",
gateway.Signal,
displaySignalResult,
Expand All @@ -223,7 +231,7 @@ func signalCmd(_ context.Context, _ *cli.Command) error {
return err
}

func reboot(_ context.Context, cmd *cli.Command) error {
func reboot(ctx context.Context, cmd *cli.Command) error {
gateway, err := initGatewayFunc(appConfig)
if err != nil {
return err
Expand Down Expand Up @@ -252,9 +260,10 @@ func reboot(_ context.Context, cmd *cli.Command) error {
}

_, ret := fetchWithFeedback(
ctx,
"Rebooting gateway...",
func() (*tmhi.SignalResult, error) {
rebootErr := gateway.Reboot()
func(ctx context.Context) (*tmhi.SignalResult, error) {
rebootErr := gateway.Reboot(ctx)
if rebootErr != nil {
return nil, fmt.Errorf("Reboot failed: %w", rebootErr)
}
Expand Down
Loading
Loading