From d275393488059e77d38f3ff6ce34236e8c4680ed Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Wed, 29 Jul 2015 10:40:15 -0400 Subject: [PATCH] Add bt alias for stack, quit and q for exit Fixes #182 --- terminal/command.go | 15 +++++++++++++-- terminal/terminal.go | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/terminal/command.go b/terminal/command.go index 32e634f2..1524c94e 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -41,6 +41,8 @@ type Commands struct { client service.Client } +var exitAliases = []string{"exit", "quit", "q"} + // Returns a Commands struct with default commands defined. func DebugCommands(client service.Client) *Commands { c := &Commands{client: client} @@ -61,13 +63,22 @@ func DebugCommands(client service.Client) *Commands { {aliases: []string{"breakpoints", "bp"}, cmdFn: breakpoints, helpMsg: "Print out info for active breakpoints."}, {aliases: []string{"print", "p"}, cmdFn: printVar, helpMsg: "Evaluate a variable."}, {aliases: []string{"info"}, cmdFn: info, helpMsg: "Subcommands: args, funcs, locals, sources, vars, or regs."}, - {aliases: []string{"exit"}, cmdFn: nullCommand, helpMsg: "Exit the debugger."}, - {aliases: []string{"stack"}, cmdFn: stackCommand, helpMsg: "stack [ []]. Prints stack."}, + {aliases: exitAliases, cmdFn: nullCommand, helpMsg: "Exit the debugger."}, + {aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [ []]. Prints stack."}, } return c } +func isExitCommand(cmdstr string) bool { + for _, a := range exitAliases { + if a == cmdstr { + return true + } + } + return false +} + // Register custom commands. Expects cf to be a func of type cmdfunc, // returning only an error. func (c *Commands) Register(cmdstr string, cf cmdfunc, helpMsg string) { diff --git a/terminal/terminal.go b/terminal/terminal.go index eb65b727..8ec3c3a0 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -84,7 +84,7 @@ func (t *Term) Run() (error, int) { } cmdstr, args := parseCommand(cmdstr) - if cmdstr == "exit" { + if isExitCommand(cmdstr) { err, status = handleExit(t.client, t) break }