mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
add reflexion method details
This commit is contained in:
parent
e847663931
commit
ff4f5e99f9
@ -1,6 +1,8 @@
|
||||
package piwigocli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
@ -13,8 +15,40 @@ type ReflexionMethodDetailsCommand struct {
|
||||
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 {
|
||||
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 {
|
||||
@ -36,17 +70,38 @@ func (c *ReflexionMethodDetailsCommand) Execute(args []string) error {
|
||||
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()
|
||||
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()
|
||||
if len(result.Parameters) > 0 {
|
||||
fmt.Println("Parameters:")
|
||||
t2 := table.NewWriter()
|
||||
t2.AppendHeader(table.Row{"Name", "Type", "Optional", "Accept Array", "Default", "Max", "Info"})
|
||||
t2.AppendSeparator()
|
||||
for _, param := range result.Parameters {
|
||||
t2.AppendRow(table.Row{
|
||||
param.Name,
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user