mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 18:22:37 +02:00
add reflexion methods
This commit is contained in:
parent
eaabd033cc
commit
e847663931
1
go.mod
1
go.mod
@ -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
2
go.sum
@ -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=
|
||||||
|
@ -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) {
|
||||||
|
12
internal/piwigocli/reflexion.go
Normal file
12
internal/piwigocli/reflexion.go
Normal 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)
|
||||||
|
}
|
52
internal/piwigocli/reflexion_method_details.go
Normal file
52
internal/piwigocli/reflexion_method_details.go
Normal 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
|
||||||
|
}
|
46
internal/piwigocli/reflexion_method_list.go
Normal file
46
internal/piwigocli/reflexion_method_list.go
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user