use regexp to handle cli command

This commit is contained in:
siddontang 2014-07-02 10:13:34 +08:00
parent 4b37a88a9d
commit 785168e8cd
1 changed files with 4 additions and 3 deletions

View File

@ -1,11 +1,10 @@
package main package main
import ( import (
// "bufio"
"flag" "flag"
"fmt" "fmt"
"github.com/siddontang/ledisdb/client/go/ledis" "github.com/siddontang/ledisdb/client/go/ledis"
// "os" "regexp"
"strings" "strings"
) )
@ -29,6 +28,8 @@ func main() {
setHistoryCapacity(100) setHistoryCapacity(100)
reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`)
for { for {
cmd, err := line(fmt.Sprintf("%s> ", cfg.Addr)) cmd, err := line(fmt.Sprintf("%s> ", cfg.Addr))
if err != nil { if err != nil {
@ -36,7 +37,7 @@ func main() {
return return
} }
cmds := strings.Fields(cmd) cmds := reg.FindAllString(cmd, -1)
if len(cmds) == 0 { if len(cmds) == 0 {
continue continue
} else { } else {