cmd/abci-cli: implement batch

Can now run batch which can be tested by:
```shell
echo -e "echo foo\necho blue" | abci-cli batch
```

giving
```shell
I[12-12|07:55:55.513] Starting socketClient
module=abci-client impl=socketClient
-> code: OK
-> data: foo
-> data.hex: 0x666F6F

-> code: OK
-> data: blue
-> data.hex: 0x626C7565

```
This commit is contained in:
Emmanuel Odeke
2017-12-12 00:55:07 -07:00
parent cabc516726
commit 5ea42475ce

View File

@ -359,14 +359,11 @@ func cmdBatch(cmd *cobra.Command, args []string) error {
return err return err
} }
if len(line) > 0 { // prevents introduction of extra space leading to argument parse errors cmdArgs := persistentArgs(line)
args = strings.Split(string(line), " ") if err := muxOnCommands(cmd, cmdArgs); err != nil {
}
if err := muxOnCommands(cmd, args); err != nil {
return err return err
} }
fmt.Println("") fmt.Println()
} }
return nil return nil
} }
@ -397,22 +394,14 @@ var (
) )
func muxOnCommands(cmd *cobra.Command, pArgs []string) error { func muxOnCommands(cmd *cobra.Command, pArgs []string) error {
if len(pArgs) < 2 {
if len(pArgs) < 1 && cmd.Use != "batch" {
return errBadPersistentArgs return errBadPersistentArgs
} }
subCommand, actualArgs := pArgs[1], pArgs[2:]
subCommand, actualArgs := pArgs[0], pArgs[1:]
//if cmd.Use == "batch" {
// cmd.Use = subCommand
//}
switch strings.ToLower(subCommand) { switch strings.ToLower(subCommand) {
case "batch": case "batch":
fmt.Println("WTF") return muxOnCommands(cmd, actualArgs)
return nil
case "check_tx": case "check_tx":
return cmdCheckTx(cmd, actualArgs) return cmdCheckTx(cmd, actualArgs)
case "commit": case "commit":
@ -438,6 +427,9 @@ func cmdUnimplemented(cmd *cobra.Command, args []string) error {
if err := cmd.Help(); err != nil { if err := cmd.Help(); err != nil {
msg = err.Error() msg = err.Error()
} }
if len(args) > 0 {
msg += fmt.Sprintf(" args: [%s]", strings.Join(args, " "))
}
printResponse(cmd, args, response{ printResponse(cmd, args, response{
Code: codeBad, Code: codeBad,
Log: msg, Log: msg,