提交 405cfd97 作者: Matt Bell 提交者: Juan Batiz-Benet

commands/http: Made parser/client handle variadic arguments

上级 2c8fc856
...@@ -49,8 +49,15 @@ func Send(req cmds.Request) (cmds.Response, error) { ...@@ -49,8 +49,15 @@ func Send(req cmds.Request) (cmds.Response, error) {
} }
args := req.Arguments() args := req.Arguments()
argDefs := req.Command().Arguments
var argDef cmds.Argument
for i, arg := range args { for i, arg := range args {
if req.Command().Arguments[i].Type == cmds.ArgString { if i < len(argDefs) {
argDef = argDefs[i]
}
if argDef.Type == cmds.ArgString {
query += "&arg=" + arg.(string) query += "&arg=" + arg.(string)
} else { } else {
......
...@@ -36,17 +36,18 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) { ...@@ -36,17 +36,18 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
// Note that the argument handling here is dumb, it does not do any error-checking. // Note that the argument handling here is dumb, it does not do any error-checking.
// (Arguments are further processed when the request is passed to the command to run) // (Arguments are further processed when the request is passed to the command to run)
args := make([]interface{}, len(cmd.Arguments)) args := make([]interface{}, 0)
for i, arg := range cmd.Arguments {
for _, arg := range cmd.Arguments {
if arg.Type == cmds.ArgString { if arg.Type == cmds.ArgString {
if len(stringArgs) > 0 { for j := 0; len(stringArgs) > 0 && arg.Variadic || j == 0; j++ {
args[i] = stringArgs[0] args = append(args, stringArgs[0])
stringArgs = stringArgs[1:] stringArgs = stringArgs[1:]
} }
} else { } else {
// TODO: create multipart streams for file args // TODO: create multipart streams for file args
args[i] = r.Body args = append(args, r.Body)
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论