Documentation
¶
Overview ¶
Package cmdutil provides generic command execution utilities including running commands with timeouts, capturing output, and monitoring output line-by-line.
Index ¶
- Constants
- func ExecuteHook(ctx context.Context, hook HookConfig, dir string) error
- func GetDefaultShell() string
- func RunCommand(ctx context.Context, name string, args []string, dir string) error
- func RunCommandWithOutput(ctx context.Context, name string, args []string, dir string) ([]byte, error)
- func RunWithContext(ctx context.Context, name string, args []string, dir string) error
- func RunWithTimeout(name string, args []string, dir string, timeout time.Duration) error
- func StartCommand(ctx context.Context, name string, args []string, dir string) (*exec.Cmd, error)
- func StartCommandWithOutputMonitoring(ctx context.Context, name string, args []string, dir string, ...) (*exec.Cmd, error)
- type HookConfig
- type OutputLineHandler
Constants ¶
const ( ShellSh = "sh" ShellBash = "bash" ShellPwsh = "pwsh" ShellPowerShell = "powershell" ShellCmd = "cmd" ShellZsh = "zsh" )
Shell type constants for platform-specific shell detection.
const DefaultTimeout = 30 * time.Minute
DefaultTimeout is the default timeout for command execution.
Variables ¶
This section is empty.
Functions ¶
func ExecuteHook ¶
func ExecuteHook(ctx context.Context, hook HookConfig, dir string) error
ExecuteHook runs a lifecycle hook command with the specified shell.
func GetDefaultShell ¶
func GetDefaultShell() string
GetDefaultShell returns the default shell for the current platform.
func RunCommand ¶
RunCommand runs a command and waits for it to complete. stdout and stderr go to os.Stdout and os.Stderr.
func RunCommandWithOutput ¶
func RunCommandWithOutput(ctx context.Context, name string, args []string, dir string) ([]byte, error)
RunCommandWithOutput runs a command and returns its combined output. The command inherits environment variables from the parent process.
func RunWithContext ¶
RunWithContext runs a command with the given context for cancellation. The command inherits environment variables, stdout, stderr, and stdin from the parent process.
func RunWithTimeout ¶
RunWithTimeout runs a command with a timeout.
func StartCommand ¶
StartCommand starts a command without waiting for it to complete. Returns the started Cmd for the caller to manage.
func StartCommandWithOutputMonitoring ¶
func StartCommandWithOutputMonitoring(ctx context.Context, name string, args []string, dir string, handler OutputLineHandler) (*exec.Cmd, error)
StartCommandWithOutputMonitoring starts a command and calls handler for each line of output. Output is also written to os.Stdout/os.Stderr in real-time. The caller is responsible for calling cmd.Wait() on the returned Cmd.
Types ¶
type HookConfig ¶
type HookConfig struct {
Run string // Command to run
Shell string // Shell to use (bash, sh, pwsh, cmd, zsh) - auto-detected if empty
ContinueOnError bool // Don't fail on non-zero exit
Interactive bool // Pass through stdin
Env []string // Additional environment variables (KEY=VALUE format)
}
HookConfig defines a lifecycle hook to execute.
type OutputLineHandler ¶
type OutputLineHandler func(line string)
OutputLineHandler is a callback for processing output lines in real-time.