Prioritize shortcuts over commands [skip ci]

This commit is contained in:
Elara 2020-11-28 16:38:45 -08:00
parent fb89448324
commit 34208e4399

16
main.go
View File

@ -130,6 +130,14 @@ func main() {
distance = append(distance, JaroWinkler(command, args[0], 1, 0)) distance = append(distance, JaroWinkler(command, args[0], 1, 0))
} }
// Deals with shortcuts
for index, shortcut := range shortcuts {
// If the first argument is a shortcut and similarTo does not already contain its mapping, append it
if args[0] == shortcut && !Contains(similarTo, shortcutMappings[index]) {
similarTo = append(similarTo, shortcutMappings[index])
}
}
// Compares each distance to the max of the distance slice and appends the closest command to similarTo // Compares each distance to the max of the distance slice and appends the closest command to similarTo
for index, element := range distance { for index, element := range distance {
// If current element is the closest to the first argument // If current element is the closest to the first argument
@ -139,14 +147,6 @@ func main() {
} }
} }
// Deals with shortcuts
for index, shortcut := range shortcuts {
// If the first argument is a shortcut and similarTo does not already contain its mapping, append it
if args[0] == shortcut && !Contains(similarTo, shortcutMappings[index]) {
similarTo = append(similarTo, shortcutMappings[index])
}
}
// If similarTo is still empty, log it fatally as something is wrong with the config or the code // If similarTo is still empty, log it fatally as something is wrong with the config or the code
if len(similarTo) == 0 { log.Fatalln("This command does not match any known commands or shortcuts") } if len(similarTo) == 0 { log.Fatalln("This command does not match any known commands or shortcuts") }