From 2d8cc085136194ebcfd7f998fb3039286770738d Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Wed, 21 May 2014 10:18:54 -0500 Subject: [PATCH] Default DebugCommands() to include null replay --- command/command.go | 6 ++---- command/command_test.go | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/command/command.go b/command/command.go index 934f6db4..5392eaea 100644 --- a/command/command.go +++ b/command/command.go @@ -11,9 +11,11 @@ type Commands struct { cmds map[string]cmdfunc } +// Returns a Commands struct with default commands defined. func DebugCommands() *Commands { cmds := map[string]cmdfunc{ "exit": exitFunc, + "": nullCommand, } return &Commands{cmds} @@ -29,10 +31,6 @@ func (c *Commands) Register(cmdstr string, cf cmdfunc) { func (c *Commands) Find(cmdstr string) cmdfunc { cmd, ok := c.cmds[cmdstr] if !ok { - if cmdstr == "" { - return nullCommand - } - return noCmdAvailable } diff --git a/command/command_test.go b/command/command_test.go index 95d1aa51..ee06085b 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -39,7 +39,7 @@ func TestCommandRegister(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") }) cmd := cmds.Find("foo") @@ -57,7 +57,7 @@ func TestCommandReplay(t *testing.T) { func TestCommandReplayWithoutPreviousCommand(t *testing.T) { var ( - cmds = Commands{make(map[string]cmdfunc)} + cmds = DebugCommands() cmd = cmds.Find("") err = cmd() )