MCPcopy
hub / github.com/go-task/task / FindMatchingTasks

Method FindMatchingTasks

task.go:478–518  ·  view source on GitHub ↗

FindMatchingTasks returns a list of tasks that match the given call. A task matches a call if its name is equal to the call's task name, or one of aliases, or if it matches a wildcard pattern. The function returns a list of MatchingTask structs, each containing a task and a list of wildcards that we

(call *Call)

Source from the content-addressed store, hash-verified

476// containing a task and a list of wildcards that were matched.
477// If multiple tasks match due to aliases, a TaskNameConflictError is returned.
478func (e *Executor) FindMatchingTasks(call *Call) ([]*MatchingTask, error) {
479 if call == nil {
480 return nil, nil
481 }
482 var matchingTasks []*MatchingTask
483 // If there is a direct match, return it
484 if task, ok := e.Taskfile.Tasks.Get(call.Task); ok {
485 matchingTasks = append(matchingTasks, &MatchingTask{Task: task, Wildcards: nil})
486 return matchingTasks, nil
487 }
488 var aliasedTasks []string
489 for task := range e.Taskfile.Tasks.Values(nil) {
490 if slices.Contains(task.Aliases, call.Task) {
491 aliasedTasks = append(aliasedTasks, task.Task)
492 matchingTasks = append(matchingTasks, &MatchingTask{Task: task, Wildcards: nil})
493 }
494 }
495
496 if len(aliasedTasks) == 1 {
497 return matchingTasks, nil
498 }
499
500 // If we found multiple tasks
501 if len(aliasedTasks) > 1 {
502 return nil, &errors.TaskNameConflictError{
503 Call: call.Task,
504 TaskNames: aliasedTasks,
505 }
506 }
507
508 // Attempt a wildcard match
509 for _, value := range e.Taskfile.Tasks.All(nil) {
510 if match, wildcards := value.WildcardMatch(call.Task); match {
511 matchingTasks = append(matchingTasks, &MatchingTask{
512 Task: value,
513 Wildcards: wildcards,
514 })
515 }
516 }
517 return matchingTasks, nil
518}
519
520// GetTask will return the task with the name matching the given call from the taskfile.
521// If no task is found, it will search for tasks with a matching alias.

Callers 1

GetTaskMethod · 0.95

Calls 4

WildcardMatchMethod · 0.80
GetMethod · 0.45
ValuesMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected