common

package
v0.0.0-...-7f7efcf Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: BSD-2-Clause Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TarantoolVersionFileName = "tarantool.txt"
)

Variables

View Source
var (
	ColorErr  *color.Color
	ColorWarn *color.Color
	ColorOk   *color.Color

	ColorRed       *color.Color
	ColorYellow    *color.Color
	ColorGreen     *color.Color
	ColorCyan      *color.Color
	ColorHiCyan    *color.Color
	ColorMagenta   *color.Color
	ColorHiMagenta *color.Color
	ColorBlue      *color.Color
	ColorHiBlue    *color.Color
)

Functions

func CheckRecommendedBinaries

func CheckRecommendedBinaries(binaries ...string)

CheckRecommendedBinaries warns if some binaries not found in PATH

func CheckRequiredBinaries

func CheckRequiredBinaries(binaries ...string) error

CheckRequiredBinaries returns an error if some binaries not found in PATH

func CheckTarantoolBinaries

func CheckTarantoolBinaries() error

CheckTarantoolBinaries returns an error if tarantool or tarantoolctl is not found in PATH

func ClearDir

func ClearDir(dirPath string) error

ClearDir removes all files from specified directory

func CompressGzip

func CompressGzip(srcFilePath string, destFilePath string) error

CompressGzip compresses specified file with gzip.BestCompression level

func ConcatBuffers

func ConcatBuffers(dest *bytes.Buffer, sources ...*bytes.Buffer) error

ConcatBuffers appends sources content to dest

func ContainsUpperSymbols

func ContainsUpperSymbols(src string) bool

func ConvertToSlice

func ConvertToSlice(raw interface{}) ([]interface{}, error)

func ConvertToStringsSlice

func ConvertToStringsSlice(s interface{}) ([]string, error)

func DecodeMsgpackStruct

func DecodeMsgpackStruct(d *msgpack.Decoder, v interface{}) error

func ErrWrapCheckInstanceNameCommonMisprint

func ErrWrapCheckInstanceNameCommonMisprint(instanceNames []string, projectName string, err error) error

func FileLinesScanner

func FileLinesScanner(file *os.File) *bufio.Scanner

FileLinesScanner returns scanner for file

func FileMD5

func FileMD5(path string) ([]byte, error)

FileMD5 computes MD5 for a given file. The result is returned in a binary form

func FileMD5Hex

func FileMD5Hex(path string) (string, error)

FileMD5Hex computes MD5 for a given file. The result is returned in a hex form

func FileSHA1Hex

func FileSHA1Hex(path string) (string, error)

FileSHA1Hex computes SHA1 for a given file. The result is returned in a hex form

func FileSHA256Hex

func FileSHA256Hex(path string) (string, error)

FileSHA256Hex computes SHA256 for a given file. The result is returned in a hex form

func FindRockspec

func FindRockspec(path string) (string, error)

FindRockspec finds *.rockspec file in specified path

func FormatStringStringMap

func FormatStringStringMap(mapStringString map[string]string) string

func GetCartridgeVersionStr

func GetCartridgeVersionStr(conn *connector.Conn) (string, error)

func GetCurrentUserID

func GetCurrentUserID() (string, error)

GetCurrentUserID returns current user UID

func GetFileContent

func GetFileContent(path string) (string, error)

GetFileContent returns file content as a string

func GetFileContentBytes

func GetFileContentBytes(path string) ([]byte, error)

GetFileContent returns file content as a bytes slice

func GetHomeDir

func GetHomeDir() (string, error)

GetHomeDir returns current home directory

func GetInstancesFromArgs

func GetInstancesFromArgs(args []string) ([]string, error)

func GetLastNLines

func GetLastNLines(filepath string, linesN int) ([]string, error)

func GetLastNLinesBegin

func GetLastNLinesBegin(filepath string, lines int) (int64, error)

GetLastNLinesBegin return the position of last lines begin

func GetMajorCartridgeVersion

func GetMajorCartridgeVersion(conn *connector.Conn) (int, error)

func GetMajorMinorVersion

func GetMajorMinorVersion(version string) string

GetMajorMinorVersion computes returns `<major>.<minor>` string for a given version

func GetMinimalRequiredVersion

