util

package
v0.0.0-...-f64704c Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WorkingPathAbs string

WorkingPathAbs This is determined using the current working directory and the value of Config.Options.WorkingPath

Functions

func CleanPath

func CleanPath(path string) (err error)

cleanUp is a helper function which empties the target folder

func Config

func Config(conf config.Config) afero.Fs

Config Configure the utility subsystems depending on testing

func ConfigFileSystem

func ConfigFileSystem()

func Create

func Create(filename string) (afero.File, error)

func DebugDiffString

func DebugDiffString(l, r string)

DebugDiffString Diff two strings

func DebugDiffStrings

func DebugDiffStrings(l, r []string)

DebugDiffStrings Diff two arrays of strings

func DebugDump

func DebugDump(obj interface{})

DebugDump Pretty print a data structure

func DebugDumpDiff

func DebugDumpDiff(left interface{}, right interface{})

DebugDumpDiff Pretty print differences between data structures

func DebugDumpDiffDetail

func DebugDumpDiffDetail(left interface{}, right interface{}, leftTitle, rightTitle string)

DebugDumpDiffDetail Pretty print differences between data structures

func DeleteFile

func DeleteFile(filename string) error

func DirExists

func DirExists(path string) (bool, error)

func ErrorCheck

func ErrorCheck(err error) bool

func ErrorCheckf

func ErrorCheckf(err error, format string, context ...interface{}) bool

func FileExists

func FileExists(path string) (bool, error)

func LogAlert

func LogAlert(alert ...interface{})

func LogAlertf

func LogAlertf(format string, alert ...interface{})

func LogAttention

func LogAttention(info ...interface{})

func LogAttentionf

func LogAttentionf(format string, info ...interface{})

func LogColour

func LogColour(out string, attr color.Attribute)

func LogCyan

func LogCyan(out string)

func LogError

func LogError(err ...interface{})

func LogErrorf

func LogErrorf(format string, err ...interface{})

func LogFatal

func LogFatal(code int, err ...interface{})

func LogGreen

func LogGreen(out string)

func LogInfo

func LogInfo(info ...interface{})

func LogInfof

func LogInfof(format string, info ...interface{})

func LogMagenta

func LogMagenta(out string)

func LogOk

func LogOk(info ...interface{})

func LogOkf

func LogOkf(format string, info ...interface{})

func LogRed

func LogRed(out string)

func LogRedBright

func LogRedBright(out string)

func LogWarn

func LogWarn(warn ...interface{})

func LogWarnf

func LogWarnf(format string, warn ...interface{})

func LogWhite

func LogWhite(out string)

func LogYellow

func LogYellow(out string)

func Mkdir

func Mkdir(path string, perm os.FileMode) error

func Open

func Open(filename string) (afero.File, error)

func PropertyIDGen

func PropertyIDGen(seed string) (hash string)

PropertyIDGen Generate an MD5 hash of the seed input data. If no seed is provided then the current unix timestamp is used

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

func ReadDirAbsolute

func ReadDirAbsolute(path string, fileType string, recursive bool, files *[]string) (err error)

func ReadDirRelative

func ReadDirRelative(path string, fileType string, recursive bool, files *[]string) (err error)

Recursively check the path for typetype files and add them to the schema list as we're going

func ReadFile

func ReadFile(filename string) (data []byte, err error)

func RecreateFolder

func RecreateFolder(path string) (err error)

func SelectAction

func SelectAction(actionDesc string, options []string) (action string, err error)

SelectAction Generic function for a cli option selection prompt

func SetConfigTesting

func SetConfigTesting()

SetConfigTesting Enable unit test file and command subsystems

func SetLogFile

func SetLogFile(file string) func()

func SetVerbose

func SetVerbose(v bool)

func ShutdownFileSystem

func ShutdownFileSystem()

func Stat

func Stat(path string) (os.FileInfo, error)

func StringInArray

func StringInArray(a string, list []string) bool

func VerboseOverrideRestore

func VerboseOverrideRestore()

func VerboseOverrideSet

func VerboseOverrideSet(ovr bool)

func WorkingSubDir

func WorkingSubDir(subDir string) string

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

Types

type ExpectedCommand

type ExpectedCommand struct {
	Cmd       string
	Args      []string
	Triggered bool
	// contains filtered or unexported fields
}

ExpectedCommand Defines a mock command input and output

func (ExpectedCommand) Compare

func (c ExpectedCommand) Compare(cmd string, args ...string) error

Compare Check if the input command matches this mock command

func (ExpectedCommand) GetResult

func (c ExpectedCommand) GetResult(prefix string) string

GetResult Return the command result with the correct prefix

func (ExpectedCommand) Lambda

func (c ExpectedCommand) Lambda() error

Lambda Execute simulated function

func (ExpectedCommand) String

func (c ExpectedCommand) String() string

String String representation of the mock command

type Lambda

type Lambda func(string, []string) error

Lambda Callback type to allow simulated execution of shell commands

type MockShellExecutor

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

MockShellExecutor A mock command executor that fulfills the Runner interface modelled after DATA-DOG/go-sqlmock

func (MockShellExecutor) Count

func (e MockShellExecutor) Count() int

func (*MockShellExecutor) ExpectExec

func (e *MockShellExecutor) ExpectExec(cmd string, args []string, output string, err error)

ExpectExec Create a expected command

func (*MockShellExecutor) ExpectExecWithLambda

func (e *MockShellExecutor) ExpectExecWithLambda(cmd string, args []string, output string, err error, lb Lambda)

ExpectExecWithLambda Create a expected command

func (*MockShellExecutor) ExpectationsWereMet

func (e *MockShellExecutor) ExpectationsWereMet() error

func (*MockShellExecutor) Run

func (e *MockShellExecutor) Run(cmd string, args ...string) (out string, err error)

Run Execute a command. This function checks all expected commands for a match in order of creation and returns the expected output or error if found.

func (*MockShellExecutor) SetPrefix

func (e *MockShellExecutor) SetPrefix(prefix string)

SetPrefix Set a prefix on the command output

type Params

type Params struct {
	Values []string
	Sep    string
}

Params Used to easily manage strings of values

func (*Params) Add

func (p *Params) Add(param string)

func (*Params) String

func (p *Params) String() string

type ShellExecutor

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

ShellExecutor Shell Command wrapper

func (ShellExecutor) Run

func (e ShellExecutor) Run(command string, args ...string) (out string, err error)

Run executes a command with arguments. Both stdout and stderr are captured from the command and logged using the prefix defined in the shellPrefix parameter. The command output and any error is also returned. This function blocks until the shell command is complete.

func (*ShellExecutor) SetPrefix

func (e *ShellExecutor) SetPrefix(prefix string)

SetPrefix Sets the prefix that will be used for console output

type ShellRunner

type ShellRunner interface {
	SetPrefix(string)
	Run(string, ...string) (string, error)
}

ShellRunner An interface to abstract shell command structs

func GetShell

func GetShell() ShellRunner

GetShell Get the shell command object

Jump to

Keyboard shortcuts

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