runner

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package runner provides a generic subprocess runner for acli. It handles timeout, signal forwarding, zombie cleanup, and both passthrough (interactive) and capture (parseable) execution modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunPassThrough

func RunPassThrough(ctx context.Context, binary string, args []string) error

RunPassThrough is a shorthand for Run with PassThrough=true. Returns only the error.

func RunWith

func RunWith(ctx context.Context, binary string, opts Options) error

RunWith runs a command with full Options and returns only the error, discarding the Result. Prefer this over Run when output is streamed via PassThrough and the Result is not needed.

Types

type Options

type Options struct {
	// Args are the arguments passed to the binary (not including the binary itself).
	Args []string

	// Env variables merged on top of the current process environment.
	// Format: "KEY=VALUE"
	Env []string

	// Stdin is forwarded to the child process stdin. If nil, os.Stdin is used
	// only in PassThrough mode; otherwise /dev/null is used.
	Stdin io.Reader

	// PassThrough streams the child stdout/stderr directly to the terminal
	// instead of capturing them. Use for interactive commands (adb shell,
	// emulator, gradlew with live output).
	PassThrough bool

	// Timeout for the process. Zero means no timeout.
	Timeout time.Duration

	// WorkDir sets the working directory. Defaults to the current directory.
	WorkDir string
}

Options configures how a subprocess is run.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
}

Result holds the output of a captured (non-passthrough) run.

func Run

func Run(ctx context.Context, binary string, opts Options) (*Result, error)

Run executes binary with opts. In passthrough mode, stdout/stderr stream directly to the terminal and Result.Stdout/Stderr will be empty.

func RunCapture

func RunCapture(ctx context.Context, binary string, args []string) (*Result, error)

RunCapture is a shorthand for Run with PassThrough=false.

func RunWithStdin

func RunWithStdin(ctx context.Context, binary string, args []string, stdin io.Reader) (*Result, error)

RunWithStdin runs a command with the given stdin reader (captured mode).

Jump to

Keyboard shortcuts

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