utils

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnableDebug bool
View Source
var ValidateAlphaNumeric = survey.ComposeValidators(
	survey.Required,
	RegexValidator("[a-z][0-9\\-a-z]+", "Must be an alphanumeric string"),
)
View Source
var ValidateResourceGroupName = survey.ComposeValidators(
	survey.Required,
	RegexValidator("[a-z][a-z0-9]{2,62}", "Must be between 3 and 63 characters in length, start with lowercase letter and may contain numbers and lowercase letters only"),
)

ValidateResourceGroupName validates Azure resource group names.

View Source
var ValidateStorageAccountName = survey.ComposeValidators(
	survey.Required,
	RegexValidator("[a-z][a-z0-9]{2,23}", "Must be between 3 and 24 characters in length, start with lowercase letter and may contain numbers and lowercase letters only"),
)

ValidateStorageAccountName validates Azure storage account names.

Functions

func CheckLatestVersion

func CheckLatestVersion(currentVersion string)

func CleanUpInterfaceMap

func CleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{}

func Cmd

func Cmd(conf *config.Config, program string, args ...string) error

func CompareFileContent

func CompareFileContent(filename, content string) (bool, error)

func Confirm

func Confirm(msg string) bool

func CopyDir

func CopyDir(src string, dst string) error

func CopyFile

func CopyFile(src, dest string) error

func Dedupe

func Dedupe(l []string) []string

func DiffMap

func DiffMap(base, diff map[string]interface{}, conditions ...DiffCondition) map[string]interface{}

DiffMap removes keys from the base map based on provided DiffCondition match against the same keys in provided diff map. It always uses an equal comparison for the values, but specific keys can use extended comparison if needed by passing custom DiffCondition function.

Example:

A: {a: 1, b: 1, c: 2}
B: {a: 1, d: 2, c: 3}
Result: {b: 1, c: 2}

Note: It does not remove null value keys by default.

func DownloadFile

func DownloadFile(filepath string, url string) error

func EmptyDirectory

func EmptyDirectory(dir string) error

func Error

func Error(line string, args ...interface{})

func Exec

func Exec(program string, args ...string) error

func Execute

func Execute(cmd *exec.Cmd) error

func ExecuteWithOutput

func ExecuteWithOutput(cmd *exec.Cmd) (string, error)

func Exists

func Exists(path string) bool

func FileExists

func FileExists(val interface{}) error

func GenAESKey

func GenAESKey() string

func GetEnvBoolValue

func GetEnvBoolValue(key string) (bool, bool)

func GetEnvStringValue

func GetEnvStringValue(key string) (string, bool)

func GetKindClusterKubeconfig added in v0.8.5

func GetKindClusterKubeconfig(name string, internal bool) (string, error)

func Highlight

func Highlight(line string, args ...interface{})

func HighlightError

func HighlightError(err error) error

func IsDir added in v0.9.3

func IsDir(path string) bool

func IsEmpty

func IsEmpty(name string) (bool, error)

func IsKindClusterAlreadyExists added in v0.8.5

func IsKindClusterAlreadyExists(name string) bool

func ListDirectory added in v0.9.3

func ListDirectory(dir string) ([]string, error)

func LogError

func LogError() *log.Logger

func LogInfo

func LogInfo() *log.Logger

func Map

func Map[T any, R SimpleType](slice []T, mapper func(elem T) R) []R

func MapLua

func MapLua(tbl *lua.LTable, st interface{}) error

MapLua maps the lua table to the given struct pointer with default options.

func MkCmd

func MkCmd(conf *config.Config, program string, args ...string) *exec.Cmd

func Note

func Note(line string, args ...interface{})

func PatchInterfaceMap

func PatchInterfaceMap(defaultValues, values map[string]map[string]interface{}) (map[string]map[string]interface{}, error)

func Pluralize

func Pluralize(one, many string, count int) string

func PrintAttributes

func PrintAttributes(attrs map[string]string)

func PrintTable

func PrintTable[T any](list []T, headers []string, rowFun func(T) ([]string, error)) error

func ProjectRoot

func ProjectRoot() (root string, found bool)

func ReadAlphaNum

func ReadAlphaNum(prompt string) (string, error)

func ReadAlphaNumDefault

func ReadAlphaNumDefault(prompt string, def string) (string, error)

func ReadFile

func ReadFile(name string) (string, error)

func ReadLine

func ReadLine(prompt string) (string, error)

func ReadLineDefault

func ReadLineDefault(prompt string, def string) (string, error)

func ReadPwd

func ReadPwd(prompt string) (string, error)

func RegexValidator

func RegexValidator(regex, message string) survey.Validator

func RemoveNulls

func RemoveNulls(m map[string]interface{})

func Sha

func Sha(bv []byte) string

func Sha256

func Sha256(path string) (string, error)

func Success

func Success(line string, args ...interface{})

func Tar

func Tar(src string, w io.Writer, regex string) error

func ToGoValue

func ToGoValue(lv lua.LValue) interface{}

ToGoValue converts the given LValue to a Go object.

func ToString

func ToString(val interface{}) string

func Untar

func Untar(r io.Reader, dir, relpath string) error

func ValidateDns

func ValidateDns(val string) error

func ValidateRegex

func ValidateRegex(val, regex, message string) error

func ValidateSingleLevelDeep

func ValidateSingleLevelDeep(val, subdomain string) error

func WaitFor

func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error

func Warn

func Warn(line string, args ...interface{})

func Which

func Which(command string) (exists bool, path string)

func WriteFile

func WriteFile(name string, content []byte) error

func YamlFile added in v0.8.7

func YamlFile(name string, out interface{}) error

Types

type DiffCondition

type DiffCondition func(key string, value, diffValue any) bool

type Mapper

type Mapper struct {
}

Mapper maps a lua table to a Go struct pointer.

func NewMapper

func NewMapper() *Mapper

NewMapper returns a new mapper.

func (*Mapper) Map

func (mapper *Mapper) Map(tbl *lua.LTable, st interface{}) error

Map maps the lua table to the given struct pointer.

type Printer

type Printer interface {
	PrettyPrint()
}

func NewJsonPrinter

func NewJsonPrinter(i interface{}) Printer

func NewYAMLPrinter

func NewYAMLPrinter(i interface{}) Printer

type SimpleType

type SimpleType interface {
	string | int
}

type Versions

type Versions []*semverlib.Version

func (Versions) Len

func (s Versions) Len() int

func (Versions) Less

func (s Versions) Less(i, j int) bool

func (Versions) Swap

func (s Versions) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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