Documentation ¶
Overview ¶
Package exec provides command execution related helpers and utilities.
Index ¶
- Variables
- func RunAttachedCommand(name string, opts ...CommandOption) error
- func RunAttachedCommandContext(ctx context.Context, name string, opts ...CommandOption) error
- func RunCommand(name string, opts ...CommandOption) error
- func RunCommandCombinedOutput(name string, opts ...CommandOption) (string, error)
- func RunCommandContext(ctx context.Context, name string, opts ...CommandOption) error
- func RunCommandContextCombinedOutput(ctx context.Context, name string, opts ...CommandOption) (string, error)
- func RunCommandContextOutput(ctx context.Context, name string, opts ...CommandOption) (string, error)
- func RunCommandContextSplitOutput(ctx context.Context, name string, opts ...CommandOption) (string, string, error)
- func RunCommandOutput(name string, opts ...CommandOption) (string, error)
- func RunCommandSplitOutput(name string, opts ...CommandOption) (string, string, error)
- func RunSilentCommand(name string, opts ...CommandOption) error
- func RunSilentCommandContext(ctx context.Context, name string, opts ...CommandOption) error
- type CommandOption
- func CommandOptions(opts ...CommandOption) CommandOption
- func WithArgs(args ...string) CommandOption
- func WithAttachedPipes() CommandOption
- func WithDir(dir string) CommandOption
- func WithEnv(env []string) CommandOption
- func WithNopPipes() CommandOption
- func WithStderr(w io.Writer) CommandOption
- func WithStdin(r io.Reader) CommandOption
- func WithStdout(w io.Writer) CommandOption
- type Error
- type ExitError
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = exec.ErrNotFound
ErrNotFound re-exports exec.ErrNotFound for convenience.
Functions ¶
func RunAttachedCommand ¶
func RunAttachedCommand(name string, opts ...CommandOption) error
RunAttachedCommand is a convenience alias for RunCommand where WithAttachedPipes is appended to the provided options.
func RunAttachedCommandContext ¶
func RunAttachedCommandContext( ctx context.Context, name string, opts ...CommandOption, ) error
RunAttachedCommandContext is a convenience alias for RunCommandContext where WithAttachedPipes is appended to the provided options. If the given context is done before the command returns, the command will be killed.
func RunCommand ¶
func RunCommand(name string, opts ...CommandOption) error
RunCommand runs the given program or executable with the given options.
func RunCommandCombinedOutput ¶
func RunCommandCombinedOutput( name string, opts ...CommandOption, ) (string, error)
RunCommandCombinedOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error combined.
func RunCommandContext ¶
func RunCommandContext( ctx context.Context, name string, opts ...CommandOption, ) error
RunCommandContext runs the given program or executable with the given options. If the given context is done before the command returns, the command will be killed.
func RunCommandContextCombinedOutput ¶
func RunCommandContextCombinedOutput( ctx context.Context, name string, opts ...CommandOption, ) (string, error)
RunCommandContextCombinedOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error combined. If the given context is done before the command returns, the command will be killed.
func RunCommandContextOutput ¶
func RunCommandContextOutput( ctx context.Context, name string, opts ...CommandOption, ) (string, error)
RunCommandContextOutput calls RunCommand with the given name and options, and returns the command's standard output. If the given context is done before the command returns, the command will be killed.
func RunCommandContextSplitOutput ¶
func RunCommandContextSplitOutput( ctx context.Context, name string, opts ...CommandOption, ) (string, string, error)
RunCommandContextSplitOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error individually. If the given context is done before the command returns, the command will be killed.
func RunCommandOutput ¶
func RunCommandOutput(name string, opts ...CommandOption) (string, error)
RunCommandOutput calls RunCommand with the given name and options, and returns the command's standard output.
func RunCommandSplitOutput ¶
func RunCommandSplitOutput( name string, opts ...CommandOption, ) (string, string, error)
RunCommandSplitOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error individually.
func RunSilentCommand ¶
func RunSilentCommand(name string, opts ...CommandOption) error
RunSilentCommand is a convenience alias for RunCommand where WithNopPipes is appended to the provided options.
func RunSilentCommandContext ¶
func RunSilentCommandContext( ctx context.Context, name string, opts ...CommandOption, ) error
RunSilentCommandContext is a convenience alias for RunCommand where WithNopPipes is appended to the provided options. If the given context is done before the command returns, the command will be killed.
Types ¶
type CommandOption ¶
A CommandOption specializes the behavior of RunCommand and its variants.
func CommandOptions ¶
func CommandOptions(opts ...CommandOption) CommandOption
CommandOptions combines multiple CommandOption to specialize RunCommand and its variants.
func WithArgs ¶
func WithArgs(args ...string) CommandOption
WithArgs returns a new CommandOption that uses the given args as command arguments.
func WithAttachedPipes ¶
func WithAttachedPipes() CommandOption
WithAttachedPipes returns a new CommandOption that uses this program's standard output, standard error, and standard input.
func WithDir ¶
func WithDir(dir string) CommandOption
WithDir returns a new CommandOption that uses the given dir as as the working directory.
func WithEnv ¶
func WithEnv(env []string) CommandOption
WithEnv returns a new CommandOption that uses the given key=val pairs as the environment.
func WithNopPipes ¶
func WithNopPipes() CommandOption
WithNopPipes returns a new CommandOption that uses nop types for standard output, standard error, and standard input.
func WithStderr ¶
func WithStderr(w io.Writer) CommandOption
WithStderr returns a new CommandOption that uses w for standard error.
func WithStdin ¶
func WithStdin(r io.Reader) CommandOption
WithStdin returns a new CommandOption that uses w for standard input.
func WithStdout ¶
func WithStdout(w io.Writer) CommandOption
WithStdout returns a new CommandOption that uses w for standard output.
type ExitError ¶
ExitError re-exports exec.ExitError for convenience.