cmdutil

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cmdutil provides generic command execution utilities including running commands with timeouts, capturing output, and monitoring output line-by-line.

Index

Constants

View Source
const (
	ShellSh         = "sh"
	ShellBash       = "bash"
	ShellPwsh       = "pwsh"
	ShellPowerShell = "powershell"
	ShellCmd        = "cmd"
	ShellZsh        = "zsh"
)

Shell type constants for platform-specific shell detection.

View Source
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

func RunCommand(ctx context.Context, name string, args []string, dir string) error

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

func RunWithContext(ctx context.Context, name string, args []string, dir string) error

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

func RunWithTimeout(name string, args []string, dir string, timeout time.Duration) error

RunWithTimeout runs a command with a timeout.

func StartCommand

func StartCommand(ctx context.Context, name string, args []string, dir string) (*exec.Cmd, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL