Merge pull request #75 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:feature/wyq/dep-ensure-climc-shell to release/2.0.0

* commit 'e3e341561c565a8596f9aeb4312db04a786c692b':
  reserve args
  dep ensure pkg, fix climc parse input args
This commit is contained in:
李泽玺
2018-08-20 11:40:14 +08:00
3 changed files with 72 additions and 3 deletions
Generated
+1 -1
View File
@@ -890,7 +890,7 @@
"util/workqueue",
"utils"
]
revision = "30cdcc2f0c2ca0f3eef573c27eb7350bdd95a7dd"
revision = "56b426f0ca15288cc26442f5802c949f137ade60"
[[projects]]
branch = "master"
+3 -2
View File
@@ -9,6 +9,7 @@ import (
"regexp"
"strings"
"yunion.io/x/pkg/utils"
"yunion.io/x/structarg"
"yunion.io/x/onecloud/pkg/mcclient"
@@ -51,8 +52,8 @@ func Executor(s string) {
return
}
s = escaper(s)
args := strings.Split(s, " ")
e := parser.ParseArgs(strings.Split(s, " "), false)
args := utils.ArgsStringToArray(s)
e := parser.ParseArgs(utils.ArgsStringToArray(s), false)
subcmd := parser.GetSubcommand()
subparser := subcmd.GetSubParser()
if e != nil {
+68
View File
@@ -149,3 +149,71 @@ func FloatRound(num float64, precision int) float64 {
num = temp
return num
}
func getStringInQuote(s string, start, length int, quote byte, backIndex int) (string, int) {
var i = start + 1
if quote != '\'' && quote != '"' {
for i < length {
if s[i] == ' ' || s[i] == '\'' || s[i] == '"' {
return s[backIndex:i], i
}
i++
}
return s[backIndex:], i
} else {
for i < length {
if s[i] == quote {
return s[backIndex+1 : i], i + 1
}
i++
}
return s[backIndex:], i
}
}
func ArgsStringToArray(s string) []string {
var args, i, j = make([]string, 0), 0, 0
var length = len(s)
for i < length {
switch s[i] {
case ' ':
if i > j {
args = append(args, s[j:i])
j = i
}
i++
j = i
case '"':
var s1, s2 string
var oldStr = s[j:i]
s1, i = getStringInQuote(s, i, length, '"', i)
s1 = oldStr + s1
for i < length && s[i] != ' ' {
s2, i = getStringInQuote(s, i, length, s[i], i)
s1 += s2
fmt.Println(s2)
}
args = append(args, s1)
i++
j = i
case '\'':
var s1, s2 string
var oldStr = s[j:i]
s1, i = getStringInQuote(s, i, length, '\'', i)
s1 = oldStr + s1
for i < length && s[i] != ' ' {
s2, i = getStringInQuote(s, i, length, s[i], i)
s1 += s2
}
args = append(args, s1)
i++
j = i
default:
i++
}
}
if j < length {
args = append(args, s[j:])
}
return args
}