From b10afcaf4cf90339e9afadd02d825a7c0e3dd06f Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 7 Feb 2018 17:33:28 +0100 Subject: [PATCH] Rough separation of gaiad and gaiacli --- Makefile | 5 +-- examples/{chub => gaiacli}/client.go | 0 examples/{chub => gaiacli}/key.go | 0 examples/{chub => gaiacli}/main.go | 6 ---- examples/{chub => gaiacli}/version.go | 0 examples/gaiad/main.go | 44 +++++++++++++++++++++++++++ examples/{chub => gaiad}/node.go | 11 ++----- examples/gaiad/version.go | 26 ++++++++++++++++ 8 files changed, 76 insertions(+), 16 deletions(-) rename examples/{chub => gaiacli}/client.go (100%) rename examples/{chub => gaiacli}/key.go (100%) rename examples/{chub => gaiacli}/main.go (91%) rename examples/{chub => gaiacli}/version.go (100%) create mode 100644 examples/gaiad/main.go rename examples/{chub => gaiad}/node.go (77%) create mode 100644 examples/gaiad/version.go diff --git a/Makefile b/Makefile index 7fc8f75402..9d7a4345a0 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,9 @@ ci: get_tools get_vendor_deps build test_cover ### Build # This can be unified later, here for easy demos -chub: - go install $(BUILD_FLAGS) ./examples/chub +gaia: + go build $(BUILD_FLAGS) -o build/gaid ./examples/gaiad + go build $(BUILD_FLAGS) -o build/gaiacli ./examples/gaiacli build: @rm -rf examples/basecoin/vendor/ diff --git a/examples/chub/client.go b/examples/gaiacli/client.go similarity index 100% rename from examples/chub/client.go rename to examples/gaiacli/client.go diff --git a/examples/chub/key.go b/examples/gaiacli/key.go similarity index 100% rename from examples/chub/key.go rename to examples/gaiacli/key.go diff --git a/examples/chub/main.go b/examples/gaiacli/main.go similarity index 91% rename from examples/chub/main.go rename to examples/gaiacli/main.go index a39274f408..a898b98cd0 100644 --- a/examples/chub/main.go +++ b/examples/gaiacli/main.go @@ -7,8 +7,6 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tmlibs/cli" - - "github.com/cosmos/cosmos-sdk/baseapp" ) const ( @@ -53,15 +51,11 @@ func main() { // disable sorting cobra.EnableCommandSorting = false - // TODO: set this to something real - var node baseapp.BaseApp - // add commands AddGetCommand(getAccountCmd) AddPostCommand(postSendCommand()) chubCmd.AddCommand( - NodeCommands(node), KeyCommands(), ClientCommands(), diff --git a/examples/chub/version.go b/examples/gaiacli/version.go similarity index 100% rename from examples/chub/version.go rename to examples/gaiacli/version.go diff --git a/examples/gaiad/main.go b/examples/gaiad/main.go new file mode 100644 index 0000000000..ca9bb20dba --- /dev/null +++ b/examples/gaiad/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "errors" + "os" + + "github.com/spf13/cobra" + + "github.com/tendermint/tmlibs/cli" + + "github.com/cosmos/cosmos-sdk/baseapp" +) + +const ( + flagTo = "to" + flagAmount = "amount" + flagFee = "fee" +) + +// gaiadCmd is the entry point for this binary +var ( + gaiadCmd = &cobra.Command{ + Use: "gaiad", + Short: "Gaia Daemon (server)", + } +) + +func todoNotImplemented(_ *cobra.Command, _ []string) error { + return errors.New("TODO: Command not yet implemented") +} + +func main() { + // TODO: set this to something real + var node baseapp.BaseApp + + AddNodeCommands(gaiadCmd, node) + gaiadCmd.AddCommand( + VersionCmd, + ) + + // prepare and add flags + executor := cli.PrepareBaseCmd(gaiadCmd, "GA", os.ExpandEnv("$HOME/.gaiad")) + executor.Execute() +} diff --git a/examples/chub/node.go b/examples/gaiad/node.go similarity index 77% rename from examples/chub/node.go rename to examples/gaiad/node.go index 1b73c82d6d..8d362a6a78 100644 --- a/examples/chub/node.go +++ b/examples/gaiad/node.go @@ -24,21 +24,16 @@ var ( } ) -// NodeCommands registers a sub-tree of commands to interact with -// a local full-node. +// AddNodeCommands registers all commands to interact +// with a local full-node as subcommands of the argument. // // Accept an application it should start -func NodeCommands(node baseapp.BaseApp) *cobra.Command { - cmd := &cobra.Command{ - Use: "node", - Short: "Run the full node", - } +func AddNodeCommands(cmd *cobra.Command, node baseapp.BaseApp) { cmd.AddCommand( initNodeCmd, startNodeCmd(node), resetNodeCmd, ) - return cmd } func startNodeCmd(node baseapp.BaseApp) *cobra.Command { diff --git a/examples/gaiad/version.go b/examples/gaiad/version.go new file mode 100644 index 0000000000..59fd799c07 --- /dev/null +++ b/examples/gaiad/version.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/version" +) + +var ( + // VersionCmd prints out the current sdk version + VersionCmd = &cobra.Command{ + Use: "version", + Short: "Print the app version", + Run: doVersionCmd, + } +) + +func doVersionCmd(cmd *cobra.Command, args []string) { + v := version.Version + if version.GitCommit != "" { + v = v + " " + version.GitCommit + } + fmt.Println(v) +}