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
}
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{

View File

@ -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)