mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 18:22:37 +02:00
56 lines
995 B
Go
56 lines
995 B
Go
package piwigocli
|
|
|
|
import (
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/celogeek/piwigo-cli/internal/piwigo"
|
|
"github.com/jedib0t/go-pretty/v6/table"
|
|
)
|
|
|
|
type CategoriesListCommand struct {
|
|
}
|
|
|
|
type GetCategoriesListResponse struct {
|
|
Categories piwigo.Categories `json:"categories"`
|
|
}
|
|
|
|
func (c *CategoriesListCommand) Execute(args []string) error {
|
|
p := piwigo.Piwigo{}
|
|
if err := p.LoadConfig(); err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err := p.Login()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var resp GetCategoriesListResponse
|
|
|
|
if err := p.Post("pwg.categories.getList", &url.Values{
|
|
"recursive": []string{"true"},
|
|
"fullname": []string{"true"},
|
|
}, &resp); err != nil {
|
|
return err
|
|
}
|
|
|
|
t := table.NewWriter()
|
|
|
|
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
|
|
for _, category := range resp.Categories {
|
|
t.AppendRow(table.Row{
|
|
category.Id,
|
|
category.Name,
|
|
category.ImagesCount,
|
|
category.Url,
|
|
})
|
|
}
|
|
|
|
t.SetOutputMirror(os.Stdout)
|
|
t.SetStyle(table.StyleLight)
|
|
t.Render()
|
|
|
|
return nil
|
|
}
|