util

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: BSD-2-Clause Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const MinCommitHashLength = 7

MinCommitHashLength is the Git default for a short SHA.

Variables

This section is empty.

Functions

func AskConfirm

func AskConfirm(ioReader io.Reader, question string) (bool, error)

AskConfirm asks the user for confirmation and returns true if yes.

func AtoiUint64

func AtoiUint64(str string) (uint64, error)

AtoiUint64 converts string to uint64.

func BitHas32

func BitHas32(b, flag uint32) bool

BitHas32 checks if a bit is set in b.

func Bold

func Bold(s string) string

Bold makes the input string bold.

func Chdir

func Chdir(newPath string) (func() error, error)

Chdir changes current directory and updates PWD environment var accordingly. This can be useful for some scripts, which use getenv('PWD') to get working directory.

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 CheckVersionFromGit

func CheckVersionFromGit(basePath string) (string, error)

CheckVersionFromGit enters the passed path, tries to get a git version it is a git repo, parses and returns a normalized string.

func ConcatBuffers

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

ConcatBuffers appends sources content to dest.

func CopyFileChangePerms

func CopyFileChangePerms(src string, dst string, perms int) error

CopyFileChangePerms copies file from source to destination with changing perms.

func CopyFilePreserve

func CopyFilePreserve(src string, dst string) error

CopyFilePreserve copies file from source to destination with perms.

func CreateDirectory

func CreateDirectory(dirName string, fileMode os.FileMode) error

CreateDirectory create a directory with existence and error checks.

func CreateSymlink(oldName string, newName string, overwrite bool) error

CreateSymlink creates newName as a symbolic link to oldName. Overwrites existing if overwrite flag is set.

func ExecuteCommand

func ExecuteCommand(program string, isVerbose bool, writer io.Writer, workDir string,
	args ...string) error

ExecuteCommand executes program with given args in verbose or quiet mode.

func ExecuteCommandGetOutput

func ExecuteCommandGetOutput(program string, workDir string, stdinData []byte,
	args ...string) ([]byte, error)

ExecuteCommandStdin executes program with given args in verbose or quiet mode and sends stdinData to stdin pipe.

func ExecuteCommandStdin

func ExecuteCommandStdin(program string, isVerbose bool, logFile *os.File, workDir string,
	stdinData []byte, args ...string) error

ExecuteCommandStdin executes program with given args in verbose or quiet mode and sends stdinData to stdin pipe.

func ExtractTar

func ExtractTar(tarName string) error

ExtractTar extracts tar archive.

func ExtractTarGz

func ExtractTarGz(tarName string, dstDir string) error

ExtractTarGz extracts tar.gz archive.

func FileLinesScanner

func FileLinesScanner(reader io.Reader) *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 Find

func Find(src []string, find string) int

Find find index of specified string in the slice.

func FindNamedMatches

func FindNamedMatches(re *regexp.Regexp, str string) map[string]string

FindNamedMatches processes regexp with named capture groups and transforms output to a map. If capture group is optional and was not found, map value is empty string.

func GetArch

func GetArch() (string, error)

GetArch returns Architecture of machine.

func GetFileContent

func GetFileContent(path string) (string, error)

GetFileContent returns file content as a string.

func GetFileContentBytes

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

GetFileContentBytes returns file content as a bytes slice.

func GetHelpCommand

func GetHelpCommand(cmd *cobra.Command) *cobra.Command

GetHelpCommand returns the help command for the passed cmd argument.

func GetHomeDir

func GetHomeDir() (string, error)

GetHomeDir returns current home directory.

func GetLastNLines

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

GetLastNLines returns the last N lines from the file.

func GetLastNLinesBegin

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

GetLastNLinesBegin return the position of last lines begin.

func GetTextTemplatedStr

func GetTextTemplatedStr(text *string, obj interface{}) (string, error)

GetTextTemplatedStr returns the processed string text template.

func GetYamlFileName

func GetYamlFileName(fileName string, mustExist bool) (string, error)

GetYamlFileName searches for file with .yaml or .yml extension, based on the file name provided. If mustExist flag is set and no yaml files are found, ErrNotExists error is returned, passed fileName is returned otherwise.

func InstantiateFileFromTemplate added in v0.3.0

