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) } } }