1
0
mirror of https://github.com/go-task/task.git synced 2025-11-29 22:48:03 +02:00

Merge branch 'feat/suggest-similar-task'

This commit is contained in:
Andrey Nering
2022-10-14 20:08:00 -03:00
7 changed files with 51 additions and 5 deletions

View File

@@ -17,6 +17,8 @@ import (
"github.com/go-task/task/v3/internal/output"
"github.com/go-task/task/v3/taskfile"
"github.com/go-task/task/v3/taskfile/read"
"github.com/sajari/fuzzy"
)
func (e *Executor) Setup() error {
@@ -28,6 +30,8 @@ func (e *Executor) Setup() error {
return err
}
e.setupFuzzyModel()
v, err := e.Taskfile.ParsedVersion()
if err != nil {
return err
@@ -85,6 +89,25 @@ func (e *Executor) readTaskfile() error {
return err
}
func (e *Executor) setupFuzzyModel() {
if e.Taskfile != nil {
model := fuzzy.NewModel()
model.SetThreshold(1) // because we want to build grammar based on every task name
var words []string
for taskName := range e.Taskfile.Tasks {
words = append(words, taskName)
for _, task := range e.Taskfile.Tasks {
words = append(words, task.Aliases...)
}
}
model.Train(words)
e.fuzzyModel = model
}
}
func (e *Executor) setupTempDir() error {
if e.TempDir != "" {
return nil