add reflexion methods

This commit is contained in:
Celogeek 2021-12-18 15:05:24 +01:00
parent eaabd033cc
commit e847663931
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
6 changed files with 117 additions and 4 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/celogeek/piwigo-cli
go 1.17 go 1.17
require ( require (
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/jedib0t/go-pretty/v6 v6.2.4 // indirect github.com/jedib0t/go-pretty/v6 v6.2.4 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect

2
go.sum
View File

@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E= github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
github.com/jedib0t/go-pretty/v6 v6.2.4 h1:wdaj2KHD2W+mz8JgJ/Q6L/T5dB7kyqEFI16eLq7GEmk= github.com/jedib0t/go-pretty/v6 v6.2.4 h1:wdaj2KHD2W+mz8JgJ/Q6L/T5dB7kyqEFI16eLq7GEmk=
github.com/jedib0t/go-pretty/v6 v6.2.4/go.mod h1:+nE9fyyHGil+PuISTCrp7avEdo6bqoMwqZnuiK2r2a0= github.com/jedib0t/go-pretty/v6 v6.2.4/go.mod h1:+nE9fyyHGil+PuISTCrp7avEdo6bqoMwqZnuiK2r2a0=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=

View File

@ -14,10 +14,10 @@ type CategoriesListCommand struct {
} }
type Category struct { type Category struct {
Id int Id int `json:"id,string"`
Name string Name string `json:"name"`
FullName string FullName string `json:"fullname"`
ImagesCount int ImagesCount int `json:"nb_images,string"`
} }
func getInt(n interface{}) (r int) { func getInt(n interface{}) (r int) {

View File

@ -0,0 +1,12 @@
package piwigocli
type ReflexionGroup struct {
MethodList ReflexionMethodListCommand `command:"method-list" description:"List of available methods"`
MethodDetails ReflexionMethodDetailsCommand `command:"method-details" description:"Details of a method"`
}
var reflexionGroup ReflexionGroup
func init() {
parser.AddCommand("reflexion", "Reflexion management", "", &reflexionGroup)
}

View File

@ -0,0 +1,52 @@
package piwigocli
import (
"net/url"
"os"
"github.com/celogeek/piwigo-cli/internal/piwigo"
strip "github.com/grokify/html-strip-tags-go"
"github.com/jedib0t/go-pretty/v6/table"
)
type ReflexionMethodDetailsCommand struct {
MethodName string `short:"m" long:"method-name" description:"Method name to details"`
}
type ReflexionMethodDetailsResult struct {
Description string `json:"description"`
}
func (c *ReflexionMethodDetailsCommand) 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 ReflexionMethodDetailsResult
if err := p.Post("reflection.getMethodDetails", &url.Values{
"methodName": []string{c.MethodName},
}, &result); err != nil {
return err
}
desc := strip.StripTags(result.Description)
t := table.NewWriter()
t.AppendRow(table.Row{"Method", c.MethodName})
t.AppendSeparator()
t.AppendRow(table.Row{"Description", desc})
t.AppendSeparator()
t.AppendRow(table.Row{"Parameters"})
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight)
t.Render()
return nil
}

View File

@ -0,0 +1,46 @@
package piwigocli
import (
"os"
"github.com/celogeek/piwigo-cli/internal/piwigo"
"github.com/jedib0t/go-pretty/v6/table"
)
type ReflexionMethodListCommand struct{}
type ReflexionMethodListResult struct {
Methods []string `json:"methods"`
}
func (c *ReflexionMethodListCommand) 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 ReflexionMethodListResult
if err := p.Post("reflection.getMethodList", nil, &result); err != nil {
return err
}
t := table.NewWriter()
t.AppendHeader(table.Row{"Methods"})
for _, method := range result.Methods {
t.AppendRow(table.Row{
method,
})
}
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight)
t.Render()
return nil
}