From 97b1a6572d253586a3903a8f556073f4a0ac41c8 Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Mon, 10 May 2021 19:17:25 -0700 Subject: [PATCH 1/2] Adds the necessary setup to the gaia viper root to handle the home flag and config.toml file correctly --- cmd/gaiad/cmd/root.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/gaiad/cmd/root.go b/cmd/gaiad/cmd/root.go index 05d5d32a6b1..26254d35e89 100644 --- a/cmd/gaiad/cmd/root.go +++ b/cmd/gaiad/cmd/root.go @@ -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" @@ -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 @@ -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("") // In simapp, we don't use any prefix for env variables. 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 } From b6a6a189649c7be51a35f8de648822727bb3882e Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Mon, 10 May 2021 19:23:40 -0700 Subject: [PATCH 2/2] Add an environment variable prefix. --- cmd/gaiad/cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaiad/cmd/root.go b/cmd/gaiad/cmd/root.go index 26254d35e89..cbaddca2d79 100644 --- a/cmd/gaiad/cmd/root.go +++ b/cmd/gaiad/cmd/root.go @@ -45,7 +45,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { WithAccountRetriever(types.AccountRetriever{}). WithBroadcastMode(flags.BroadcastBlock). WithHomeDir(gaia.DefaultNodeHome). - WithViper("") // In simapp, we don't use any prefix for env variables. + WithViper("GAIA") rootCmd := &cobra.Command{ Use: "gaiad",