cmd

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package cmd implements a simple wrapper around "os/exec".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Command     string
	Arguments   []string
	Environment []string
	Stdin       io.Reader
	Stdout      io.Writer
	Stderr      io.Writer
}

Builder tracks the options set for a command.

func New

func New(command string) Builder

New creates a new command. Additional command options are added to the builder returned by New.

err := cmd.New("echo").
	WithArguments("Hello, World!").
	WithStdout(os.Stdout).
	Run()

func (Builder) Run

func (builder Builder) Run() error

Run runs a command.

func (Builder) RunWithContext

func (builder Builder) RunWithContext(ctx context.Context) error

RunWithContext runs a command with a context.

func (Builder) WithArguments

func (builder Builder) WithArguments(arguments ...string) Builder

WithArguments adds arguments to a command.

func (Builder) WithEnvironment

func (builder Builder) WithEnvironment(environment map[string]string) Builder

WithEnvironment adds environment variables to a command.

func (Builder) WithStderr

func (builder Builder) WithStderr(stderr io.Writer) Builder

WithStderr sets an io.Writer to retrieve the error output of the command.

func (Builder) WithStdin

func (builder Builder) WithStdin(stdin io.Reader) Builder

WithStdin sets an io.Reader to use as input to the command.

func (Builder) WithStdout

func (builder Builder) WithStdout(stdout io.Writer) Builder

WithStdout sets an io.Writer to retrieve the output of the command.

Jump to

Keyboard shortcuts

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