diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-02-18 16:59:01 +0100 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-02-18 17:00:51 +0100 |
commit | b4aaf603b0e221e3967606b9ad61af1cee6714b3 (patch) | |
tree | dfb2a1ad27b684fc3d0c9096ee899d7ca80088ec /commands.go | |
parent | Fix random crash on startup (diff) |
Recognize beginning of commands
allows to only type the beginning of a command, like "/t" for "/topic".
Diffstat (limited to 'commands.go')
-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 |