package script

import "github.com/amonks/run/internal/script"

Package script provides an immutable, reentrant wrapper around exec.Cmd for running bash scripts with robust cancellation.

A Script is a value type describing what to run. Each call to Start creates a fresh process; multiple Starts can run concurrently on the same Script.

On context cancellation, Start sends SIGINT to the process group, waits up to 2 seconds for a graceful exit, then sends SIGKILL.

Index

Types

type Script

type Script struct {
	Dir  string
	Env  []string
	Text string
}

Script describes a bash script to execute. It is an immutable value type: safe to copy, compare, and start multiple times concurrently.

func (Script) Start

func (s Script) Start(ctx context.Context, stdout, stderr io.Writer) error

Start executes the script in a new bash process and blocks until it completes or the context is canceled. It is safe to call Start multiple times, including concurrently.

stdout and stderr receive the script's respective output streams.

On context cancellation, Start sends SIGINT to the process group, waits up to 2 seconds, then sends SIGKILL. The returned error always includes context.Canceled when the context is canceled before the script completes.