From 785168e8cd37a81ae5377332282e54881c1dce09 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 2 Jul 2014 10:13:34 +0800 Subject: [PATCH] use regexp to handle cli command --- cmd/ledis-cli/main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/ledis-cli/main.go b/cmd/ledis-cli/main.go index dc16e68..4149055 100644 --- a/cmd/ledis-cli/main.go +++ b/cmd/ledis-cli/main.go @@ -1,11 +1,10 @@ package main import ( - // "bufio" "flag" "fmt" "github.com/siddontang/ledisdb/client/go/ledis" - // "os" + "regexp" "strings" ) @@ -29,6 +28,8 @@ func main() { setHistoryCapacity(100) + reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`) + for { cmd, err := line(fmt.Sprintf("%s> ", cfg.Addr)) if err != nil { @@ -36,7 +37,7 @@ func main() { return } - cmds := strings.Fields(cmd) + cmds := reg.FindAllString(cmd, -1) if len(cmds) == 0 { continue } else {