Documentation ¶
Index ¶
- func Exec(env map[string]string, stdout, stderr io.Writer, cmd string, args ...string) (ran bool, err error)
- func ExitStatus(err error) int
- func OutCmd(cmd string, args ...string) func(args ...string) (string, error)
- func Output(cmd string, args ...string) (string, error)
- func OutputWith(env map[string]string, cmd string, args ...string) (string, error)
- func Rm(path string) error
- func Run(cmd string, args ...string) error
- func RunCmd(cmd string, args ...string) func(args ...string) error
- func RunV(cmd string, args ...string) error
- func RunWith(env map[string]string, cmd string, args ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
func Exec(env map[string]string, stdout, stderr io.Writer, cmd string, args ...string) (ran bool, err error)
Exec executes the command, piping its stderr to mage's stderr and piping its stdout to the given writer. If the command fails, it will return an error that, if returned from a target or mg.Deps call, will cause mage to exit with the same code as the command failed with. Env is a list of environment variables to set when running the command, these override the current environment variables set (which are also passed to the command). cmd and args may include references to environment variables in $FOO format, in which case these will be expanded before the command is run.
Ran reports if the command ran (rather than was not found or not executable). Code reports the exit code the command returned if it ran. If err == nil, ran is always true and code is always 0.
func ExitStatus ¶
ExitStatus returns the exit status of the error if it is an exec.ExitError or if it implements ExitStatus() int. 0 if it is nil or 1 if it is a different error.
func OutputWith ¶
OutputWith is like RunWith, ubt returns what is written to stdout.
func Rm ¶
Rm removes the given file or directory even if non-empty. It will not return an error if the target doesn't exist, only if the target cannot be removed.
func RunCmd ¶
RunCmd returns a function that will call Run with the given command. This is useful for creating command aliases to make your scripts easier to read, like this:
// in a helper file somewhere var g0 = sh.RunCmd("go") // go is a keyword :( // somewhere in your main code if err := g0("install", "github.com/gohugo/hugo"); err != nil { return err }
Args passed to command get baked in as args to the command when you run it. Any args passed in when you run the returned function will be appended to the original args. For example, this is equivalent to the above:
var goInstall = sh.RunCmd("go", "install") goInstall("github.com/gohugo/hugo")
RunCmd uses Exec underneath, so see those docs for more details.
Types ¶
This section is empty.