1
0
Fork 0

Build command around description instead of form data

This commit is contained in:
Gregory Eremin 2017-11-04 18:31:30 +01:00
parent 70c9b13a9a
commit 730aaa071a
1 changed files with 10 additions and 15 deletions

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"strings" "net/url"
"github.com/localhots/cmdui/backend/api/auth" "github.com/localhots/cmdui/backend/api/auth"
"github.com/localhots/cmdui/backend/commands" "github.com/localhots/cmdui/backend/commands"
@ -61,18 +61,13 @@ func commandFromRequest(r *http.Request) (commands.Command, error) {
return cmd, fmt.Errorf("Unknown command: %q", r.PostForm.Get("command")) return cmd, fmt.Errorf("Unknown command: %q", r.PostForm.Get("command"))
} }
for key, val := range r.PostForm { return buildCommand(cmd, r.PostForm), nil
if key == "args" {
cmd.Args = val[0]
} else if strings.HasPrefix(key, "flags[") {
name := key[6 : len(key)-1]
for i, f := range cmd.Flags {
if f.Name == name {
cmd.Flags[i].Value = val[0]
}
}
}
} }
return cmd, nil func buildCommand(cmd commands.Command, p url.Values) commands.Command {
cmd.Args = p.Get("args")
for i, f := range cmd.Flags {
cmd.Flags[i].Value = p.Get(fmt.Sprintf("flags[%s]", f.Name))
}
return cmd
} }