Documentation
¶
Overview ¶
Package commandlineexecutor creates an interface to streamline execution of shell commands across multiple platforms
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandExists ¶
CommandExists returns whether or not an executable command exists within the current os runtime environment.
Types ¶
type Execute ¶
Execute is a function to execute a command. Production callers to pass commandlineexecutor.ExecuteCommand while calling this package's APIs.
type Exists ¶
Exists is a function to check if a command exists. Production callers to pass commandlineexecutor.CommandExists while calling this package's APIs.
type ExitCode ¶
ExitCode is a function to get the exit code from an error. Production callers to pass commandlineexecutor.CommandExitCode while calling this package's APIs.
type Params ¶
type Params struct { Executable string // One of ArgsToSplit or Args should be defined on the Params. // ArgsToSplit should be preferred when issuing commands with a subshell and using "-c". // An example would be an invocation like: // Executable: "/bin/sh" // ArgsToSplit: "-c 'ls /usr/sap/*/SYS/global/hdb/custom/config/global.ini'" // In this case ArgsToSplit will be split up correctly as: // []string{"-c", "'ls /usr/sap/*/SYS/global/hdb/custom/config/global.ini'"} ArgsToSplit string Args []string Timeout int // defaults to 60, so timeout will occur in 60 seconds User string Env []string }
Params encapsulates the parameters used by the Exec* and RunWithEnv funcs.
type Result ¶
type Result struct {
StdOut, StdErr string
ExitCode int
Error error
ExecutableFound bool
ExitStatusParsed bool // Will be true if "exit status ([0-9]+)" is in the error result
}
Result holds the stdout, stderr, exit code, and error from the execution.
func ExecuteCommand ¶
ExecuteCommand takes Params and returns a Result.
If the params.Executable does not exist it will return early with the Result.Error filled If the Params ArgsToSplit is not empty then it will be split into an arguments array Else the Args will be used as the arguments array If the User is not empty then the command will be executed as that user If Env is defined then that environment will be used to execute the command
The returned Result will contain the standard out, standard error, the exit code and an error if one was encountered during execution.