Browse Source

Make console more robust to typos

pull/1780/head
Ethan Frey 8 years ago
parent
commit
dcd4ab5cd2
1 changed files with 12 additions and 2 deletions
  1. +12
    -2
      cmd/tmsp-cli/tmsp-cli.go

+ 12
- 2
cmd/tmsp-cli/tmsp-cli.go View File

@ -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


Loading…
Cancel
Save