findFilePathMatch tries to match the query against task file paths and filenames.
(query string, tasks []*model.Task)
| 203 | |
| 204 | // findFilePathMatch tries to match the query against task file paths and filenames. |
| 205 | func 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. |
| 236 | func formatAmbiguousMatches(tasks []*model.Task) string { |