Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseCommand ¶
ParseCommand parses the command taking in account if the current instance uses a shell to run the commands or just calls the binary directly.
func SplitCommandAndArgs ¶
SplitCommandAndArgs takes a command string and parses it shell-style into the command and its separate arguments.
Example ¶
var commandLine string
var command string
var args []string
// just for the test - change GOOS and reset it at the end of the test
runtimeGoos = osWindows
defer func() {
runtimeGoos = runtime.GOOS
}()
commandLine = `mkdir /P "C:\Program Files"`
command, args, _ = SplitCommandAndArgs(commandLine)
fmt.Printf("Windows: %s: %s [%s]\n", commandLine, command, strings.Join(args, ","))
// set GOOS to linux
runtimeGoos = osLinux
commandLine = `mkdir -p /path/with\ space`
command, args, _ = SplitCommandAndArgs(commandLine)
fmt.Printf("Linux: %s: %s [%s]\n", commandLine, command, strings.Join(args, ","))
Output: Windows: mkdir /P "C:\Program Files": mkdir [/P,C:\Program Files] Linux: mkdir -p /path/with\ space: mkdir [-p,/path/with space]
Types ¶
Click to show internal directories.
Click to hide internal directories.