Documentation
¶
Index ¶
- func Backoff(interval time.Duration) func() time.Duration
- func Cancel()
- func Command(cmd string, opts ...Option) (string, error)
- func Context() context.Context
- func HandleSignals()
- func PeriodicStackTraces(interval func() time.Duration)
- func SetContext(ctx context.Context)
- type Option
- func Args(args ...string) Option
- func Env(key, val string) Option
- func InDir(dir string) Option
- func LDFlags(flags ...string) Option
- func NoFail() Option
- func Options(options ...Option) Option
- func Quiet() Option
- func Stderr(w io.Writer) Option
- func Stdin(in io.Reader) Option
- func Stdout(w io.Writer) Option
- func Write(path string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cancel ¶
func Cancel()
Cancel cancels any currently executing scripts, which used the current context
func Command ¶
Command runs a command, waits until completion, and returns stdout. The first argument is the path to the binary and DOES NOT shell-split. When not captured, stderr is output to os.Stderr and returned as part of the error text.
func HandleSignals ¶ added in v0.1.0
func HandleSignals()
HandleSignals sets up a top-level signal handler that cancels the run context on the first interrupt and force-exits on the second.
func PeriodicStackTraces ¶ added in v0.1.0
func SetContext ¶ added in v0.1.0
SetContext sets the context to be used for executing scripts
Types ¶
type Option ¶
Option is a functional option that modifies command execution behavior. Options are applied in order before the command runs, allowing customization of arguments, environment, I/O streams, and error handling.
func Env ¶
Env adds an environment variable to the command's environment. Note that the command inherits the current process environment by default (minus GO* and CGO_* variables which are filtered to avoid conflicts).
func InDir ¶ added in v0.1.0
InDir executes the command in the specified directory. This is equivalent to running "cd dir && cmd" but without spawning a shell. The directory change only affects this command execution.
func LDFlags ¶ added in v0.1.0
LDFlags adds Go linker flags via the -ldflags argument. If -ldflags is already present in the command arguments, the new flags are appended to the existing value rather than replacing it. This allows multiple LDFlags() calls to accumulate.
Example:
Run(`go build ./cmd/app`,
run.LDFlags("-s", "-w"),
run.LDFlags("-X main.version=1.0.0"),
)
func NoFail ¶ added in v0.1.0
func NoFail() Option
NoFail prevents the command from panicking on failure. Instead of panicking, the error is logged at Debug level and an empty string is returned. Use this when command failure is expected or acceptable.
Example:
version := Run(`git describe --tags`, run.NoFail())
if version == "" {
version = "dev"
}
func Options ¶ added in v0.1.0
Options combines multiple Options into a single Option. This is useful for creating reusable option sets or conditionally including groups of options.
Example:
buildOpts := run.Options(run.Env("CGO_ENABLED", "0"), run.Quiet())
Run(`go build ./...`, buildOpts)
func Quiet ¶
func Quiet() Option
Quiet suppresses command output at Info level. The command line is logged at Debug level instead, and stderr is discarded unless config.Debug is enabled. Useful for commands whose output is only needed programmatically.
func Stderr ¶
Stderr redirects the command's stderr to the provided writer. By default, stderr is sent to os.Stderr. Use io.Discard to suppress error output.
func Stdin ¶
Stdin provides input to the command from the given reader. By default, stdin is not connected (nil). Use this for commands that read from standard input.