@cryptotaxi247 / kubo / commits / 405cfd976

commands/http: Made parser/client handle variadic arguments

Matt Bell committed Nov 2, 2014 at 21:46 UTC 405cfd9762327bf8958cb80b40544987d9bc1bf2
2 files changed +14 -6
commands/http/client.go
+8 -1
@@ -49,8 +49,15 @@ func Send(req cmds.Request) (cmds.Response, error) {
49 }
50
51 args := req.Arguments()
52 + argDefs := req.Command().Arguments
53 + var argDef cmds.Argument
54 +
55 for i, arg := range args {
53 - if req.Command().Arguments[i].Type == cmds.ArgString {
56 + if i < len(argDefs) {
57 + argDef = argDefs[i]
58 + }
59 +
60 + if argDef.Type == cmds.ArgString {
61 query += "&arg=" + arg.(string)
62
63 } else {
commands/http/parse.go
+6 -5
@@ -36,17 +36,18 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
36
37 // Note that the argument handling here is dumb, it does not do any error-checking.
38 // (Arguments are further processed when the request is passed to the command to run)
39 - args := make([]interface{}, len(cmd.Arguments))
40 - for i, arg := range cmd.Arguments {
39 + args := make([]interface{}, 0)
40 +
41 + for _, arg := range cmd.Arguments {
42 if arg.Type == cmds.ArgString {
42 - if len(stringArgs) > 0 {
43 - args[i] = stringArgs[0]
43 + for j := 0; len(stringArgs) > 0 && arg.Variadic || j == 0; j++ {
44 + args = append(args, stringArgs[0])
45 stringArgs = stringArgs[1:]
46 }
47
48 } else {
49 // TODO: create multipart streams for file args
49 - args[i] = r.Body
50 + args = append(args, r.Body)
51 }
52 }
53