mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
add filter for categories
This commit is contained in:
parent
3ef95cd07b
commit
f55505babb
@ -3,12 +3,14 @@ package piwigocli
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"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 CategoriesListCommand struct {
|
type CategoriesListCommand struct {
|
||||||
|
Filter string `short:"x" long:"filter" description:"Regexp filter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetCategoriesListResponse struct {
|
type GetCategoriesListResponse struct {
|
||||||
@ -38,13 +40,19 @@ func (c *CategoriesListCommand) Execute(args []string) error {
|
|||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
|
|
||||||
t.AppendHeader(table.Row{"Id", "Name", "Images", "Url"})
|
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 {
|
for _, category := range resp.Categories {
|
||||||
t.AppendRow(table.Row{
|
if filter.MatchString(category.Name) {
|
||||||
category.Id,
|
t.AppendRow(table.Row{
|
||||||
category.Name,
|
category.Id,
|
||||||
category.ImagesCount,
|
category.Name,
|
||||||
category.Url,
|
category.ImagesCount,
|
||||||
})
|
category.Url,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.SetOutputMirror(os.Stdout)
|
t.SetOutputMirror(os.Stdout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user