util

package
v1.3.440 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 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"
	DROPWIZARD = "dropwizard"
)
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

func AtoInt32(text string) (int32, error)

func BackupDir

func BackupDir() (string, error)

func BasicAuth

func BasicAuth(username, password string) string

func CacheDir

func CacheDir() (string, error)

func ColorNameValues

func ColorNameValues() []string

ColorNameValues returns all the color names sorted

func CombineErrors

func CombineErrors(errs ...error) error

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

func ConfigDir

func ConfigDir() (string, error)

func Confirm

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

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

func CopyDirOverwrite

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

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

func CreateUniqueDirectory

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

func DeleteDirContents(dir string) error

DeleteDirContents removes all the contents of the given directory

func DeleteFile

func DeleteFile(fileName string) (err error)

func DiffSlices

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

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

Download a file from the given URL

func DraftDir

func DraftDir() (string, error)

func EnvironmentsDir

func EnvironmentsDir() (string, error)

func FileExists

func FileExists(path string) (bool, error)

func FirstNotEmptyString

func FirstNotEmptyString(values ...string) string

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

func FormatDate

func FormatDate(t time.Time) string

func GetColor

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

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

func GetLatestTagFromGitHub

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

func GetLatestVersionFromGitHub

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

func GetLatestVersionStringFromGitHub

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

func GetMockAPIResponseFromFile

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

func HomeDir() string

func Int32ToA

func Int32ToA(n int32) string

func InvalidArg

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

func InvalidArgError

func InvalidArgError(value string, err error) error

func InvalidArgf

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

func InvalidOption

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

func InvalidOptionError

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

func InvalidOptionf

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

func IsEmpty

func IsEmpty(name string) (bool, error)

func JXBinLocation

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

func JXBinaryLocation(commandInterface Commander) (string, error)

JXBinaryLocation Returns the path to the currently installed JX binary.

func LoadBytes

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

loads a file

func LoadCacheData

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

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

func LogsDir

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

MarkdownLink returns a markdown link

func MavenBinaryLocation

func MavenBinaryLocation() (string, error)

func MissingOption

func MissingOption(name string) error

func OrganisationsDir

func OrganisationsDir() (string, error)

func Pad

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

func PadCenter

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

func PadLeft

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

func PadRight

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

func ParseDate

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

func PathWithBinary

func PathWithBinary(paths ...string) string

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

func PickName

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

func PickNameWithDefault

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

func PickNames

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

func PickPassword

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

func PickRequiredNameWithDefault

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

func PickValue

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

func PomFlavour

func PomFlavour(path string) (string, error)

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) (string, error)

RandStringBytesMaskImprSrc returns a random hexadecimal string of length n.

func RecreateDirs

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

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

func RenameFile

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

func ReverseStrings

func ReverseStrings(a []string)

func SelectNames

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

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

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

SortedMapKeys returns the sorted keys of the given map

func StringArrayIndex

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

func StringArrayToLower

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

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

StringMapHasValue returns true if the given map contains the given value

func StringMatchesAny

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

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

func StringMatchesPattern

func StringMatchesPattern(text string, pattern string) bool

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

func SuggestionsFor

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

func ToStringMapStringFromStruct

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

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

func Unzip(src, dest string) error

func UrlHostNameWithoutPort

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

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

type Command

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

func (c *Command) Attempts() int

Attempts The number of times the command has been executed

func (*Command) DidError

func (c *Command) DidError() bool

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

func (*Command) DidFail

func (c *Command) DidFail() bool

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

func (*Command) Error

func (c *Command) Error() error

Error returns the last error

func (*Command) Run

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

Run Execute the command and block waiting for return values

func (*Command) RunWithoutRetry

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

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

func (*Command) SetArgs

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

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

func (*Command) SetDir

func (c *Command) SetDir(dir string)

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

func (*Command) SetExponentialBackOff

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

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

func (*Command) SetName

func (c *Command) SetName(name string)

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

func (*Command) SetTimeout

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

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

type Commander

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

type MethodMap map[string]string

type Router

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