command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package command provides a simple facade for running shell commands synchronously.

This package offers a straightforward way to execute shell commands with configurable options for stdout, stderr, stdin, working directory, and environment variables. It uses the options pattern for flexible configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, name string, args []string, opts ...Option) error

Run executes a command synchronously and waits for it to complete. It returns an error if the command fails to start or returns a non-zero exit code.

Types

type Option

type Option func(cmdOpts *commandOptions)

Option is used to configure command execution.

func WithDir

func WithDir(dir string) Option

WithDir sets the working directory for the command. If empty, the command runs in the calling process's current directory.

func WithEnv

func WithEnv(env []string) Option

WithEnv sets the environment variables for the command. Each entry should be in the form "key=value". If nil, the new process uses the current process's environment.

func WithExtraEnv

func WithExtraEnv(env ...string) Option

WithExtraEnv appends additional environment variables to the current process's environment. Each entry should be in the form "key=value".

func WithStderr

func WithStderr(w io.Writer) Option

WithStderr sets the writer for the command's standard error.

func WithStdin

func WithStdin(r io.Reader) Option

WithStdin sets the reader for the command's standard input.

func WithStdout

func WithStdout(w io.Writer) Option

WithStdout sets the writer for the command's standard output.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets a timeout for the command execution. If the command does not complete within the specified duration, it will be terminated.

Jump to

Keyboard shortcuts

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