@@ -404,19 +404,40 @@ func (e *Executor) startExecution(ctx context.Context, t *ast.Task, execute func
404404}
405405
406406// FindMatchingTasks returns a list of tasks that match the given call. A task
407- // matches a call if its name is equal to the call's task name or if it matches
407+ // matches a call if its name is equal to the call's task name, or one of aliases, or if it matches
408408// a wildcard pattern. The function returns a list of MatchingTask structs, each
409409// containing a task and a list of wildcards that were matched.
410- func (e * Executor ) FindMatchingTasks (call * Call ) []* MatchingTask {
410+ // If multiple tasks match due to aliases, a TaskNameConflictError is returned.
411+ func (e * Executor ) FindMatchingTasks (call * Call ) ([]* MatchingTask , error ) {
411412 if call == nil {
412- return nil
413+ return nil , nil
413414 }
414415 var matchingTasks []* MatchingTask
415416 // If there is a direct match, return it
416417 if task , ok := e .Taskfile .Tasks .Get (call .Task ); ok {
417418 matchingTasks = append (matchingTasks , & MatchingTask {Task : task , Wildcards : nil })
418- return matchingTasks
419+ return matchingTasks , nil
420+ }
421+ var aliasedTasks []string
422+ for task := range e .Taskfile .Tasks .Values (nil ) {
423+ if slices .Contains (task .Aliases , call .Task ) {
424+ aliasedTasks = append (aliasedTasks , task .Task )
425+ matchingTasks = append (matchingTasks , & MatchingTask {Task : task , Wildcards : nil })
426+ }
419427 }
428+
429+ if len (aliasedTasks ) == 1 {
430+ return matchingTasks , nil
431+ }
432+
433+ // If we found multiple tasks
434+ if len (aliasedTasks ) > 1 {
435+ return nil , & errors.TaskNameConflictError {
436+ Call : call .Task ,
437+ TaskNames : aliasedTasks ,
438+ }
439+ }
440+
420441 // Attempt a wildcard match
421442 for _ , value := range e .Taskfile .Tasks .All (nil ) {
422443 if match , wildcards := value .WildcardMatch (call .Task ); match {
@@ -426,15 +447,19 @@ func (e *Executor) FindMatchingTasks(call *Call) []*MatchingTask {
426447 })
427448 }
428449 }
429- return matchingTasks
450+ return matchingTasks , nil
430451}
431452
432453// GetTask will return the task with the name matching the given call from the taskfile.
433454// If no task is found, it will search for tasks with a matching alias.
434455// If multiple tasks contain the same alias or no matches are found an error is returned.
435456func (e * Executor ) GetTask (call * Call ) (* ast.Task , error ) {
436457 // Search for a matching task
437- matchingTasks := e .FindMatchingTasks (call )
458+ matchingTasks , err := e .FindMatchingTasks (call )
459+ if err != nil {
460+ return nil , err
461+ }
462+
438463 if len (matchingTasks ) > 0 {
439464 if call .Vars == nil {
440465 call .Vars = ast .NewVars ()
@@ -443,37 +468,18 @@ func (e *Executor) GetTask(call *Call) (*ast.Task, error) {
443468 return matchingTasks [0 ].Task , nil
444469 }
445470
446- // If didn't find one, search for a task with a matching alias
447- var matchingTask * ast.Task
448- var aliasedTasks []string
449- for task := range e .Taskfile .Tasks .Values (nil ) {
450- if slices .Contains (task .Aliases , call .Task ) {
451- aliasedTasks = append (aliasedTasks , task .Task )
452- matchingTask = task
453- }
454- }
455- // If we found multiple tasks
456- if len (aliasedTasks ) > 1 {
457- return nil , & errors.TaskNameConflictError {
458- Call : call .Task ,
459- TaskNames : aliasedTasks ,
460- }
461- }
462471 // If we found no tasks
463- if len (aliasedTasks ) == 0 {
464- didYouMean := ""
465- if ! e .DisableFuzzy {
466- e .fuzzyModelOnce .Do (e .setupFuzzyModel )
467- if e .fuzzyModel != nil {
468- didYouMean = e .fuzzyModel .SpellCheck (call .Task )
469- }
470- }
471- return nil , & errors.TaskNotFoundError {
472- TaskName : call .Task ,
473- DidYouMean : didYouMean ,
472+ didYouMean := ""
473+ if ! e .DisableFuzzy {
474+ e .fuzzyModelOnce .Do (e .setupFuzzyModel )
475+ if e .fuzzyModel != nil {
476+ didYouMean = e .fuzzyModel .SpellCheck (call .Task )
474477 }
475478 }
476- return matchingTask , nil
479+ return nil , & errors.TaskNotFoundError {
480+ TaskName : call .Task ,
481+ DidYouMean : didYouMean ,
482+ }
477483}
478484
479485type FilterFunc func (task * ast.Task ) bool
0 commit comments