diff --git a/cmd/piwigo-cli/categories_list.go b/cmd/piwigo-cli/categories_list.go index be2292a..040e43a 100644 --- a/cmd/piwigo-cli/categories_list.go +++ b/cmd/piwigo-cli/categories_list.go @@ -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) diff --git a/internal/piwigo/piwigotools/categories.go b/internal/piwigo/piwigotools/categories.go index de50e38..bf3ab70 100644 --- a/internal/piwigo/piwigotools/categories.go +++ b/internal/piwigo/piwigotools/categories.go @@ -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 {