Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dtm list enhancement #463

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/devstream/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +27,7 @@ func listCMDFunc(cmd *cobra.Command, args []string) {
log.Fatal(err)
}

list.List()
list.List(pluginFilter)
}

func validateListCMDArgs(args []string) error {
Expand All @@ -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")
}
8 changes: 6 additions & 2 deletions cmd/devstream/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package list

import (
"fmt"
"regexp"
"sort"
"strings"
)
Expand All @@ -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)
}
}
}

Expand Down