Skip to content

Commit

Permalink
Allow multiple status in pman ls --f (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandregv authored May 18, 2024
1 parent d36532d commit 325f38d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"

Expand All @@ -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)
Expand All @@ -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 <status>")
lsCmd.Flags().String("f", "", "Filter projects by status. Usage : pman ls --f <status1[,status2]>")
lsCmd.Flags().Bool("c", false, "list projects using the colorful table. Usage : pman ls --c")
}
8 changes: 5 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 325f38d

Please sign in to comment.