util

package
v0.0.0-...-397181f Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Xhyve      = "xhyve"
	VMWare     = "vmwarefusion"
	VirtualBox = "virtualbox"
)

Constants for virtualization drivers

Variables

This section is empty.

Functions

func AbsJoin

func AbsJoin(baseDir, suffixPath string) (string, error)

AbsJoin joins the two path segments, ensuring they form an absolute path.

func AskYesNo

func AskYesNo(question string) bool

AskYesNo asks the user a yes/no question Return true if they answered yes, false otherwise

func CaptureCommand

func CaptureCommand(cmd *exec.Cmd) (string, int, error)

CaptureCommand is similar to PassthruCommand except it intercepts all output. It is primarily used to evaluate shell commands for success/failure states.

Derived from: http://stackoverflow.com/a/40770011/38408

func CheckForRigUpdate

func CheckForRigUpdate(curRigVersion string) string

CheckForRigUpdate checks to see if an upgrdate to rig is available, if so, return a message

func ContainerRunning

func ContainerRunning(name string) bool

ContainerRunning determines if the named container is live.

func EscalatePrivilege

func EscalatePrivilege() error

EscalatePrivilege attempts to gain administrative privilege @todo identify administrative escalation on Windows. E.g., "runas", "/noprofile", "/user:Administrator

func FileExists

func FileExists(pathToFile, workingDir string) bool

FileExists reports whether a file exists.

func ForceStreamCommand

func ForceStreamCommand(path string, arg ...string) error

ForceStreamCommand sets up the output streams (and colors) to stream command output regardless of verbosity

func GetBridgeIP

func GetBridgeIP() (string, error)

GetBridgeIP returns the IP address of the Docker bridge network gateway

func GetCurrentDockerVersion

func GetCurrentDockerVersion() *version.Version

GetCurrentDockerVersion returns a Version based in the Docker semver

func GetDockerClientAPIVersion

func GetDockerClientAPIVersion() *version.Version

GetDockerClientAPIVersion returns a Version for the docker client API version

func GetDockerServerAPIVersion

func GetDockerServerAPIVersion() (*version.Version, error)

GetDockerServerAPIVersion returns a Version for the docker server API version

func GetDockerServerMinAPIVersion

func GetDockerServerMinAPIVersion() (*version.Version, error)

GetDockerServerMinAPIVersion returns the minimum compatability version for the docker server

func GetExecutableDir

func GetExecutableDir() (string, error)

GetExecutableDir returns the directory of this binary

func GetRawCurrentDockerVersion

func GetRawCurrentDockerVersion() string

GetRawCurrentDockerVersion returns the entire semver string from the docker version cli

func GetUnisonMinorVersion

func GetUnisonMinorVersion() string

GetUnisonMinorVersion will return the local Unison version to try to load a compatible unison image This function discovers a semver like 2.48.4 and return 2.48

func ImageOlderThan

func ImageOlderThan(image string, elapsedSeconds float64) (bool, float64, error)

ImageOlderThan determines the age of the Docker Image and whether the image is older than the designated timestamp.

func IndexOfString

func IndexOfString(slice []string, search string) (int, bool)

IndexOfString is a general utility function that can find the index of a value present in a string slice. The second value is true if the item is found.

func IndexOfSubstring

func IndexOfSubstring(slice []string, search string) (int, bool)

IndexOfSubstring is a variation on IndexOfString which checks to see if a given slice value matches our search string, or if that search string is a substring of the element. The second value is true if the item is found.

func IsLinux

func IsLinux() bool

IsLinux detects if we are running on the linux platform

func IsMac

func IsMac() bool

IsMac detects if we are running on the darwin platform

func IsWindows

func IsWindows() bool

IsWindows detects if we are running on the microsoft windows platform

func LoggerInit

func LoggerInit(verbose bool)

LoggerInit initializes the global logger

func NotifyError

func NotifyError(ctx *cli.Context, message string) error

NotifyError send a notification for a failed command run

func NotifyInit

func NotifyInit(label string) error

NotifyInit initializes notification config

func NotifySuccess

func NotifySuccess(ctx *cli.Context, message string)

NotifySuccess send a notification for a successful command run

func PassthruCommand

func PassthruCommand(cmd *exec.Cmd) (exitCode int)

PassthruCommand is similar to ForceStreamCommand in that it will issue all output regardless of verbose mode. Further, this version of the command captures the exit status of any executed command. This function is intended to simulate native execution of the command passed to it.

Derived from: http://stackoverflow.com/a/40770011/38408

func PrintDebugHelp

func PrintDebugHelp(message, errorName string, exitCode int)

PrintDebugHelp provides expanded troubleshooting help content for an error. It is primarily called by command.go:Failure(). @todo consider switching this to a template.

func RemoveFile

func RemoveFile(pathToFile, workingDir string) error

RemoveFile removes the designated file relative to the Working Directory.

func RemoveFileGlob

func RemoveFileGlob(glob, targetDirectory string, logger *RigLogger) error

RemoveFileGlob removes all files under the working directory that match the glob. This recursively traverses all sub-directories. If a logger is passed the action will be verbosely logged, otherwise pass nil to skip all output.

