command

package
v0.0.0-...-3fb1d06 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package command provides functionality for working with programs the host OS. It provides a high level API over os/exec for running commands, which is easier to use for common cases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(ctx context.Context, name string, args ...string) error

Exec executes the named program with the given arguments. This is a shorthand for when the default command options wish to be used.

func Exists

func Exists(command string) bool

Exists checks if the command exists on the system by seeing if it's in the user's PATH.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command manages the configuration of a command that will be run in a child process.

func New

func New(opts ...Option) *Command

New creates a command instance from the given options.

func (*Command) Exec

func (c *Command) Exec(ctx context.Context, name string, args ...string) error

Exec executes the named program with the given arguments.

The provided context can be used to kill the process if the context becomes done before the program completes on its own.

type Option

type Option func(*Command)

Option is a function that takes a command and applies a configuration to it.

func WithDir

func WithDir(dir string) Option

WithDir sets the directory the command should be run in.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv sets the environment variables for the process the command will be run in.

func WithStderr

func WithStderr(stderr io.Writer) Option

WithStderr sets the writer that the command's stderr should be written to.

func WithStdin

func WithStdin(stdin io.Reader) Option

WithStdin sets the reader the the command's stdin should read from.

func WithStdout

func WithStdout(stdout io.Writer) Option

WithStdout sets the writer that the command's stdout should be written to.

Jump to

Keyboard shortcuts

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