From 6a389be6a777139330177746b35d376aef7a77b0 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 1 Sep 2022 09:26:10 -0500 Subject: [PATCH] Add helper to split the command and arguments --- lib/common.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/common.go b/lib/common.go index b6b82ae..6c9d824 100644 --- a/lib/common.go +++ b/lib/common.go @@ -68,3 +68,21 @@ func HasCommand(s, prefix, cmd string) bool { 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 +}