-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
73 lines (63 loc) · 1.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"os"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/version"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
hubtypes "github.com/sentinel-official/hub/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/sentinel-official/cli-client/cmd"
"github.com/sentinel-official/cli-client/types"
)
func main() {
hubtypes.GetConfig().Seal()
root := &cobra.Command{
Use: "sentinelcli",
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
home := viper.GetString(flags.FlagHome)
if _, err := os.Stat(home); err != nil {
if err := os.MkdirAll(home, 0700); err != nil {
return err
}
}
var (
config = types.DefaultEncodingConfig()
clientCtx = client.Context{}.
WithCodec(config.Codec).
WithInterfaceRegistry(config.InterfaceRegistry).
WithTxConfig(config.TxConfig).
WithLegacyAmino(config.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(types.DefaultHomeDirectory)
)
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}
return nil
},
}
root.AddCommand(
cmd.ConnectCmd(),
cmd.DisconnectCmd(),
cmd.QueryCommand(),
cmd.TxCommand(),
keys.Commands(types.DefaultHomeDirectory),
version.NewVersionCommand(),
)
root.PersistentFlags().String(flags.FlagHome, types.DefaultHomeDirectory, "application home directory")
_ = viper.BindPFlag(flags.FlagHome, root.PersistentFlags().Lookup(flags.FlagHome))
_ = root.ExecuteContext(
context.WithValue(
context.Background(),
client.ClientContextKey,
&client.Context{},
),
)
}