Compare commits

..

2 Commits

Author SHA1 Message Date
6a389be6a7
Add helper to split the command and arguments
All checks were successful
continuous-integration/drone/push Build is passing
2022-09-01 09:26:23 -05:00
35c72daff4
Trim spaces 2022-09-01 09:25:59 -05:00

View File

@ -51,6 +51,9 @@ func BuildURI(rawuri, rawpath string) string {
} }
func HasCommand(s, prefix, cmd string) bool { func HasCommand(s, prefix, cmd string) bool {
s = strings.TrimSpace(s)
// a command cannot be less than two characters e.g. !x
if len(s) < 2 { if len(s) < 2 {
return false return false
} }
@ -65,3 +68,21 @@ func HasCommand(s, prefix, cmd string) bool {
return false return false
} }
func SplitCommandAndArgs(s, prefix string) (cmd string, args []string) {
s = strings.TrimSpace(s)
x := strings.Split(s, " ")
if len(x) > 1 {
args = x[1:]
}
cmd = x[0]
if strings.Index(s, prefix) == 0 {
cmd = cmd[len(prefix):]
}
return cmd, args
}