Browse Source

cli: use cobra's new ExactArgs() feature

pull/1780/head
Zach Ramsay 7 years ago
parent
commit
f013ee5cf9
3 changed files with 16 additions and 20 deletions
  1. +11
    -16
      cmd/abci-cli/abci-cli.go
  2. +4
    -4
      glide.lock
  3. +1
    -0
      glide.yaml

+ 11
- 16
cmd/abci-cli/abci-cli.go View File

@ -144,6 +144,7 @@ var batchCmd = &cobra.Command{
Use: "batch",
Short: "Run a batch of abci commands against an application",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdBatch(cmd, args)
},
@ -153,6 +154,7 @@ var consoleCmd = &cobra.Command{
Use: "console",
Short: "Start an interactive abci console for multiple commands",
Long: "",
Args: cobra.ExactArgs(0),
ValidArgs: []string{"batch", "echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"},
RunE: func(cmd *cobra.Command, args []string) error {
return cmdConsole(cmd, args)
@ -163,6 +165,7 @@ var echoCmd = &cobra.Command{
Use: "echo",
Short: "Have the application echo a message",
Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdEcho(cmd, args)
},
@ -171,6 +174,7 @@ var infoCmd = &cobra.Command{
Use: "info",
Short: "Get some info about the application",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdInfo(cmd, args)
},
@ -179,6 +183,7 @@ var setOptionCmd = &cobra.Command{
Use: "set_option",
Short: "Set an option on the application",
Long: "",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdSetOption(cmd, args)
},
@ -188,6 +193,7 @@ var deliverTxCmd = &cobra.Command{
Use: "deliver_tx",
Short: "Deliver a new transaction to the application",
Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdDeliverTx(cmd, args)
},
@ -197,6 +203,7 @@ var checkTxCmd = &cobra.Command{
Use: "check_tx",
Short: "Validate a transaction",
Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdCheckTx(cmd, args)
},
@ -206,6 +213,7 @@ var commitCmd = &cobra.Command{
Use: "commit",
Short: "Commit the application state and return the Merkle root hash",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdCommit(cmd, args)
},
@ -215,6 +223,7 @@ var queryCmd = &cobra.Command{
Use: "query",
Short: "Query the application state",
Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdQuery(cmd, args)
},
@ -224,6 +233,7 @@ var counterCmd = &cobra.Command{
Use: "counter",
Short: "ABCI demo example",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdCounter(cmd, args)
},
@ -233,6 +243,7 @@ var dummyCmd = &cobra.Command{
Use: "dummy",
Short: "ABCI demo example",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdDummy(cmd, args)
},
@ -302,9 +313,6 @@ func cmdConsole(cmd *cobra.Command, args []string) error {
// Have the application echo a message
func cmdEcho(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("Command echo takes only 1 argument")
}
resEcho := client.EchoSync(args[0])
printResponse(cmd, args, response{
Data: resEcho.Data,
@ -330,9 +338,6 @@ func cmdInfo(cmd *cobra.Command, args []string) error {
// Set an option on the application
func cmdSetOption(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return errors.New("Command set_option takes exactly 2 arguments (key, value)")
}
resSetOption := client.SetOptionSync(args[0], args[1])
printResponse(cmd, args, response{
Log: resSetOption.Log,
@ -342,9 +347,6 @@ func cmdSetOption(cmd *cobra.Command, args []string) error {
// Append a new tx to application
func cmdDeliverTx(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("Command deliver_tx takes only 1 argument")
}
txBytes, err := stringOrHexToBytes(args[0])
if err != nil {
return err
@ -360,9 +362,6 @@ func cmdDeliverTx(cmd *cobra.Command, args []string) error {
// Validate a tx
func cmdCheckTx(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("Command check_tx takes only 1 argument")
}
txBytes, err := stringOrHexToBytes(args[0])
if err != nil {
return err
@ -389,10 +388,6 @@ func cmdCommit(cmd *cobra.Command, args []string) error {
// Query application state
func cmdQuery(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("Command query takes only 1 argument, the query bytes")
}
queryBytes, err := stringOrHexToBytes(args[0])
if err != nil {
return err


+ 4
- 4
glide.lock View File

@ -1,5 +1,5 @@
hash: 1530ad93695fa2861f1572e3e1eef1b6604beb548fd4832985f6c6350260c2b3
updated: 2017-10-18T14:27:16.428209213-04:00
hash: 3c8680f0a289567a29f737be5f1d5f242c7e2afd84bdd023dd74596b88508fc2
updated: 2017-10-26T08:45:51.300025559-04:00
imports:
- name: github.com/btcsuite/btcd
version: b8df516b4b267acf2de46be593a9d948d1d2c420
@ -39,7 +39,7 @@ imports:
- name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/spf13/cobra
version: 4cdb38c072b86bf795d2c81de50784d9fdd6eb77
version: 2df9a531813370438a4d79bfc33e21f58063ed87
- name: github.com/spf13/pflag
version: e57e3eeb33f795204c1ca35f56c44f83227c6e66
- name: github.com/syndtr/goleveldb
@ -69,7 +69,7 @@ imports:
subpackages:
- data
- name: github.com/tendermint/iavl
version: 721710e7aa59f61dbfbf558943a207ba3fe6b926
version: 595f3dcd5b6cd4a292e90757ae6d367fd7a6e653
- name: github.com/tendermint/tmlibs
version: 8e5266a9ef2527e68a1571f932db8228a331b556
subpackages:


+ 1
- 0
glide.yaml View File

@ -19,6 +19,7 @@ import:
- merkle
- process
- package: github.com/spf13/cobra
version: master
- package: golang.org/x/net
subpackages:
- context


Loading…
Cancel
Save