Documentation ¶
Overview ¶
Package util contains a collection of miscellaneous utility functions.
Index ¶
- func Basename(p string) string
- func Bool(x interface{}) bool
- func BoolMapTrue(l []bool) bool
- func BoolMapValues(m map[string]bool) []bool
- func Code(code string) string
- func CopyDiskToFs(dstFs afero.Fs, src, dst string, force bool) error
- func CopyFs(srcFs, dstFs afero.Fs, src, dst string, force bool) error
- func CopyFsToDisk(srcFs afero.Fs, src, dst string, force bool) error
- func DirifyFileList(fileList []string, removeDirs bool) []string
- func Dirname(p string) string
- func ExpandHome(p string) (string, error)
- func FirstToUpper(str string) string
- func FlattenListWithSplit(input []string, split []string) []string
- func FsTree(fs afero.Fs, name string) (string, error)
- func HasPathPrefix(p, prefix string) bool
- func NumToAlpha(idx int) string
- func PathPrefixDelta(p, prefix string) int
- func PathSplit(p string) []string
- func PathSplitFullReversed(p string) []string
- func RemoveCommonFilePrefixes(paths []string) []string
- func ReverseStringList(in []string) []string
- func SortedStrSliceCompare(a, b []string) error
- func StrFilterElementsInList(filter []string, list []string) []string
- func StrInList(needle string, haystack []string) bool
- func StrInPathPrefixList(needle string, haystack []string) bool
- func StrListIntersection(list1 []string, list2 []string) []string
- func StrMapKeys(m map[string]string) []string
- func StrMapKeysUint64(m map[string]uint64) []string
- func StrMapValues(m map[string]string) []string
- func StrMapValuesUint64(m map[uint64]string) []string
- func StrRemoveDuplicatesInList(list []string) []string
- func SystemBusPrivateUsable() (conn *dbus.Conn, err error)
- func TimeAfterOrBlock(t int) <-chan time.Time
- func Uint(x interface{}) uint
- func Uint64KeyFromStrInMap(needle string, haystack map[uint64]string) (uint64, bool)
- type EasyExit
- type EasyOnce
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
func Bool(x interface{}) bool
Bool returns the interface value if it is a bool, and otherwise it panics.
func BoolMapTrue ¶
BoolMapTrue returns true if everyone in the list is true.
func BoolMapValues ¶
BoolMapValues returns the sorted list of bool values in a map with string values.
func Code ¶
Code takes a code block as a backtick enclosed `heredoc` and removes any common indentation from each line. This helps inline code as strings to be formatted nicely without unnecessary indentation. It also drops the very first line of code if it has zero length.
func CopyDiskToFs ¶
CopyDiskToFs performs exactly as CopyFs, except that the src fs is our local disk os fs.
func CopyFs ¶
CopyFs copies a dir from the srcFs to a dir on the dstFs. It expects that the dst will be either empty, or that the force flag will be set to true. If the dst has a different set of contents in the same location, the behaviour is currently undefined. TODO: this should be made more rsync like and robust!
func CopyFsToDisk ¶
CopyFsToDisk performs exactly as CopyFs, except that the dst fs is our local disk os fs.
func DirifyFileList ¶
DirifyFileList adds trailing slashes to any likely dirs in a package manager fileList if removeDirs is true, otherwise, don't keep the dirs in our output.
func ExpandHome ¶
ExpandHome does an expansion of ~/ or ~james/ into user's home dir value.
func FirstToUpper ¶
FirstToUpper returns the string with the first character capitalized.
func FlattenListWithSplit ¶
FlattenListWithSplit flattens a list of input by splitting each element by any and all of the strings listed in the split array
func FsTree ¶
FsTree returns a string representation of the file system tree similar to the well-known `tree` command.
func HasPathPrefix ¶
HasPathPrefix tells us if a path string contain the given path prefix in it.
func NumToAlpha ¶
NumToAlpha returns a lower case string of letters representing a number. If you specify 0, you'll get `a`, 25 gives you `z`, and 26 gives you `aa` and so on...
func PathPrefixDelta ¶
PathPrefixDelta returns the delta of the path prefix, which tells you how many path tokens different the prefix is.
func PathSplit ¶
PathSplit splits a path into an array of tokens excluding any trailing empty tokens.
func PathSplitFullReversed ¶
PathSplitFullReversed returns the full list of "dependency" paths for a given path in reverse order.
func RemoveCommonFilePrefixes ¶
RemoveCommonFilePrefixes removes redundant file path prefixes that are under the tree of other files.
func ReverseStringList ¶
ReverseStringList reverses a list of strings.
func SortedStrSliceCompare ¶
SortedStrSliceCompare takes two lists of strings and returns whether or not they are equivalent. It will return nil if both sets contain the same elements, regardless of order, and an error if they do not.
func StrFilterElementsInList ¶
StrFilterElementsInList removes any of the elements in filter, if they exist in the list.
func StrInPathPrefixList ¶
StrInPathPrefixList returns true if the needle is a PathPrefix in the haystack.
func StrListIntersection ¶
StrListIntersection removes any of the elements in filter, if they don't exist in the list. This is an in order intersection of two lists.
func StrMapKeys ¶
StrMapKeys return the sorted list of string keys in a map with string keys. NOTE: i thought it would be nice for this to use: map[string]interface{} but it turns out that's not allowed. I know we don't have generics, but come on!
func StrMapKeysUint64 ¶
StrMapKeysUint64 return the sorted list of string keys in a map with string keys but uint64 values.
func StrMapValues ¶
StrMapValues returns the sorted list of string values in a map with string values.
func StrMapValuesUint64 ¶
StrMapValuesUint64 return the sorted list of string values in a map with string values.
func StrRemoveDuplicatesInList ¶
StrRemoveDuplicatesInList removes any duplicate values in the list. This implementation is possibly sub-optimal (O(n^2)?) but preserves ordering.
func SystemBusPrivateUsable ¶
SystemBusPrivateUsable makes using the private bus usable TODO: should be upstream: https://github.com/godbus/dbus/issues/15
func TimeAfterOrBlock ¶
TimeAfterOrBlock is aspecial version of time.After that blocks when given a negative integer. When used in a case statement, the timer restarts on each select call to it.
Types ¶
type EasyExit ¶
type EasyExit struct {
// contains filtered or unexported fields
}
EasyExit is a struct that helps you build a close switch and signal which can be called multiple times safely, and used as a signal many times in parallel.
func (*EasyExit) Done ¶
Done triggers the exit signal. It associates an error condition with it too.