Start with demo chub command

Add version and node subcommand as TODOs
This commit is contained in:
Ethan Frey 2018-01-18 12:19:41 +01:00 committed by Ethan Buchman
parent 809102c952
commit 90a102cf3e
4 changed files with 116 additions and 0 deletions

View File

@ -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/...

57
examples/chub/main.go Normal file
View File

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

44
examples/chub/node.go Normal file
View File

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

11
examples/chub/version.go Normal file
View File

@ -0,0 +1,11 @@
package main
import "github.com/spf13/cobra"
var (
versionCmd = &cobra.Command{
Use: "version",
Short: "Print the app version",
RunE: todoNotImplemented,
}
)