Documentation ¶
Index ¶
- func AskForConfirmation() bool
- func CaptureOutputToFile() (func() string, error)
- func CaptureStdOut() func() string
- func CaptureUserOut() func() string
- func CheckClose(c io.Closer)
- func CheckErr(err error)
- func ColorizeText(s string, c string) (out string)
- func Confirm(prompt string) bool
- func Debug(format string, a ...interface{})
- func DisableColors()
- func DownloadFile(destPath string, url string, progressBar bool) (err error)
- func ElapsedDuration(start time.Time) func() time.Duration
- func ElapsedTime(start time.Time) func() float64
- func EnsureHTTPStatus(o *HTTPOptions) error
- func Error(format string, a ...interface{})
- func Failed(format string, a ...interface{})
- func FindBashPath() string
- func FormatDuration(d time.Duration) string
- func FormatPlural(count int, single string, plural string) string
- func GetContainerUIDGid() (uidStr string, gidStr string, username string)
- func GetFirstWord(s string) string
- func GetInput(defaultValue string) string
- func HashSalt(projectName string) string
- func InterfaceSliceToStringSlice(v []interface{}) ([]string, error)
- func IsBeforeCutoffTime(cutoff string) bool
- func IsCommandAvailable(cmdName string) bool
- func Killall(processName string)
- func MapKeysToArray(mapWithKeys map[string]interface{}) []string
- func Prompt(prompt string, defaultValue string) string
- func RandString(n int) string
- func SemverValidate(constraint string, ver string) (bool, error)
- func SetInputScanner(scanner *bufio.Scanner)
- func SetLetterBytes(lb string)
- func SliceToUniqueSlice(inSlice *[]string) []string
- func Success(format string, a ...interface{})
- func TimeTrack() func()
- func TimeTrackC(customName string) func()
- func Verbose(format string, a ...interface{})
- func Warning(format string, a ...interface{})
- func YamlFileToMap(fname string) (map[string]interface{}, error)
- func YamlToDict(topm interface{}) (map[string]interface{}, error)
- type HTTPOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AskForConfirmation ¶
func AskForConfirmation() bool
AskForConfirmation requests a y/n from user.
func CaptureOutputToFile ¶ added in v1.21.5
CaptureOutputToFile captures Stdout to a string. Capturing starts when it is called. It returns an anonymous function that when called, will return a string containing the output during capture, and revert once again to the original value of os.StdOut.
func CaptureStdOut ¶ added in v1.4.0
func CaptureStdOut() func() string
CaptureStdOut captures Stdout to a string. Capturing starts when it is called. It returns an anonymous function that when called, will return a string containing the output during capture, and revert once again to the original value of os.StdOut.
func CaptureUserOut ¶ added in v1.4.0
func CaptureUserOut() func() string
CaptureUserOut captures output written to UserOut to a string. Capturing starts when it is called. It returns an anonymous function that when called, will return a string containing the output during capture, and revert once again to the original value of os.StdOut.
func CheckClose ¶
CheckClose is used to check the return from Close in a defer statement. From https://groups.google.com/d/msg/golang-nuts/-eo7navkp10/BY3ym_vMhRcJ
func CheckErr ¶
func CheckErr(err error)
CheckErr exits with a log.Fatal() if an error is encountered. It is normally used for errors that we never expect to happen, and don't have any normal handling technique. From https://davidnix.io/post/error-handling-in-go/
func ColorizeText ¶ added in v1.21.5
ColorizeText colorizes text unless SimpleFormatting is turned on
func Confirm ¶ added in v1.4.0
Confirm handles the asking and interpreting of a basic yes/no question. If DDEV_NONINTERACTIVE is set, Confirm() returns true. The prompt will be presented at most three times before returning false.
func Debug ¶ added in v1.21.5
func Debug(format string, a ...interface{})
Output controlled by DDEV_DEBUG environment variable
func DisableColors ¶ added in v1.21.5
func DisableColors()
func DownloadFile ¶
DownloadFile retrieves a file.
func ElapsedDuration ¶ added in v1.21.5
ElapsedDuration is an easy way to report how long something took. It returns an anonymous function that, when called, will return the elapsed duration.
func ElapsedTime ¶ added in v1.21.5
ElapsedTime is an easy way to report how long something took. It returns an anonymous function that, when called, will return the elapsed seconds.
func EnsureHTTPStatus ¶
func EnsureHTTPStatus(o *HTTPOptions) error
EnsureHTTPStatus will verify a URL responds with a given response code within the Timeout period (in seconds)
func Error ¶
func Error(format string, a ...interface{})
Error will print a red error message but will not exit.
func Failed ¶
func Failed(format string, a ...interface{})
Failed will print a red error message and exit with failure.
func FindBashPath ¶ added in v1.21.5
func FindBashPath() string
FindBashPath returns the PATH to Bash on any system on Windows preferring git-bash On Windows we'll need the path to Bash to execute anything. Returns empty string if not found, path if found
func FormatDuration ¶ added in v1.21.5
FormatDuration formats with 5m20s instead of lots of decimal points Based on https://stackoverflow.com/a/47342272/215713
func FormatPlural ¶
FormatPlural is a simple wrapper which returns different strings based on the count value.
func GetContainerUIDGid ¶ added in v1.4.0
GetContainerUIDGid returns the uid and gid (and string forms) to be used running most containers
func GetFirstWord ¶ added in v1.21.5
GetFirstWord returns the first space-separated word in a string.
func HashSalt ¶ added in v1.22.2
HashSalt returns a hash of the projectName to be used as a salt. This is appropriate onlly for development work, but means that the HashSalt will be predictable for users on a team
func InterfaceSliceToStringSlice ¶ added in v1.21.5
InterfaceSliceToStringSlice converts a slice of interfaces to a slice of strings
func IsBeforeCutoffTime ¶ added in v1.21.5
IsBeforeCutoffTime returns true if the current time is before the cutoff time, in format "01 Jan 21 10:00 UTC"
func IsCommandAvailable ¶ added in v1.4.0
IsCommandAvailable uses shell's "command" to find out if a command is available https://siongui.github.io/2018/03/16/go-check-if-command-exists/ This lives here instead of in fileutil to avoid unnecessary import cycles.
func Killall ¶ added in v1.21.5
func Killall(processName string)
Killall a process name on Linux/macOS/Windows. Avoid this as it may have unintended consequences.
func MapKeysToArray ¶ added in v1.1.0
MapKeysToArray takes the keys of the map and turns them into a string array
func RandString ¶
RandString returns a random string of given length n.
func SemverValidate ¶ added in v1.21.5
SemverValidate validates a string ver against a string constraint Returns bool, error
func SetInputScanner ¶
SetInputScanner allows you to override the default input scanner with your own.
func SetLetterBytes ¶ added in v1.1.0
func SetLetterBytes(lb string)
SetLetterBytes exists solely so that tests can override the default characters used by RandString. It should probably be avoided for 'normal' operations. this is actually used in utils_test.go (test only) so we set nolint on it. nolint: deadcode
func SliceToUniqueSlice ¶ added in v1.21.5
SliceToUniqueSlice processes a slice of string to make sure there are no duplicates
func Success ¶
func Success(format string, a ...interface{})
Success will indicate an operation succeeded with colored confirmation text.
func TimeTrack ¶ added in v1.21.5
func TimeTrack() func()
TimeTrack determines the amount of time a function takes to return. Timer starts when it is called. The printed name is determined from the calling function. It returns an anonymous function that, when called, will print the elapsed run time.
It only tracks if DDEV_VERBOSE is set.
Usage:
defer util.TimeTrack()()
or
tracker := util.TimeTrack() ... tracker()
func TimeTrackC ¶ added in v1.22.0
func TimeTrackC(customName string) func()
TimeTrackC determines the amount of time a function takes to return. Timer starts when it is called. The customName parameter is printed. It returns an anonymous function that, when called, will print the elapsed run time.
It only tracks if DDEV_VERBOSE is set.
Usage:
defer util.TimeTrackC("a custom name")()
or
tracker := util.TimeTrackC("a custom name") ... tracker()
func Verbose ¶ added in v1.22.0
func Verbose(format string, a ...interface{})
Output controlled by DDEV_VERBOSE environment variable
func Warning ¶
func Warning(format string, a ...interface{})
Warning will present the user with warning text.
func YamlFileToMap ¶ added in v1.21.5
YamlFileToMap() reads the named file into a map[string]interface{}
func YamlToDict ¶ added in v1.21.5
YamlToDict turns random yaml-based interface into a map[string]interface{}
Types ¶
type HTTPOptions ¶
type HTTPOptions struct { URL string Username string Password string Timeout time.Duration TickerInterval time.Duration ExpectedStatus int Headers map[string]string }
HTTPOptions defines the URL and other common HTTP options for EnsureHTTPStatus.
func NewHTTPOptions ¶
func NewHTTPOptions(URL string) *HTTPOptions
NewHTTPOptions returns a new HTTPOptions struct with some sane defaults.