Documentation
¶
Index ¶
- func SetSilent(s bool)
- type Result
- func (r Result) Code() int
- func (r Result) Error() error
- func (r Result) ErrorWith(msg string) error
- func (r Result) IsCode(code int) bool
- func (r Result) IsFailure() bool
- func (r Result) IsSuccess() bool
- func (r Result) Output() string
- func (r Result) String() string
- func (r Result) Unwrap() Result
- func (r Result) UnwrapWith(msg string, args ...any) Result
- type Shell
- func (s *Shell) Args() []string
- func (s *Shell) Cmd() *exec.Cmd
- func (s *Shell) Command() string
- func (s *Shell) Dir() string
- func (s *Shell) Envs() map[string]string
- func (s *Shell) Run() Result
- func (s *Shell) Stderr() io.Writer
- func (s *Shell) Stdin() io.Reader
- func (s *Shell) Stdout() io.Writer
- func (s *Shell) Timeout() time.Duration
- func (s *Shell) WithDir(dir string) *Shell
- func (s *Shell) WithEnv(key, value string) *Shell
- func (s *Shell) WithEnvs(envs map[string]string) *Shell
- func (s *Shell) WithStderr(stderr io.Writer) *Shell
- func (s *Shell) WithStdin(stdin io.Reader) *Shell
- func (s *Shell) WithStdout(stdout io.Writer) *Shell
- func (s *Shell) WithTimeout(timeout time.Duration) *Shell
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result holds the outcome of a shell command execution: its combined output, resulting error (if any), and exit code.
func NewResult ¶
NewResult builds a Result from a command's execution error, its combined stdout+stderr output, and its stderr-only output. If err is non-nil, it is replaced with an error wrapping errorOutput, and the exit code is extracted from err when it is an *exec.ExitError.
func (Result) ErrorWith ¶
ErrorWith returns the command's error prefixed with msg, or nil if the command succeeded.
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell describes a command to run, along with its working directory, environment, timeout, and I/O streams.
func New ¶
New creates a new Shell instance with stdin/stdout/stderr set up to os.Stdin, os.Stdout, and os.Stderr, respectively.
func (*Shell) Run ¶
Run executes the shell command and returns its combined output and any error that occurred during execution. If stdout or stderr is set, it will return an empty string for the output and the error from cmd.Run() instead.
func (*Shell) WithStderr ¶
WithStderr sets the standard error for the shell command.
func (*Shell) WithStdout ¶
WithStdout sets the standard output for the shell command.