From c949e05425346b36da2aed0db13a2b777dca7d94 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 2 Jan 2020 12:30:44 +0100 Subject: [PATCH] Add additional documentation Signed-off-by: Sascha Grunert --- suggestions.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/suggestions.go b/suggestions.go index ca5e251adb..3e9d1a1fa9 100644 --- a/suggestions.go +++ b/suggestions.go @@ -31,6 +31,8 @@ func (a *App) suggestFlagFromError(err error, command string) (string, error) { return fmt.Sprintf(didYouMeanTemplate+"\n\n", suggestion), nil } +// suggestFlag takes a list of flags and a provided string to suggest a +// flag name by calculating the Jaro Winkler distance. func (a *App) suggestFlag(flags []Flag, provided string) (suggestion string) { distance := 0.0 @@ -40,6 +42,9 @@ func (a *App) suggestFlag(flags []Flag, provided string) (suggestion string) { flagNames = append(flagNames, HelpFlag.Names()...) } for _, name := range flagNames { + // JaroWinkler computes the Jaro-Winkler edit distance between two + // strings. This is a modification of the Jaro algorithm that gives + // additional weight to prefix matches. newDistance := matchr.JaroWinkler(name, provided, true) if newDistance > distance { distance = newDistance @@ -58,11 +63,14 @@ func (a *App) suggestFlag(flags []Flag, provided string) (suggestion string) { } // suggestCommand takes a list of commands and a provided string to suggest a -// command name +// command name by calculating the Jaro Winkler distance. func suggestCommand(commands []*Command, provided string) (suggestion string) { distance := 0.0 for _, command := range commands { for _, name := range append(command.Names(), helpName, helpAlias) { + // JaroWinkler computes the Jaro-Winkler edit distance between two + // strings. This is a modification of the Jaro algorithm that gives + // additional weight to prefix matches. newDistance := matchr.JaroWinkler(name, provided, true) if newDistance > distance { distance = newDistance