Add bt alias for stack, quit and q for exit

Fixes #182
This commit is contained in:
Joe Shaw
2015-07-29 10:40:15 -04:00
committed by Derek Parker
parent e5b20612e5
commit d275393488
2 changed files with 14 additions and 3 deletions

View File

@ -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 [<depth> [<goroutine id>]]. Prints stack."},
{aliases: exitAliases, cmdFn: nullCommand, helpMsg: "Exit the debugger."},
{aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [<depth> [<goroutine id>]]. 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) {

View File

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