aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--logic/cmd.go1
-rw-r--r--logic/cmd_test.go8
2 files changed, 9 insertions, 0 deletions
diff --git a/logic/cmd.go b/logic/cmd.go
index 33cd705..078da36 100644
--- a/logic/cmd.go
+++ b/logic/cmd.go
@@ -29,6 +29,7 @@ var cmdTable = map[string]int{
// we ignore arguments which are to much
func ParseCmd(s string) (Cmd, error) {
+ s = strings.Trim(s, " \t")
split := strings.Split(s, " ")
if len(split) == 0 {
return Cmd{}, errors.New("Empty command")
diff --git a/logic/cmd_test.go b/logic/cmd_test.go
index d7c88ba..78e9b41 100644
--- a/logic/cmd_test.go
+++ b/logic/cmd_test.go
@@ -11,6 +11,14 @@ func TestParseCmd(t *testing.T) {
t.Errorf("Parsing an empty string should return an error")
}
+ cmd, err = ParseCmd(" q \t ")
+ if err != nil {
+ t.Errorf("Parsing \" q \\t \" should not return \"%v\"", err)
+ }
+ if cmd.Cmd != "q" {
+ t.Errorf("Parsing \" q \\t \" should return \"q\" as command")
+ }
+
for _, s := range []string{"d", "p", "h"} {
cmd, err = ParseCmd(s)
if err != nil {