github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/util/spellcheck/spellcheck.go (about)

     1  package spellcheck
     2  
     3  import (
     4  	"github.com/sajari/fuzzy"
     5  )
     6  
     7  type CommandSuggester struct {
     8  	model *fuzzy.Model
     9  }
    10  
    11  func (s CommandSuggester) Recommend(cmd string) []string {
    12  	return s.model.Suggestions(cmd, true)
    13  }
    14  
    15  func NewCommandSuggester(existingCmds []string) CommandSuggester {
    16  	model := fuzzy.NewModel()
    17  	model.SetThreshold(1)
    18  	model.SetDepth(1)
    19  
    20  	model.Train(existingCmds)
    21  
    22  	return CommandSuggester{model: model}
    23  }