Documentation ¶
Overview ¶
Package helper provides helpers for modules, in order to simplify their development
Index ¶
- Variables
- func DownloadJSON(url string, destination interface{}) error
- func Exec(env []string, cmd string, args ...string) ([]byte, error)
- func ExecSudo(env []string, args ...string) ([]byte, error)
- func HTTPGet(url string) ([]byte, error)
- func HTTPPost(url string, payload []byte) ([]byte, error)
- func MapStringString(input interface{}) (map[string]string, error)
- func Path(str string) string
- func SliceString(input interface{}) ([]string, error)
- func Store(key, value string)
- func String(v interface{}) (str string, err error)
- type ResultStatus
- func Directory(path string, root bool) (ResultStatus, error)
- func DownloadFile(url, path string, out output.Output) (ResultStatus, error)
- func ExtractTarxz(tarxzfilepath, dest string) (ResultStatus, error)
- func ExtractZip(zipfilepath, dest string, out output.Output) (ResultStatus, error)
- func File(path string, content []byte, permission os.FileMode, root bool) (ResultStatus, error)
- func GitClone(repo, dest string, depth int) (ResultStatus, error)
- func GitPull(path string) (ResultStatus, error)
- func Remove(path string) (ResultStatus, error)
- func Symlink(path, target string) (status ResultStatus, err error)
Constants ¶
This section is empty.
Variables ¶
var Dryrun bool
Dryrun allows running instructions without system modification
var SudoPassword string
SudoPassword must contain the sudo password, in order to user ExecSudo. This password may be set with the sudo-password instruction.
Functions ¶
func DownloadJSON ¶
DownloadJSON downloads the given URL and decodes it to the given destination.
The URL is downloaded even in dry-run mode.
func Exec ¶
Exec executes a command as the current user, returning its stdin and stdout outputs combined.
If command fails, its combined output is in the error message.
func ExecSudo ¶
ExecSudo executes a command as root by using sudo, returning its stdin and stdout outputs combined.
If command fails, its combined output is in the error message.
func HTTPGet ¶
HTTPGet downloads the given URL and returns it as a []byte.
The URL is downloaded even in dry-run mode.
func HTTPPost ¶
HTTPPost uses method POST on the given URL and returns the result as a []byte.
The URL is downloaded even in dry-run mode.
func MapStringString ¶
MapStringString transforms an interface to a map from strings to strings
func Path ¶
Path returns the absolute path for the given file path. Relative paths are prefixed with the home directory. if the argument is empty, it returns the home directory path.
func SliceString ¶
SliceString transforms a slice of interfaces to a slice of strings
Types ¶
type ResultStatus ¶
type ResultStatus int
ResultStatus is returned by helper to inform the module of the result status
const ( // ResultError means there is an error ResultError ResultStatus = iota // ResultSuccess means the requested action is successful ResultSuccess // ResultDryrun means the action is not done because of dry-run mode ResultDryrun // ResultAlready means the action was already done ResultAlready )
func Directory ¶
func Directory(path string, root bool) (ResultStatus, error)
Directory creates a new directory, and its parents if needed. Directory owner is root if the root boolean is true.
If the directory already exists, it returns ResultAlready.
In dry-run mode, ResultDryrun is returned.
func DownloadFile ¶
func DownloadFile(url, path string, out output.Output) (ResultStatus, error)
DownloadFile downloads the given URL to the given path, writing the percentage to the given output if provided.
If in dry-run mode, it returns ResultDryrun right away, without downloading.
func ExtractTarxz ¶
func ExtractTarxz(tarxzfilepath, dest string) (ResultStatus, error)
ExtractTarxz extracts a tar.xz archive.
In dry-run mode, only return ResultDryrun.
func ExtractZip ¶
func ExtractZip(zipfilepath, dest string, out output.Output) (ResultStatus, error)
ExtractZip unzips the given file into the given destination.
In dry-run mode, only return ResultDryrun.
If out is provided, a "X on Y" loader is provided to the user.
func File ¶
File writes the provided content to the provided path, with the given permission. The file owner is root if the root boolean is true.
If the file already exists and already has the same content, ResultAlready is returned.
In dry-run mode, comparison is done (thus, ResultAlready may be returned) but ResultDryrun is returned if file need to be created or modified.
func GitClone ¶
func GitClone(repo, dest string, depth int) (ResultStatus, error)
GitClone clones a Git repository to the provided destination.
depth is the number of commits to fetch for clone (if 0, only fetch HEAD).
If the provided destination is already this repository, return ResultAlready ¶
In dry-run mode, do not clone, return ResultDryrun
func GitPull ¶
func GitPull(path string) (ResultStatus, error)
GitPull pulls the latest HEAD of the given Git repository from origin.
If the provided destination is already at the latest HEAD from origin, return ResultAlready.
In dry-run mode, do not pull, return ResultDryrun.
func Remove ¶
func Remove(path string) (ResultStatus, error)
Remove removes a file or empty directory from the system.
If the path is a non-empty directory, it returns an error.
If the path does not exist, it returns ResultAlready.
In dry-run mode, file or directory is not removed and ResultDryrun is returned.
func Symlink ¶
func Symlink(path, target string) (status ResultStatus, err error)
Symlink creates a symbolic link.
If the symlink already exists and points to the specified target, return ResultAlready.
If in dry-run mode, do not create nor change the symlink.