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", Use: "batch",
Short: "Run a batch of abci commands against an application", Short: "Run a batch of abci commands against an application",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdBatch(cmd, args) return cmdBatch(cmd, args)
}, },
@ -153,6 +154,7 @@ var consoleCmd = &cobra.Command{
Use: "console", Use: "console",
Short: "Start an interactive abci console for multiple commands", Short: "Start an interactive abci console for multiple commands",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
ValidArgs: []string{"batch", "echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"}, ValidArgs: []string{"batch", "echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"},
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdConsole(cmd, args) return cmdConsole(cmd, args)
@ -163,6 +165,7 @@ var echoCmd = &cobra.Command{
Use: "echo", Use: "echo",
Short: "Have the application echo a message", Short: "Have the application echo a message",
Long: "", Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdEcho(cmd, args) return cmdEcho(cmd, args)
}, },
@ -171,6 +174,7 @@ var infoCmd = &cobra.Command{
Use: "info", Use: "info",
Short: "Get some info about the application", Short: "Get some info about the application",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdInfo(cmd, args) return cmdInfo(cmd, args)
}, },
@ -179,6 +183,7 @@ var setOptionCmd = &cobra.Command{
Use: "set_option", Use: "set_option",
Short: "Set an option on the application", Short: "Set an option on the application",
Long: "", Long: "",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdSetOption(cmd, args) return cmdSetOption(cmd, args)
}, },
@ -188,6 +193,7 @@ var deliverTxCmd = &cobra.Command{
Use: "deliver_tx", Use: "deliver_tx",
Short: "Deliver a new transaction to the application", Short: "Deliver a new transaction to the application",
Long: "", Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdDeliverTx(cmd, args) return cmdDeliverTx(cmd, args)
}, },
@ -197,6 +203,7 @@ var checkTxCmd = &cobra.Command{
Use: "check_tx", Use: "check_tx",
Short: "Validate a transaction", Short: "Validate a transaction",
Long: "", Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdCheckTx(cmd, args) return cmdCheckTx(cmd, args)
}, },
@ -206,6 +213,7 @@ var commitCmd = &cobra.Command{
Use: "commit", Use: "commit",
Short: "Commit the application state and return the Merkle root hash", Short: "Commit the application state and return the Merkle root hash",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdCommit(cmd, args) return cmdCommit(cmd, args)
}, },
@ -215,6 +223,7 @@ var queryCmd = &cobra.Command{
Use: "query", Use: "query",
Short: "Query the application state", Short: "Query the application state",
Long: "", Long: "",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdQuery(cmd, args) return cmdQuery(cmd, args)
}, },
@ -224,6 +233,7 @@ var counterCmd = &cobra.Command{
Use: "counter", Use: "counter",
Short: "ABCI demo example", Short: "ABCI demo example",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdCounter(cmd, args) return cmdCounter(cmd, args)
}, },
@ -233,6 +243,7 @@ var dummyCmd = &cobra.Command{
Use: "dummy", Use: "dummy",
Short: "ABCI demo example", Short: "ABCI demo example",
Long: "", Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdDummy(cmd, args) return cmdDummy(cmd, args)
}, },
@ -302,9 +313,6 @@ func cmdConsole(cmd *cobra.Command, args []string) error {
// Have the application echo a message // Have the application echo a message
func cmdEcho(cmd *cobra.Command, args []string) error { 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]) resEcho := client.EchoSync(args[0])
printResponse(cmd, args, response{ printResponse(cmd, args, response{
Data: resEcho.Data, Data: resEcho.Data,
@ -330,9 +338,6 @@ func cmdInfo(cmd *cobra.Command, args []string) error {
// Set an option on the application // Set an option on the application
func cmdSetOption(cmd *cobra.Command, args []string) error { 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]) resSetOption := client.SetOptionSync(args[0], args[1])
printResponse(cmd, args, response{ printResponse(cmd, args, response{
Log: resSetOption.Log, Log: resSetOption.Log,
@ -342,9 +347,6 @@ func cmdSetOption(cmd *cobra.Command, args []string) error {
// Append a new tx to application // Append a new tx to application
func cmdDeliverTx(cmd *cobra.Command, args []string) error { 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]) txBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err return err
@ -360,9 +362,6 @@ func cmdDeliverTx(cmd *cobra.Command, args []string) error {
// Validate a tx // Validate a tx
func cmdCheckTx(cmd *cobra.Command, args []string) error { 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]) txBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err return err
@ -389,10 +388,6 @@ func cmdCommit(cmd *cobra.Command, args []string) error {
// Query application state // Query application state
func cmdQuery(cmd *cobra.Command, args []string) error { 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]) queryBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err 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: imports:
- name: github.com/btcsuite/btcd - name: github.com/btcsuite/btcd
version: b8df516b4b267acf2de46be593a9d948d1d2c420 version: b8df516b4b267acf2de46be593a9d948d1d2c420
@ -39,7 +39,7 @@ imports:
- name: github.com/pkg/errors - name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/spf13/cobra - name: github.com/spf13/cobra
version: 4cdb38c072b86bf795d2c81de50784d9fdd6eb77
version: 2df9a531813370438a4d79bfc33e21f58063ed87
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 version: e57e3eeb33f795204c1ca35f56c44f83227c6e66
- name: github.com/syndtr/goleveldb - name: github.com/syndtr/goleveldb
@ -69,7 +69,7 @@ imports:
subpackages: subpackages:
- data - data
- name: github.com/tendermint/iavl - name: github.com/tendermint/iavl
version: 721710e7aa59f61dbfbf558943a207ba3fe6b926
version: 595f3dcd5b6cd4a292e90757ae6d367fd7a6e653
- name: github.com/tendermint/tmlibs - name: github.com/tendermint/tmlibs
version: 8e5266a9ef2527e68a1571f932db8228a331b556 version: 8e5266a9ef2527e68a1571f932db8228a331b556
subpackages: subpackages:


+ 1
- 0
glide.yaml View File

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


Loading…
Cancel
Save