diff --git a/examples/chub/client.go b/examples/chub/client.go index 6f709dda09..9f47a6e761 100644 --- a/examples/chub/client.go +++ b/examples/chub/client.go @@ -32,7 +32,6 @@ var ( Short: "Query ABCI state data", Long: `Query ABCI state data. Subcommands should be defined for each particular object to query.`, - Run: help, } postCmd = &cobra.Command{ @@ -40,15 +39,16 @@ Subcommands should be defined for each particular object to query.`, Short: "Create a new transaction and post it to the chain", Long: `Create a new transaction and post it to the chain. Subcommands should be defined for each particular transaction type.`, - Run: help, } ) -func clientCommand() *cobra.Command { +// ClientCommands returns a sub-tree of all basic client commands +// +// Call AddGetCommand and AddPostCommand to add custom txs and queries +func ClientCommands() *cobra.Command { cmd := &cobra.Command{ Use: "client", Short: "Interact with the chain via a light-client", - Run: help, } cmd.AddCommand( initClientCommand(), @@ -67,6 +67,16 @@ func clientCommand() *cobra.Command { return cmd } +// AddGetCommand adds one or more query subcommands +func AddGetCommand(cmds ...*cobra.Command) { + getCmd.AddCommand(cmds...) +} + +// AddPostCommand adds one or more subcommands to create transactions +func AddPostCommand(cmds ...*cobra.Command) { + postCmd.AddCommand(cmds...) +} + func initClientCommand() *cobra.Command { cmd := &cobra.Command{ Use: "init", diff --git a/examples/chub/key.go b/examples/chub/key.go index 29ff1ec2a3..f7b46d416e 100644 --- a/examples/chub/key.go +++ b/examples/chub/key.go @@ -24,11 +24,12 @@ var ( } ) -func keyCommand() *cobra.Command { +// KeyCommands registers a sub-tree of commands to interact with +// local private key storage. +func KeyCommands() *cobra.Command { cmd := &cobra.Command{ Use: "keys", Short: "Add or view local private keys", - Run: help, } cmd.AddCommand( addKeyCommand(), diff --git a/examples/chub/main.go b/examples/chub/main.go index 9f69968931..bcd826a279 100644 --- a/examples/chub/main.go +++ b/examples/chub/main.go @@ -11,23 +11,42 @@ import ( "github.com/cosmos/cosmos-sdk/app" ) +const ( + flagTo = "to" + flagAmount = "amount" + flagFee = "fee" +) + // 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) {}} + + getAccountCmd = &cobra.Command{ + Use: "account
", + Short: "Query account balance", + RunE: todoNotImplemented, + } ) func todoNotImplemented(_ *cobra.Command, _ []string) error { return errors.New("TODO: Command not yet implemented") } -func help(cmd *cobra.Command, args []string) { - cmd.Help() +func postSendCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "send", + Short: "Create and sign a send tx", + RunE: todoNotImplemented, + } + cmd.Flags().String(flagTo, "", "Address to send coins") + cmd.Flags().String(flagAmount, "", "Amount of coins to send") + cmd.Flags().String(flagFee, "", "Fee to pay along with transaction") + return cmd } func main() { @@ -38,15 +57,16 @@ func main() { var node app.App // add commands - // prepareClientCommands() + AddGetCommand(getAccountCmd) + AddPostCommand(postSendCommand()) chubCmd.AddCommand( - nodeCommand(node), - keyCommand(), - clientCommand(), + NodeCommands(node), + KeyCommands(), + ClientCommands(), lineBreak, - versionCmd, + VersionCmd, ) // prepare and add flags diff --git a/examples/chub/node.go b/examples/chub/node.go index be20b64a27..e0c865cfec 100644 --- a/examples/chub/node.go +++ b/examples/chub/node.go @@ -6,6 +6,10 @@ import ( "github.com/cosmos/cosmos-sdk/app" ) +const ( + flagWithTendermint = "with-tendermint" +) + var ( initNodeCmd = &cobra.Command{ Use: "init ", @@ -20,20 +24,14 @@ var ( } ) -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 { +// NodeCommands registers a sub-tree of commands to interact with +// a local full-node. +// +// Accept an application it should start +func NodeCommands(node app.App) *cobra.Command { cmd := &cobra.Command{ Use: "node", Short: "Run the full node", - Run: help, } cmd.AddCommand( initNodeCmd, @@ -42,3 +40,13 @@ func nodeCommand(node app.App) *cobra.Command { ) return cmd } + +func startNodeCmd(node app.App) *cobra.Command { + cmd := &cobra.Command{ + Use: "start", + Short: "Run the full node", + RunE: todoNotImplemented, + } + cmd.Flags().Bool(flagWithTendermint, true, "run abci app embedded in-process with tendermint") + return cmd +} diff --git a/examples/chub/version.go b/examples/chub/version.go index 0c83c1bacd..59fd799c07 100644 --- a/examples/chub/version.go +++ b/examples/chub/version.go @@ -9,7 +9,8 @@ import ( ) var ( - versionCmd = &cobra.Command{ + // VersionCmd prints out the current sdk version + VersionCmd = &cobra.Command{ Use: "version", Short: "Print the app version", Run: doVersionCmd,