From 91c2e5b85a4fd1db1b9cb2d9d537b74c3d7f08f4 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Thu, 23 Dec 2021 19:36:48 +0100 Subject: [PATCH] filter method list --- internal/piwigocli/categories_list.go | 6 +++--- internal/piwigocli/method_list.go | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/piwigocli/categories_list.go b/internal/piwigocli/categories_list.go index 7b0ee77..5214148 100644 --- a/internal/piwigocli/categories_list.go +++ b/internal/piwigocli/categories_list.go @@ -37,13 +37,13 @@ func (c *CategoriesListCommand) Execute(args []string) error { return err } - t := table.NewWriter() - - t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"}) filter := regexp.MustCompile("") if c.Filter != "" { filter = regexp.MustCompile("(?i)" + c.Filter) } + + t := table.NewWriter() + t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"}) for _, category := range resp.Categories { if filter.MatchString(category.Name) { t.AppendRow(table.Row{ diff --git a/internal/piwigocli/method_list.go b/internal/piwigocli/method_list.go index cee5695..cc16a30 100644 --- a/internal/piwigocli/method_list.go +++ b/internal/piwigocli/method_list.go @@ -2,12 +2,15 @@ package piwigocli import ( "os" + "regexp" "github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/jedib0t/go-pretty/v6/table" ) -type MethodListCommand struct{} +type MethodListCommand struct { + Filter string `short:"x" long:"filter" description:"Regexp filter"` +} type MethodListResult struct { Methods piwigo.Methods `json:"methods"` @@ -30,13 +33,19 @@ func (c *MethodListCommand) Execute(args []string) error { return err } - t := table.NewWriter() + filter := regexp.MustCompile("") + if c.Filter != "" { + filter = regexp.MustCompile("(?i)" + c.Filter) + } + t := table.NewWriter() t.AppendHeader(table.Row{"Methods"}) for _, method := range result.Methods { - t.AppendRow(table.Row{ - method, - }) + if filter.MatchString(method) { + t.AppendRow(table.Row{ + method, + }) + } } t.SetOutputMirror(os.Stdout) t.SetStyle(table.StyleLight)