From dcd4ab5cd2415519a129da23230f0126ff162092 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 12 Sep 2016 10:21:20 +0200 Subject: [PATCH] Make console more robust to typos --- cmd/tmsp-cli/tmsp-cli.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/tmsp-cli/tmsp-cli.go b/cmd/tmsp-cli/tmsp-cli.go index 964dbe69c..0c2e1c4f2 100644 --- a/cmd/tmsp-cli/tmsp-cli.go +++ b/cmd/tmsp-cli/tmsp-cli.go @@ -123,6 +123,14 @@ func before(c *cli.Context) error { return nil } +// 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) +} + //-------------------------------------------------------------------------------- func cmdBatch(app *cli.App, c *cli.Context) error { @@ -149,6 +157,8 @@ func cmdBatch(app *cli.App, c *cli.Context) error { } func cmdConsole(app *cli.App, c *cli.Context) error { + // don't hard exit on mistyped commands (eg. check vs check_tx) + app.CommandNotFound = badCmd for { fmt.Printf("\n> ") bufReader := bufio.NewReader(os.Stdin) @@ -162,10 +172,10 @@ func cmdConsole(app *cli.App, c *cli.Context) error { args := []string{"tmsp-cli"} args = append(args, strings.Split(string(line), " ")...) if err := app.Run(args); err != nil { - return err + // if the command doesn't succeed, inform the user without exiting + fmt.Println("Error:", err.Error()) } } - return nil } // Have the application echo a message