MCPcopy Create free account
hub / github.com/driangle/taskmd / suggestValue

Function suggestValue

apps/cli/internal/cli/suggest.go:27–40  ·  view source on GitHub ↗

suggestValue finds the closest match from valid options using Levenshtein distance. Returns the closest match, or empty string if no reasonable match exists.

(input string, valid []string)

Source from the content-addressed store, hash-verified

25// suggestValue finds the closest match from valid options using Levenshtein distance.
26// Returns the closest match, or empty string if no reasonable match exists.
27func suggestValue(input string, valid []string) string {
28 input = strings.ToLower(input)
29 best := ""
30 bestDist := len(input)/2 + 1 // threshold: must be within half the input length
31
32 for _, v := range valid {
33 d := levenshtein(input, strings.ToLower(v))
34 if d < bestDist {
35 bestDist = d
36 best = v
37 }
38 }
39 return best
40}
41
42// invalidValueError creates an error message with an optional suggestion for the closest valid value.
43func invalidValueError(field, value string, valid []string) error {

Callers 2

invalidValueErrorFunction · 0.85
TestSuggestValueFunction · 0.85

Calls 1

levenshteinFunction · 0.85

Tested by 1

TestSuggestValueFunction · 0.68