Skip to content

Commit

Permalink
Cleaned up root command to be less basecoin-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Sep 4, 2017
1 parent ec68439 commit 2887d0d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
16 changes: 11 additions & 5 deletions examples/basecoin/cmd/basecoin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ 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"
"github.com/cosmos/cosmos-sdk/modules/fee"
"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(
Expand All @@ -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()
}
13 changes: 8 additions & 5 deletions examples/counter/cmd/counter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -27,6 +29,7 @@ func main() {
commands.UnsafeResetAllCmd,
client.VersionCmd,
)
commands.SetUpRoot(RootCmd)

cmd := cli.PrepareMainCmd(RootCmd, "CT", os.ExpandEnv("$HOME/.counter"))
cmd.Execute()
Expand Down
19 changes: 12 additions & 7 deletions examples/eyes/cmd/eyes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion server/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
32 changes: 15 additions & 17 deletions server/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
8 changes: 4 additions & 4 deletions server/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
}

Expand All @@ -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)
}
Expand Down

0 comments on commit 2887d0d

Please sign in to comment.