exec

package
v0.0.0-...-ff55af6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package exec contains an interface for executing commands, along with helpers

Index

Constants

This section is empty.

Variables

View Source
var DefaultCmder = &LocalCmder{}

DefaultCmder is a LocalCmder instance used for convienience

Functions

func CombinedOutputLines

func CombinedOutputLines(cmd Cmd) (lines []string, err error)

CombinedOutputLines is like os/exec's cmd.CombinedOutput(), but over our Cmd interface, and instead of returning the byte buffer of stderr + stdout, it scans these for lines and returns a slice of output lines

func OutputLines

func OutputLines(cmd Cmd) (lines []string, err error)

OutputLines is like os/exec's cmd.Output(), but over our Cmd interface, and instead of returning the byte buffer of stdout, it scans these for lines and returns a slice of output lines

func RunLoggingOutputOnFail

func RunLoggingOutputOnFail(cmd Cmd) error

RunLoggingOutputOnFail runs the cmd, logging error output if Run returns an error

func RunWithStdinWriter

func RunWithStdinWriter(cmd Cmd, writerFunc func(io.Writer) error) error

RunWithStdinWriter runs cmd with writerFunc piped to stdin

func RunWithStdoutReader

func RunWithStdoutReader(cmd Cmd, readerFunc func(io.Reader) error) error

RunWithStdoutReader runs cmd with stdout piped to readerFunc

Types

type Cmd

type Cmd interface {
	Run() error
	// Each entry should be of the form "key=value"
	SetEnv(...string) Cmd
	SetStdin(io.Reader) Cmd
	SetStdout(io.Writer) Cmd
	SetStderr(io.Writer) Cmd
}

Cmd abstracts over running a command somewhere, this is useful for testing

func Command

func Command(command string, args ...string) Cmd

Command is a convience wrapper over DefaultCmder.Command

func InheritOutput

func InheritOutput(cmd Cmd) Cmd

InheritOutput sets cmd's output to write to the current process's stdout and stderr

type Cmder

type Cmder interface {
	// command, args..., just like os/exec.Cmd
	Command(string, ...string) Cmd
}

Cmder abstracts over creating commands

type LocalCmd

type LocalCmd struct {
	*osexec.Cmd
}

LocalCmd wraps os/exec.Cmd, implementing interface

func (*LocalCmd) Run

func (cmd *LocalCmd) Run() error

Run runs

func (*LocalCmd) SetEnv

func (cmd *LocalCmd) SetEnv(env ...string) Cmd

SetEnv sets env

func (*LocalCmd) SetStderr

func (cmd *LocalCmd) SetStderr(w io.Writer) Cmd

SetStderr sets stderr

func (*LocalCmd) SetStdin

func (cmd *LocalCmd) SetStdin(r io.Reader) Cmd

SetStdin sets stdin

func (*LocalCmd) SetStdout

func (cmd *LocalCmd) SetStdout(w io.Writer) Cmd

SetStdout set stdout

type LocalCmder

type LocalCmder struct{}

LocalCmder is a factory for LocalCmd, implementing Cmder

func (*LocalCmder) Command

func (c *LocalCmder) Command(name string, arg ...string) Cmd

Command returns a new exec.Cmd backed by Cmd

Jump to

Keyboard shortcuts

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