find empty categories

This commit is contained in:
Celogeek 2022-01-03 09:06:42 +01:00
parent da735d87ca
commit 28499d8dbd
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 20 additions and 13 deletions

View File

@ -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,23 +29,28 @@ 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) {
continue
}
if c.Empty && category.TotalImagesCount != 0 {
continue
}
t.AppendRow(table.Row{ t.AppendRow(table.Row{
category.Id, category.Id,
category.Name, category.Name,
category.ImagesCount, category.ImagesCount,
category.TotalImagesCount,
category.Url, category.Url,
}) })
} }
}
t.SetOutputMirror(os.Stdout) t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight) t.SetStyle(table.StyleLight)

View File

@ -6,6 +6,7 @@ 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"`
TotalImagesCount int `json:"total_nb_images"`
Url string `json:"url"` Url string `json:"url"`
} }