Documentation ¶
Overview ¶
Package shellx helps to write shell-like Go code.
Index ¶
- Constants
- Variables
- func CopyFile(source, dest string, perms fs.FileMode) error
- func Output(logger logmodel.Logger, command string, args ...string) ([]byte, error)
- func OutputCommandLine(logger logmodel.Logger, cmdline string) ([]byte, error)
- func OutputCommandLineQuiet(cmdline string) ([]byte, error)
- func OutputEx(config *Config, argv *Argv, envp *Envp) ([]byte, error)
- func OutputQuiet(command string, args ...string) ([]byte, error)
- func QuotedCommandLineUnsafe(command string, args ...string) string
- func Run(logger logmodel.Logger, command string, args ...string) error
- func RunCommandLine(logger logmodel.Logger, cmdline string) error
- func RunCommandLineQuiet(cmdline string) error
- func RunEx(config *Config, argv *Argv, envp *Envp) error
- func RunQuiet(command string, args ...string) error
- type Argv
- type Config
- type Dependencies
- type Envp
- type StdlibDependencies
Constants ¶
const ( // FlagShowStdoutStderr enables connecting the child's stdout and stderr // to the current program's stdout and stderr. FlagShowStdoutStderr = 1 << iota )
Variables ¶
var ErrNoCommandToExecute = errors.New("shellx: no command to execute")
ErrNoCommandToExecute means that the command line is empty.
Functions ¶
func Output ¶ added in v3.17.0
Output is like OutputQuiet except that it logs the command to be executed and the environment variables specific to this command.
func OutputCommandLine ¶ added in v3.17.0
OutputCommandLine is like OutputCommandLineQuiet but logs the command to execute as well as the command-specific environment variables.
func OutputCommandLineQuiet ¶ added in v3.17.0
OutputCommandLineQuiet is like OutputQuiet but takes a command line as argument.
func OutputEx ¶ added in v3.17.0
OutputEx implements Output and OutputQuiet.
func OutputQuiet ¶ added in v3.17.0
OutputQuiet is like RunQuiet except that, in case of success, it captures the standard output and returns it to the caller.
func QuotedCommandLineUnsafe ¶ added in v3.19.0
QuotedCommandLineUnsafe returns a quoted command line. This function is unsafe and SHOULD only be used to produce a nice output.
func Run ¶
Run is like RunQuiet except that it also logs the command to exec, the environment variables specific to this command, the text logged to stdout and stderr.
func RunCommandLine ¶ added in v3.17.0
RunCommandLine is like RunCommandLineQuiet but logs the command to execute as well as the command-specific environment variables.
func RunCommandLineQuiet ¶ added in v3.17.0
RunCommandLineQuiet is like RunQuiet but takes a command line as argument.
Types ¶
type Argv ¶ added in v3.17.0
type Argv struct { // P is the MANDATORY program to execute. P string // V contains the OPTIONAL arguments. V []string }
Argv contains the complete argv.
func ParseCommandLine ¶ added in v3.17.0
ParseCommandLine creates an instance of Argv from the given command line.
type Config ¶ added in v3.17.0
type Config struct { // Logger is the OPTIONAL logger to use. Logger logmodel.Logger // Flags contains OPTIONAL binary flags to configure the program. Flags int64 }
Config contains config for executing programs.
type Dependencies ¶ added in v3.17.0
type Dependencies interface { // CmdOutput is equivalent to calling c.Output. CmdOutput(c *execabs.Cmd) ([]byte, error) // CmdRun is equivalent to calling c.Run. CmdRun(c *execabs.Cmd) error // LookPath is equivalent to calling execabs.LookPath. LookPath(file string) (string, error) }
Dependencies is the library on which this package depends.
var Library Dependencies = &StdlibDependencies{}
Library contains the default dependencies.
type Envp ¶ added in v3.17.0
type Envp struct { // V contains the OPTIONAL environment variables to add to the current // environment when we're executing commands. V []string }
Envp is the environment in which we execute commands.
type StdlibDependencies ¶ added in v3.17.0
type StdlibDependencies struct{}
StdlibDependencies contains the stdlib implementation of the Dependencies.
func (*StdlibDependencies) CmdOutput ¶ added in v3.17.0
func (*StdlibDependencies) CmdOutput(c *execabs.Cmd) ([]byte, error)
CmdOutput implements Dependencies.
func (*StdlibDependencies) CmdRun ¶ added in v3.17.0
func (*StdlibDependencies) CmdRun(c *execabs.Cmd) error
CmdRun implements Dependencies.
func (*StdlibDependencies) LookPath ¶ added in v3.17.0
func (*StdlibDependencies) LookPath(file string) (string, error)
LookPath implements Dependencies.
Directories ¶
Path | Synopsis |
---|---|
Package shellxtesting supports shellx testing.
|
Package shellxtesting supports shellx testing. |