1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

feat: suggest the most similar task name when a given task does not exist

This commit is contained in:
Max Pushkarov
2022-10-02 18:49:38 +03:00
parent d2061ec898
commit 3e5ee2332a
7 changed files with 48 additions and 6 deletions

11
task.go
View File

@@ -16,6 +16,7 @@ import (
"github.com/go-task/task/v3/internal/templater"
"github.com/go-task/task/v3/taskfile"
"github.com/sajari/fuzzy"
"golang.org/x/sync/errgroup"
)
@@ -51,7 +52,8 @@ type Executor struct {
Output output.Output
OutputStyle taskfile.Output
taskvars *taskfile.Vars
taskvars *taskfile.Vars
fuzzyModel *fuzzy.Model
concurrencySemaphore chan struct{}
taskCallCount map[string]*int32
@@ -68,7 +70,12 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
if !ok {
// FIXME: move to the main package
e.ListTasksWithDesc()
return &taskNotFoundError{taskName: c.Task}
didYouMean := ""
if e.fuzzyModel != nil {
didYouMean = e.fuzzyModel.SpellCheck(c.Task)
}
return &taskNotFoundError{taskName: c.Task, didYouMean: didYouMean}
}
if t.Internal {
e.ListTasksWithDesc()