goexec

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 10 Imported by: 0

README

goexec

GoReport GoLang GoDoc License

Package goexec is a fluent decorator based API for os/exec.

Usage

go get -u github.com/brad-jones/goexec

package main

import (
	"github.com/brad-jones/goexec"
)

func main() {
	goexec.Run("ping", "-c", "4", "8.8.8.8")
}

Documentation

Overview

Package goexec is a fluent decorator based API for os/exec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(args ...string) func(*exec.Cmd) error

Args allows you to define the arguments sent to the command to be run

func Cmd

func Cmd(cmd string, decorators ...func(*exec.Cmd) error) (c *exec.Cmd, err error)

Cmd provides a fluent, decorator based API for os/exec.

Cmd("ping", Args("-c", "4", "1.1.1.1"))

func Cwd

func Cwd(dir string) func(*exec.Cmd) error

Cwd allows you to configure the working directory of the command to be run

func Env

func Env(env map[string]string) func(*exec.Cmd) error

Env allows you to set the exact environment in which the command will be run

func EnvCombined

func EnvCombined(env map[string]string) func(*exec.Cmd) error

EnvCombined will add the variables you provide to the existing environment

func MustCmd

func MustCmd(cmd string, decorators ...func(*exec.Cmd) error) *exec.Cmd

MustCmd does the same as Cmd but panics if an error is encountered.

func MustPipe

func MustPipe(cmds ...*exec.Cmd)

MustPipe does the same as Pipe but panics if an error is encountered.

func MustPipePrefixed

func MustPipePrefixed(prefix string, cmds ...*exec.Cmd)

MustPipePrefixed does the same as PipePrefixed but panics if an error is encountered.

func MustRun

func MustRun(cmd string, args ...string)

MustRun does the same as Run but panics if an error is encountered.

func MustRunPrefixed

func MustRunPrefixed(prefix, cmd string, args ...string)

MustRunPrefixed does the same as RunPrefixed but panics if an error is encountered.

func MustRunPrefixedCmd

func MustRunPrefixedCmd(prefix string, cmd *exec.Cmd)

MustRunPrefixedCmd does the same as RunPrefixedCmd but panics if an error is encountered.

func Pipe

func Pipe(cmds ...*exec.Cmd) (err error)

Pipe will send the output of the first command to the input of the second and so on.

func PipeAsync

func PipeAsync(cmds ...*exec.Cmd) *task.Task

PipeAsync does the same as Pipe but does so asynchronously.

func PipeBufferedAsync

func PipeBufferedAsync(cmds ...*exec.Cmd) *task.Task

PipeBufferedAsync does the same as PipeBuffered but does so asynchronously.

func PipePrefixed

func PipePrefixed(prefix string, cmds ...*exec.Cmd) (err error)

PipePrefixed will prefix all StdOut and StdErr with given prefix. This is useful when running many pipes concurrently, output will look similar to docker-compose.

func PipePrefixedAsync

func PipePrefixedAsync(prefix string, cmds ...*exec.Cmd) *task.Task

PipePrefixedAsync does the same as PipePrefixed but does so asynchronously.

func Run

func Run(cmd string, args ...string) (err error)

Run is a convenience function for simple cases.

Instead of:

Cmd("ping", Args("-c", "4", "8.8.8.8")).Run()

You might write:

Run("ping", "-c", "4", "8.8.8.8")

func RunAsync

func RunAsync(cmd string, args ...string) *task.Task

RunAsync does the same as Run but does so asynchronously.

func RunBufferedAsync

func RunBufferedAsync(cmd string, args ...string) *task.Task

RunBufferedAsync does the same as RunBuffered but does so asynchronously.

func RunBufferedCmdAsync

func RunBufferedCmdAsync(cmd *exec.Cmd) *task.Task

RunBufferedCmdAsync does the same as RunBufferedCmd but does so asynchronously.

func RunPrefixed

func RunPrefixed(prefix, cmd string, args ...string) (err error)

RunPrefixed is a convenience function for simple cases.

Instead of:

RunPrefixedCmd("foo", Cmd("ping", Args("-c", "4", "8.8.8.8")))

You might write:

RunPrefixed("foo", "ping", "-c", "4", "8.8.8.8")

func RunPrefixedAsync

func RunPrefixedAsync(prefix, cmd string, args ...string) *task.Task

RunPrefixedAsync does the same as RunPrefixed but does so asynchronously.

func RunPrefixedCmd

func RunPrefixedCmd(prefix string, cmd *exec.Cmd) (err error)

RunPrefixedCmd will prefix all StdOut and StdErr with given prefix. This is useful when running many commands concurrently, output will look similar to docker-compose.

func RunPrefixedCmdAsync

func RunPrefixedCmdAsync(prefix string, cmd *exec.Cmd) *task.Task

RunPrefixedCmdAsync does the same as RunPrefixedCmd but does so asynchronously.

func SetErr

func SetErr(err io.Writer) func(*exec.Cmd) error

SetErr allows you to set a custom StdErr stream

func SetIn

func SetIn(in io.Reader) func(*exec.Cmd) error

SetIn allows you to set a custom StdIn stream

func SetOut

func SetOut(out io.Writer) func(*exec.Cmd) error

SetOut allows you to set a custom StdOut stream

Types

type StdBytes

type StdBytes struct {
	StdOut []byte
	StdErr []byte
}

StdBytes represents the buffered output from a process.

func MustPipeBuffered

func MustPipeBuffered(cmds ...*exec.Cmd) *StdBytes

MustPipeBuffered does the same as PipeBuffered but panics if an error is encountered.

func MustRunBufferedCmd

func MustRunBufferedCmd(cmd *exec.Cmd) *StdBytes

MustRunBufferedCmd does the same as RunBufferedCmd but panics if an error is encountered.

func PipeBuffered

func PipeBuffered(cmds ...*exec.Cmd) (out *StdBytes, err error)

PipeBuffered will buffer all StdOut and StdErr, returning the buffers. This is useful when you wish to parse the results of a pipe.

func RunBufferedCmd

func RunBufferedCmd(cmd *exec.Cmd) (out *StdBytes, err error)

RunBufferedCmd will buffer all StdOut and StdErr, returning the buffers. This is useful when you wish to parse the results of a command.

type StdStrings

type StdStrings struct {
	StdOut string
	StdErr string
}

StdStrings represents the buffered output from a process after having been casted to strings.

func MustRunBuffered

func MustRunBuffered(cmd string, args ...string) *StdStrings

MustRunBuffered does the same as RunBuffered but panics if an error is encountered.

func RunBuffered

func RunBuffered(cmd string, args ...string) (out *StdStrings, err error)

RunBuffered is a convenience function for simple cases.

Instead of:

RunBufferedCmd(Cmd("ping", Args("-c", "4", "8.8.8.8")))

You might write:

RunBuffered("ping", "-c", "4", "8.8.8.8")

NOTE: `RunBuffered()` returns stdOut and stdErr as strings if you want the untouched byte arrays you could use `RunBufferedCmd()` instead.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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