Skip to content

Commit

Permalink
A non-regex solution
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhare committed Nov 20, 2017
1 parent 89589ad commit 9ac37ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions cmd/influx/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os/signal"
"path/filepath"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -399,10 +398,8 @@ func (c *CommandLine) clear(cmd string) {
}
}

var useCmdRegexp = regexp.MustCompile(`([^\s"]+)|"([^"]+)"`)

func (c *CommandLine) use(cmd string) {
args := useCmdRegexp.FindAllString(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), -1)
args := strings.SplitAfterN(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ", 2)
if len(args) != 2 {
fmt.Printf("Could not parse database name from %q.\n", cmd)
return
Expand All @@ -416,6 +413,7 @@ func (c *CommandLine) use(cmd string) {
}

if !c.databaseExists(db) {
fmt.Println("DB does not exist!")
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/influx/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func TestParseCommand_Use(t *testing.T) {
}

if m.Database != test.db {
t.Fatalf(`Command "use" changed database to %q. Expected %s`, m.Database, test.db)
t.Fatalf(`Command "%s" changed database to %q. Expected %s`, test.cmd, m.Database, test.db)
}
}
}
Expand Down

0 comments on commit 9ac37ca

Please sign in to comment.