From 4e436b96d97736aecbc27ac1fbb7744d197c31d8 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sun, 19 Dec 2021 00:03:09 +0100 Subject: [PATCH] add try method --- internal/piwigocli/method.go | 1 + internal/piwigocli/method_try.go | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 internal/piwigocli/method_try.go diff --git a/internal/piwigocli/method.go b/internal/piwigocli/method.go index be1ff1b..37ed616 100644 --- a/internal/piwigocli/method.go +++ b/internal/piwigocli/method.go @@ -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 diff --git a/internal/piwigocli/method_try.go b/internal/piwigocli/method_try.go new file mode 100644 index 0000000..d211de4 --- /dev/null +++ b/internal/piwigocli/method_try.go @@ -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 +}