refactor shortcut code to be a little nicer

remotes/origin/persistence
Adam Veldhousen 2019-11-18 22:37:06 -06:00
parent 15667ca704
commit 547bec5eb7
Signed by: adam
GPG Key ID: 6DB29003C6DD1E4B
1 changed files with 6 additions and 5 deletions

View File

@ -25,7 +25,6 @@ func (c *CommandHandler) Handle(input string) (Command, error) {
rawArgs := strings.Fields(input) rawArgs := strings.Fields(input)
fragmentCount := len(rawArgs) fragmentCount := len(rawArgs)
farg := "*" farg := "*"
parameters := input
var shortcut string var shortcut string
@ -34,7 +33,6 @@ func (c *CommandHandler) Handle(input string) (Command, error) {
if fragmentCount > 1 { if fragmentCount > 1 {
shortcut = rawArgs[1] shortcut = rawArgs[1]
parameters = strings.Join(rawArgs[1:], " ")
} }
var updateShortcutParams string var updateShortcutParams string
@ -47,7 +45,7 @@ func (c *CommandHandler) Handle(input string) (Command, error) {
} }
} }
return c.getShortcut(farg, parameters, input), nil return c.getShortcut(farg, rawArgs...), nil
} }
func (c *CommandHandler) updateShortcut(action, shortcut, location string) (Command, error) { func (c *CommandHandler) updateShortcut(action, shortcut, location string) (Command, error) {
@ -85,12 +83,15 @@ func (c *CommandHandler) updateShortcut(action, shortcut, location string) (Comm
return command, nil return command, nil
} }
func (c *CommandHandler) getShortcut(key, parameter, rawInput string) Command { func (c *CommandHandler) getShortcut(key string, input ...string) Command {
location, ok := c.Shortcuts[key] location, ok := c.Shortcuts[key]
var parameter string
if !ok { if !ok {
location = DefaultSearchProvider location = DefaultSearchProvider
key = "*" key = "*"
parameter = rawInput parameter = strings.Join(input, " ")
} else {
parameter = strings.Join(input[1:], " ")
} }
if strings.Contains(location, "%s") { if strings.Contains(location, "%s") {