Documentation ¶
Index ¶
- Constants
- Variables
- func AddExitListener(name string, callbk func(int) ExitBehavior)
- func AnyToStrNoTabs(any interface{}) string
- func CheckForCleanString(s string) (cleanString string, err error)
- func CopyFile(source, target string) error
- func CreateBgColor() string
- func CreateBgColorCode() string
- func CreateColorCode() (string, string)
- func Exists(path string) (bool, error)
- func Exit(code int) bool
- func FileExists(path string) bool
- func FillString(str string, length int) string
- func FindStartChars(str string) string
- func GetDefaultBg() string
- func GetReset() string
- func GetStdOutTermSize() (width, height int, err error)
- func IsDirWriteable(path string) bool
- func IsStdOutTerminal() bool
- func LabelPrint(message string, attribute int) string
- func LabelPrintWithArg(message string, fg string, bg string, attribute int) string
- func MapRangeSortedFn(m map[string]any, fn func(key string, value any))
- func NoEscapeSequences(str string) string
- func PadString(line string, max int) string
- func PadStringToR(line string, max int) string
- func PathCompare(left, right string) bool
- func PrintColored(code string, outputs string) string
- func PrintableChars(str string) string
- func ReadFileAsString(filename string) (string, error)
- func ReadFileAsStrings(filename string) ([]string, error)
- func RemoveBadCharacters(input string, dictionary []string) string
- func RemoveFromSliceOnce(slice []string, search string) []string
- func ResetColors(print bool) string
- func SanitizeFilename(name string, relativePath bool) string
- func ShortLabel(label string, max int) string
- func SliceContains(slice []string, search string) bool
- func SliceContainsSub(slice []string, search string) bool
- func SortByKeyString(m map[string]any, rowExec func(k string, v any))
- func SplitQuoted(oristr string, sep string) []string
- func StrContains(str string, substr string) bool
- func StrLen(str string) int
- func StrStr2StrAny(m map[string]string) map[string]any
- func StringInSlice(search string, slice []string) bool
- func StringSplitArgs(argLine string, prefix string) (string, map[string]string)
- func StringSubLeft(path string, max int) string
- func StringSubRight(inStr string, max int) string
- func TestColorCombinations()
- func TrimAllSpaces(s string) string
- func UpdateExistingFileIfNotContains(filename, content, doNotContain string) (bool, error)
- func WatchSigTerm(callback func(os.Signal))
- func WriteFile(filename, content string) error
- func WriteFileIfNotExists(filename, content string) (int, error)
- type ExitBehavior
- type LabelColor
Constants ¶
const ( ExitOk = 0 // Everything is fine ErrorExitDefault = 1 // any exit depending an error that do not need being specific ErrorInitApp = 2 // any application error while setting up ErrorWhileLoadCfg = 3 // any error while loading configuration ErrorOnConfigImport = 5 // a import could not handled ErrorTemplate = 6 // template related error. depending reported issues about version, lint, yaml structure ErrorTemplateReading = 7 // errors processing the template ErrorCheatMacros = 8 // errors processing the cheat macros ErrorBySystem = 10 // errors related to the system, like while change dir or reading a file ExitByStopReason = 101 // ExitByStopReason the process stopped because of a defined reason ExitNoCode = 102 // ExitNoCode means there was no code associated ExitCmdError = 103 // ExitCmdError means the execution of the command fails. a error by the command itself ExitByRequirement = 104 // ExitByRequirement means a requirement was not fulfills ExitAlreadyRunning = 105 // ExitAlreadyRunning means the task is not started, because it is already created ExitByNoTargetExists = 106 // none of the targets are matching in requirements ExitByNothingToDo = 107 // none of the targets have any usefull work to do or did not match any requirements ExitByTimeout = 108 // ExitByTimeout means the task was stopped because of a timeout ExitByUnsupportedVersion = 109 // ExitByWongVersion means the version is not matching. it needs to be equal or higher ExitNoTasks = 110 // ExitNoTasks means there are no tasks to run ErrorInvalidTargetName = 111 // ErrorInvalidTargetName means the target name is not valid )
Variables ¶
var CurrentBgColor = "42"
CurrentBgColor current used background color
var CurrentColor = "32"
CurrentColor current used foreground color
Functions ¶
func AddExitListener ¶
func AddExitListener(name string, callbk func(int) ExitBehavior)
adds a callback as listener
func AnyToStrNoTabs ¶
func AnyToStrNoTabs(any interface{}) string
AnyToStrNoTabs just converts any tab (\t) to a space so "hello\tworld" will be "hello world"
func CheckForCleanString ¶
CheckForCleanString checks if a string contains only accepted chars for a string. these are A-Z, a-z, 0-9, _ and - so "hello_my-friend" is a clean string "hello_my-friend!" is not a clean string there are chars they will just be replaced by a clean char and in this case no error will be returned so "hello.my:friend" will be "hello-my--friend" and no error will be returned but if after that the string contains any other char (what will be checked by a regex) an error will be returned this is usefull for keys in json, yaml or other config files
func CreateBgColor ¶
func CreateBgColor() string
CreateBgColor defines a random color and returns a id
func CreateBgColorCode ¶
func CreateBgColorCode() string
CreateBgColorCode returns the colorcode by a random number
func CreateColorCode ¶
CreateColorCode returns the colorcode by a random number
func Exit ¶
Exit maps the os.Exit but executes all callbacks before it the exit was aborted, you will get false in return
func FileExists ¶
fileExists reports whether the named file exists. it checks for file and not for directory
func FillString ¶
FillString fills a string with spaces to a given length but only if the string is shorter than the length so "hello" with a length of 10 will be "hello " and "hello" with a length of 3 will be "hello"
func FindStartChars ¶
FindStartChars returns the first chars of a string that are a letter or a number so "hello my friend" will be "hmf"
func GetStdOutTermSize ¶
func IsDirWriteable ¶
func IsStdOutTerminal ¶
func IsStdOutTerminal() bool
func LabelPrint ¶
LabelPrint prints message by using current fore and background
func LabelPrintWithArg ¶
LabelPrintWithArg prints message by using current fore and background
func MapRangeSortedFn ¶
an callback handler to sort the entries in a map by key first and then call the callback function with the key and value
func NoEscapeSequences ¶
this function removes any escape sequences from a string
func PadStringToR ¶
PadStringToR Returns max len string filled with spaces right placed
func PathCompare ¶
func PrintColored ¶
PrintColored formats string colored by the color id
func PrintableChars ¶
returns the string where any non printable chars are removed so "hello\x00my\x01friend" will be "hellomyfriend"
func ReadFileAsString ¶
func ReadFileAsStrings ¶
ReadFileAsStrings reads a file and returns its content as a slice of strings each line is a string
func RemoveBadCharacters ¶
func RemoveFromSliceOnce ¶
RemoveFromSliceOnce removes the first occurence of search in slice
func ResetColors ¶
ResetColors resets terminal colors if print false you get the ansi code only
func SanitizeFilename ¶
func ShortLabel ¶
this function creates a short label from a string by looking for the first char that is a letter until a non letter char is found. so hello-my-friend will be hmf or hello_my_friend will be hmf or hello my friend will be hmf also for escape sequences so \033[1;32mC.H.E.C.K\033[0m will be CHECK
func SliceContains ¶
func SliceContainsSub ¶
like SliceContains but with strings.Contains so we can search for substrings
func SplitQuoted ¶
SplitQuoted splits a string by a separator and respects quoted strings so 'hello my friend' will be ['hello my friend'] and hello my friend will be ['hello', 'my', 'friend'] this func is only using single quotes
func StrContains ¶
StrContains checks if a string contains a substring by not using the strings.Contains function because the use template strings and the function would not work as expected
func StringSplitArgs ¶
StringSplitArgs splits a string into a command and arguments the first argument is the command, the rest are arguments the prefix is used to create the map keys for the arguments so the first argument will be prefix0, the second prefix1 etc.
func StringSubLeft ¶
StringSubLeft returns the left part of a string
func StringSubRight ¶
StringSubRight returns the right part of a string
func TestColorCombinations ¶
func TestColorCombinations()
func TrimAllSpaces ¶
returns the string where any spaces, with an length of more than 1 are replaced by one space so "hello my friend" will be "hello my friend"
func UpdateExistingFileIfNotContains ¶
UpdateExistingFileIfNotContains updates a file if it does not contain a string this is made to avoid multiple updates of the same file
func WatchSigTerm ¶
WatchSigTerm adds a callback function that will be executed if the app receives a SIGTERM signal if no callback is given, the app will exit with code 0 and all registered callbacks will be executed
func WriteFileIfNotExists ¶
WriteFileIfNotExists writes a file if it does not exist reports 0 if file was written, 1 if file exists, 2 if error on error, error is returned
Types ¶
type ExitBehavior ¶
type ExitBehavior struct {
// contains filtered or unexported fields
}
var ( Continue ExitBehavior = ExitBehavior{/* contains filtered or unexported fields */} Interrupt ExitBehavior = ExitBehavior{/* contains filtered or unexported fields */} )
type LabelColor ¶
LabelColor contains fore and background color