commands/http: Made parser/client handle variadic arguments

This commit is contained in:
Matt Bell 2014-11-02 21:46:31 -08:00 committed by Juan Batiz-Benet
parent 2c8fc8564c
commit 405cfd9762
2 changed files with 14 additions and 6 deletions

View File

@ -49,8 +49,15 @@ func Send(req cmds.Request) (cmds.Response, error) {
}
args := req.Arguments()
argDefs := req.Command().Arguments
var argDef cmds.Argument
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)
} else {

View File

@ -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.
// (Arguments are further processed when the request is passed to the command to run)
args := make([]interface{}, len(cmd.Arguments))
for i, arg := range cmd.Arguments {
args := make([]interface{}, 0)
for _, arg := range cmd.Arguments {
if arg.Type == cmds.ArgString {
if len(stringArgs) > 0 {
args[i] = stringArgs[0]
for j := 0; len(stringArgs) > 0 && arg.Variadic || j == 0; j++ {
args = append(args, stringArgs[0])
stringArgs = stringArgs[1:]
}
} else {
// TODO: create multipart streams for file args
args[i] = r.Body
args = append(args, r.Body)
}
}