Skip to content

Commit 764fc78

Browse files
chore: add GetBusFromCmd() CLI helper
1 parent b6cf8bc commit 764fc78

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/client/cli/helpers/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ var (
2525

2626
// fetchPeerstore retrieves the providers from the CLI context and uses them to retrieve the address book for the current height
2727
func FetchPeerstore(cmd *cobra.Command) (types.Peerstore, error) {
28-
bus, ok := GetValueFromCLIContext[modules.Bus](cmd, BusCLICtxKey)
29-
if !ok || bus == nil {
30-
return nil, errors.New("retrieving bus from CLI context")
28+
bus, err := GetBusFromCmd(cmd)
29+
if err != nil {
30+
return nil, err
3131
}
3232
// TECHDEBT(#810, #811): use `bus.GetPeerstoreProvider()` after peerstore provider
3333
// is retrievable as a proper submodule

app/client/cli/helpers/context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package helpers
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/spf13/cobra"
8+
9+
"github.com/pokt-network/pocket/shared/modules"
710
)
811

912
const BusCLICtxKey cliContextKey = "bus"
1013

14+
var ErrCxtFromBus = fmt.Errorf("could not get context from bus")
15+
1116
// NOTE: this is required by the linter, otherwise a simple string constant would have been enough
1217
type cliContextKey string
1318

@@ -19,3 +24,12 @@ func GetValueFromCLIContext[T any](cmd *cobra.Command, key cliContextKey) (T, bo
1924
value, ok := cmd.Context().Value(key).(T)
2025
return value, ok
2126
}
27+
28+
func GetBusFromCmd(cmd *cobra.Command) (modules.Bus, error) {
29+
bus, ok := GetValueFromCLIContext[modules.Bus](cmd, BusCLICtxKey)
30+
if !ok {
31+
return nil, ErrCxtFromBus
32+
}
33+
34+
return bus, nil
35+
}

0 commit comments

Comments
 (0)