util

package
v0.26.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: MIT Imports: 15 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectLogChannel

func ConnectLogChannel(cmdPlus *execplus.CmdPlus, logger *Logger)

ConnectLogChannel connects a log channel that wants to receive only each new output

func CreateEmptyDirectory

func CreateEmptyDirectory(dir string) error

CreateEmptyDirectory creates an empty dir directory and returns an error if any

func DoesDirectoryExist

func DoesDirectoryExist(dirPath string) (bool, error)

DoesDirectoryExist returns true if the directory dirPath is an existing directory, and false otherwise

func DoesFileExist

func DoesFileExist(filePath string) (bool, error)

DoesFileExist returns true if the file filePath exists, and false otherwise

func DoesStringArrayContain

func DoesStringArrayContain(strings []string, targetString string) bool

DoesStringArrayContain returns whether the given string slice contains the given string.

func GetHomeDirectory

func GetHomeDirectory() (string, error)

GetHomeDirectory returns the path to the user's home directory

func GetServiceExitCode

func GetServiceExitCode(role, dockerComposeLog string) (int, error)

GetServiceExitCode parses the given docker-compose output and returns the exit code of the given service and an error if any

func GetSubdirectories

func GetSubdirectories(dirPath string) (result []string, err error)

GetSubdirectories returns a slice of subdirectories in the directory dirPath

func IsEmptyFile

func IsEmptyFile(filePath string) (bool, error)

IsEmptyFile returns true if filePath is an empty file, and false otherwise

func JoinStringMaps

func JoinStringMaps(maps ...map[string]string) map[string]string

JoinStringMaps joins the given string maps

func JoinStringSlices

func JoinStringSlices(slices ...[]string) []string

JoinStringSlices joins the given slices

func Merge

func Merge(map1 map[string]string, map2 map[string]string)

Merge merges two maps. It overwrites existing keys of map1 if conflicting keys exist

func MoveDirectory

func MoveDirectory(srcPath, destPath string) error

MoveDirectory moves srcPath to destPath

func NormalizeDockerComposeLog

func NormalizeDockerComposeLog(line string) string

NormalizeDockerComposeLog removes colors, control characters, and converts carriage returns to newlines

func ParseCommand

func ParseCommand(command string) ([]string, error)

ParseCommand parses the command string into a string array

func ParseDockerComposeLog

func ParseDockerComposeLog(role, line string) (string, string)

ParseDockerComposeLog parses the given docker-compose output and returns the service name and service output

func Run

func Run(dir string, commandWords ...string) (string, error)

Run runs the given command, waits for the process to finish and returns the output string and error (if any)

func RunAndLog

func RunAndLog(dir string, env []string, logger *Logger, commandWords ...string) error

RunAndLog runs the given command, logs the process to the given channel, waits for the process to finish and returns an error (if any)

func RunSeries

func RunSeries(dir string, commands [][]string) error

RunSeries runs each command in commands and returns an error if any

func Strip

func Strip(regex, text string) string

Strip strips off substrings that match the given regex from the given text

Types

type Logger added in v0.26.3

type Logger struct {
	Roles         []string
	SilencedRoles []string
	Length        int
	Colors        map[string]color.Attribute
	Writer        io.Writer
	DefaultRole   string
}

Logger represents a logger

func NewLogger added in v0.26.3

func NewLogger(roles, silencedRoles []string, defaultRole string, writer io.Writer) *Logger

NewLogger is Logger's constructor

func (*Logger) Log added in v0.26.3

func (l *Logger) Log(text string)

Log logs the given text, panics if the write fails

func (*Logger) Logf added in v0.26.3

func (l *Logger) Logf(format string, a ...interface{})

Logf convience method for Log(fmt.Sprintf(...))

Jump to

Keyboard shortcuts

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