diff --git a/Makefile b/Makefile index 703a0803e..7fc8f7540 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ 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 + build: @rm -rf examples/basecoin/vendor/ go build $(BUILD_FLAGS) -o build/basecoin ./examples/basecoin/cmd/... diff --git a/examples/chub/main.go b/examples/chub/main.go new file mode 100644 index 000000000..761fe26f3 --- /dev/null +++ b/examples/chub/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "errors" + "os" + + "github.com/spf13/cobra" + + "github.com/tendermint/tmlibs/cli" + + "github.com/cosmos/cosmos-sdk/app" +) + +// chubCmd is the entry point for this binary +var ( + chubCmd = &cobra.Command{ + Use: "chub", + Short: "Cosmos Hub command-line tool", + Run: help, + } + + lineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}} +) + +func todoNotImplemented(_ *cobra.Command, _ []string) error { + return errors.New("TODO: Command not yet implemented") +} + +func help(cmd *cobra.Command, args []string) { + cmd.Help() +} + +func main() { + // disable sorting + cobra.EnableCommandSorting = false + + // TODO: set this to something real + var node app.App + + // add commands + // prepareRestServerCommands() + // prepareClientCommands() + + chubCmd.AddCommand( + nodeCommand(node), + // restServerCmd, + // clientCmd, + + lineBreak, + versionCmd, + ) + + // prepare and add flags + // executor := cli.PrepareMainCmd(chubCmd, "CH", os.ExpandEnv("$HOME/.cosmos-chub")) + executor := cli.PrepareBaseCmd(chubCmd, "CH", os.ExpandEnv("$HOME/.cosmos-chub")) + executor.Execute() +} diff --git a/examples/chub/node.go b/examples/chub/node.go new file mode 100644 index 000000000..3befdc3c8 --- /dev/null +++ b/examples/chub/node.go @@ -0,0 +1,44 @@ +package main + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/app" +) + +var ( + initNodeCmd = &cobra.Command{ + Use: "init", + Short: "Initialize full node", + RunE: todoNotImplemented, + } + + resetNodeCmd = &cobra.Command{ + Use: "unsafe_reset_all", + Short: "Reset full node data (danger, must resync)", + RunE: todoNotImplemented, + } +) + +func startNodeCmd(node app.App) *cobra.Command { + cmd := &cobra.Command{ + Use: "start", + Short: "Run the full node", + RunE: todoNotImplemented, + } + return cmd +} + +func nodeCommand(node app.App) *cobra.Command { + cmd := &cobra.Command{ + Use: "node", + Short: "Run the full node", + RunE: todoNotImplemented, + } + cmd.AddCommand( + initNodeCmd, + startNodeCmd(node), + resetNodeCmd, + ) + return cmd +} diff --git a/examples/chub/version.go b/examples/chub/version.go new file mode 100644 index 000000000..4afcddb99 --- /dev/null +++ b/examples/chub/version.go @@ -0,0 +1,11 @@ +package main + +import "github.com/spf13/cobra" + +var ( + versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the app version", + RunE: todoNotImplemented, + } +)