utils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 26 Imported by: 17

Documentation

Index

Constants

View Source
const ModRelativePathPattern = `\$\{([a-zA-Z0-9_-]+:)?KCL_MOD\}/`

Variables

View Source
var PkgArchiveNotFound = goerrors.New("failed to find the downloaded kcl package tar file")

Functions

func AbsTarPath added in v0.3.7

func AbsTarPath(tarPath string) (string, error)

AbsTarPath checks whether path 'tarPath' exists and whether path 'tarPath' ends with '.tar' And after checking, absTarPath return the abs path for 'tarPath'.

func CheckPackageSum added in v0.3.7

func CheckPackageSum(checkedSum, localPath string) bool

CheckPackageSum will check whether the 'checkedSum' is equal to the hash of the package under 'localPath'.

func CreateFileIfNotExist

func CreateFileIfNotExist(filePath string, storeFunc func() error) error

CreateFileIfNotExist will check whether the file under a certain path 'filePath/fileName' exists, and return an error if it exists, and call the method 'storeFunc' to save the file if it does not exist.

func CreateSubdirInUserHome

func CreateSubdirInUserHome(subdir string) (string, error)

DefaultKpmHome create the '.kpm' in the user home and return the path of ".kpm".

func CreateSymlink(oldName, newName string) error

CreateSymlink will create symbolic link named 'newName' for 'oldName', and if the symbolic link already exists, it will be deleted and recreated. Note: CreateSymlink is only useful on unix-like systems.

func DirExists

func DirExists(path string) bool

DirExists will check whether the directory 'path' exists.

func Exists

func Exists(path string) (bool, error)

Whether the file exists

func ExtractTarball added in v0.8.3

func ExtractTarball(tarPath, destDir string) error

ExtractTarball support extracting tarball with '.tgz' format.

func FindKFiles

func FindKFiles(path string) ([]string, error)

FindKFiles will find all the '.k' files in the 'path' directory.

func FindPackage added in v0.10.0

func FindPackage(root, targetPackage string) (string, error)

FindPackage finds the package with the package name 'targetPackage' under the 'root' directory kcl.mod file.

func FindPkgArchive added in v0.11.0

func FindPkgArchive(path string) (string, error)

FindPkgArchive will find the full path of the KCL package archive in the 'path' directory.

func GenerateModRelativePath added in v0.11.0

func GenerateModRelativePath(pkgName, path string) string

GenerateModRelativePath generates a mod relative path from the package name and path

func GetUsernamePassword

func GetUsernamePassword(usernameOpt string, passwordOpt string, passwordFromStdinOpt bool) (string, string, error)

Copied/Adapted from https://github.com/helm/helm

func HashDir

func HashDir(dir string) (string, error)

HashDir computes the checksum of a directory by concatenating all files and hashing them by sha256.

func IsGitRepoUrl added in v0.8.0

func IsGitRepoUrl(str string) bool

IsGitRepoUrl will check whether the string 'str' is a git repo url

func IsKfile added in v0.3.6

func IsKfile(str string) bool

IsKfile will check whether the string 'str' is a k file path.

func IsModRelativePath added in v0.9.1

func IsModRelativePath(s string) bool

If the path preffix is `${KCL_MOD}` or `${KCL_MOD:xxx}`

func IsRef added in v0.3.6

func IsRef(str string) bool

IsRef will check whether the string 'str' is a reference.

func IsSymlinkValidAndExists added in v0.8.5

func IsSymlinkValidAndExists(symlinkPath string) (bool, bool, error)

IsSymlinkValidAndExists will check whether the symlink exists and points to a valid target return three values: whether the symlink exists, whether it points to a valid target, and any error encountered Note: IsSymlinkValidAndExists is only useful on unix-like systems.

func IsTar added in v0.3.6

func IsTar(str string) bool

IsTar will check whether the string 'str' is a tar path.

func IsURL added in v0.3.6

func IsURL(str string) bool

IsUrl will check whether the string 'str' is a url.

func JoinPath added in v0.3.2

func JoinPath(elems ...string) string

JoinPath will join the 'elem' to the 'base' with '/'.

func MatchesPackageName added in v0.11.0

func MatchesPackageName(kclModPath, targetPackage string) bool

MatchesPackageName checks whether the package name in the kcl.mod file under 'kclModPath' is equal to 'targetPackage'.

func MoveFile added in v0.9.0

func MoveFile(src, dest string) error

MoveFile will move the file from 'src' to 'dest'. On windows, it will copy the file from 'src' to 'dest', and then delete the file under 'src'. On unix-like systems, it will rename the file from 'src' to 'dest'.

func MoveOrCopy added in v0.11.0

func MoveOrCopy(src, dest string) error

MoveOrCopy moves or copies the tmpDir to localPath based on the OS and error conditions. On windows, it will copy the file from 'src' to 'dest'. On unix-like systems, it will rename the file from 'src' to 'dest'.

func ParseModRelativePath added in v0.11.0

func ParseModRelativePath(s string) (string, string, error)

ParseModRelativePath parses the package name and path from a mod relative path

func ParseRepoNameFromGitUrl

func ParseRepoNameFromGitUrl(gitUrl string) string

ParseRepoNameFromGitUrl get the repo name from git url, the repo name in 'https://github.com/xxx/kcl1.git' is 'kcl1'.

func RmNewline

func RmNewline(s string) string

RmNewline will remove all the '\r\n' and '\n' in the string 's'.

func ShortHash added in v0.11.0

func ShortHash(input string) (string, error)

ShortHash takes a string (in this case, the Git URL) and returns a siphash. The method name references `cargo` which means performs a simple and quick hash

func StoreToFile

func StoreToFile(filePath string, dataStr string) error

StoreToFile will store 'data' into toml file under 'filePath'.

func TarDir

func TarDir(srcDir string, tarPath string, include []string, exclude []string) error

func UnTarDir

func UnTarDir(tarPath string, destDir string) error

UnTarDir will extract tar from 'tarPath' to 'destDir'.

Types

This section is empty.

Jump to

Keyboard shortcuts

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