diff --git a/examples/basecoin/cmd/basecoin/main.go b/examples/basecoin/cmd/basecoin/main.go index 73d153924..2a96f76bd 100644 --- a/examples/basecoin/cmd/basecoin/main.go +++ b/examples/basecoin/cmd/basecoin/main.go @@ -3,11 +3,11 @@ package main import ( "os" + "github.com/spf13/cobra" "github.com/tendermint/tmlibs/cli" sdk "github.com/cosmos/cosmos-sdk" client "github.com/cosmos/cosmos-sdk/client/commands" - "github.com/cosmos/cosmos-sdk/server/commands" "github.com/cosmos/cosmos-sdk/modules/auth" "github.com/cosmos/cosmos-sdk/modules/base" "github.com/cosmos/cosmos-sdk/modules/coin" @@ -15,9 +15,16 @@ import ( "github.com/cosmos/cosmos-sdk/modules/ibc" "github.com/cosmos/cosmos-sdk/modules/nonce" "github.com/cosmos/cosmos-sdk/modules/roles" + "github.com/cosmos/cosmos-sdk/server/commands" "github.com/cosmos/cosmos-sdk/stack" ) +// RootCmd is the entry point for this binary +var RootCmd = &cobra.Command{ + Use: "basecoin", + Short: "A cryptocurrency framework in Golang based on Tendermint-Core", +} + // BuildApp constructs the stack we want to use for this app func BuildApp(feeDenom string) sdk.Handler { return stack.New( @@ -42,19 +49,18 @@ func BuildApp(feeDenom string) sdk.Handler { } func main() { - rt := commands.RootCmd - // require all fees in mycoin - change this in your app! commands.Handler = BuildApp("mycoin") - rt.AddCommand( + RootCmd.AddCommand( commands.InitCmd, commands.StartCmd, //commands.RelayCmd, commands.UnsafeResetAllCmd, client.VersionCmd, ) + commands.SetUpRoot(RootCmd) - cmd := cli.PrepareMainCmd(rt, "BC", os.ExpandEnv("$HOME/.basecoin")) + cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin")) cmd.Execute() } diff --git a/examples/counter/cmd/counter/main.go b/examples/counter/cmd/counter/main.go index 48b9f75f3..b747e3be0 100644 --- a/examples/counter/cmd/counter/main.go +++ b/examples/counter/cmd/counter/main.go @@ -8,15 +8,17 @@ import ( "github.com/tendermint/tmlibs/cli" client "github.com/cosmos/cosmos-sdk/client/commands" - "github.com/cosmos/cosmos-sdk/server/commands" "github.com/cosmos/cosmos-sdk/examples/counter/plugins/counter" + "github.com/cosmos/cosmos-sdk/server/commands" ) +// RootCmd is the entry point for this binary +var RootCmd = &cobra.Command{ + Use: "counter", + Short: "demo application for cosmos sdk", +} + func main() { - var RootCmd = &cobra.Command{ - Use: "counter", - Short: "demo plugin for basecoin", - } // TODO: register the counter here commands.Handler = counter.NewHandler("mycoin") @@ -27,6 +29,7 @@ func main() { commands.UnsafeResetAllCmd, client.VersionCmd, ) + commands.SetUpRoot(RootCmd) cmd := cli.PrepareMainCmd(RootCmd, "CT", os.ExpandEnv("$HOME/.counter")) cmd.Execute() diff --git a/examples/eyes/cmd/eyes/main.go b/examples/eyes/cmd/eyes/main.go index 29655479a..ed9b406ef 100644 --- a/examples/eyes/cmd/eyes/main.go +++ b/examples/eyes/cmd/eyes/main.go @@ -3,16 +3,24 @@ package main import ( "os" + "github.com/spf13/cobra" "github.com/tendermint/tmlibs/cli" sdk "github.com/cosmos/cosmos-sdk" client "github.com/cosmos/cosmos-sdk/client/commands" - "github.com/cosmos/cosmos-sdk/server/commands" "github.com/cosmos/cosmos-sdk/modules/base" "github.com/cosmos/cosmos-sdk/modules/eyes" + "github.com/cosmos/cosmos-sdk/server/commands" "github.com/cosmos/cosmos-sdk/stack" ) +// RootCmd is the entry point for this binary +var RootCmd = &cobra.Command{ + Use: "eyes", + Short: "key-value store", + Long: "A demo app to show key-value store with proofs over abci", +} + // BuildApp constructs the stack we want to use for this app func BuildApp() sdk.Handler { return stack.New( @@ -26,20 +34,17 @@ func BuildApp() sdk.Handler { } func main() { - rt := commands.RootCmd - rt.Short = "eyes" - rt.Long = "A demo app to show key-value store with proofs over abci" - commands.Handler = BuildApp() - rt.AddCommand( + RootCmd.AddCommand( // out own init command to not require argument InitCmd, commands.StartCmd, commands.UnsafeResetAllCmd, client.VersionCmd, ) + commands.SetUpRoot(RootCmd) - cmd := cli.PrepareMainCmd(rt, "EYE", os.ExpandEnv("$HOME/.eyes")) + cmd := cli.PrepareMainCmd(RootCmd, "EYE", os.ExpandEnv("$HOME/.eyes")) cmd.Execute() } diff --git a/server/commands/init.go b/server/commands/init.go index 85ca02886..bb8617d08 100644 --- a/server/commands/init.go +++ b/server/commands/init.go @@ -18,7 +18,7 @@ import ( // InitCmd - node initialization command var InitCmd = &cobra.Command{ Use: "init [address]", - Short: "Initialize a basecoin blockchain", + Short: "Initialize genesis files for a blockchain", RunE: initCmd, } diff --git a/server/commands/root.go b/server/commands/root.go index 5d76c83e5..7974d3532 100644 --- a/server/commands/root.go +++ b/server/commands/root.go @@ -21,23 +21,21 @@ var ( logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main") ) -// RootCmd - main node command -var RootCmd = &cobra.Command{ - Use: "basecoin", - Short: "A cryptocurrency framework in Golang based on Tendermint-Core", - PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { - level := viper.GetString(FlagLogLevel) - logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel) - if err != nil { - return err - } - if viper.GetBool(cli.TraceFlag) { - logger = log.NewTracingLogger(logger) - } - return nil - }, +// preRunSetup should be set as PersistentPreRunE on the root command to +// properly handle the logging and the tracer +func preRunSetup(cmd *cobra.Command, args []string) (err error) { + level := viper.GetString(FlagLogLevel) + logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel) + if err != nil { + return err + } + if viper.GetBool(cli.TraceFlag) { + logger = log.NewTracingLogger(logger) + } + return nil } -func init() { - RootCmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level") +func SetUpRoot(cmd *cobra.Command) { + cmd.PersistentPreRunE = preRunSetup + cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level") } diff --git a/server/commands/start.go b/server/commands/start.go index 5a94a60c7..92f50fdbb 100644 --- a/server/commands/start.go +++ b/server/commands/start.go @@ -9,8 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/abci/server" sdk "github.com/cosmos/cosmos-sdk" + "github.com/tendermint/abci/server" "github.com/tendermint/tmlibs/cli" cmn "github.com/tendermint/tmlibs/common" @@ -22,10 +22,10 @@ import ( "github.com/cosmos/cosmos-sdk/app" ) -// StartCmd - command to start running the basecoin node! +// StartCmd - command to start running the abci app (and tendermint)! var StartCmd = &cobra.Command{ Use: "start", - Short: "Start basecoin", + Short: "Start this full node", RunE: startCmd, } @@ -47,7 +47,7 @@ var ( func init() { flags := StartCmd.Flags() flags.String(FlagAddress, "tcp://0.0.0.0:46658", "Listen address") - flags.Bool(FlagWithoutTendermint, false, "Only run basecoin abci app, assume external tendermint process") + flags.Bool(FlagWithoutTendermint, false, "Only run abci app, assume external tendermint process") // add all standard 'tendermint node' flags tcmd.AddNodeFlags(StartCmd) }