diff --git a/Makefile b/Makefile index 6c72d0632..588e12df5 100644 --- a/Makefile +++ b/Makefile @@ -70,13 +70,13 @@ metalinter_test: tools --enable=vetshadow \ ./... - #--enable=dupl \ - #--enable=errcheck \ - #--enable=gocyclo \ - #--enable=golint \ <== comments on anything exported - #--enable=gotype \ - #--enable=interfacer \ - #--enable=unparam \ - #--enable=vet \ + #--enable=dupl \ + #--enable=errcheck \ + #--enable=gocyclo \ + #--enable=golint \ <== comments on anything exported + #--enable=gotype \ + #--enable=interfacer \ + #--enable=unparam \ + #--enable=vet \ .PHONY: all build test fmt get_deps tools diff --git a/README.md b/README.md index f1b2ebb37..33b037da0 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,9 @@ The `abci-cli` tool wraps any ABCI client and can be used for probing/testing an See [the documentation](http://tendermint.readthedocs.io/en/master/) for more details. Multiple example apps are included: -- the `counter` application, which illustrates nonce checking in txs -- the `dummy` application, which illustrates a simple key-value merkle tree -- the `dummy --persistent` application, which augments the dummy with persistence and validator set changes +- the `abci-cli counter` application, which illustrates nonce checking in txs +- the `abci-cli dummy` application, which illustrates a simple key-value merkle tree +- the `abci-cli dummy --persistent` application, which augments the dummy with persistence and validator set changes ## Specification diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index c73169499..1beb08507 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -7,13 +7,18 @@ import ( "fmt" "io" "os" + "os/exec" "strings" abcicli "github.com/tendermint/abci/client" + "github.com/tendermint/abci/example/counter" + "github.com/tendermint/abci/example/dummy" + "github.com/tendermint/abci/server" "github.com/tendermint/abci/types" - "github.com/tendermint/abci/version" + cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" - "github.com/urfave/cli" + + "github.com/spf13/cobra" ) // Structure for data passed to print response. @@ -38,149 +43,213 @@ var client abcicli.Client var logger log.Logger -func main() { - - //workaround for the cli library (https://github.com/urfave/cli/issues/565) - cli.OsExiter = func(_ int) {} +// flags +var ( + // global + address string + abci string + verbose bool + + // query + path string + height int + prove bool + + // counter + addrC string + serial bool + + // dummy + addrD string + persist string +) - app := cli.NewApp() - app.Name = "abci-cli" - app.Usage = "abci-cli [command] [args...]" - app.Version = version.Version - app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "address", - Value: "tcp://127.0.0.1:46658", - Usage: "address of application socket", - }, - cli.StringFlag{ - Name: "abci", - Value: "socket", - Usage: "socket or grpc", - }, - cli.BoolFlag{ - Name: "verbose", - Usage: "print the command and results as if it were a console session", - }, - } - app.Commands = []cli.Command{ - { - Name: "batch", - Usage: "Run a batch of abci commands against an application", - Action: func(c *cli.Context) error { - return cmdBatch(app, c) - }, - }, - { - Name: "console", - Usage: "Start an interactive abci console for multiple commands", - Action: func(c *cli.Context) error { - return cmdConsole(app, c) - }, - }, - { - Name: "echo", - Usage: "Have the application echo a message", - Action: func(c *cli.Context) error { - return cmdEcho(c) - }, - }, - { - Name: "info", - Usage: "Get some info about the application", - Action: func(c *cli.Context) error { - return cmdInfo(c) - }, - }, - { - Name: "set_option", - Usage: "Set an option on the application", - Action: func(c *cli.Context) error { - return cmdSetOption(c) - }, - }, - { - Name: "deliver_tx", - Usage: "Deliver a new tx to application", - Action: func(c *cli.Context) error { - return cmdDeliverTx(c) - }, - }, - { - Name: "check_tx", - Usage: "Validate a tx", - Action: func(c *cli.Context) error { - return cmdCheckTx(c) - }, - }, - { - Name: "commit", - Usage: "Commit the application state and return the Merkle root hash", - Action: func(c *cli.Context) error { - return cmdCommit(c) - }, - }, - { - Name: "query", - Usage: "Query application state", - Action: func(c *cli.Context) error { - return cmdQuery(c) - }, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "path", - Value: "/store", - Usage: "Path to prefix the query with", - }, - cli.IntFlag{ - Name: "height", - Value: 0, - Usage: "Height to query the blockchain at", - }, - cli.BoolFlag{ - Name: "prove", - Usage: "Whether or not to return a merkle proof of the query result", - }, - }, - }, - } - app.Before = before - err := app.Run(os.Args) - if err != nil { - logger.Error(err.Error()) - os.Exit(1) - } +var RootCmd = &cobra.Command{ + Use: "abci-cli", + Short: "", + Long: "", + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { -} + switch cmd.Use { + // for the examples apps, don't pre-run + case "counter", "dummy": + return nil + } -func before(c *cli.Context) error { - if logger == nil { - logger = log.NewFilter(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), log.AllowError()) - } - if client == nil { - var err error - client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false) - if err != nil { - logger.Error(err.Error()) - os.Exit(1) + if logger == nil { + logger = log.NewFilter(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), log.AllowError()) } - client.SetLogger(logger.With("module", "abci-client")) - if _, err := client.Start(); err != nil { - return err + if client == nil { + var err error + client, err = abcicli.NewClient(address, abci, false) + if err != nil { + return err + } + client.SetLogger(logger.With("module", "abci-client")) + if _, err := client.Start(); err != nil { + return err + } } - } - return nil + return nil + }, +} + +func Execute() { + addGlobalFlags() + addCommands() + RootCmd.Execute() +} + +func addGlobalFlags() { + RootCmd.PersistentFlags().StringVarP(&address, "address", "", "tcp://127.0.0.1:46658", "Address of application socket") + RootCmd.PersistentFlags().StringVarP(&abci, "abci", "", "socket", "Either socket or grpc") + RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Print the command and results as if it were a console session") +} + +func addQueryFlags() { + queryCmd.PersistentFlags().StringVarP(&path, "path", "", "/store", "Path to prefix query with") + queryCmd.PersistentFlags().IntVarP(&height, "height", "", 0, "Height to query the blockchain at") + queryCmd.PersistentFlags().BoolVarP(&prove, "prove", "", false, "Whether or not to return a merkle proof of the query result") +} + +func addCounterFlags() { + counterCmd.PersistentFlags().StringVarP(&addrC, "addr", "", "tcp://0.0.0.0:46658", "Listen address") + counterCmd.PersistentFlags().BoolVarP(&serial, "serial", "", false, "Enforce incrementing (serial) transactions") +} + +func addDummyFlags() { + dummyCmd.PersistentFlags().StringVarP(&addrD, "addr", "", "tcp://0.0.0.0:46658", "Listen address") + dummyCmd.PersistentFlags().StringVarP(&persist, "persist", "", "", "Directory to use for a database") +} +func addCommands() { + RootCmd.AddCommand(batchCmd) + RootCmd.AddCommand(consoleCmd) + RootCmd.AddCommand(echoCmd) + RootCmd.AddCommand(infoCmd) + RootCmd.AddCommand(setOptionCmd) + RootCmd.AddCommand(deliverTxCmd) + RootCmd.AddCommand(checkTxCmd) + RootCmd.AddCommand(commitCmd) + addQueryFlags() + RootCmd.AddCommand(queryCmd) + + // examples + addCounterFlags() + RootCmd.AddCommand(counterCmd) + addDummyFlags() + RootCmd.AddCommand(dummyCmd) +} + +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) + }, +} + +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) + }, +} + +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) + }, +} +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) + }, +} +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) + }, +} + +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) + }, +} + +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) + }, +} + +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) + }, +} + +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) + }, +} + +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) + }, } -// badCmd is called when we invoke with an invalid first argument (just for console for now) -func badCmd(c *cli.Context, cmd string) { - fmt.Println("Unknown command:", cmd) - fmt.Println("Please try one of the following:") - fmt.Println("") - cli.DefaultAppComplete(c) +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) + }, } -//Generates new Args array based off of previous call args to maintain flag persistence +// Generates new Args array based off of previous call args to maintain flag persistence func persistentArgs(line []byte) []string { // generate the arguments to run from original os.Args @@ -196,7 +265,7 @@ func persistentArgs(line []byte) []string { //-------------------------------------------------------------------------------- -func cmdBatch(app *cli.App, c *cli.Context) error { +func cmdBatch(cmd *cobra.Command, args []string) error { bufReader := bufio.NewReader(os.Stdin) for { line, more, err := bufReader.ReadLine() @@ -210,18 +279,20 @@ func cmdBatch(app *cli.App, c *cli.Context) error { return err } - args := persistentArgs(line) - app.Run(args) //cli prints error within its func call + pArgs := persistentArgs(line) + out, err := exec.Command(pArgs[0], pArgs[1:]...).Output() + if err != nil { + return err + } + fmt.Println(string(out)) } return nil } -func cmdConsole(app *cli.App, c *cli.Context) error { - // don't hard exit on mistyped commands (eg. check vs check_tx) - app.CommandNotFound = badCmd +func cmdConsole(cmd *cobra.Command, args []string) error { for { - fmt.Printf("\n> ") + fmt.Printf("> ") bufReader := bufio.NewReader(os.Stdin) line, more, err := bufReader.ReadLine() if more { @@ -230,27 +301,27 @@ func cmdConsole(app *cli.App, c *cli.Context) error { return err } - args := persistentArgs(line) - app.Run(args) //cli prints error within its func call + pArgs := persistentArgs(line) + out, err := exec.Command(pArgs[0], pArgs[1:]...).Output() + if err != nil { + return err + } + fmt.Println(string(out)) } + return nil } // Have the application echo a message -func cmdEcho(c *cli.Context) error { - args := c.Args() - if len(args) != 1 { - return errors.New("Command echo takes 1 argument") - } +func cmdEcho(cmd *cobra.Command, args []string) error { resEcho := client.EchoSync(args[0]) - printResponse(c, response{ + printResponse(cmd, args, response{ Data: resEcho.Data, }) return nil } // Get some info from the application -func cmdInfo(c *cli.Context) error { - args := c.Args() +func cmdInfo(cmd *cobra.Command, args []string) error { var version string if len(args) == 1 { version = args[0] @@ -259,37 +330,29 @@ func cmdInfo(c *cli.Context) error { if err != nil { return err } - printResponse(c, response{ + printResponse(cmd, args, response{ Data: []byte(resInfo.Data), }) return nil } // Set an option on the application -func cmdSetOption(c *cli.Context) error { - args := c.Args() - if len(args) != 2 { - return errors.New("Command set_option takes 2 arguments (key, value)") - } +func cmdSetOption(cmd *cobra.Command, args []string) error { resSetOption := client.SetOptionSync(args[0], args[1]) - printResponse(c, response{ + printResponse(cmd, args, response{ Log: resSetOption.Log, }) return nil } // Append a new tx to application -func cmdDeliverTx(c *cli.Context) error { - args := c.Args() - if len(args) != 1 { - return errors.New("Command deliver_tx takes 1 argument") - } - txBytes, err := stringOrHexToBytes(c.Args()[0]) +func cmdDeliverTx(cmd *cobra.Command, args []string) error { + txBytes, err := stringOrHexToBytes(args[0]) if err != nil { return err } res := client.DeliverTxSync(txBytes) - printResponse(c, response{ + printResponse(cmd, args, response{ Code: res.Code, Data: res.Data, Log: res.Log, @@ -298,17 +361,13 @@ func cmdDeliverTx(c *cli.Context) error { } // Validate a tx -func cmdCheckTx(c *cli.Context) error { - args := c.Args() - if len(args) != 1 { - return errors.New("Command check_tx takes 1 argument") - } - txBytes, err := stringOrHexToBytes(c.Args()[0]) +func cmdCheckTx(cmd *cobra.Command, args []string) error { + txBytes, err := stringOrHexToBytes(args[0]) if err != nil { return err } res := client.CheckTxSync(txBytes) - printResponse(c, response{ + printResponse(cmd, args, response{ Code: res.Code, Data: res.Data, Log: res.Log, @@ -317,9 +376,9 @@ func cmdCheckTx(c *cli.Context) error { } // Get application Merkle root hash -func cmdCommit(c *cli.Context) error { +func cmdCommit(cmd *cobra.Command, args []string) error { res := client.CommitSync() - printResponse(c, response{ + printResponse(cmd, args, response{ Code: res.Code, Data: res.Data, Log: res.Log, @@ -328,22 +387,12 @@ func cmdCommit(c *cli.Context) error { } // Query application state -func cmdQuery(c *cli.Context) error { - args := c.Args() - - if len(args) != 1 { - return errors.New("Command query takes 1 argument, the query bytes") - } - +func cmdQuery(cmd *cobra.Command, args []string) error { queryBytes, err := stringOrHexToBytes(args[0]) if err != nil { return err } - path := c.String("path") - height := c.Int("height") - prove := c.Bool("prove") - resQuery, err := client.QuerySync(types.RequestQuery{ Data: queryBytes, Path: path, @@ -353,7 +402,7 @@ func cmdQuery(c *cli.Context) error { if err != nil { return err } - printResponse(c, response{ + printResponse(cmd, args, response{ Code: resQuery.Code, Log: resQuery.Log, Query: &queryResponse{ @@ -366,22 +415,78 @@ func cmdQuery(c *cli.Context) error { return nil } -//-------------------------------------------------------------------------------- +func cmdCounter(cmd *cobra.Command, args []string) error { -func printResponse(c *cli.Context, rsp response) { + app := counter.NewCounterApplication(serial) - verbose := c.GlobalBool("verbose") + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - if verbose { - fmt.Println(">", c.Command.Name, strings.Join(c.Args(), " ")) + // Start the listener + srv, err := server.NewServer(addrC, abci, app) + if err != nil { + return err + } + srv.SetLogger(logger.With("module", "abci-server")) + if _, err := srv.Start(); err != nil { + return err + } + + // Wait forever + cmn.TrapSignal(func() { + // Cleanup + srv.Stop() + }) + return nil +} + +func cmdDummy(cmd *cobra.Command, args []string) error { + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + + // Create the application - in memory or persisted to disk + var app types.Application + if persist == "" { + app = dummy.NewDummyApplication() + } else { + app = dummy.NewPersistentDummyApplication(persist) + app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy")) } - if !rsp.Code.IsOK() { - fmt.Printf("-> code: %s\n", rsp.Code.String()) + // Start the listener + srv, err := server.NewServer(addrD, abci, app) + if err != nil { + return err + } + srv.SetLogger(logger.With("module", "abci-server")) + if _, err := srv.Start(); err != nil { + return err + } + + // Wait forever + cmn.TrapSignal(func() { + // Cleanup + srv.Stop() + }) + return nil +} + +//-------------------------------------------------------------------------------- + +func printResponse(cmd *cobra.Command, args []string, rsp response) { + + if verbose { + fmt.Println(">", cmd.Use, strings.Join(args, " ")) } + + // Always print the status code. + fmt.Printf("-> code: %s\n", rsp.Code.String()) + if len(rsp.Data) != 0 { - fmt.Printf("-> data: %s\n", rsp.Data) - fmt.Printf("-> data.hex: %X\n", rsp.Data) + // Do no print this line when using the commit command + // because the string comes out as gibberish + if cmd.Use != "commit" { + fmt.Printf("-> data: %s\n", rsp.Data) + } + fmt.Printf("-> data.hex: 0x%X\n", rsp.Data) } if rsp.Log != "" { fmt.Printf("-> log: %s\n", rsp.Log) @@ -401,11 +506,6 @@ func printResponse(c *cli.Context, rsp response) { fmt.Printf("-> proof: %X\n", rsp.Query.Proof) } } - - if verbose { - fmt.Println("") - } - } // NOTE: s is interpreted as a string unless prefixed with 0x diff --git a/cmd/abci-cli/main.go b/cmd/abci-cli/main.go new file mode 100644 index 000000000..736ef3102 --- /dev/null +++ b/cmd/abci-cli/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + Execute() +} diff --git a/cmd/counter/main.go b/cmd/counter/main.go deleted file mode 100644 index aa55778cc..000000000 --- a/cmd/counter/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/tendermint/abci/example/counter" - "github.com/tendermint/abci/server" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/log" -) - -func main() { - - addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address") - abciPtr := flag.String("abci", "socket", "ABCI server: socket | grpc") - serialPtr := flag.Bool("serial", false, "Enforce incrementing (serial) txs") - flag.Parse() - app := counter.NewCounterApplication(*serialPtr) - - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - - // Start the listener - srv, err := server.NewServer(*addrPtr, *abciPtr, app) - if err != nil { - logger.Error(err.Error()) - os.Exit(1) - } - srv.SetLogger(logger.With("module", "abci-server")) - if _, err := srv.Start(); err != nil { - logger.Error(err.Error()) - os.Exit(1) - } - - // Wait forever - cmn.TrapSignal(func() { - // Cleanup - srv.Stop() - }) - -} diff --git a/cmd/dummy/main.go b/cmd/dummy/main.go deleted file mode 100644 index 85bbca18d..000000000 --- a/cmd/dummy/main.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "flag" - "os" - - "github.com/tendermint/abci/example/dummy" - "github.com/tendermint/abci/server" - "github.com/tendermint/abci/types" - cmn "github.com/tendermint/tmlibs/common" - "github.com/tendermint/tmlibs/log" -) - -func main() { - - addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address") - abciPtr := flag.String("abci", "socket", "socket | grpc") - persistencePtr := flag.String("persist", "", "directory to use for a database") - flag.Parse() - - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) - - // Create the application - in memory or persisted to disk - var app types.Application - if *persistencePtr == "" { - app = dummy.NewDummyApplication() - } else { - app = dummy.NewPersistentDummyApplication(*persistencePtr) - app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy")) - } - - // Start the listener - srv, err := server.NewServer(*addrPtr, *abciPtr, app) - if err != nil { - logger.Error(err.Error()) - os.Exit(1) - } - srv.SetLogger(logger.With("module", "abci-server")) - if _, err := srv.Start(); err != nil { - logger.Error(err.Error()) - os.Exit(1) - } - - // Wait forever - cmn.TrapSignal(func() { - // Cleanup - srv.Stop() - }) - -} diff --git a/glide.lock b/glide.lock index cc94dbd55..8ee12dc75 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: 876bc65024f66612325ebafcedeb3e4d5014d46b339cf7583f1c00c6bac6e32c -updated: 2017-10-23T14:04:02.596189966+02:00 +hash: 3c8680f0a289567a29f737be5f1d5f242c7e2afd84bdd023dd74596b88508fc2 +updated: 2017-10-26T08:45:51.300025559-04:00 imports: - name: github.com/btcsuite/btcd version: b8df516b4b267acf2de46be593a9d948d1d2c420 @@ -30,12 +30,18 @@ imports: - ptypes/any - name: github.com/golang/snappy version: 553a641470496b2327abcac10b36396bd98e45c9 +- name: github.com/inconshreveable/mousetrap + version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 - name: github.com/jmhodges/levigo version: c42d9e0ca023e2198120196f842701bb4c55d7b9 - name: github.com/kr/logfmt version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/pkg/errors version: 645ef00459ed84a119197bfb8d8205042c6df63d +- name: github.com/spf13/cobra + version: 2df9a531813370438a4d79bfc33e21f58063ed87 +- name: github.com/spf13/pflag + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -63,7 +69,7 @@ imports: subpackages: - data - name: github.com/tendermint/iavl - version: 721710e7aa59f61dbfbf558943a207ba3fe6b926 + version: 595f3dcd5b6cd4a292e90757ae6d367fd7a6e653 - name: github.com/tendermint/tmlibs version: 8e5266a9ef2527e68a1571f932db8228a331b556 subpackages: @@ -72,8 +78,6 @@ imports: - log - merkle - process -- name: github.com/urfave/cli - version: 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c - name: golang.org/x/crypto version: c7af5bf2638a1164f2eb5467c39c6cffbd13a02e subpackages: diff --git a/glide.yaml b/glide.yaml index e8cf8302c..ccd41cdc3 100644 --- a/glide.yaml +++ b/glide.yaml @@ -18,7 +18,8 @@ import: - log - merkle - process -- package: github.com/urfave/cli +- package: github.com/spf13/cobra + version: master - package: golang.org/x/net subpackages: - context diff --git a/scripts/dist_build.sh b/scripts/dist_build.sh index 0f5e3e3b0..adaca24a8 100755 --- a/scripts/dist_build.sh +++ b/scripts/dist_build.sh @@ -24,30 +24,28 @@ make tools # Get VENDORED dependencies make get_vendor_deps -BINARIES=( "abci-cli" "dummy" "counter" ) - -for binary in ${BINARIES[@]}; do - # Build! - echo "==> Building..." - "$(which gox)" \ - -os="${XC_OS}" \ - -arch="${XC_ARCH}" \ - -osarch="!darwin/arm !solaris/amd64 !freebsd/amd64" \ - -ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \ - -output "build/pkg/{{.OS}}_{{.Arch}}/$binary" \ - -tags="${BUILD_TAGS}" \ - github.com/tendermint/abci/cmd/$binary - - # Zip all the files. - echo "==> Packaging..." - for PLATFORM in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type d); do - OSARCH=$(basename "${PLATFORM}") - echo "--> ${OSARCH}" - - pushd "$PLATFORM" >/dev/null 2>&1 - zip "../${OSARCH}.zip" ./* - popd >/dev/null 2>&1 - done +BINARY="abci-cli" + +# Build! +echo "==> Building..." +"$(which gox)" \ + -os="${XC_OS}" \ + -arch="${XC_ARCH}" \ + -osarch="!darwin/arm !solaris/amd64 !freebsd/amd64" \ + -ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \ + -output "build/pkg/{{.OS}}_{{.Arch}}/$BINARY" \ + -tags="${BUILD_TAGS}" \ + github.com/tendermint/abci/cmd/$BINARY + +# Zip all the files. +echo "==> Packaging..." +for PLATFORM in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type d); do + OSARCH=$(basename "${PLATFORM}") + echo "--> ${OSARCH}" + + pushd "$PLATFORM" >/dev/null 2>&1 + zip "../${OSARCH}.zip" ./* + popd >/dev/null 2>&1 done diff --git a/tests/test_cli/ex1.abci.out b/tests/test_cli/ex1.abci.out index 21c778c71..6e3440712 100644 --- a/tests/test_cli/ex1.abci.out +++ b/tests/test_cli/ex1.abci.out @@ -1,36 +1,44 @@ > echo hello +-> code: OK -> data: hello --> data.hex: 68656C6C6F +-> data.hex: 0x68656C6C6F > info +-> code: OK -> data: {"size":0} --> data.hex: 7B2273697A65223A307D +-> data.hex: 0x7B2273697A65223A307D > commit +-> code: OK > deliver_tx "abc" +-> code: OK > info +-> code: OK -> data: {"size":1} --> data.hex: 7B2273697A65223A317D +-> data.hex: 0x7B2273697A65223A317D > commit --> data: IßÑ\ͬޮ—(ËûµèhŒ¥‹‘ --> data.hex: 49DFD15CCDACDEAE9728CB01FBB5E8688CA58B91 +-> code: OK +-> data.hex: 0x49DFD15CCDACDEAE9728CB01FBB5E8688CA58B91 > query "abc" +-> code: OK -> log: exists -> height: 0 -> value: abc -> value.hex: 616263 > deliver_tx "def=xyz" +-> code: OK > commit --> data: p-³"€7?¿?Ÿ‰Ú* Î,Ö+ --> data.hex: 70102DB32280373FBF3F9F89DA2A20CE2CD62B0B +-> code: OK +-> data.hex: 0x70102DB32280373FBF3F9F89DA2A20CE2CD62B0B > query "def" +-> code: OK -> log: exists -> height: 0 -> value: xyz diff --git a/tests/test_cli/ex2.abci.out b/tests/test_cli/ex2.abci.out index 202861cf4..40e10f83e 100644 --- a/tests/test_cli/ex2.abci.out +++ b/tests/test_cli/ex2.abci.out @@ -1,22 +1,28 @@ > set_option serial on +-> code: OK > check_tx 0x00 +-> code: OK > check_tx 0xff +-> code: OK > deliver_tx 0x00 +-> code: OK > check_tx 0x00 -> code: BadNonce -> log: Invalid nonce. Expected >= 1, got 0 > deliver_tx 0x01 +-> code: OK > deliver_tx 0x04 -> code: BadNonce -> log: Invalid nonce. Expected 2, got 4 > info +-> code: OK -> data: {"hashes":0,"txs":2} --> data.hex: 7B22686173686573223A302C22747873223A327D +-> data.hex: 0x7B22686173686573223A302C22747873223A327D diff --git a/tests/test_cli/test.sh b/tests/test_cli/test.sh index 4266dd16f..81b06a0ec 100644 --- a/tests/test_cli/test.sh +++ b/tests/test_cli/test.sh @@ -11,13 +11,13 @@ cd "$DIR" || exit function testExample() { N=$1 INPUT=$2 - APP=$3 + APP="$3 $4" - echo "Example $N" + echo "Example $N: $APP" $APP &> /dev/null & sleep 2 abci-cli --verbose batch < "$INPUT" > "${INPUT}.out.new" - killall "$APP" + killall $3 pre=$(shasum < "${INPUT}.out") post=$(shasum < "${INPUT}.out.new") @@ -34,8 +34,8 @@ function testExample() { rm "${INPUT}".out.new } -testExample 1 tests/test_cli/ex1.abci dummy -testExample 2 tests/test_cli/ex2.abci counter +testExample 1 tests/test_cli/ex1.abci abci-cli dummy +testExample 2 tests/test_cli/ex2.abci abci-cli counter echo "" echo "PASS"