Build command around description instead of form data
This commit is contained in:
parent
70c9b13a9a
commit
730aaa071a
|
@ -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[") {
|
func buildCommand(cmd commands.Command, p url.Values) commands.Command {
|
||||||
name := key[6 : len(key)-1]
|
cmd.Args = p.Get("args")
|
||||||
for i, f := range cmd.Flags {
|
for i, f := range cmd.Flags {
|
||||||
if f.Name == name {
|
cmd.Flags[i].Value = p.Get(fmt.Sprintf("flags[%s]", f.Name))
|
||||||
cmd.Flags[i].Value = val[0]
|
}
|
||||||
}
|
return cmd
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue