utils

package
v0.0.0-...-bbf7051 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: GPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ignore        = 0 // Redirect to null
	Show          = 1 // Show on stdout/stderr as normal
	ShowIfVerbose = 2 // Show if verbose is set, Ignore otherwise
	Capture       = 3 // Capture into buffer
)

Variables

View Source
var SOURCE_CONTROL_FOLDERS = map[string]bool{"CVS": true, "RCS": true, ".git": true, ".github": true, ".svn": true, ".hg": true, ".bzr": true, ".vscode": true, ".settings": true}

Functions

func AbsolutizePaths

func AbsolutizePaths(files []string) ([]string, error)

func AppendIfNotPresent

func AppendIfNotPresent(target []string, elements ...string) []string

func CopyDir

func CopyDir(src string, dst string, extensions CheckExtensionFunc) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func EnsureFolderExists

func EnsureFolderExists(folder string) error

func ExecCommand

func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int) ([]byte, []byte, error)

func Filter

func Filter(slice []string, fn filterFunc) []string

func FilterDirs

func FilterDirs(files []os.FileInfo) []os.FileInfo

func FilterFiles

func FilterFiles() filterFiles

func FilterFilesWithExtensions

func FilterFilesWithExtensions(extensions ...string) filterFiles

func FilterOutFoldersByNames

func FilterOutFoldersByNames(folders []os.FileInfo, names ...string) []os.FileInfo

func FindAllSubdirectories

func FindAllSubdirectories(folder string, output *[]string) error

func FindFilesInFolder

func FindFilesInFolder(files *[]string, folder string, extensions CheckExtensionFunc, recurse bool) error

func GetParentFolder

func GetParentFolder(basefolder string, n int) string

func IsHiddenFile

func IsHiddenFile(file os.FileInfo) bool

func IsSCCSFile

func IsSCCSFile(file os.FileInfo) bool

func IsSCCSOrHiddenFile

func IsSCCSOrHiddenFile(file os.FileInfo) bool

func LogIfVerbose

func LogIfVerbose(level string, format string, args ...interface{}) types.Command

func LogThis

func LogThis(level string, format string, args ...interface{}) types.Command

func MD5Sum

func MD5Sum(data []byte) string

func Map

func Map(slice []string, fn mapFunc) []string

func MapHas

func MapHas(aMap map[string]interface{}, key string) bool

func MapStringStringHas

func MapStringStringHas(aMap map[string]string, key string) bool

func NULLFile

func NULLFile() string

func NormalizeUTF8

func NormalizeUTF8(buf []byte) []byte

Normalizes an UTF8 byte slice TODO: use it more often troughout all the project (maybe on logger interface?)

func ParseCommandLine

func ParseCommandLine(input string, logger i18n.Logger) ([]string, error)

func ParseCppString

func ParseCppString(line string) (string, string, bool)

Parse a C-preprocessor string as emitted by the preprocessor. This is a string contained in double quotes, with any backslashes or quotes escaped with a backslash. If a valid string was present at the start of the given line, returns the unquoted string contents, the remaineder of the line (everything after the closing "), and true. Otherwise, returns the empty string, the entire line and false.

func PrepareCommand

func PrepareCommand(pattern string, logger i18n.Logger, relativePath string) (*exec.Cmd, error)

func PrepareCommandFilteredArgs

func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger, relativePath string) (*exec.Cmd, error)

func PrettyOSName

func PrettyOSName() string

func PrintableCommand

func PrintableCommand(parts []string) string

Convert a command and argument slice back to a printable string. This adds basic escaping which is sufficient for debug output, but probably not for shell interpretation. This essentially reverses ParseCommandLine.

func QuoteCppString

func QuoteCppString(str string) string

Returns the given string as a quoted string for use with the C preprocessor. This adds double quotes around it and escapes any double quotes and backslashes in the string.

func ReadDirFiltered

func ReadDirFiltered(folder string, fn filterFiles) ([]os.FileInfo, error)

func ReadFileToRows

func ReadFileToRows(file string) ([]string, error)

func SliceContains

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

func SliceToMapStringBool

func SliceToMapStringBool(keys []string, value bool) map[string]bool

func TheOnlySubfolderOf

func TheOnlySubfolderOf(folder string) (string, error)

func TouchFile

func TouchFile(targetFilePath string) error

func TrimSpace

func TrimSpace(value string) string

func WrapWithHyphenI

func WrapWithHyphenI(value string) string

func WriteFile

func WriteFile(targetFilePath string, data string) error

func WriteFileBytes

func WriteFileBytes(targetFilePath string, data []byte) error

Types

type CheckExtensionFunc

type CheckExtensionFunc func(ext string) bool

Jump to

Keyboard shortcuts

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