mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 12:59:01 +08:00
Default DebugCommands() to include null replay
This commit is contained in:
@ -11,9 +11,11 @@ type Commands struct {
|
|||||||
cmds map[string]cmdfunc
|
cmds map[string]cmdfunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a Commands struct with default commands defined.
|
||||||
func DebugCommands() *Commands {
|
func DebugCommands() *Commands {
|
||||||
cmds := map[string]cmdfunc{
|
cmds := map[string]cmdfunc{
|
||||||
"exit": exitFunc,
|
"exit": exitFunc,
|
||||||
|
"": nullCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Commands{cmds}
|
return &Commands{cmds}
|
||||||
@ -29,10 +31,6 @@ func (c *Commands) Register(cmdstr string, cf cmdfunc) {
|
|||||||
func (c *Commands) Find(cmdstr string) cmdfunc {
|
func (c *Commands) Find(cmdstr string) cmdfunc {
|
||||||
cmd, ok := c.cmds[cmdstr]
|
cmd, ok := c.cmds[cmdstr]
|
||||||
if !ok {
|
if !ok {
|
||||||
if cmdstr == "" {
|
|
||||||
return nullCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
return noCmdAvailable
|
return noCmdAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func TestCommandRegister(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandReplay(t *testing.T) {
|
func TestCommandReplay(t *testing.T) {
|
||||||
cmds := Commands{make(map[string]cmdfunc)}
|
cmds := DebugCommands()
|
||||||
cmds.Register("foo", func() error { return fmt.Errorf("registered command") })
|
cmds.Register("foo", func() error { return fmt.Errorf("registered command") })
|
||||||
cmd := cmds.Find("foo")
|
cmd := cmds.Find("foo")
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func TestCommandReplay(t *testing.T) {
|
|||||||
|
|
||||||
func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
|
func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
cmds = Commands{make(map[string]cmdfunc)}
|
cmds = DebugCommands()
|
||||||
cmd = cmds.Find("")
|
cmd = cmds.Find("")
|
||||||
err = cmd()
|
err = cmd()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user