diff --git a/cmd/tendermint/commands/reset.go b/cmd/tendermint/commands/reset.go index dd022060b..86beb6a56 100644 --- a/cmd/tendermint/commands/reset.go +++ b/cmd/tendermint/commands/reset.go @@ -29,7 +29,7 @@ var ResetStateCmd = &cobra.Command{ Short: "Remove all the data and WAL", PreRun: deprecateSnakeCase, RunE: func(cmd *cobra.Command, args []string) (err error) { - config, err = ParseConfig() + config, err = ParseConfig(cmd) if err != nil { return err } @@ -54,7 +54,7 @@ var ResetPrivValidatorCmd = &cobra.Command{ // XXX: this is totally unsafe. // it's only suitable for testnets. func resetAllCmd(cmd *cobra.Command, args []string) (err error) { - config, err = ParseConfig() + config, err = ParseConfig(cmd) if err != nil { return err } @@ -71,7 +71,7 @@ func resetAllCmd(cmd *cobra.Command, args []string) (err error) { // XXX: this is totally unsafe. // it's only suitable for testnets. func resetPrivValidator(cmd *cobra.Command, args []string) (err error) { - config, err = ParseConfig() + config, err = ParseConfig(cmd) if err != nil { return err } diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 2478f95a5..46c9ac7c7 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -29,12 +29,25 @@ func registerFlagsRootCmd(cmd *cobra.Command) { // ParseConfig retrieves the default environment configuration, // sets up the Tendermint root and ensures that the root exists -func ParseConfig() (*cfg.Config, error) { +func ParseConfig(cmd *cobra.Command) (*cfg.Config, error) { conf := cfg.DefaultConfig() err := viper.Unmarshal(conf) if err != nil { return nil, err } + + var home string + if os.Getenv("TMHOME") != "" { + home = os.Getenv("TMHOME") + } else { + home, err = cmd.Flags().GetString(cli.HomeFlag) + if err != nil { + return nil, err + } + } + + conf.RootDir = home + conf.SetRoot(conf.RootDir) cfg.EnsureRoot(conf.RootDir) if err := conf.ValidateBasic(); err != nil { @@ -52,7 +65,7 @@ var RootCmd = &cobra.Command{ return nil } - config, err = ParseConfig() + config, err = ParseConfig(cmd) if err != nil { return err }