util

package
v0.4.48 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveUrl

func ArchiveUrl(repoUrl, ref string, trunk string, token string) (string, error)

ArchiveUrl returns the archive url for the repo at a given commit hash or branch or v release

func BuildCommand

func BuildCommand(command string, arguments string) (string, []string)

BuildCommand builds up the command to be used, depending on the OS in use This is required so that on Windows the command is prepended with "cmd /C" and the arguments need to be split up into a slice so that they are passed to the exec.Command method

func BuildGitHubAPIUrl

func BuildGitHubAPIUrl(repoUrl string, ref string, trunk string, archive bool, token string) string

func CallHTTPAPI

func CallHTTPAPI(url string, token string) (map[string]interface{}, error)

func CheckConnectivity

func CheckConnectivity(target string) error

func Copy

func Copy(srcFile, dstFile string) error

func CopyDirectory

func CopyDirectory(srcDir, dest string) error

using this as an inspiration https://github.com/moby/moby/blob/master/daemon/graphdriver/copy/copy.go CopyDirectory

func CopySymLink(source, dest string) error

func CreateIfNotExists

func CreateIfNotExists(dir string, perm os.FileMode) error

func Exists

func Exists(filePath string) bool

func GetDefaultCacheDir

func GetDefaultCacheDir() string

GetDefaultCacheDir returns the directory that should be used for caching all downloads that the CLI makes

func GetDefaultTempDir

func GetDefaultTempDir() string

GetDefaultTempDir determines the path to be used for the temporary directory It does not create it, but it will be set in the config for the CLI to create as and when it is required

func GetDefaultWorkingDir

func GetDefaultWorkingDir() string

GetDefaultWorkingDir returns the current directory as the default working directory for where projects will be created

func GetFileContent added in v0.4.17

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

func GetFileList added in v0.4.17

func GetFileList(pattern string, parent string) ([]string, error)

GetFileList returns a list of files that match the specified pattern

func GetGitHubArchiveUrl

func GetGitHubArchiveUrl(path string, token string) (string, error)

func GetPlatformOS

func GetPlatformOS() string

GetPlatformOS is a helper function to the runtime environment variable

func GetStacksCLIDir added in v0.4.17

func GetStacksCLIDir() string

GetStacksCLIDir returns the directory that should be used for storing all configuration

func GetUserHomeDir

func GetUserHomeDir() string

GetUserHomeDir returns the currenmt users home directory

func GetValueByDottedPath

func GetValueByDottedPath(data interface{}, path string) (interface{}, error)

GetValueByDottedPath returns the value of a field in a struct by using a string This is useful when checking the values of a struct for a specific value, or if it is null The string must be names of the attributes in the struct and not the ones in the mapstructure

func GitClone

func GitClone(repoUrl, ref, trunk string, tmpPath string, token string) (string, error)

GitClone uses standard network library to fetch a defined commit and avoids bloating the binary

func IsEmpty

func IsEmpty(name string) (bool, error)

IsEmpty states if the specified directory is empty or not

func IsUnixShell

func IsUnixShell() bool

IsUnixShell determines if the program is running in a Unix shell. This is required for the situations where Bash is being run on Windows for example.

This function is used to determine if the CLI should use forward slashes in any paths that are generated and shown to the user

func NestedMapLookup

func NestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{}, err error)

NestedMapLookup m: a map from strings to other maps or values, of arbitrary depth ks: successive keys to reach an internal or leaf node (variadic) If an internal node is reached, will return the internal map

Returns: (Exactly one of these will be nil) rval: the target node (if found) err: an error created by fmt.Errorf

func NormalisePath

func NormalisePath(path string, separator string) string

Normalise paths ensures that the path separator is correct for the specified platform

func RandomString

func RandomString(length int) string

RandomString returns a string with the specified number of characters. Useful for creating temporary filenames etc Uses the crypto random generator so as to always give a new string, using time as the seed was not fast enough for the tests.

func SliceContains

func SliceContains(slice []string, value string) bool

func TransformCRLF

func TransformCRLF(input string) string

TransformCRLF takes an input and ensures that all line endings are in LF This is to ensure that files read on a Windows machine behave as required with some libraries

func Unzip

func Unzip(src, dest string) (string, error)

Unzip will decompress a zip archive, moving all files and folders within the zip file (parameter 1) to an output directory (parameter 2). Returns all unzipped files (abs path)

func WriteYAMLToFile

func WriteYAMLToFile(object interface{}, path string, perm uint32) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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