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

execz

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package execz builds on stdlib os/exec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(ctx context.Context, cmd *Cmd) (err error)

Exec executes cmd. It returns an error if cmd is nil.

Types

type Cmd

type Cmd struct {
	// Stdin is the command's stdin. If nil, [os.Stdin] is used.
	Stdin io.Reader

	// Stdout is the command's stdout. If nil, [os.Stdout] is used.
	Stdout io.Writer

	// Stderr is the command's stderr. If nil, [os.Stderr] is used.
	Stderr io.Writer

	// Name is the executable name, e.g. "pg_dump".
	Name string

	// Label is a human-readable label for the command, e.g. "@sakila: dump".
	// If empty, [Cmd.Name] is used.
	Label string

	// ErrPrefix is the prefix to use for error messages.
	ErrPrefix string

	// UsesOutputFile indicates that the command writes its output to this
	// filepath instead of stdout. If empty, stdout is being used.
	UsesOutputFile string

	// Args is the set of args to the command.
	Args []string

	// Env is the set of environment variables to set for the command.
	Env []string

	// NoProgress indicates that progress messages should not be output.
	NoProgress bool

	// ProgressFromStderr indicates that the command outputs progress messages
	// on stderr.
	ProgressFromStderr bool

	// CmdDirPath controls whether the command's PATH will include the parent dir
	// of the command. This allows the command to access sibling commands in the
	// same dir,  e.g. "pg_dumpall" needs to invoke "pg_dump".
	CmdDirPath bool
}

Cmd represents an external command being prepared or run.

func (*Cmd) LogValue

func (c *Cmd) LogValue() slog.Value

LogValue implements slog.LogValuer. It redacts sensitive information (passwords etc.) from URL-like values.

func (*Cmd) String

func (c *Cmd) String() string

String returns what command would look like if executed in a shell. Note that the returned string could contain sensitive information such as passwords, so it's not safe for logging. Instead, see Cmd.LogValue.

Jump to

Keyboard shortcuts

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