MCPcopy Create free account
hub / github.com/driangle/taskmd / findFilePathMatch

Function findFilePathMatch

apps/cli/internal/cli/get.go:205–233  ·  view source on GitHub ↗

findFilePathMatch tries to match the query against task file paths and filenames.

(query string, tasks []*model.Task)

Source from the content-addressed store, hash-verified

203
204// findFilePathMatch tries to match the query against task file paths and filenames.
205func findFilePathMatch(query string, tasks []*model.Task) (*model.Task, error) {
206 queryBase := filepath.Base(query)
207 queryNoExt := strings.TrimSuffix(queryBase, ".md")
208
209 var matches []*model.Task
210 for _, t := range tasks {
211 // Exact full path match — return immediately
212 if t.FilePath == query {
213 return t, nil
214 }
215
216 taskBase := filepath.Base(t.FilePath)
217 taskNoExt := strings.TrimSuffix(taskBase, ".md")
218
219 if taskBase == queryBase || taskNoExt == queryNoExt {
220 matches = append(matches, t)
221 }
222 }
223
224 switch len(matches) {
225 case 0:
226 return nil, nil
227 case 1:
228 return matches[0], nil
229 default:
230 return nil, fmt.Errorf("ambiguous filename %q matches multiple tasks: %s",
231 query, formatAmbiguousMatches(matches))
232 }
233}
234
235// formatAmbiguousMatches formats a list of tasks for an ambiguity error message.
236func formatAmbiguousMatches(tasks []*model.Task) string {

Callers 2

TestFindFilePathMatchFunction · 0.85
resolveTaskFunction · 0.85

Calls 1

formatAmbiguousMatchesFunction · 0.85

Tested by 1

TestFindFilePathMatchFunction · 0.68