mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 18:22:37 +02:00
add reflexion method details
This commit is contained in:
parent
e847663931
commit
ff4f5e99f9
@ -1,6 +1,8 @@
|
|||||||
package piwigocli
|
package piwigocli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -13,8 +15,40 @@ type ReflexionMethodDetailsCommand struct {
|
|||||||
MethodName string `short:"m" long:"method-name" description:"Method name to details"`
|
MethodName string `short:"m" long:"method-name" description:"Method name to details"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ReflexionMethodDetailsParams struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Optional bool `json:"optional"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
AcceptArray bool `json:"acceptArray"`
|
||||||
|
DefaultValue interface{} `json:"defaultValue"`
|
||||||
|
MaxValue interface{} `json:"maxValue"`
|
||||||
|
Info string `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReflexionMethodDetailsOptions struct {
|
||||||
|
Admin bool `json:"admin_only"`
|
||||||
|
PostOnly bool `json:"post_only"`
|
||||||
|
}
|
||||||
|
|
||||||
type ReflexionMethodDetailsResult struct {
|
type ReflexionMethodDetailsResult struct {
|
||||||
Description string `json:"description"`
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Options ReflexionMethodDetailsOptions `json:"options"`
|
||||||
|
Parameters []ReflexionMethodDetailsParams `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *ReflexionMethodDetailsOptions) UnmarshalJSON(data []byte) error {
|
||||||
|
var r interface{}
|
||||||
|
if err := json.Unmarshal(data, &r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r := r.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
j.Admin, _ = r["admin_only"].(bool)
|
||||||
|
j.PostOnly, _ = r["post_only"].(bool)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ReflexionMethodDetailsCommand) Execute(args []string) error {
|
func (c *ReflexionMethodDetailsCommand) Execute(args []string) error {
|
||||||
@ -36,17 +70,38 @@ func (c *ReflexionMethodDetailsCommand) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
desc := strip.StripTags(result.Description)
|
t1 := table.NewWriter()
|
||||||
|
t1.AppendRow(table.Row{"Name", result.Name})
|
||||||
|
t1.AppendSeparator()
|
||||||
|
t1.AppendRow(table.Row{"Description", strip.StripTags(result.Description)})
|
||||||
|
t1.AppendRow(table.Row{"Admin", result.Options.Admin})
|
||||||
|
t1.AppendRow(table.Row{"Post Only", result.Options.PostOnly})
|
||||||
|
t1.SetOutputMirror(os.Stdout)
|
||||||
|
t1.SetStyle(table.StyleLight)
|
||||||
|
t1.Render()
|
||||||
|
|
||||||
t := table.NewWriter()
|
if len(result.Parameters) > 0 {
|
||||||
t.AppendRow(table.Row{"Method", c.MethodName})
|
fmt.Println("Parameters:")
|
||||||
t.AppendSeparator()
|
t2 := table.NewWriter()
|
||||||
t.AppendRow(table.Row{"Description", desc})
|
t2.AppendHeader(table.Row{"Name", "Type", "Optional", "Accept Array", "Default", "Max", "Info"})
|
||||||
t.AppendSeparator()
|
t2.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Parameters"})
|
for _, param := range result.Parameters {
|
||||||
t.SetOutputMirror(os.Stdout)
|
t2.AppendRow(table.Row{
|
||||||
t.SetStyle(table.StyleLight)
|
param.Name,
|
||||||
t.Render()
|
param.Type,
|
||||||
|
param.Optional,
|
||||||
|
param.AcceptArray,
|
||||||
|
fmt.Sprintf("%v", param.DefaultValue),
|
||||||
|
fmt.Sprintf("%v", param.MaxValue),
|
||||||
|
param.Info,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
t2.SetOutputMirror(os.Stdout)
|
||||||
|
t2.SetStyle(table.StyleLight)
|
||||||
|
t2.Style().Options.SeparateHeader = true
|
||||||
|
t2.Style().Options.DrawBorder = true
|
||||||
|
t2.Render()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user