diff --git a/http/client.go b/http/client.go index ca4fa93a..a4500258 100644 --- a/http/client.go +++ b/http/client.go @@ -230,6 +230,15 @@ func getQuery(req *cmds.Request) (string, error) { if OptionSkipMap[k] { continue } + + optArr, ok := v.([]string) + if ok { + for _, o := range optArr { + query.Add(k, o) + } + continue + } + str := fmt.Sprintf("%v", v) query.Set(k, str) } diff --git a/http/parse.go b/http/parse.go index a7bfa67b..0915ddf0 100644 --- a/http/parse.go +++ b/http/parse.go @@ -61,22 +61,28 @@ func parseRequest(r *http.Request, root *cmds.Command) (*cmds.Request, error) { } opts, stringArgs2 := parseOptions(r) + iopts := make(map[string]interface{}, len(opts)) optDefs, err := root.GetOptions(pth) if err != nil { return nil, err } for k, v := range opts { + iopts[k] = v if optDef, ok := optDefs[k]; ok { name := optDef.Names()[0] if k != name { - opts[name] = v - delete(opts, k) + iopts[name] = v + delete(iopts, k) + } + + if optDef.Type() != cmds.Strings && len(v) > 0 { + iopts[name] = v[0] } } } // default to setting encoding to JSON - if _, ok := opts[cmds.EncLong]; !ok { - opts[cmds.EncLong] = cmds.JSON + if _, ok := iopts[cmds.EncLong]; !ok { + iopts[cmds.EncLong] = cmds.JSON } stringArgs = append(stringArgs, stringArgs2...) @@ -148,7 +154,7 @@ func parseRequest(r *http.Request, root *cmds.Command) (*cmds.Request, error) { } ctx := logging.ContextWithLoggable(r.Context(), uuidLoggable()) - req, err := cmds.NewRequest(ctx, pth, opts, args, f, root) + req, err := cmds.NewRequest(ctx, pth, iopts, args, f, root) if err != nil { return nil, err } @@ -162,8 +168,8 @@ func parseRequest(r *http.Request, root *cmds.Command) (*cmds.Request, error) { return req, err } -func parseOptions(r *http.Request) (map[string]interface{}, []string) { - opts := make(map[string]interface{}) +func parseOptions(r *http.Request) (map[string][]string, []string) { + opts := make(map[string][]string) var args []string query := r.URL.Query() @@ -171,8 +177,7 @@ func parseOptions(r *http.Request) (map[string]interface{}, []string) { if k == "arg" { args = v } else { - - opts[k] = v[0] + opts[k] = v } }