From 325f38d0db52dc117a140e66516fe445da74a61c Mon Sep 17 00:00:00 2001 From: Alexandre GUIOT--VALENTIN Date: Sat, 18 May 2024 15:09:37 +0200 Subject: [PATCH] Allow multiple status in `pman ls --f` (#36) --- cmd/ls.go | 5 +++-- pkg/utils/utils.go | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/ls.go b/cmd/ls.go index 7dc2644..b2e5007 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "strings" "github.com/spf13/cobra" @@ -25,7 +26,7 @@ var lsCmd = &cobra.Command{ } if filterFlag != "" { fmt.Println("Filtering by status : ", filterFlag) - data = utils.FilterByStatus(data, filterFlag) + data = utils.FilterByStatuses(data, strings.Split(filterFlag, ",")) } if oldUI { return ui.RenderTable(data) @@ -36,6 +37,6 @@ var lsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(lsCmd) - lsCmd.Flags().String("f", "", "Filter projects by status. Usage : pman ls --f ") + lsCmd.Flags().String("f", "", "Filter projects by status. Usage : pman ls --f ") lsCmd.Flags().Bool("c", false, "list projects using the colorful table. Usage : pman ls --c") } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 670afdf..49e399b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -26,11 +26,13 @@ func TitleCase(s string) string { return c.String(s) } -func FilterByStatus(data map[string]string, status string) map[string]string { +func FilterByStatuses(data map[string]string, status []string) map[string]string { filteredData := make(map[string]string) for k, v := range data { - if v == status { - filteredData[k] = v + for _, s := range status { + if v == s { + filteredData[k] = v + } } } return filteredData