mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-06-20 22:09:56 +02:00
add multi params with try
This commit is contained in:
parent
4e436b96d9
commit
ad8253ff18
internal/piwigocli
@ -3,7 +3,7 @@ package piwigocli
|
||||
type MethodGroup struct {
|
||||
List MethodListCommand `command:"list" description:"List of available methods"`
|
||||
Details MethodDetailsCommand `command:"details" description:"Details of a method"`
|
||||
Try MethodTryCommand `command:"try" description:"Test a method"`
|
||||
Try MethodTryCommand `command:"try" description:"Test a method. Parameters after the command as k=v, can be repeated like k=v1 k=v2."`
|
||||
}
|
||||
|
||||
var methodGroup MethodGroup
|
||||
|
@ -1,14 +1,15 @@
|
||||
package piwigocli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
||||
)
|
||||
|
||||
type MethodTryCommand struct {
|
||||
MethodName string `short:"m" long:"method-name" description:"Method name to test"`
|
||||
MethodParams url.Values `short:"p" long:"params" description:"Parameter for the method" env-delim:","`
|
||||
MethodName string `short:"m" long:"method-name" description:"Method name to test"`
|
||||
}
|
||||
|
||||
func (c *MethodTryCommand) Execute(args []string) error {
|
||||
@ -23,13 +24,21 @@ func (c *MethodTryCommand) Execute(args []string) error {
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
params := &url.Values{}
|
||||
for _, arg := range args {
|
||||
r := strings.SplitN(arg, "=", 2)
|
||||
if len(r) != 2 {
|
||||
return errors.New("args should be key=value")
|
||||
}
|
||||
params.Add(r[0], r[1])
|
||||
}
|
||||
|
||||
if err := p.Post(c.MethodName, &c.MethodParams, &result); err != nil {
|
||||
if err := p.Post(c.MethodName, params, &result); err != nil {
|
||||
piwigo.DumpResponse(params)
|
||||
return err
|
||||
}
|
||||
|
||||
piwigo.DumpResponse(result)
|
||||
piwigo.DumpResponse(c.MethodParams)
|
||||
|
||||
piwigo.DumpResponse(params)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user