Cleaned up root command to be less basecoin-specific

This commit is contained in:
Ethan Frey 2017-09-04 16:37:52 +02:00
parent ec6843928e
commit 2887d0d288
6 changed files with 51 additions and 39 deletions

View File

@ -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()
}

View File

@ -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()

View File

@ -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()
}

View File

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

View File

@ -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")
}

View File

@ -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)
}