mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-06-21 22:39:56 +02:00
add multi params with try
This commit is contained in:
parent
4e436b96d9
commit
ad8253ff18
@ -3,7 +3,7 @@ package piwigocli
|
|||||||
type MethodGroup struct {
|
type MethodGroup struct {
|
||||||
List MethodListCommand `command:"list" description:"List of available methods"`
|
List MethodListCommand `command:"list" description:"List of available methods"`
|
||||||
Details MethodDetailsCommand `command:"details" description:"Details of a method"`
|
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
|
var methodGroup MethodGroup
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package piwigocli
|
package piwigocli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MethodTryCommand struct {
|
type MethodTryCommand struct {
|
||||||
MethodName string `short:"m" long:"method-name" description:"Method name to test"`
|
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:","`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MethodTryCommand) Execute(args []string) error {
|
func (c *MethodTryCommand) Execute(args []string) error {
|
||||||
@ -23,13 +24,21 @@ func (c *MethodTryCommand) Execute(args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result map[string]interface{}
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
piwigo.DumpResponse(result)
|
piwigo.DumpResponse(result)
|
||||||
piwigo.DumpResponse(c.MethodParams)
|
piwigo.DumpResponse(params)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user