Skip to content

Commit

Permalink
Fix for the --home flag (#852)
Browse files Browse the repository at this point in the history
* Adds the necessary setup to the gaia viper root to handle the home flag and config.toml file correctly

* Add an environment variable prefix.
  • Loading branch information
zmanian authored and shahankhatch committed May 11, 2021
1 parent eb5bb34 commit 4e97411
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/gaiad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
config "github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
Expand All @@ -22,14 +23,13 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
gaia "github.com/cosmos/gaia/v4/app"
"github.com/cosmos/gaia/v4/app/params"
"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

gaia "github.com/cosmos/gaia/v4/app"
"github.com/cosmos/gaia/v4/app/params"
)

// NewRootCmd creates a new root command for simd. It is called once in the
Expand All @@ -44,12 +44,24 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(gaia.DefaultNodeHome)
WithHomeDir(gaia.DefaultNodeHome).
WithViper("GAIA")

rootCmd := &cobra.Command{
Use: "gaiad",
Short: "Stargate Cosmos Hub App",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())

initClientCtx = client.ReadHomeFlag(initClientCtx, cmd)

initClientCtx, err := config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}

if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
Expand Down

0 comments on commit 4e97411

Please sign in to comment.