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

Fixes multimatch query #1

Merged
merged 1 commit into from
Jan 23, 2019
Merged
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
20 changes: 17 additions & 3 deletions internal/config/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ func SearchProjects(query string, config Config) []Project {
return projects
}

func MatchProjects(query string, config Config) (project Project) {
for _, p := range config.Projects {
if p.Name == query {
project = p
}
}
return
}

func GetOneProject(query string, config Config) (project Project, err error) {
projects := SearchProjects(query, config)
numProjects := len(projects)
Expand All @@ -27,10 +36,15 @@ func GetOneProject(query string, config Config) (project Project, err error) {
err = errors.New("no match")
}
if numProjects > 1 {
for _, project := range projects {
fmt.Println(project.Name)
exactMatch := MatchProjects(query, config)
if exactMatch.Name == query {
project = exactMatch
} else {
for _, project := range projects {
fmt.Println(project.Name)
}
err = errors.New("multiple matches")
}
err = errors.New("multiple matches")
}
return
}