Allow adding custom query/post commands to chub
This commit is contained in:
parent
27aa06bb73
commit
acf24f1c1b
|
@ -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",
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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 <address>",
|
||||
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
|
||||
|
|
|
@ -6,6 +6,10 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/app"
|
||||
)
|
||||
|
||||
const (
|
||||
flagWithTendermint = "with-tendermint"
|
||||
)
|
||||
|
||||
var (
|
||||
initNodeCmd = &cobra.Command{
|
||||
Use: "init <flags???>",
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue