filter method list

This commit is contained in:
Celogeek 2021-12-23 19:36:48 +01:00
parent 9f3d9a0f0c
commit 91c2e5b85a
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 17 additions and 8 deletions

View File

@ -37,13 +37,13 @@ func (c *CategoriesListCommand) Execute(args []string) error {
return err return err
} }
t := table.NewWriter()
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
filter := regexp.MustCompile("") filter := regexp.MustCompile("")
if c.Filter != "" { if c.Filter != "" {
filter = regexp.MustCompile("(?i)" + c.Filter) filter = regexp.MustCompile("(?i)" + c.Filter)
} }
t := table.NewWriter()
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
for _, category := range resp.Categories { for _, category := range resp.Categories {
if filter.MatchString(category.Name) { if filter.MatchString(category.Name) {
t.AppendRow(table.Row{ t.AppendRow(table.Row{

View File

@ -2,12 +2,15 @@ package piwigocli
import ( import (
"os" "os"
"regexp"
"github.com/celogeek/piwigo-cli/internal/piwigo" "github.com/celogeek/piwigo-cli/internal/piwigo"
"github.com/jedib0t/go-pretty/v6/table" "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 { type MethodListResult struct {
Methods piwigo.Methods `json:"methods"` Methods piwigo.Methods `json:"methods"`
@ -30,14 +33,20 @@ func (c *MethodListCommand) Execute(args []string) error {
return err 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"}) t.AppendHeader(table.Row{"Methods"})
for _, method := range result.Methods { for _, method := range result.Methods {
if filter.MatchString(method) {
t.AppendRow(table.Row{ t.AppendRow(table.Row{
method, method,
}) })
} }
}
t.SetOutputMirror(os.Stdout) t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight) t.SetStyle(table.StyleLight)
t.Render() t.Render()