helper

package
v0.0.0-...-59f78f7 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package helper contains collection of common functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPath

func BuildPath(path string) string

BuildPath changes the given path to a more cross platform friendly format

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 https://github.com/mactsouk/opensource.com/blob/master/cp2.go

func CopyFileTo

func CopyFileTo(sourceFile string, destinationFile string) error

CopyFileTo copy a file from sourceFile location to destinationFile location

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 EncodePrivateSSHKeyToPEM

func EncodePrivateSSHKeyToPEM(privateKey *rsa.PrivateKey) []byte

EncodePrivateSSHKeyToPEM encodes Private Key from RSA to PEM format

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 GeneratePrivateSSHKey

func GeneratePrivateSSHKey(bitSize int) (*rsa.PrivateKey, error)

GeneratePrivateSSHKey creates a RSA Private Key of specified byte size

func GeneratePublicSSHKey

func GeneratePublicSSHKey(privatekey *rsa.PublicKey) ([]byte, error)

GeneratePublicSSHKey take a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ..."

func GenerateSSHKeys

func GenerateSSHKeys(dir string)

GenerateSSHKeys create SSH keys (private and public) into a given directory

func GetCmdFlagString

func GetCmdFlagString(cmd *cobra.Command, flag string) string

GetCmdFlagString return the value of a flag string

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 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 ValidateCmdArgsV2

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

ValidateCmdArgsV2 check if first arg is valid

func ValidateCmdFlagString

func ValidateCmdFlagString(cmd *cobra.Command, flag string) error

ValidateCmdFlagString check if there's any error with a flag of string type

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.

func WriteInterfaceToFile

func WriteInterfaceToFile(in interface{}, path string) error

WriteInterfaceToFile write the given interface into a file

func WriteSSHKeyToFile

func WriteSSHKeyToFile(keyBytes []byte, saveFileTo string) error

WriteSSHKeyToFile writes keys to a file

Types

type Manual

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

Manual mapping the fields used by a Cobra command

func GetManual

func GetManual(command string, args []string) (Manual, error)

GetManual returns the command's manuall

Jump to

Keyboard shortcuts

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