diff --git a/cmd/devstream/list.go b/cmd/devstream/list.go index d048d17e5..87e8eab1e 100644 --- a/cmd/devstream/list.go +++ b/cmd/devstream/list.go @@ -9,6 +9,10 @@ import ( "github.com/devstream-io/devstream/pkg/util/log" ) +var ( + pluginFilter string +) + var listCMD = &cobra.Command{ Use: "list", Short: "This command lists all of the plugins", @@ -23,7 +27,7 @@ func listCMDFunc(cmd *cobra.Command, args []string) { log.Fatal(err) } - list.List() + list.List(pluginFilter) } func validateListCMDArgs(args []string) error { @@ -38,5 +42,7 @@ func validateListCMDArgs(args []string) error { return nil } -// TODO Use `--filter=someone` (can support regex) to filter plugins on feature, // TODO Use `--group=somegroup` to filter the specified groups on feature +func init() { + listCMD.PersistentFlags().StringVarP(&pluginFilter, "filter", "r", "", "filter plugin by regex") +} diff --git a/cmd/devstream/list/list.go b/cmd/devstream/list/list.go index 52f52e84d..49000ea44 100644 --- a/cmd/devstream/list/list.go +++ b/cmd/devstream/list/list.go @@ -2,6 +2,7 @@ package list import ( "fmt" + "regexp" "sort" "strings" ) @@ -14,11 +15,14 @@ import ( var PluginsName string // List all of plugins name -func List() { +func List(pluginFilter string) { listPluginsName := strings.Fields(PluginsName) + r, _ := regexp.Compile(pluginFilter) sort.Strings(listPluginsName) for _, pluginName := range listPluginsName { - fmt.Println(pluginName) + if r.Match([]byte(pluginName)) { + fmt.Println(pluginName) + } } }