github.com/sercand/please@v13.4.0+incompatible/src/parse/suggest.go (about) 1 package parse 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/thought-machine/please/src/core" 8 "github.com/thought-machine/please/src/utils" 9 ) 10 11 // Max levenshtein distance that we'll suggest at. 12 const maxSuggestionDistance = 3 13 14 // suggestTargets suggests the targets in the given package that might be misspellings of 15 // the requested one. 16 func suggestTargets(pkg *core.Package, label, dependor core.BuildLabel) string { 17 // The initial haystack only contains target names 18 haystack := []string{} 19 for _, t := range pkg.AllTargets() { 20 haystack = append(haystack, fmt.Sprintf("//%s:%s", pkg.Name, t.Label.Name)) 21 } 22 msg := utils.PrettyPrintSuggestion(label.String(), haystack, maxSuggestionDistance) 23 if pkg.Name != dependor.PackageName { 24 return msg 25 } 26 // Use relative package labels where possible. 27 return strings.Replace(msg, "//"+pkg.Name+":", ":", -1) 28 }