util

package
v1.3.409 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2018 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultWritePermissions = 0760

	MaximumNewDirectoryAttempts = 1000
)
View Source
const (
	ALIGN_LEFT   = 0
	ALIGN_CENTER = 1
	ALIGN_RIGHT  = 2
)
View Source
const (
	APPSERVER = "appserver"
	LIBERTY   = "liberty"
)
View Source
const DateFormat = "January 2 2006"
View Source
const (
	DefaultSuggestionsMinimumDistance = 2
)

Variables

View Source
var ColorError = color.New(color.FgRed).SprintFunc()
View Source
var ColorInfo = color.New(color.FgGreen).SprintFunc()
View Source
var ColorStatus = color.New(color.FgBlue).SprintFunc()
View Source
var ColorWarning = color.New(color.FgYellow).SprintFunc()

Functions

func AtoInt32 added in v1.0.2

func AtoInt32(text string) (int32, error)

func BackupDir added in v1.3.170

func BackupDir() (string, error)

func BasicAuth added in v1.2.27

func BasicAuth(username, password string) string

func CacheDir added in v1.0.6

func CacheDir() (string, error)

func ColorNameValues added in v1.3.49

func ColorNameValues() []string

ColorNameValues returns all the color names sorted

func CombineErrors added in v1.3.336

func CombineErrors(errs ...error) error

Combine combines the non null errors into a single error or returns null

func ConfigDir added in v1.0.6

func ConfigDir() (string, error)

func Confirm added in v1.1.4

func Confirm(message string, defaultValue bool, help string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) bool

Confirm prompts the user to confirm something

func Contains added in v1.0.29

func Contains(arr []string, str string) bool

func CopyDir added in v1.0.75

func CopyDir(src string, dst string, force bool) (err error)

credit https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func CopyDirOverwrite added in v1.2.67

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

CopyDirOverwrite copies from the source dir to the destination dir overwriting files along the way

func CopyFile added in v1.0.75

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

credit https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func CreateUniqueDirectory added in v1.0.2

func CreateUniqueDirectory(dir string, name string, maximumAttempts int) (string, error)

CreateUniqueDirectory creates a new directory but if the combination of dir and name exists then append a number until a unique name is found

func DeleteDirContents added in v1.3.336

func DeleteDirContents(dir string) error

DeleteDirContents removes all the contents of the given directory

func DeleteFile added in v1.3.50

func DeleteFile(fileName string) (err error)

func DiffSlices added in v1.3.249

func DiffSlices(oldSlice []string, newSlice []string) ([]string, []string)

DiffSlices compares the two slices and returns an array of items to delete from the old slice and a slice of new values to add to

func DownloadFile added in v1.0.6

func DownloadFile(filepath string, url string) (err error)

Download a file from the given URL

func DraftDir added in v1.1.3

func DraftDir() (string, error)

func EnvironmentsDir added in v1.0.6

func EnvironmentsDir() (string, error)

func FileExists

func FileExists(path string) (bool, error)

func FirstNotEmptyString added in v1.0.26

func FirstNotEmptyString(values ...string) string

FirstNotEmptyString returns the first non empty string or the empty string if none can be found

func FormatDate added in v1.3.30

func FormatDate(t time.Time) string

func GetColor added in v1.3.49

func GetColor(optionName string, colorNames []string) (*color.Color, error)

GetColor returns the color for the list of colour names and option name

func GetLatestVersionFromGitHub added in v1.0.6

func GetLatestVersionFromGitHub(githubOwner, githubRepo string) (semver.Version, error)

func GetLatestVersionStringFromGitHub added in v1.3.57

func GetLatestVersionStringFromGitHub(githubOwner, githubRepo string) (string, error)

func GetMockAPIResponseFromFile added in v1.1.43

func GetMockAPIResponseFromFile(dataDir string, route MethodMap) mocker

@param dataDir Location of test data json file @param router Should map a URL path to a map that maps a method to a JSON response file name. Conceptually: (url, method) -> file See pkg/gits/bitbucket_test.go for an example.

func HomeDir added in v1.0.6

func HomeDir() string

func Int32ToA added in v1.0.2

func Int32ToA(n int32) string

func InvalidArg added in v1.0.2

func InvalidArg(value string, values []string) error

func InvalidArgError added in v1.0.2

func InvalidArgError(value string, err error) error

func InvalidArgf added in v1.0.2

