mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +08:00
commands/http: Made parser/client handle variadic arguments
This commit is contained in:
parent
2c8fc8564c
commit
405cfd9762
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user