diff --git a/cmd/tendermint/commands/replay.go b/cmd/tendermint/commands/replay.go index 227931152..0c88b2443 100644 --- a/cmd/tendermint/commands/replay.go +++ b/cmd/tendermint/commands/replay.go @@ -10,7 +10,7 @@ var replayCmd = &cobra.Command{ Use: "replay", Short: "Replay messages from WAL", Run: func(cmd *cobra.Command, args []string) { - consensus.RunReplayFile(&config.Config, config.Consensus, false) + consensus.RunReplayFile(config.BaseConfig, config.Consensus, false) }, } @@ -18,7 +18,7 @@ var replayConsoleCmd = &cobra.Command{ Use: "replay_console", Short: "Replay messages from WAL in a console", Run: func(cmd *cobra.Command, args []string) { - consensus.RunReplayFile(&config.Config, config.Consensus, true) + consensus.RunReplayFile(config.BaseConfig, config.Consensus, true) }, } diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 1f69a2158..63ee0db5c 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -4,38 +4,26 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - cfg "github.com/tendermint/tendermint/config/tendermint" - "github.com/tendermint/tendermint/node" + cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tmlibs/logger" ) var ( - viperConfig *viper.Viper - config *node.Config - log = logger.New("module", "main") + config *cfg.Config + log = logger.New("module", "main") ) func init() { - viperConfig = cfg.GetConfig("") -} - -// unmarshal viper into the Tendermint config -func getConfig() *node.Config { - return node.ConfigFromViper(viperConfig) + config = cfg.DefaultConfig("REMOVE-ROOT") + RootCmd.PersistentFlags().String("log_level", config.LogLevel, "Log level") } var RootCmd = &cobra.Command{ Use: "tendermint", Short: "Tendermint Core (BFT Consensus) in Go", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - // set the log level - config = getConfig() + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + err := viper.Unmarshal(config) logger.SetLogLevel(config.LogLevel) + return err }, } - -func init() { - //parse flag and set config - RootCmd.PersistentFlags().String("log_level", viperConfig.GetString("log_level"), "Log level") - viperConfig.BindPFlag("log_level", RootCmd.PersistentFlags().Lookup("log_level")) -} diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 58cdd3cf2..d8c268c26 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -18,38 +18,28 @@ var runNodeCmd = &cobra.Command{ RunE: runNode, } -func registerRunNodeFlagString(flagName, desc string) { - runNodeCmd.Flags().String(flagName, viperConfig.GetString(flagName), desc) - viperConfig.BindPFlag(flagName, runNodeCmd.Flags().Lookup(flagName)) -} - -func registerRunNodeFlagBool(flagName, desc string) { - runNodeCmd.Flags().Bool(flagName, viperConfig.GetBool(flagName), desc) - viperConfig.BindPFlag(flagName, runNodeCmd.Flags().Lookup(flagName)) -} - func init() { // bind flags + runNodeCmd.Flags().String("moniker", config.Moniker, "Node Name") // node flags - registerRunNodeFlagString("moniker", "Node Name") - registerRunNodeFlagBool("fast_sync", "Fast blockchain syncing") + runNodeCmd.Flags().Bool("fast_sync", config.FastSync, "Fast blockchain syncing") // abci flags - registerRunNodeFlagString("proxy_app", "Proxy app address, or 'nilapp' or 'dummy' for local testing.") - registerRunNodeFlagString("abci", "Specify abci transport (socket | grpc)") + runNodeCmd.Flags().String("proxy_app", config.ProxyApp, "Proxy app address, or 'nilapp' or 'dummy' for local testing.") + runNodeCmd.Flags().String("abci", config.ABCI, "Specify abci transport (socket | grpc)") // rpc flags - registerRunNodeFlagString("rpc_laddr", "RPC listen address. Port required") - registerRunNodeFlagString("grpc_laddr", "GRPC listen address (BroadcastTx only). Port required") + runNodeCmd.Flags().String("rpc_laddr", config.RPCListenAddress, "RPC listen address. Port required") + runNodeCmd.Flags().String("grpc_laddr", config.GRPCListenAddress, "GRPC listen address (BroadcastTx only). Port required") // p2p flags - registerRunNodeFlagString("p2p.laddr", "Node listen address. (0.0.0.0:0 means any interface, any port)") - registerRunNodeFlagString("p2p.seeds", "Comma delimited host:port seed nodes") - registerRunNodeFlagBool("p2p.skip_upnp", "Skip UPNP configuration") + runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)") + runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes") + runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration") // feature flags - registerRunNodeFlagBool("p2p.pex", "Enable Peer-Exchange (dev feature)") + runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)") RootCmd.AddCommand(runNodeCmd) } diff --git a/cmd/tendermint/main.go b/cmd/tendermint/main.go index cddae985b..5493e4f2f 100644 --- a/cmd/tendermint/main.go +++ b/cmd/tendermint/main.go @@ -1,15 +1,13 @@ package main import ( - "fmt" "os" "github.com/tendermint/tendermint/cmd/tendermint/commands" + "github.com/tendermint/tmlibs/cli" ) func main() { - if err := commands.RootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } + cmd := cli.PrepareBaseCmd(commands.RootCmd, "TM", os.ExpandEnv("$HOME/.tendermint")) + cmd.Execute() } diff --git a/consensus/replay_file.go b/consensus/replay_file.go index 2db228c91..e7d904bff 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -20,7 +20,7 @@ import ( //-------------------------------------------------------- // replay messages interactively or all at once -func RunReplayFile(config *cfg.Config, csConfig *cfg.ConsensusConfig, console bool) { +func RunReplayFile(config *cfg.BaseConfig, csConfig *cfg.ConsensusConfig, console bool) { consensusState := newConsensusStateForReplay(config, csConfig) if err := consensusState.ReplayFile(csConfig.WalFile, console); err != nil { @@ -235,7 +235,7 @@ func (pb *playback) replayConsoleLoop() int { //-------------------------------------------------------------------------------- // convenience for replay mode -func newConsensusStateForReplay(config *cfg.Config, csConfig *cfg.ConsensusConfig) *ConsensusState { +func newConsensusStateForReplay(config *cfg.BaseConfig, csConfig *cfg.ConsensusConfig) *ConsensusState { // Get BlockStore blockStoreDB := dbm.NewDB("blockstore", config.DBBackend, config.DBDir) blockStore := bc.NewBlockStore(blockStoreDB)