Documentation
¶
Overview ¶
Package command provides a simple facade for running shell commands synchronously.
Use this package when executing external programs with control over input, working directory, environment, and output limits. It captures combined output and supports timeouts through context cancellation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMaxOutputSizeExceeded = errors.New("maximum output size exceeded")
ErrMaxOutputSizeExceeded is returned when the output exceeds the maximum size limit.
Functions ¶
func Run ¶
Run executes a command synchronously and waits for it to complete. The combined stdout and stderr output is stored in memory and returned. Use WithMaxOutputSize to limit the amount of output stored. It returns an error if the command fails to start or returns a non-zero exit code.
Types ¶
type Option ¶
type Option func(cmdOpts *commandOptions)
Option is used to configure command execution.
func WithDir ¶
WithDir sets the working directory for the command. If empty, the command runs in the calling process's current directory.
func WithEnv ¶
WithEnv sets the environment variables for the command. Each entry should be in the form "key=value". If nil, the new process uses the current process's environment.
func WithExtraEnv ¶
WithExtraEnv appends additional environment variables to the current process's environment. Each entry should be in the form "key=value".
func WithMaxOutputSize ¶ added in v0.1.1
WithMaxOutputSize sets the maximum size in bytes for the combined output buffer. If the output exceeds this limit, it will be truncated. If size is 0 or negative, the output buffer has no size limit.
func WithTimeout ¶
WithTimeout sets a timeout for the command execution. If the command does not complete within the specified duration, it will be terminated.