• Stars
    star
    230
  • Rank 174,053 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

deputy is a go package that adds smarts on top of os/exec

deputy GoDoc Build Status

deputy is a go package that adds smarts on top of os/exec

deputy-sm

image: creative commons, © MatsuRD

Example

// 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.
cancel := make(chan struct{})
go func() {
    <-time.After(time.Second * 30)
    close(cancel)
}()

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)
}

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.

func (Deputy) Run

func (d Deputy) Run(cmd *exec.Cmd) error

Run starts the specified command and waits for it to complete. Its behavior conforms to the Options passed to it at construction time.

Note that, like cmd.Run, Deputy.Run should not be used with StdoutPipe or StderrPipe.

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
)

More Repositories

1

lumberjack

lumberjack is a log rolling package for Go
Go
4,272
star
2

gorram

It's like go run for any go function
Go
1,038
star
3

pie

a toolkit for creating plugins for Go applications
Go
747
star
4

npipe

A Windows named pipe implementation written in pure Go.
Go
282
star
5

atomic

atomic is a go package for atomic file writing
Go
190
star
6

godocgo

An example of good godoc documentation.
Go
154
star
7

gocog

Generate code for any language, with any language.
Go
68
star
8

sh

Package sh makes working with shell commands more shell-like. Inspired by https://github.com/amoffat/sh
Go
52
star
9

npf

code to host a professional site
CSS
52
star
10

graffiti

graffiti is a tool to automatically add struct tags to fields in your go code
Go
38
star
11

claymud

Highly configurable and performant MUD written in Go
Go
28
star
12

keep

Go bindings wrapping the Google Keep API
Go
22
star
13

diceware

an implementation of the diceware passphrase generation algorithm
Go
21
star
14

blogimport

A tool to import from Blogger to Hugo
Go
20
star
15

tree

A statically typed binary tree in Go without casts or reflection
Go
19
star
16

pcgrep

Go
15
star
17

covergen

autogenerate a coverage badge for your README with with one dumb trick
Go
10
star
18

convert

An application to convert and resize images written in Go.
Go
10
star
19

plugman

a plugin manifest manager for go
9
star
20

q

Q is a CLI tool for developers that can do anything.
Go
8
star
21

avl

Go
6
star
22

natefinch.github.io

nate's sweet website
HTML
5
star
23

tod

A Hugo site for my D&D campaign
CSS
4
star
24

filterr

go package that helps filter returned errors to a specific list
Go
4
star
25

wrap

Wrap contains a method for wrapping one Go error with another.
Go
4
star
26

Ashes2Ashes

A modified CircleMUD that ran in the late 90's.
C
3
star
27

cavalier

a command line interface generator for Go
Go
3
star
28

emojis-and-dragons

2
star
29

nolog

just a dumb little tool to run juju tests and filter out all the logging
Go
2
star
30

natefinch

1
star
31

harvard-4-h

CSS
1
star
32

rpg

a personal website about RPGs
CSS
1
star
33

circle2json

converts CircleMUD room definitions to json equivalents
Go
1
star
34

go-quickstart

Go
1
star
35

burningchrome

A website for the in-development Burning Chrome RPG.
CSS
1
star
36

eg

An enhanced error package for Go
Go
1
star
37

tabletop.design

HTML
1
star
38

treesample

Sample project using natefinch/tree
Go
1
star