mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
add try method
This commit is contained in:
parent
d8e82a7c37
commit
4e436b96d9
@ -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
|
||||
|
35
internal/piwigocli/method_try.go
Normal file
35
internal/piwigocli/method_try.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user