add try method

This commit is contained in:
Celogeek 2021-12-19 00:03:09 +01:00
parent d8e82a7c37
commit 4e436b96d9
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 36 additions and 0 deletions

View File

@ -3,6 +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"`
}
var methodGroup MethodGroup

View File

@ -0,0 +1,35 @@
package piwigocli
import (
"net/url"
"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:","`
}
func (c *MethodTryCommand) Execute(args []string) error {
p := piwigo.Piwigo{}
if err := p.LoadConfig(); err != nil {
return err
}
_, err := p.Login()
if err != nil {
return err
}
var result map[string]interface{}
if err := p.Post(c.MethodName, &c.MethodParams, &result); err != nil {
return err
}
piwigo.DumpResponse(result)
piwigo.DumpResponse(c.MethodParams)
return nil
}