func InvalidArgf(value string, message string, a ...interface{}) error

func InvalidOption added in v1.0.2

func InvalidOption(name string, value string, values []string) error

func InvalidOptionError added in v1.0.2

func InvalidOptionError(option string, value string, err error) error

func InvalidOptionf added in v1.0.2

func InvalidOptionf(option string, value string, message string, a ...interface{}) error

func IsEmpty added in v1.1.3

func IsEmpty(name string) (bool, error)

func JXBinLocation added in v1.3.189

func JXBinLocation() (string, error)

JXBinLocation finds the JX config directory and creates a bin directory inside it if it does not already exist. Returns the JX bin path

func JXBinaryLocation added in v1.3.189

func JXBinaryLocation(commandInterface Commander) (string, error)

JXBinaryLocation Returns the path to the currently installed JX binary.

func LoadBytes added in v1.0.135

func LoadBytes(dir, name string) ([]byte, error)

loads a file

func LoadCacheData added in v1.0.2

func LoadCacheData(fileName string, loader CacheLoader) ([]byte, error)

LoadCacheData loads cached data from the given cache file name and loader

func LogsDir added in v1.3.247

func LogsDir() (string, error)
func MarkdownLink(text string, url string) string

MarkdownLink returns a markdown link

func MavenBinaryLocation added in v1.3.28

func MavenBinaryLocation() (string, error)

func MissingOption added in v1.0.54

func MissingOption(name string) error

func OrganisationsDir added in v1.3.29

func OrganisationsDir() (string, error)

func Pad added in v1.0.123

func Pad(s, pad string, width int, align int) string

func PadCenter added in v1.0.123

func PadCenter(s, pad string, width int) string

func PadLeft added in v1.0.123

func PadLeft(s, pad string, width int) string

func PadRight added in v1.0.123

func PadRight(s, pad string, width int) string

func ParseDate added in v1.3.30

func ParseDate(dateText string) (time.Time, error)

func PathWithBinary added in v1.2.122

func PathWithBinary(paths ...string) string

PathWithBinary Sets the $PATH variable. Accepts an optional slice of strings containing paths to add to $PATH

func PickName added in v1.0.10

func PickName(names []string, message string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error)

func PickNameWithDefault added in v1.0.10

func PickNameWithDefault(names []string, message string, defaultValue string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error)

func PickNames added in v1.0.10

func PickNames(names []string, message string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) ([]string, error)

func PickPassword added in v1.1.48

func PickPassword(message string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error)

func PickRequiredNameWithDefault added in v1.1.15

func PickRequiredNameWithDefault(names []string, message string, defaultValue string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error)

func PickValue added in v1.0.112

func PickValue(message string, defaultValue string, required bool, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) (string, error)

func PomFlavour added in v1.3.49

func PomFlavour(path string) (string, error)

func RandStringBytesMaskImprSrc added in v1.3.93

func RandStringBytesMaskImprSrc(n int) (string, error)

RandStringBytesMaskImprSrc returns a random hexadecimal string of length n.

func RecreateDirs added in v1.3.336

func RecreateDirs(dirs ...string) error

DeleteDirContents removes all the contents of the given directory

func RegexpSplit

func RegexpSplit(text string, regexSeperator string) []string

RegexpSplit splits a string into an array using the regexSep as a separator

func RenameDir added in v1.1.14

func RenameDir(src string, dst string, force bool) (err error)

func RenameFile added in v1.1.14

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

func ReverseStrings added in v1.0.69

func ReverseStrings(a []string)

func SelectNames added in v1.0.119

func SelectNames(names []string, message string, selectAll bool, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) ([]string, error)

SelectNames select which names from the list should be chosen

func SelectNamesWithFilter added in v1.2.39

func SelectNamesWithFilter(names []string, message string, selectAll bool, filter string, in terminal.FileReader, out terminal.FileWriter, outErr io.Writer) ([]string, error)

SelectNamesWithFilter selects from a list of names with a given filter. Optionally selecting them all

func SortedMapKeys added in v1.0.54

func SortedMapKeys(m map[string]string) []string

SortedMapKeys returns the sorted keys of the given map

func StringArrayIndex added in v1.0.2

func StringArrayIndex(array []string, value string) int

func StringArrayToLower added in v1.1.4

func StringArrayToLower(values []string) []string

StringArrayToLower returns a string slice with all the values converted to lower case

func StringIndexes

