Help us shape the future of Go! Take the 2026 Go Developer Survey

shellrun

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package shellrun runs a POSIX shell script in-process (mvdan.cc/sh), so the same script behaves identically on every OS — including Windows, where no `sh` binary is on PATH. External programs the script invokes (npm, go, docker, ...) are resolved by the interpreter's default exec handler, which uses LookPathDir: PATH search plus PATHEXT on Windows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PortableCommands

func PortableCommands() map[string]CommandFunc

PortableCommands returns in-process grep and rg (minimal) implementations for scripts that must run where those tools are absent. Supported: -q -i -s -n -F -E -r -e PATTERN, --include/--exclude/ --exclude-dir, then FILE... (directories need -r). Without -E or -F a grep pattern is a POSIX basic regular expression, as GNU grep reads it.

func Run

func Run(ctx context.Context, script string, opts Options) error

Run parses and executes script. A non-zero exit yields an ExitError; context cancellation yields the context's error.

Types

type CommandFunc

type CommandFunc func(ctx context.Context, dir string, args []string, stdin io.Reader, stdout, stderr io.Writer) int

CommandFunc is an in-process command. args excludes the command name. Return an interp.ExitStatus-compatible error via ExitCode(n).

type ExitError

type ExitError struct{ Code int }

ExitError is returned when the script exits non-zero.

func (ExitError) Error

func (e ExitError) Error() string

type Options

type Options struct {
	// Dir is the working directory; empty inherits the process cwd.
	Dir string
	// Env overlays the process environment; overlay keys win.
	Env map[string]string
	// Stdout/Stderr default to io.Discard when nil.
	Stdout, Stderr io.Writer
	// Commands maps command names to in-process implementations that take
	// precedence over PATH lookup (e.g. a portable grep).
	Commands map[string]CommandFunc
}

Options configures one Run.

Jump to

Keyboard shortcuts

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