mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-24 17:52:36 +02:00
find empty categories
This commit is contained in:
parent
da735d87ca
commit
28499d8dbd
@ -10,6 +10,7 @@ import (
|
||||
|
||||
type CategoriesListCommand struct {
|
||||
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 {
|
||||
@ -28,22 +29,27 @@ func (c *CategoriesListCommand) Execute(args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filter := regexp.MustCompile("")
|
||||
var filter *regexp.Regexp
|
||||
if c.Filter != "" {
|
||||
filter = regexp.MustCompile("(?i)" + c.Filter)
|
||||
}
|
||||
|
||||
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 {
|
||||
if filter.MatchString(category.Name) {
|
||||
t.AppendRow(table.Row{
|
||||
category.Id,
|
||||
category.Name,
|
||||
category.ImagesCount,
|
||||
category.Url,
|
||||
})
|
||||
if filter != nil && !filter.MatchString(category.Name) {
|
||||
continue
|
||||
}
|
||||
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)
|
||||
|
@ -3,10 +3,11 @@ package piwigotools
|
||||
type Categories []*Category
|
||||
|
||||
type Category struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ImagesCount int `json:"nb_images"`
|
||||
Url string `json:"url"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ImagesCount int `json:"nb_images"`
|
||||
TotalImagesCount int `json:"total_nb_images"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
func (c *Categories) Names() []string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user