Cleaned up client commands more

This commit is contained in:
Ethan Frey 2018-02-07 17:48:21 +01:00 committed by Ethan Buchman
parent c7f31bdf26
commit 91592a91f1
2 changed files with 23 additions and 36 deletions

View File

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

View File

@ -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,
)