MCPcopy
hub / github.com/filebrowser/filebrowser / SplitCommandAndArgs

Function SplitCommandAndArgs

runner/commands.go:34–58  ·  view source on GitHub ↗

SplitCommandAndArgs takes a command string and parses it shell-style into the command and its separate arguments.

(command string)

Source from the content-addressed store, hash-verified

32// SplitCommandAndArgs takes a command string and parses it shell-style into the
33// command and its separate arguments.
34func SplitCommandAndArgs(command string) (cmd string, args []string, err error) {
35 var parts []string
36
37 if runtimeGoos == osWindows {
38 parts = parseWindowsCommand(command) // parse it Windows-style
39 } else {
40 parts, err = parseUnixCommand(command) // parse it Unix-style
41 if err != nil {
42 err = errors.New("error parsing command: " + err.Error())
43 return
44 }
45 }
46
47 if len(parts) == 0 {
48 err = errors.New("no command contained in '" + command + "'")
49 return
50 }
51
52 cmd = parts[0]
53 if len(parts) > 1 {
54 args = parts[1:]
55 }
56
57 return
58}
59
60// parseUnixCommand parses a unix style command line and returns the
61// command and its arguments or an error

Callers 3

ParseCommandFunction · 0.85
TestSplitCommandAndArgsFunction · 0.85

Calls 3

parseWindowsCommandFunction · 0.85
parseUnixCommandFunction · 0.85
ErrorMethod · 0.80

Tested by 2

TestSplitCommandAndArgsFunction · 0.68