Start with demo chub command

Add version and node subcommand as TODOs
This commit is contained in:
Ethan Frey
2018-02-13 08:39:42 -05:00
committed by Ethan Buchman
parent 809102c952
commit 90a102cf3e
4 changed files with 116 additions and 0 deletions
+57
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
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
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,
}
)