util

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2016 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package util provides utility functions used by other packages.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ArnRegexp *regexp.Regexp = regexp.MustCompile("arn:([^:]+):([^:]+):([^:]+):([^:]*):(.*)")

ArnRegexp matches an AWS ARN with the following capture groups:

1: partition
2: service
3: region
4: account-id
5: resource

Note that the resource may be in one of these forms:

resource, resourcetype:resource, resourcetype/resource

See: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns

View Source
var ErrGitDetached = errors.New("Your repo looks like it is in a detached state")

ErrDetached is returned if it looks like a Git repo is in a detached state.

Functions

func Cmd

func Cmd(dir string, command string) *exec.Cmd

Cmd creates an exec.Cmd to run in the given directory.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of one file to another file. If the dst file already exists, its contents will be replaced.

func GitBranch

func GitBranch(dir string) (branch string, err error)

GitBranch returns the current git branch for the given directory

func NewCaptureLogger

func NewCaptureLogger() (*CaptureWriter, *StandardLogger)

NewCaptureLogger returns a StandardLogger which will write its Print*() outputs to the returned CaptureWriter. This can be used to capture the outputs of Print*() methods instead of printing them to stdout.

Example
w, log := NewCaptureLogger()
log.Println("foo") // nothing written to stdout
log.Debugln("bar") // "bar" is written to stderr
log.Println("baz") // nothing written to stdout
w.Out()            // []string{"foo", "baz"}
Output:

Types

type Arn

type Arn struct {
	Partition string
	Service   string
	Region    string
	AccountId string
	Resource  string
}

An Arn specifies the pieces of an AWS ARN

func NewArn

func NewArn(arn string) (*Arn, error)

NewArn parses an ARN string and returns an Arn struct. If the ARN is invalid, it returns an error.

func (*Arn) String

func (arn *Arn) String() string

String returns a string representation of the ARN

type CaptureWriter

type CaptureWriter struct {
	// contains filtered or unexported fields
}

CaptureWriter is an io.Writer that simply captures its inputs in a []string.

Example
w := &CaptureWriter{}
w.Write([]byte("foo"))
w.Write([]byte("bar"))
w.Out() // []string{"foo", "bar"}
Output:

func (*CaptureWriter) Out

func (w *CaptureWriter) Out() []string

func (*CaptureWriter) Write

func (w *CaptureWriter) Write(b []byte) (n int, err error)

type CmdOutput

type CmdOutput struct {
	Cmd    string
	Output string
	Err    error
}

CmdOutput represents the output of a bash command.

func RunAll

func RunAll(dir string, commands ...string) ([]*CmdOutput, error)

RunAll runs all the given commands in the given directory, and returns a list of CmdOutputs.

func RunAllLog

func RunAllLog(log Logger, dir string, commands ...string) ([]*CmdOutput, error)

RunAllLog is the same as RunAll but it logs commands as they are run.

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Print(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Println(args ...interface{})
	Warnln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
}

Logger is the interface used throughout devicefarm to write logs. The convention is that methods starting with Print write unformatted logs to sdout, while all other methods write formatted logs to stderr. Method signatures copied from Logrus: https://github.com/Sirupsen/logrus/blob/4b6ea7319e214d98c938f12692336f7ca9348d6b/logrus.go

type StandardLogger

type StandardLogger struct {
	Logger
	// contains filtered or unexported fields
}

StandardLogger is the basis for all loggers used in devicefarm.

DefaultLogger writes to stdout and stderr

NilLogger silences logs by writing to ioutil.Discard (equivalent of /dev/null)

func NewStandardLogger

func NewStandardLogger(out, err io.Writer) *StandardLogger

NewStandardLogger creates a StandardLogger with the given io.Writers. For Print*() methods, the out io.Writer is used. For non-Print methods, a standard logrus.Logger is used (and it is provided the err io.Writer).

Example
log := NewStandardLogger(os.Stdout, os.Stderr)
log.Println("foo") // unformatted log to stdout
log.Debugln("bar") // logrus formatted log to stderr
Output:

func (*StandardLogger) Print

func (logger *StandardLogger) Print(args ...interface{})

func (*StandardLogger) Printf

func (logger *StandardLogger) Printf(format string, args ...interface{})

func (*StandardLogger) Println

func (logger *StandardLogger) Println(args ...interface{})

Jump to

Keyboard shortcuts

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