@@ -3,9 +3,18 @@ package cli
33import (
44 "fmt"
55
6- "github.com/antzucaro/matchr "
6+ "github.com/xrash/smetrics "
77)
88
9+ func jaroWinkler (a , b string ) float64 {
10+ // magic values are from https://github.com/xrash/smetrics/blob/039620a656736e6ad994090895784a7af15e0b80/jaro-winkler.go#L8
11+ const (
12+ boostThreshold = 0.7
13+ prefixSize = 4
14+ )
15+ return smetrics .JaroWinkler (a , b , boostThreshold , prefixSize )
16+ }
17+
918func suggestFlag (flags []Flag , provided string , hideHelp bool ) string {
1019 distance := 0.0
1120 suggestion := ""
@@ -16,7 +25,7 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string {
1625 flagNames = append (flagNames , HelpFlag .Names ()... )
1726 }
1827 for _ , name := range flagNames {
19- newDistance := matchr . JaroWinkler (name , provided , true )
28+ newDistance := jaroWinkler (name , provided )
2029 if newDistance > distance {
2130 distance = newDistance
2231 suggestion = name
@@ -39,7 +48,7 @@ func suggestCommand(commands []*Command, provided string) (suggestion string) {
3948 distance := 0.0
4049 for _ , command := range commands {
4150 for _ , name := range append (command .Names (), helpName , helpAlias ) {
42- newDistance := matchr . JaroWinkler (name , provided , true )
51+ newDistance := jaroWinkler (name , provided )
4352 if newDistance > distance {
4453 distance = newDistance
4554 suggestion = name
0 commit comments