helper

package
v0.0.0-...-7ecf171 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsString

func ContainsString(slice []string, item string) bool

ContainsString return true if slice contains item

func CopyFile

func CopyFile(sourceFile string, destinationFile string)

CopyFile copies a file from source into a given destination path

func CopyFileTo

func CopyFileTo(source string, dest string) error

CopyFileTo copy a file from source to destination

func CreateDirectoryNamedPath

func CreateDirectoryNamedPath(path string) (string, error)

CreateDirectoryNamedPath creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories. If path is already a directory does nothing and returns nil.

func CreateTempDir

func CreateTempDir(dir string, pattern string) string

CreateTempDir creates a new temporary directory in the directory dir. The directory name is generated by taking pattern and applying a random string to the end

func DeleteFile

func DeleteFile(name string) error

DeleteFile removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func DirOrFileExists

func DirOrFileExists(path string) bool

DirOrFileExists an error is known to report that a file or directory does not exist. It is satisfied by ErrNotExist as well as some syscall errors.

func DownloadFile

func DownloadFile(url string, dirPath string, filename string) error

DownloadFile downloads a file and saves into the given directory with the given file name

func DownloadFileTo

func DownloadFileTo(url string, destination string) error

DownloadFileTo downloads a file and saves into the given directory with the given file name

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func FileSize

func FileSize(path string) (int64, error)

FileSize return the size of the give file path. Gives an error if files does not exist

func GetStringBetweenDoubleQuotes

func GetStringBetweenDoubleQuotes(str string) (result string, found bool)

GetStringBetweenDoubleQuotes return the string between double quotes

func GetStringInBetweenTwoString

func GetStringInBetweenTwoString(str string, startS string, endS string) (result string, found bool)

GetStringInBetweenTwoString return the string between two strings

func GetStringTrimmed

func GetStringTrimmed(s string, sep string) []string

GetStringTrimmed splits the string by the given separator and trims it by removing all spaces in between

func ListFiles

func ListFiles(dir string) []os.FileInfo

ListFiles list of all file names in the given directory. Pass "." if you want to list at the current directory.

func MkDirsIfNotExist

func MkDirsIfNotExist(name string) bool

MkDirsIfNotExist creates a directory named path, along with any necessary parents, and returns true, or else returns false. The dirs have permission bits 511 (before umask) are used for all directories that this function creates. If path is already a directory, the function does nothing and returns false.

func TrimRightFile

func TrimRightFile(path string, overwrite bool) error

TrimRightFile open file in `path`, read line by line removing all trailing characters. Overwrite original file in `path` if `true`, it creates a new file `path`.tmp otherwise.

func ValidateCmdArgAndFlag

func ValidateCmdArgAndFlag(cmd *cobra.Command, args []string, cmdName string, arg string, flag string) error

ValidateCmdArgAndFlag basic validation for the given arg on args, and if flag is empty, return error if fails

func ValidateCmdArgs

func ValidateCmdArgs(cmd *cobra.Command, args []string, cmdName string) error

ValidateCmdArgs basic validation of a command's arguments, return error if fails

func WriteFile

func WriteFile(filename string, data []byte) bool

WriteFile writes a file and return true if successful

func WriteFileFromBox

func WriteFileFromBox(source string, dest string) bool

WriteFileFromBox get the file from box's resources and write into the given destination, returns false if not able to.

Types

type Manual

type Manual struct {
	Use     string `yaml:"use"`
	Example string `yaml:"example"`
	Short   string `yaml:"short"`
	Long    string `yaml:"long"`
}

Manual mapping the fields used by a Cobra command

func GetManual

func GetManual(command string) (Manual, error)

GetManual retrieve information about the given command

Jump to

Keyboard shortcuts

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