mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 02:02:37 +02:00
find empty categories
This commit is contained in:
parent
da735d87ca
commit
28499d8dbd
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type CategoriesListCommand struct {
|
type CategoriesListCommand struct {
|
||||||
Filter string `short:"x" long:"filter" description:"Regexp filter"`
|
Filter string `short:"x" long:"filter" description:"Regexp filter"`
|
||||||
|
Empty bool `short:"e" long:"empty" description:"Find empty album without any photo or sub album"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CategoriesListCommand) Execute(args []string) error {
|
func (c *CategoriesListCommand) Execute(args []string) error {
|
||||||
@ -28,22 +29,27 @@ func (c *CategoriesListCommand) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
filter := regexp.MustCompile("")
|
var filter *regexp.Regexp
|
||||||
if c.Filter != "" {
|
if c.Filter != "" {
|
||||||
filter = regexp.MustCompile("(?i)" + c.Filter)
|
filter = regexp.MustCompile("(?i)" + c.Filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
|
t.AppendHeader(table.Row{"Id", "Name", "Images", "Total Images", "Url"})
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
if filter.MatchString(category.Name) {
|
if filter != nil && !filter.MatchString(category.Name) {
|
||||||
t.AppendRow(table.Row{
|
continue
|
||||||
category.Id,
|
|
||||||
category.Name,
|
|
||||||
category.ImagesCount,
|
|
||||||
category.Url,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
if c.Empty && category.TotalImagesCount != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t.AppendRow(table.Row{
|
||||||
|
category.Id,
|
||||||
|
category.Name,
|
||||||
|
category.ImagesCount,
|
||||||
|
category.TotalImagesCount,
|
||||||
|
category.Url,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
t.SetOutputMirror(os.Stdout)
|
t.SetOutputMirror(os.Stdout)
|
||||||
|
@ -3,10 +3,11 @@ package piwigotools
|
|||||||
type Categories []*Category
|
type Categories []*Category
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ImagesCount int `json:"nb_images"`
|
ImagesCount int `json:"nb_images"`
|
||||||
Url string `json:"url"`
|
TotalImagesCount int `json:"total_nb_images"`
|
||||||
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Categories) Names() []string {
|
func (c *Categories) Names() []string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user