mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
28 lines
572 B
Go
28 lines
572 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"github.com/flynn/go-shlex"
|
||
|
)
|
||
|
|
||
|
// SplitCommandAndArgs takes a command string and parses it
|
||
|
// shell-style into the command and its separate arguments.
|
||
|
func SplitCommandAndArgs(command string) (cmd string, args []string, err error) {
|
||
|
parts, err := shlex.Split(command)
|
||
|
if err != nil {
|
||
|
err = errors.New("Error parsing command: " + err.Error())
|
||
|
return
|
||
|
} else if len(parts) == 0 {
|
||
|
err = errors.New("No command contained in '" + command + "'")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
cmd = parts[0]
|
||
|
if len(parts) > 1 {
|
||
|
args = parts[1:]
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|