From 91592a91f187a0e3f738fbcbc40c42efd7ff928d Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 7 Feb 2018 17:48:21 +0100 Subject: [PATCH] Cleaned up client commands more --- examples/gaiacli/client.go | 44 +++++++++++--------------------------- examples/gaiacli/main.go | 15 ++++++++----- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/examples/gaiacli/client.go b/examples/gaiacli/client.go index 5daae467f..682a571e6 100644 --- a/examples/gaiacli/client.go +++ b/examples/gaiacli/client.go @@ -30,29 +30,8 @@ var ( Short: "Query remote node for status", RunE: todoNotImplemented, } - - getCmd = &cobra.Command{ - Use: "get", - Short: "Query ABCI state data", - Long: `Query ABCI state data. -Subcommands should be defined for each particular object to query.`, - } - - postCmd = &cobra.Command{ - Use: "post", - 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.`, - } ) -func init() { - getCmd.PersistentFlags().Bool(flagTrustNode, false, "Don't verify proofs for responses") - - postCmd.PersistentFlags().String(flagName, "", "Name of private key with which to sign") - postCmd.PersistentFlags().String(flagPassword, "", "Password to use the named private key") -} - // AddClientCommands returns a sub-tree of all basic client commands // // Call AddGetCommand and AddPostCommand to add custom txs and queries @@ -66,21 +45,24 @@ func AddClientCommands(cmd *cobra.Command) { txSearchCommand(), txCommand(), lineBreak, - getCmd, - postCmd, - lineBreak, - serveCommand(), ) } -// AddGetCommand adds one or more query subcommands -func AddGetCommand(cmds ...*cobra.Command) { - getCmd.AddCommand(cmds...) +// GetCommands adds common flags to query commands +func GetCommands(cmds ...*cobra.Command) []*cobra.Command { + for _, c := range cmds { + c.Flags().Bool(flagTrustNode, false, "Don't verify proofs for responses") + } + return cmds } -// AddPostCommand adds one or more subcommands to create transactions -func AddPostCommand(cmds ...*cobra.Command) { - postCmd.AddCommand(cmds...) +// PostCommands adds common flags for commands to post tx +func PostCommands(cmds ...*cobra.Command) []*cobra.Command { + for _, c := range cmds { + c.Flags().String(flagName, "", "Name of private key with which to sign") + c.Flags().String(flagPassword, "", "Password to use the named private key") + } + return cmds } func initClientCommand() *cobra.Command { diff --git a/examples/gaiacli/main.go b/examples/gaiacli/main.go index a6570d227..4957a26ce 100644 --- a/examples/gaiacli/main.go +++ b/examples/gaiacli/main.go @@ -51,14 +51,19 @@ func main() { // disable sorting cobra.EnableCommandSorting = false - // add commands - AddGetCommand(getAccountCmd) - AddPostCommand(postSendCommand()) - + // generic client commands AddClientCommands(gaiacliCmd) + // query commands (custom to binary) gaiacliCmd.AddCommand( + GetCommands(getAccountCmd)...) + // post tx commands (custom to binary) + gaiacliCmd.AddCommand( + PostCommands(postSendCommand())...) + // add proxy, version and key info + gaiacliCmd.AddCommand( + lineBreak, + serveCommand(), KeyCommands(), - lineBreak, VersionCmd, )