func StreamCommand

func StreamCommand(path string, arg ...string) error

StreamCommand sets up the output streams (and colors) to stream command output if verbose is configured

func StringPad

func StringPad(s string, pad string, size int) string

StringPad takes your string and returns it with the pad value repeatedly appended until it is the intended length. Note that if the delta between the initial string length and the intended size is not evenly divisible by the pad length, your final string could be slightly short -- partial padding is not applied. For guaranteed results, use a pad string of length 1.

func SupportsNativeDocker

func SupportsNativeDocker() bool

SupportsNativeDocker determines if the runtime OS support docker natively, versus needing to run docker in a virtual machine

func TouchFile

func TouchFile(pathToFile string, workingDir string) error

TouchFile creates an empty file, usually for temporary use. @see https://stackoverflow.com/questions/35558787/create-an-empty-text-file/35558965

Types

type Executor

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

Executor wraps exec.Cmd to allow consistent manipulation of executed commands.

func Command

func Command(path string, arg ...string) Executor

Command creates a new Executor instance from the execution arguments.

func Convert

func Convert(cmd *exec.Cmd) Executor

Convert takes a exec.Cmd pointer and wraps it in an executor object.

func (Executor) CombinedOutput

func (x Executor) CombinedOutput() ([]byte, error)

CombinedOutput runs a command via exec.CombinedOutput() without modification or output of the underlying command.

func (Executor) Execute

func (x Executor) Execute(forceOutput bool) error

Execute executes the provided command, it also can specify if the output should be forced to print to the console

func (Executor) IsPrivileged

func (x Executor) IsPrivileged() bool

IsPrivileged evaluates the command to determine if administrative privilege is required. @todo identify administrative escalation on Windows. E.g., "runas", "/noprofile", "/user:Administrator

func (Executor) Log

func (x Executor) Log(tag string)

Log verbosely logs the command.

func (Executor) Output

func (x Executor) Output() ([]byte, error)

Output runs a command via exec.Output() without modification or output of the underlying command.

func (Executor) Run

func (x Executor) Run() error

Run runs a command via exec.Run() without modification or output of the underlying command.

func (Executor) Start

func (x Executor) Start() error

Start runs a command via exec.Start() without modification or output of the underlying command.

func (Executor) String

func (x Executor) String() string

String converts a Command to a human-readable string with key context details. It is automatically applied in contexts such as fmt functions.

type NotifyConfig

type NotifyConfig struct {
	// The label for the app to be displayed in notifications.
	Label string

	// Relative path to notification logo.
	Icon string
}

NotifyConfig holds configuration for notification support

type RigLogger

type RigLogger struct {
	Channel    logChannels
	Progress   *RigSpinner
	IsVerbose  bool
	Spinning   bool
	Privileged bool
}

RigLogger is the global logger object

func Logger

func Logger() *RigLogger

Logger returns the instance of the global logger

func (*RigLogger) Error

func (log *RigLogger) Error(format string, a ...interface{})

Error indicates an error in the spinner-associated task.

func (*RigLogger) Info

func (log *RigLogger) Info(format string, a ...interface{})

Info indicates success behavior of the spinner-associated task.

func (*RigLogger) NoSpin

func (log *RigLogger) NoSpin()

NoSpin stops the Progress spinner.

func (*RigLogger) Note

func (log *RigLogger) Note(format string, a ...interface{})

Note allows output of an info log, bypassing the spinner if in use.

func (*RigLogger) PrivilegeEscalationPrompt

func (log *RigLogger) PrivilegeEscalationPrompt()

PrivilegeEscalationPrompt interrupts a running spinner to ensure clear prompting to the user for sudo password entry. It is up to the caller to know that privilege is needed. This prompt is only displayed on the first privilege escalation of a given rig process.

func (*RigLogger) SetVerbose

func (log *RigLogger) SetVerbose(verbose bool)

SetVerbose allows toggling verbose mode mid-execution of the program.

func (*RigLogger) Spin

func (log *RigLogger) Spin(message string)

Spin restarts the spinner for a new task.

func (*RigLogger) SpinWithVerbose

func (log *RigLogger) SpinWithVerbose(message string, a ...interface{})

SpinWithVerbose operates the spinner but also writes to the verbose log. This is used in cases where the spinner's initial context is needed for detailed verbose logging purposes.

func (*RigLogger) Verbose

func (log *RigLogger) Verbose(format string, a ...interface{})

Verbose allows Verbose logging of more advanced activities/information. In practice, if the spinner can be in use verbose is a no-op.

func (*RigLogger) Warn

func (log *RigLogger) Warn(format string, a ...interface{})

Warn is a convenience wrapper for Warning.

func (*RigLogger) Warning

func (log *RigLogger) Warning(format string, a ...interface{})

Warning indicates a warning in the resolution of the spinner-associated task.

type RigSpinner

type RigSpinner struct {
	Spins *spun.Spinner
}

RigSpinner object wrapper to facilitate our spinner service as a different

Jump to

Keyboard shortcuts

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