func GetMinimalRequiredVersion(ver TarantoolVersion) (string, error)

GetMinimalRequiredVersion computes minimal required Tarantool version for a package (rpm, deb).

func GetMissedBinaries

func GetMissedBinaries(binaries ...string) []string

GetMissedBinaries returns list of binaries not found in PATH

func GetNextMajorVersion

func GetNextMajorVersion(ver TarantoolVersion) string

GetNextMajorVersion computes next Major version for a given one. For example, for 1.10.3 it's 2 .

func GetOutput

func GetOutput(cmd *exec.Cmd, dir *string) (string, error)

GetOutput runs specified command and returns it's stdout

func GetStringSlicesDifference

func GetStringSlicesDifference(s1, s2 []string) []string

func GetTarantoolDir

func GetTarantoolDir() (string, error)

GetTarantoolDir returns Tarantool executable directory.

func GetTarantoolVersion

func GetTarantoolVersion(tarantoolDir string) (string, error)

GetTarantoolVersion gets Tarantool version from the environment.

func GetTarantoolVersionFromFile

func GetTarantoolVersionFromFile(tarantoolVersionFilePath string) (string, error)

GetTarantoolVersionFromFile gets Tarantool version from config file.

func GitIsInstalled

func GitIsInstalled() bool

GitIsInstalled checks if git binary is in the PATH

func HasPerm

func HasPerm(fileInfo os.FileInfo, perm os.FileMode) bool

HasPerm checks if specified file has permissions

func InsertInStringSlice

func InsertInStringSlice(s []string, i int, elem string) []string

func IntsToStrings

func IntsToStrings(numbers []int) []string

IntsToStrings converts int slice to strings slice

func IsExecOwner

func IsExecOwner(path string) (bool, error)

IsExecOwner checks if specified file has owner execute permissions

func IsGitProject

func IsGitProject(path string) bool

IsGitProject checks if specified path is a git project

func IsSocket

func IsSocket(path string) (bool, error)

IsSocket checks if specified file is a socket

func IsSubDir

func IsSubDir(subdir string, dir string) (bool, error)

IsSubDir checks if directory is subdirectory of other

func LuaReadStringVar

func LuaReadStringVar(filePath string, varName string) (string, error)

LuaReadStringVar reads global string variable from specified Lua file

func MergeFiles

func MergeFiles(destFilePath string, srcFilePaths ...string) error

MergeFiles creates a file that is a concatenation of srcFilePaths

func OnlyOneIsTrue

func OnlyOneIsTrue(values ...bool) bool

OnlyOneIsTrue checks if one and only one of boolean values is true

func OptValue

func OptValue(opt OptionalUint64) (uint64, bool)

OptFrom returns Optional value and "is set" flag.

func ParseYmlFile

func ParseYmlFile(path string) (map[string]interface{}, error)

ParseYmlFile reads YAML file and returns it's content as a map

func PrintFromStart

func PrintFromStart(file *os.File) error

func Prompt

func Prompt(text, defaultValue string) string

Prompt a value with given text and default value

func RandomString

func RandomString(n int) string

RandomString generates random string length n

func RemoveFromStringSlice

func RemoveFromStringSlice(s []string, i int) []string

func ReplaceFileLinesByRe

func ReplaceFileLinesByRe(filePath string, re *regexp.Regexp, repl string) error

func RunCommand

func RunCommand(cmd *exec.Cmd, dir string, showOutput bool) error

RunCommand runs specified command and returns an error If showOutput is set to true, command output is shown Else spinner is shown while command is running

func RunFunctionWithSpinner

func RunFunctionWithSpinner(f func() error, prefix string) error

RunFunctionWithSpinner executes function and starts a spinner with specified prefix in a background until function returns

func RunHook

func RunHook(hookPath string, showOutput bool) error

RunHook runs specified hook and returns an error If showOutput is set to true, command output is shown

func SendReady

func SendReady(c ReadyChan)

func StartCommandSpinner

func StartCommandSpinner(c ReadyChan, wg *sync.WaitGroup, prefix string)

StartCommandSpinner starts running spinner until `ready` flag is received from the channel

func StdinHasUnreadData

func StdinHasUnreadData() (bool, error)

