@@ -22,8 +22,10 @@ import (
2222
2323 "utils"
2424
25+ "github.com/lithammer/fuzzysearch/fuzzy"
2526 guuid "github.com/satori/go.uuid"
2627 "github.com/simonleung8/flags"
28+ "sort"
2729)
2830
2931// The JavaPlugin is a cf cli plugin that supports taking heap and thread dumps on demand
@@ -412,7 +414,18 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
412414 for _ , command := range commands {
413415 avCommands = append (avCommands , command .Name )
414416 }
415- return "" , & InvalidUsageError {message : fmt .Sprintf ("Unrecognized command %q: supported commands are %s' (see cf help)" , commandName , strings .Join (avCommands , ", " ))}
417+ matches := fuzzy .RankFind (commandName , avCommands )
418+ sort .Sort (matches )
419+ matchedCommands := make ([]string , 0 , 3 )
420+ // first three matches
421+ for i := 0 ; i < 3 && i < len (matches ); i ++ {
422+ matchedCommands = append (matchedCommands , matches [i ].Target )
423+ }
424+ // concat with or at the end
425+ if len (matchedCommands ) > 1 {
426+ matchedCommands [len (matchedCommands )- 1 ] = "or " + matchedCommands [len (matchedCommands )- 1 ]
427+ }
428+ return "" , & InvalidUsageError {message : fmt .Sprintf ("Unrecognized command %q, did you mean: %s?" , commandName , strings .Join (matchedCommands , ", " ))}
416429 }
417430
418431 command := commands [index ]
0 commit comments