systools

package module
v0.0.0-...-4d11a70 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 13 Imported by: 9

Documentation

Index

Constants

View Source
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

View Source
var CurrentBgColor = "42"

CurrentBgColor current used background color

View Source
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

func CheckForCleanString(s string) (cleanString string, err error)

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 CopyFile

func CopyFile(source, target string) error

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

func CreateColorCode() (string, string)

CreateColorCode returns the colorcode by a random number

func Exists

func Exists(path string) (bool, error)

Exists reports whether the named file or directory exists.

func Exit

func Exit(code int) bool

Exit maps the os.Exit but executes all callbacks before it the exit was aborted, you will get false in return

func FileExists

func FileExists(path string) bool

fileExists reports whether the named file exists. it checks for file and not for directory

func FillString

func FillString(str string, length int) string

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

func FindStartChars(str string) string

FindStartChars returns the first chars of a string that are a letter or a number so "hello my friend" will be "hmf"

func GetDefaultBg

func GetDefaultBg() string

GetDefaultBg Get the Default Background

func GetReset

func GetReset() string

GetReset gets the reset code

func GetStdOutTermSize

func GetStdOutTermSize() (width, height int, err error)

func IsDirWriteable

func IsDirWriteable(path string) bool

func IsStdOutTerminal

func IsStdOutTerminal() bool

func LabelPrint

func LabelPrint(message string, attribute int) string

LabelPrint prints message by using current fore and background

func LabelPrintWithArg

func LabelPrintWithArg(message string, fg string, bg string, attribute int) string

LabelPrintWithArg prints message by using current fore and background

func MapRangeSortedFn

func MapRangeSortedFn(m map[string]any, fn func(key string, value any))

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

func NoEscapeSequences(str string) string

this function removes any escape sequences from a string

func PadString

func PadString(line string, max int) string

PadString Returns max len string filled with spaces

func PadStringToR

func PadStringToR(line string, max int) string

PadStringToR Returns max len string filled with spaces right placed

func PathCompare

func PathCompare(left, right string) bool

func PrintColored

func PrintColored(code string, outputs string) string

PrintColored formats string colored by the color id

func PrintableChars

func PrintableChars(str string) string

returns the string where any non printable chars are removed so "hello\x00my\x01friend" will be "hellomyfriend"

func ReadFileAsString

func ReadFileAsString(filename string) (string, error)

func ReadFileAsStrings

func ReadFileAsStrings(filename string) ([]string, error)

ReadFileAsStrings reads a file and returns its content as a slice of strings each line is a string

func RemoveBadCharacters

func RemoveBadCharacters(input string, dictionary []string) string

func RemoveFromSliceOnce

func RemoveFromSliceOnce(slice []string, search string) []string

RemoveFromSliceOnce removes the first occurence of search in slice

func ResetColors

func ResetColors(print bool) string

ResetColors resets terminal colors if print false you get the ansi code only

func SanitizeFilename

func SanitizeFilename(name string, relativePath bool) string

func ShortLabel

func ShortLabel(label string, max int) string

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 SliceContains(slice []string, search string) bool

func SliceContainsSub

func SliceContainsSub(slice []string, search string) bool

like SliceContains but with strings.Contains so we can search for substrings

func SortByKeyString

func SortByKeyString(m map[string]any, rowExec func(k string, v any))

func SplitQuoted

func SplitQuoted(oristr string, sep string) []string

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

func StrContains(str string, substr string) bool

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 StrLen

func StrLen(str string) int

func StrStr2StrAny

func StrStr2StrAny(m map[string]string) map[string]any

func StringInSlice

func StringInSlice(search string, slice []string) bool

Alias for SliceContains

func StringSplitArgs

func StringSplitArgs(argLine string, prefix string) (string, map[string]string)

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

func StringSubLeft(path string, max int) string

StringSubLeft returns the left part of a string

func StringSubRight

func StringSubRight(inStr string, max int) string

StringSubRight returns the right part of a string

func TestColorCombinations

func TestColorCombinations()

func TrimAllSpaces

func TrimAllSpaces(s string) string

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

func UpdateExistingFileIfNotContains(filename, content, doNotContain string) (bool, error)

UpdateExistingFileIfNotContains updates a file if it does not contain a string this is made to avoid multiple updates of the same file

func WatchSigTerm

func WatchSigTerm(callback func(os.Signal))

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 WriteFile

func WriteFile(filename, content string) error

func WriteFileIfNotExists

func WriteFileIfNotExists(filename, content string) (int, error)

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

type LabelColor struct {
	Color   string
	BgColor string
}

LabelColor contains fore and background color

Jump to

Keyboard shortcuts

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