subproc

package
v0.199.12 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: BSD-2-Clause Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package subproc provides bounded-duration subprocess execution for short-lived read-only commands (git status, docker ps). Each call emits a warning to stderr after warnAfter and is cancelled at timeout.

Index

Constants

View Source
const (
	DefaultWarnAfter = 3 * time.Second
	DefaultTimeout   = 10 * time.Second
)

Default thresholds for RunWithWarnAndTimeout.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

type Runner interface {
	// RunWithWarnAndTimeout runs `name args...` bounded by the configured
	// warnAfter/timeout. On timeout it returns a non-nil error and the
	// caller should treat the operation as skipped.
	//
	// op is a human-readable operation label used in warn/skip messages
	// (e.g. "git status --porcelain").
	RunWithWarnAndTimeout(
		ctx context.Context,
		op string,
		name string,
		args ...string,
	) ([]byte, error)

	// RunWithWarnAndTimeoutDir is identical to RunWithWarnAndTimeout but sets
	// cmd.Dir = dir before running, preserving the working directory.
	RunWithWarnAndTimeoutDir(
		ctx context.Context,
		op string,
		dir string,
		name string,
		args ...string,
	) ([]byte, error)

	// RunWithWarnAndTimeoutEnv is identical to RunWithWarnAndTimeoutDir but also
	// appends extraEnv (each "KEY=VALUE") to the child's environment on top of
	// os.Environ(). Pass dir="" to inherit the current working directory and
	// extraEnv=nil for no extra env.
	RunWithWarnAndTimeoutEnv(
		ctx context.Context,
		op string,
		dir string,
		extraEnv []string,
		name string,
		args ...string,
	) ([]byte, error)
}

Runner runs short subprocesses with warn + timeout semantics.

func NewRunner

func NewRunner() Runner

NewRunner returns a Runner using the default 3s/10s thresholds.

func NewRunnerWithThresholds

func NewRunnerWithThresholds(warnAfter, timeout time.Duration) Runner

NewRunnerWithThresholds returns a Runner with custom thresholds (for tests).

Jump to

Keyboard shortcuts

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