Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix param #151

Merged
merged 4 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.11
require (
github.com/c-bata/go-prompt v0.2.6
github.com/jedib0t/go-pretty/v6 v6.0.5
github.com/jievince/liner v1.2.3
github.com/jievince/liner v1.2.4-0.20211229025353-9af8863139ef
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295 h1:ZA+qQ3d2In
github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
github.com/jedib0t/go-pretty/v6 v6.0.5 h1:oOo0/jSb3NEYKT6l1hhFXoX2UZnkanMuCE2DVT1mqnE=
github.com/jedib0t/go-pretty/v6 v6.0.5/go.mod h1:MTr6FgcfNdnN5wPVBzJ6mhJeDyiF0yBvS2TMXEV/XSU=
github.com/jievince/liner v1.2.3 h1:hpMEqBKkIg/RHzHCHZqbs19MDq8bT8b5o85D3o/Yggk=
github.com/jievince/liner v1.2.3/go.mod h1:6szfFB+ea00sIHdOn/4gDFoD6sa2UaUHR28Ca8QGj9U=
github.com/jievince/liner v1.2.4-0.20211229025353-9af8863139ef h1:pc985l3jVFf0GSk1B4TmS1KrLoFaPfrgmL08Y+1T5ws=
github.com/jievince/liner v1.2.4-0.20211229025353-9af8863139ef/go.mod h1:6szfFB+ea00sIHdOn/4gDFoD6sa2UaUHR28Ca8QGj9U=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -23,15 +23,18 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand Down
84 changes: 37 additions & 47 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,81 +105,71 @@ func playData(data string) (string, error) {
}

func defineParams(args string) {
reg := regexp.MustCompile(`^\s*:param\s+\s*(.+)\s*$`)
argsRewritten := strings.Replace(args, "'", "\"", -1)
reg := regexp.MustCompile(`^\s*:param\s+(\S+)\s*=>(.*)$`)
if reg == nil {
fmt.Println("invalid regular expression")
return
}
argsRewritten := strings.Replace(args, "'", "\"", -1)
matchResult := reg.FindAllStringSubmatch(argsRewritten, -1)
if len(matchResult) != 1 || len(matchResult[0]) != 2 {
if len(matchResult) != 1 || len(matchResult[0]) != 3 {
fmt.Println("Wrong local command format", matchResult)
return
}
items := strings.Split(matchResult[0][1], ",")
for _, item := range items {
reg := regexp.MustCompile(`^\s*(\S+)\s*=>\s*(\S*)\s*$`)
if reg == nil {
fmt.Println("invalid regular expression")
return
}
kv := reg.FindAllStringSubmatch(item, -1)
if len(kv) != 1 || len(kv[0]) != 3 {
/*
* :param p1=> -> [":param p1=>",":p1",""]
* :param p2=>3 -> [":param p2=>3",":p2","3"]
*/
paramKey := matchResult[0][1]
paramValue := matchResult[0][2]
if len(paramValue) == 0 {
delete(parameterMap, paramKey)
} else {
paramsWithGoType := make(ParameterMap)
param := "{\"" + paramKey + "\"" + ":" + paramValue + "}"
err := json.Unmarshal([]byte(param), &paramsWithGoType)
if err != nil {
fmt.Println("Error: parameter parsing failed")
return
}
if len(kv[0][2]) == 0 {
delete(parameterMap, kv[0][1])
} else {
paramsWithGoType := make(ParameterMap)
param := "{\"" + kv[0][1] + "\"" + ":" + kv[0][2] + "}"
err := json.Unmarshal([]byte(param), &paramsWithGoType)
if err != nil {
fmt.Println("Error: parameter parsing failed")
return
}
for k, v := range paramsWithGoType {
parameterMap[k] = v
}
for k, v := range paramsWithGoType {
parameterMap[k] = v
}
}
}

func ListParams(args string) {
reg := regexp.MustCompile(`^\s*(:params(.*))$`)
reg := regexp.MustCompile(`^\s*:params\s*(\S*)\s*$`)
if reg == nil {
fmt.Println("invalid regular expression")
return
}
matchResult := reg.FindAllStringSubmatch(args, -1)
if len(matchResult) != 1 {
fmt.Println("Wrong local command format", matchResult)
return
}
if len(matchResult[0]) != 3 {
res := matchResult[0]
/*
* :params -> [":params",""]
* :params p1 -> ["params","p1"]
*/
if len(res) != 2 {
return
}
if len(matchResult[0][2]) != 0 {
items := strings.Split(matchResult[0][2], ",")
for _, item := range items {
reg := regexp.MustCompile(`^\s*(\S+)\s*$`)
if reg == nil {
fmt.Println("invalid regular expression")
return
}
res := reg.FindAllStringSubmatch(item, -1)
if len(res) != 1 || len(res[0]) != 2 {
return
} else {
paramKey := matchResult[0][1]
if len(paramKey) == 0 {
for k, v := range parameterMap {
fmt.Println(k, " => ", v)
}
paramKey := res[0][1]
paramValue := parameterMap[paramKey]
if paramValue != nil {
} else {
if paramValue, ok := parameterMap[paramKey]; ok {
fmt.Println(paramKey, " => ", paramValue)
} else {
fmt.Println("Unknown parameter: ", paramKey)
}
}
} else {
for k, v := range parameterMap {
fmt.Println(k, " => ", v)
}
}

}

// Console side cmd will not be sent to server
Expand Down