Documentation
¶
Overview ¶
Package deputy provides more advanced options for running commands.
Example ¶
package main
import (
"log"
"os/exec"
"time"
"github.com/Complead/deputy"
)
func main() {
cancel := make(chan struct{})
go func() {
<-time.After(time.Second * 30)
close(cancel)
}()
// Make a new deputy that'll return the data written to stderr as the error
// message, log everything written to stdout to this application's log, and
// timeout after 30 seconds.
d := deputy.Deputy{
Errors: deputy.FromStderr,
StdoutLog: func(b []byte) { log.Print(string(b)) },
Cancel: cancel,
}
if err := d.Run(exec.Command("foo")); err != nil {
log.Print(err)
}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deputy ¶
type Deputy struct {
// Cancel, when closed, will cause the command to close.
Cancel <-chan struct{}
// Errors describes how errors should be handled.
Errors ErrorHandling
// StdoutLog takes a function that will receive lines written to stdout from
// the command (with the newline elided).
StdoutLog func([]byte)
// StdoutLog takes a function that will receive lines written to stderr from
// the command (with the newline elided).
StderrLog func([]byte)
// contains filtered or unexported fields
}
Deputy is a type that runs Commands with advanced options not available from os/exec. See the comments on field values for details.
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling is a flag that tells Deputy how to handle errors running a command. See the values below for the different modes.
const ( // DefaultErrs represents the default handling of command errors - this // simply returns the error from Cmd.Run() DefaultErrs ErrorHandling = iota // FromStderr tells Deputy to convert the stderr output of a command into // the text of an error, if the command exits with an error. FromStderr // FromStdout tells Deputy to convert the stdout output of a command into // the text of an error, if the command exits with an error. FromStdout )
Click to show internal directories.
Click to hide internal directories.

