Skip to content

Commit

Permalink
Add additional documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <mail@saschagrunert.de>
  • Loading branch information
saschagrunert committed Jan 2, 2020
1 parent 07b5809 commit c949e05
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion suggestions.go
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c949e05

Please sign in to comment.