func InstantiateFileFromTemplate(templatePath string, templateContent string,
	params map[string]interface{}) error

InstantiateFileFromTemplate accepts the path to file, template content and parameters for its filling.

func InternalError

func InternalError(format string, f VersionFunc, err ...interface{}) error

InternalError shows error information, version of tt and call stack.

func IsApp

func IsApp(path string) bool

IsApp detects if the passed path is an application.

func IsDir

func IsDir(filePath string) bool

isRegularFile checks if filePath is a directory. Returns true if the directory exists.

func IsExecOwner

func IsExecOwner(path string) (bool, error)

IsExecOwner checks if specified file has owner execute permissions.

func IsGitFetchJobsSupported added in v1.0.0

func IsGitFetchJobsSupported() bool

IsGitFetchJobsSupported checks if fetchJobs option (-j) is supported by current git version.

func IsPullRequest added in v1.3.0

func IsPullRequest(input string) (bool, string)

IsPullRequest returns is this pull-request format and pr num.

func IsRegularFile

func IsRegularFile(filePath string) bool

isRegularFile checks if filePath is a regular file. Returns true if the file exists and it is a regular file.

func IsValidCommitHash added in v1.3.0

func IsValidCommitHash(hash string) (bool, error)

IsValidCommitHash checks hash format.

func JoinAbspath

func JoinAbspath(paths ...string) (string, error)

JoinAbspath concat paths and makes the resulting path absolute.

func Max

func Max(x, y int) int

Max returns the maximum value.

func MergeFiles

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

MergeFiles creates a file that is a concatenation of srcFilePaths.

func Min added in v1.3.0

func Min[T constraints.Ordered](a, b T) T

Min returns minimal of two values.

func NewArgError added in v0.4.0

func NewArgError(text string) error

NewArgError creates and returns new argument error.

func ParseYAML

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

ParseYAML parse yaml file at specified path.

func PrintFromStart

func PrintFromStart(file *os.File) error

func ReadEmbedFile

func ReadEmbedFile(fs embed.FS, path string) (string, error)

ReadEmbedFile reads content of embed file in string mode.

func ReadEmbedFileBinary

func ReadEmbedFileBinary(fs embed.FS, path string) ([]byte, error)

ReadEmbedFileBinary reads content of embed file in byte mode.

func RelativeToCurrentWorkingDir added in v1.0.1

func RelativeToCurrentWorkingDir(fullpath string) string

RelativeToCurrentWorkingDir returns a path relative to current working dir. In case of error, fullpath is returned.

func ResolveSymlink(linkPath string) (string, error)

ResolveSymlink resolves symlink path.

func RunCommand

func RunCommand(cmd *exec.Cmd, workingDir 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 RunCommandAndGetOutput

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

RunCommandAndGetOutput returns output of command.

func RunHook

func RunHook(hookPath string, showOutput bool) error

RunHook runs the specified hook. If showOutput is set to true, command output is shown.

func StartCommandSpinner

func StartCommandSpinner(readyChannel readyChan, wg *sync.WaitGroup, prefix string)

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

func StringSHA1Hex

func StringSHA1Hex(source string) string

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

func WriteYaml

func WriteYaml(fileName string, o interface{}) error

writeYaml writes YAML encoding of object o to fileName.

Types

type AppListEntry added in v0.4.0

type AppListEntry struct {
	// Name is application name.
	Name string
	// Location is application source file or directory.
	Location string
}

AppListEntry contains information about found application.

func CollectAppList added in v0.3.0

func CollectAppList(baseDir string, appsPath string, verbose bool) ([]AppListEntry, error)

CollectAppList collects all the supposed applications in passed appsPath directory.

type ArgError added in v0.4.0

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

ArgError represents command line arguments error.

func (ArgError) Error added in v0.4.0

func (e ArgError) Error() string

Error returns error message.

type OsType

type OsType uint16
const (
	OsLinux OsType = iota
	OsMacos
	OsUnknown
)

func GetOs

func GetOs() (OsType, error)

GetOs returns the operating system version of the host.

type VersionFunc

type VersionFunc func(bool, bool) string

VersionFunc is a type of function that return string with current Tarantool CLI version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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