From f55505babb616e441eb6289ace117916c62a6857 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:21:48 +0100 Subject: [PATCH] add filter for categories --- internal/piwigocli/categories_list.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/piwigocli/categories_list.go b/internal/piwigocli/categories_list.go index de27231..7b0ee77 100644 --- a/internal/piwigocli/categories_list.go +++ b/internal/piwigocli/categories_list.go @@ -3,12 +3,14 @@ package piwigocli import ( "net/url" "os" + "regexp" "github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/jedib0t/go-pretty/v6/table" ) type CategoriesListCommand struct { + Filter string `short:"x" long:"filter" description:"Regexp filter"` } type GetCategoriesListResponse struct { @@ -38,13 +40,19 @@ func (c *CategoriesListCommand) Execute(args []string) error { t := table.NewWriter() t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"}) + filter := regexp.MustCompile("") + if c.Filter != "" { + filter = regexp.MustCompile("(?i)" + c.Filter) + } for _, category := range resp.Categories { - t.AppendRow(table.Row{ - category.Id, - category.Name, - category.ImagesCount, - category.Url, - }) + if filter.MatchString(category.Name) { + t.AppendRow(table.Row{ + category.Id, + category.Name, + category.ImagesCount, + category.Url, + }) + } } t.SetOutputMirror(os.Stdout)