diff options
-rw-r--r-- | commands.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/commands.go b/commands.go index 253b0d4..993698d 100644 --- a/commands.go +++ b/commands.go @@ -71,7 +71,7 @@ func init() { Desc: "send raw protocol data", Handle: commandDoQuote, }, - "R": { + "REPLY": { AllowHome: true, MinArgs: 1, Usage: "<message>", @@ -314,11 +314,27 @@ func parseCommand(s string) (command, args string) { func (app *App) handleInput(buffer, content string) error { cmdName, rawArgs := parseCommand(content) - cmd, ok := commands[cmdName] + var chosenCMDName string + var ok bool + for key := range commands { + if cmdName == "" && key != "" { + continue + } + if !strings.HasPrefix(key, cmdName) { + continue + } + if ok { + return fmt.Errorf("ambiguous command %q (could mean %v or %v)", cmdName, chosenCMDName, key) + } + chosenCMDName = key + ok = true + } if !ok { return fmt.Errorf("command %q doesn't exist", cmdName) } + cmd := commands[chosenCMDName] + var args []string if rawArgs == "" { args = nil |