From 5ea42475ced24148e1d636de39450172f87dbb04 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Tue, 12 Dec 2017 00:55:07 -0700 Subject: [PATCH] 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 ``` --- cmd/abci-cli/abci-cli.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index b36948a3c..cce7addd7 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -359,14 +359,11 @@ func cmdBatch(cmd *cobra.Command, args []string) error { return err } - if len(line) > 0 { // prevents introduction of extra space leading to argument parse errors - args = strings.Split(string(line), " ") - } - - if err := muxOnCommands(cmd, args); err != nil { + cmdArgs := persistentArgs(line) + if err := muxOnCommands(cmd, cmdArgs); err != nil { return err } - fmt.Println("") + fmt.Println() } return nil } @@ -397,22 +394,14 @@ var ( ) func muxOnCommands(cmd *cobra.Command, pArgs []string) error { - - if len(pArgs) < 1 && cmd.Use != "batch" { + if len(pArgs) < 2 { return errBadPersistentArgs } - - subCommand, actualArgs := pArgs[0], pArgs[1:] - - //if cmd.Use == "batch" { - // cmd.Use = subCommand - //} - + subCommand, actualArgs := pArgs[1], pArgs[2:] switch strings.ToLower(subCommand) { case "batch": - fmt.Println("WTF") - return nil + return muxOnCommands(cmd, actualArgs) case "check_tx": return cmdCheckTx(cmd, actualArgs) case "commit": @@ -438,6 +427,9 @@ func cmdUnimplemented(cmd *cobra.Command, args []string) error { if err := cmd.Help(); err != nil { msg = err.Error() } + if len(args) > 0 { + msg += fmt.Sprintf(" args: [%s]", strings.Join(args, " ")) + } printResponse(cmd, args, response{ Code: codeBad, Log: msg,