Add helper to split the command and arguments
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ryan Cavicchioni 2022-09-01 09:26:10 -05:00
parent 35c72daff4
commit 6a389be6a7
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -68,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
}