- had to add a Type field to interface DbEntry so that db.List()
is able to distinguish between Upload and Form properly.
- added form describe and delete commands
- added --query parameter to form+upload list for filtering
This commit is contained in:
2023-03-30 10:22:57 +02:00
parent 26f2b25e22
commit 8a791d8017
13 changed files with 208 additions and 40 deletions

View File

@@ -48,6 +48,7 @@ type Request struct {
type ListParams struct {
Apicontext string `json:"apicontext"`
Query string `json:"query"`
}
const Maxwidth = 12
@@ -216,7 +217,7 @@ func List(w io.Writer, c *cfg.Config, args []string, typ int) error {
rq = Setup(c, "/forms")
}
params := &ListParams{Apicontext: c.Apicontext}
params := &ListParams{Apicontext: c.Apicontext, Query: c.Query}
resp, err := rq.R.
SetBodyJsonMarshal(params).
Get(rq.Url)
@@ -239,9 +240,18 @@ func List(w io.Writer, c *cfg.Config, args []string, typ int) error {
return nil
}
func Delete(w io.Writer, c *cfg.Config, args []string) error {
func Delete(w io.Writer, c *cfg.Config, args []string, typ int) error {
for _, id := range args {
rq := Setup(c, "/uploads/"+id+"/")
var rq *Request
caption := "Upload"
switch typ {
case common.TypeUpload:
rq = Setup(c, "/uploads/"+id)
case common.TypeForm:
rq = Setup(c, "/forms/"+id)
caption = "Form"
}
resp, err := rq.R.Delete(rq.Url)
@@ -253,20 +263,27 @@ func Delete(w io.Writer, c *cfg.Config, args []string) error {
return err
}
fmt.Fprintf(w, "Upload %s successfully deleted.\n", id)
fmt.Fprintf(w, "%s %s successfully deleted.\n", caption, id)
}
return nil
}
func Describe(w io.Writer, c *cfg.Config, args []string) error {
func Describe(w io.Writer, c *cfg.Config, args []string, typ int) error {
if len(args) == 0 {
return errors.New("No id provided!")
}
var rq *Request
id := args[0] // we describe only 1 object
rq := Setup(c, "/uploads/"+id)
switch typ {
case common.TypeUpload:
rq = Setup(c, "/uploads/"+id)
case common.TypeForm:
rq = Setup(c, "/forms/"+id)
}
resp, err := rq.R.Get(rq.Url)
if err != nil {