execplus

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2017 License: MIT Imports: 12 Imported by: 6

README

go-execplus Build Status Go Report Card

An abstraction around os/exec.Cmd that allows you to:

  • wait for specific text to appear in the output
  • receive output chunks via a channel

Requires Go 1.7 or above.

See the tests for examples

Documentation

Index

Constants

View Source
const Version = "v0.9.2"

Version of package - based on Semantic Versioning 2.0.0 http://semver.org/

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdPlus

type CmdPlus struct {
	Cmd       *exec.Cmd
	StdinPipe io.WriteCloser
	// contains filtered or unexported fields
}

CmdPlus represents a more observable exec.Cmd command

func NewCmdPlus

func NewCmdPlus(commandWords ...string) *CmdPlus

NewCmdPlus is CmdPlus's constructor

func (*CmdPlus) AppendEnv added in v0.9.0

func (c *CmdPlus) AppendEnv(env []string)

AppendEnv sets the environment for the CmdPlus to the current process environment appended with the given environment

func (*CmdPlus) GetOutput

func (c *CmdPlus) GetOutput() string

GetOutput returns the output thus far

func (*CmdPlus) GetOutputChannel

func (c *CmdPlus) GetOutputChannel() (chan OutputChunk, func())

GetOutputChannel returns a channel that passes OutputChunk as they occur. It will immediately send an OutputChunk with an empty chunk and the full output thus far. It also returns a function that when called closes the channel

func (*CmdPlus) Kill

func (c *CmdPlus) Kill() error

Kill kills the CmdPlus if it is running

func (*CmdPlus) Run

func (c *CmdPlus) Run() error

Run is shorthand for Start() followed by Wait()

func (*CmdPlus) SetDir

func (c *CmdPlus) SetDir(dir string)

SetDir sets the directory that the CmdPlus should be run in

func (*CmdPlus) Start

func (c *CmdPlus) Start() error

Start runs the CmdPlus and returns an error if any

func (*CmdPlus) Wait

func (c *CmdPlus) Wait() error

Wait waits for the CmdPlus to finish, can only be called after Start()

func (*CmdPlus) WaitForCondition

func (c *CmdPlus) WaitForCondition(condition func(string, string) bool, duration time.Duration) error

WaitForCondition calls the given function with the latest chunk of output and the full output until it returns true returns an error if it does not match after the given duration

func (*CmdPlus) WaitForRegexp

func (c *CmdPlus) WaitForRegexp(isValid *regexp.Regexp, duration time.Duration) error

WaitForRegexp waits for the full output to match the given regex returns an error if it does not match after the given duration

func (*CmdPlus) WaitForText

func (c *CmdPlus) WaitForText(text string, duration time.Duration) error

WaitForText waits for the full output to contain the given text returns an error if it does not match after the given duration

type OutputChunk

type OutputChunk struct {
	Chunk string
	Full  string
}

OutputChunk represents a chunk of output for the CmdPlus

Jump to

Keyboard shortcuts

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