func StringIndexes(text string, value string) []int

StringIndexes returns all the indices where the value occurs in the given string

func StringMapHasValue added in v1.2.141

func StringMapHasValue(m map[string]string, value string) bool

StringMapHasValue returns true if the given map contains the given value

func StringMatchesAny added in v1.2.84

func StringMatchesAny(text string, includes []string, excludes []string) bool

StringMatches returns true if the given text matches the includes/excludes lists

func StringMatchesPattern added in v1.2.84

func StringMatchesPattern(text string, pattern string) bool

StringMatchesPattern returns true if the given text matches the includes/excludes lists

func SuggestionsFor added in v1.0.2

func SuggestionsFor(typedName string, values []string, suggestionsMinimumDistance int, explicitSuggestions ...string) []string

func ToStringMapStringFromStruct added in v1.3.242

func ToStringMapStringFromStruct(obj interface{}) map[string]string

ToStringMapStringFromStruct returns string[map]string from any struct. Use structs tag to change map keys. e.g. ServerName string `structs:"server_name"`

func UnTargz added in v1.0.6

func UnTargz(tarball, target string, onlyFiles []string) error

untargz a tarball to a target, from http://blog.ralch.com/tutorial/golang-working-with-tar-and-gzipf

func Unzip added in v1.0.2

func Unzip(src, dest string) error

func UrlHostNameWithoutPort added in v1.2.137

func UrlHostNameWithoutPort(rawUri string) (string, error)

UrlHostNameWithoutPort returns the host name without any port of the given URL like string

func UrlJoin

func UrlJoin(paths ...string) string

UrlJoin joins the given paths so that there is only ever one '/' character between the paths

Types

type CacheLoader added in v1.0.2

type CacheLoader func() ([]byte, error)

type Command added in v1.3.106

type Command struct {
	Errors             []error
	Dir                string
	Name               string
	Args               []string
	ExponentialBackOff *backoff.ExponentialBackOff
	Timeout            time.Duration
	Out                io.Writer
	Err                io.Writer
	Env                map[string]string
	// contains filtered or unexported fields
}

Command is a struct containing the details of an external command to be executed

func (*Command) Attempts added in v1.3.106

func (c *Command) Attempts() int

Attempts The number of times the command has been executed

func (*Command) DidError added in v1.3.106

func (c *Command) DidError() bool

DidError returns a boolean if any error occurred in any execution of the command

func (*Command) DidFail added in v1.3.106

func (c *Command) DidFail() bool

DidFail returns a boolean if the command could not complete (errored on every attempt)

func (*Command) Error added in v1.3.106

func (c *Command) Error() error

Error returns the last error

func (*Command) Run added in v1.3.106

func (c *Command) Run() (string, error)

Run Execute the command and block waiting for return values

func (*Command) RunWithoutRetry added in v1.3.106

func (c *Command) RunWithoutRetry() (string, error)

RunWithoutRetry Execute the command without retrying on failure and block waiting for return values

func (*Command) SetArgs added in v1.3.189

func (c *Command) SetArgs(args []string)

SetArgs Setter method for Args to enable use of interface instead of Command struct

func (*Command) SetDir added in v1.3.189

func (c *Command) SetDir(dir string)

SetDir Setter method for Dir to enable use of interface instead of Command struct

func (*Command) SetExponentialBackOff added in v1.3.189

func (c *Command) SetExponentialBackOff(backoff *backoff.ExponentialBackOff)

SetExponentialBackOff Setter method for ExponentialBackOff to enable use of interface instead of Command struct

func (*Command) SetName added in v1.3.189

func (c *Command) SetName(name string)

SetName Setter method for Name to enable use of interface instead of Command struct

func (*Command) SetTimeout added in v1.3.189

func (c *Command) SetTimeout(timeout time.Duration)

SetTimeout Setter method for Timeout to enable use of interface instead of Command struct

type Commander added in v1.3.262

type Commander interface {
	DidError() bool
	DidFail() bool
	Error() error
	Run() (string, error)
	RunWithoutRetry() (string, error)
	SetName(string)
	SetDir(string)
	SetArgs([]string)
	SetTimeout(time.Duration)
	SetExponentialBackOff(*backoff.ExponentialBackOff)
}

Commander defines the interface for a Command

type MethodMap added in v1.1.43

type MethodMap map[string]string

type Router added in v1.1.43

type Router map[string]MethodMap

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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