func StringSHA1Hex

func StringSHA1Hex(source string) string

StringSHA1Hex computes SHA1 for a given string The result is returned in a hex form

func StringSliceContains

func StringSliceContains(s []string, elem string) bool

func StringsSliceElemIndex

func StringsSliceElemIndex(s []string, elem string) int

func TarantoolIsEnterprise

func TarantoolIsEnterprise(tarantoolDir string) (bool, error)

TarantoolIsEnterprise checks if Tarantool is Enterprise

func TrimSince

func TrimSince(s string, since string) string

TrimSince trims a string starts with a given substring. For example, TrimSince("a = 1 # comment", "#") is "a = 1 "

func WriteTarArchive

func WriteTarArchive(srcDirPath string, compressWriter io.Writer) error

WriteTarArchive creates Tar archive of specified path using specified writer

func WriteTgzArchive

func WriteTgzArchive(srcDirPath string, destFilePath string) error

WriteTgzArchive creates TGZ archive of specified path

Types

type DepRelation

type DepRelation struct {
	Relation string `@( "=" "=" | "=" | ">" "=" | "<" "=" | ">" | "<" )`
	Version  string `@Number`
}

type OptionalUint64

type OptionalUint64 struct {
	// contains filtered or unexported fields
}

OptionalUint64 is optional value.

func OptFrom

func OptFrom(newValue uint64) OptionalUint64

OptFrom initializes Optional struct with provided value.

type PackDependencies

type PackDependencies []PackDependency

func ParseDependencies

func ParseDependencies(rawDeps []string) (PackDependencies, error)

func (*PackDependencies) AddTarantool

func (deps *PackDependencies) AddTarantool(minVersion, maxVersion string)

type PackDependency

type PackDependency struct {
	Name      string        `@Ident`
	Relations []DepRelation `(@@ ( "," @@ )?)?`
}

type ReadyChan

type ReadyChan chan emptyStruct

type ResChan

type ResChan chan Result

type ResMessageType

type ResMessageType int
const (
	ResMessageWarn ResMessageType = iota + 10
	ResMessageDebug
	ResMessageInfo
	ResMessageErr
)

type ResStatusType

type ResStatusType int
const (
	ResStatusOk ResStatusType = iota
	ResStatusSkipped
	ResStatusFailed
	ResStatusExited
	ResStatusUpdated
	ResStatusCreated
)

type Result

type Result struct {
	ID       string
	Status   ResStatusType
	Error    error
	Messages []ResultMessage
}

func (*Result) FormatError

func (res *Result) FormatError() error

func (*Result) String

func (res *Result) String() string

type ResultMessage

type ResultMessage struct {
	Type ResMessageType
	Text string
}

func GetDebugMessage

func GetDebugMessage(format string, a ...interface{}) ResultMessage

func GetErrMessage

func GetErrMessage(format string, a ...interface{}) ResultMessage

func GetInfoMessage

func GetInfoMessage(format string, a ...interface{}) ResultMessage

func GetMessage

func GetMessage(msgType ResMessageType, format string, a ...interface{}) ResultMessage

func GetWarnMessage

func GetWarnMessage(format string, a ...interface{}) ResultMessage

type RocksVersions

type RocksVersions map[string][]string

func LuaGetRocksVersions

func LuaGetRocksVersions(appDirPath string) (RocksVersions, error)

LuaGetRocksVersions gets map which contains {name: versions} from rocks manifest

type TarantoolVersion

type TarantoolVersion struct {
	Major                 uint64
	Minor                 OptionalUint64
	Patch                 OptionalUint64
	TagSuffix             string
	CommitsSinceTag       uint64
	CommitHashId          string
	EnterpriseSDKRevision string
	EnterpriseIsOnMacOS   bool
	IsDevelopmentBuild    bool
}

func ParseShortTarantoolVersion

func ParseShortTarantoolVersion(version string) (TarantoolVersion, error)

ParseShortTarantoolVersion parse Tarantool version provided by user.

func ParseTarantoolVersion

func ParseTarantoolVersion(version string) (TarantoolVersion, error)

ParseTarantoolVersion extracts Tarantool version string to a TarantoolVersion struct.

Jump to

Keyboard shortcuts

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