Skip to content

Commit 4000e34

Browse files
committed
move cmd out of grogu package
1 parent 4612530 commit 4000e34

File tree

5 files changed

+91
-98
lines changed

5 files changed

+91
-98
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

cmd/grogu/main.go

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,95 @@
1-
package main
1+
package grogu
22

3-
import "github.com/bandprotocol/chain/v2/grogu"
3+
import (
4+
"fmt"
5+
"os"
6+
"path"
7+
"path/filepath"
8+
9+
"github.com/cosmos/cosmos-sdk/client/flags"
10+
"github.com/cosmos/cosmos-sdk/crypto/keyring"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
12+
"github.com/cosmos/cosmos-sdk/version"
13+
"github.com/spf13/cobra"
14+
"github.com/spf13/viper"
15+
16+
band "github.com/bandprotocol/chain/v2/app"
17+
"github.com/bandprotocol/chain/v2/cmd/grogu/cmd"
18+
"github.com/bandprotocol/chain/v2/grogu/context"
19+
)
420

521
func main() {
6-
grogu.Main()
22+
appConfig := sdk.GetConfig()
23+
band.SetBech32AddressPrefixesAndBip44CoinTypeAndSeal(appConfig)
24+
25+
ctx := &context.Context{}
26+
rootCmd := createRootCmd(ctx)
27+
28+
if err := rootCmd.Execute(); err != nil {
29+
fmt.Println(err)
30+
os.Exit(1)
31+
}
32+
}
33+
34+
func createRootCmd(ctx *context.Context) *cobra.Command {
35+
rootCmd := &cobra.Command{
36+
Use: "grogu",
37+
Short: "BandChain daemon to submit signal prices for feeds module",
38+
}
39+
40+
rootCmd.AddCommand(
41+
cmd.ConfigCmd(),
42+
cmd.KeysCmd(ctx),
43+
cmd.RunCmd(ctx),
44+
version.NewVersionCommand(),
45+
)
46+
47+
rootCmd.PersistentPreRunE = createPersistentPreRunE(rootCmd, ctx)
48+
rootCmd.PersistentFlags().String(flags.FlagHome, getDefaultHome(), "home directory")
49+
return rootCmd
50+
}
51+
52+
func createPersistentPreRunE(rootCmd *cobra.Command, ctx *context.Context) func(
53+
cmd *cobra.Command,
54+
args []string,
55+
) error {
56+
return func(_ *cobra.Command, _ []string) error {
57+
home, err := rootCmd.PersistentFlags().GetString(flags.FlagHome)
58+
if err != nil {
59+
return err
60+
}
61+
ctx.Home = home
62+
63+
if err = os.MkdirAll(home, os.ModePerm); err != nil {
64+
return err
65+
}
66+
67+
cdc := band.MakeEncodingConfig().Marshaler
68+
ctx.Keyring, err = keyring.New("band", keyring.BackendTest, home, nil, cdc)
69+
if err != nil {
70+
return err
71+
}
72+
73+
return initConfig(ctx, rootCmd)
74+
}
75+
}
76+
77+
func initConfig(c *context.Context, _ *cobra.Command) error {
78+
viper.SetConfigFile(path.Join(c.Home, "config.yaml"))
79+
80+
// If the config file cannot be read, only cmd flags will be used.
81+
_ = viper.ReadInConfig()
82+
if err := viper.Unmarshal(&c.Config); err != nil {
83+
return err
84+
}
85+
return nil
86+
}
87+
88+
func getDefaultHome() string {
89+
userHomeDir, err := os.UserHomeDir()
90+
if err != nil {
91+
panic(err)
92+
}
93+
94+
return filepath.Join(userHomeDir, ".grogu")
795
}

grogu/main.go

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)