Skip to content

Commit

Permalink
Improve: Add partial match for use command (#40)
Browse files Browse the repository at this point in the history
- If the complete match does not work, then add a partial match logic when the 'use' command is used.
  • Loading branch information
raymondmars committed Apr 25, 2022
1 parent 4dd2672 commit 214c267
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions internal/actions/use.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package actions

import (
"sort"
"strings"

"github.com/TimothyYe/skm/internal/utils"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"gopkg.in/urfave/cli.v1"
"sort"
)

func Use(c *cli.Context) error {
Expand Down Expand Up @@ -46,11 +48,25 @@ func Use(c *cli.Context) error {
alias = result
}

// complete match key
_, ok := keyMap[alias]

if !ok {
color.Red("Key alias: %s doesn't exist!", alias)
return nil
// partial match key
canPartialMatch := false

for k, _ := range keyMap {
if strings.Index(k, alias) >= 0 {
alias = k
canPartialMatch = true
break
}
}

if !canPartialMatch {
color.Red("Key alias: %s doesn't exist!", alias)
return nil
}
}

// Set key with related alias as default used key
Expand Down

0 comments on commit 214c267

Please sign in to comment.