Prioritize shortcuts over commands [skip ci]
This commit is contained in:
parent
fb89448324
commit
34208e4399
16
main.go
16
main.go
@ -130,6 +130,14 @@ func main() {
|
||||
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
|
||||
for index, element := range distance {
|
||||
// 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 len(similarTo) == 0 { log.Fatalln("This command does not match any known commands or shortcuts") }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user