utils

package
v0.0.0-...-1f80534 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CurrentPath string

Functions

func CanonicalPath

func CanonicalPath(path string, basePath string) (string, error)

Return the canonical version of the given path, relative to the given base path. That is, if the given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.

func CanonicalPaths

func CanonicalPaths(paths []string, basePath string) ([]string, error)

Return the canonical version of the given paths, relative to the given base path. That is, if a given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.

func CheckAndExit

func CheckAndExit(err error)

func CheckAndStackTrace

func CheckAndStackTrace(err error)

func CheckErr

func CheckErr(err error) bool

func CheckOS

func CheckOS()

func CleanPath

func CleanPath(path string) string

Use this function when cleaning paths to ensure the returned path uses / as the path separator to improve cross-platform compatibility

func CopyFile

func CopyFile(source string, destination string) error

Copy a file from source to destination

func CopyFolderContents

func CopyFolderContents(source, destination, manifestFile string) error

Copy the files and folders within the source folder into the destination folder. Note that hidden files and folders (those starting with a dot) will be skipped. Will create a specified manifest file that contains paths of all copied files.

func CopyFolderContentsWithFilter

func CopyFolderContentsWithFilter(source, destination, manifestFile string, filter func(path string) bool) error

Copy the files and folders within the source folder into the destination folder. Pass each file and folder through the given filter function and only copy it if the filter returns true. Will create a specified manifest file that contains paths of all copied files.

func EncodeBase64Sha1

func EncodeBase64Sha1(str string) string

Returns the base 64 encoded sha1 hash of the given string

func FileExists

func FileExists(path string) bool

Return true if the given file exists

func FileNotExists

func FileNotExists(path string) bool

Return true if the given file does not exist

func GetPathRelativeTo

func GetPathRelativeTo(path string, basePath string) (string, error)

Return the relative path you would have to take to get from basePath to path

func Grep

func Grep(regex *regexp.Regexp, glob string) (bool, error)

Returns true if the given regex can be found in any of the files matched by the given glob

func IsDir

func IsDir(path string) bool

Return true if the path points to a directory

func IsFile

func IsFile(path string) bool

Return true if the path points to a file

func IsSymLink(path string) bool

IsSymLink returns true if the given file is a symbolic link Per https://stackoverflow.com/a/18062079/2308858

func JoinPath

func JoinPath(elem ...string) string

Windows systems use \ as the path separator *nix uses / Use this function when joining paths to force the returned path to use / as the path separator This will improve cross-platform compatibility

func JoinTerraformModulePath

func JoinTerraformModulePath(modulesFolder string, path string) string

Join two paths together with a double-slash between them, as this is what Terraform uses to identify where a "repo" ends and a path within the repo begins. Note: The Terraform docs only mention two forward-slashes, so it's not clear if on Windows those should be two back-slashes? https://www.terraform.io/docs/modules/sources.html

func MustExec

func MustExec(name string, arg ...string)

func MustExecNoOut

func MustExecNoOut(name string, arg ...string)

func MustExecRtOut

func MustExecRtOut(name string, arg ...string) string

func PathContainsHiddenFileOrFolder

func PathContainsHiddenFileOrFolder(path string) bool

func ReadFileAsString

func ReadFileAsString(path string) (string, error)

Return the contents of the file at the given path as a string

func Root

func Root() bool

func TryExec

func TryExec(name string, arg ...string) error

func WriteFileWithSamePermissions

func WriteFileWithSamePermissions(source string, destination string, contents []byte) error

Write a file to the given destination with the given contents using the same permissions as the file at source

Types

This section is empty.

Jump to

Keyboard shortcuts

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