From d7b13f16cadc0bcb7e91cc7e3b2aa75ec707a216 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Sun, 5 Mar 2023 13:15:04 -0800 Subject: [PATCH] feat: start now accepts multiple arguments --- cmd/start.go | 7 +++---- src/haunt/schema.go | 13 +++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 6d1863c..e453050 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -14,7 +14,7 @@ var startConfig config.Flags var startCmd = &cobra.Command{ Use: "start", Short: "Start haunt on a given path, generates a config file if one does not already exist", - Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs), + Args: cobra.MatchAll(cobra.OnlyValidArgs), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return getProjectNamesToStart(toComplete), cobra.ShellCompDirectiveNoFileComp }, @@ -72,10 +72,9 @@ func start(_ *cobra.Command, args []string) (err error) { if err != nil { return err } - if len(args) >= 1 && args[0] != "" { - name := args[0] + if len(args) >= 1 { // filter by name flag if exist - r.Projects = r.Filter("Name", name) + r.Projects = r.Filter(args) if len(r.Projects) == 0 { fmt.Println("Project not found, exiting") return diff --git a/src/haunt/schema.go b/src/haunt/schema.go index 9185220..cbd34df 100644 --- a/src/haunt/schema.go +++ b/src/haunt/schema.go @@ -70,16 +70,13 @@ func (s *Schema) New(flags config.Flags) Project { return project } -// Filter project list by field -func (s *Schema) Filter(field string, value interface{}) []Project { +// Filter project list by names +func (s *Schema) Filter(names []string) []Project { result := []Project{} for _, item := range s.Projects { - v := reflect.ValueOf(item) - for i := 0; i < v.NumField(); i++ { - if v.Type().Field(i).Name == field { - if reflect.DeepEqual(v.Field(i).Interface(), value) { - result = append(result, item) - } + for _, name := range names { + if item.Name == name { + result = append(result, item) } } }