A wrapper for Go's command execution packages.
go get github.com/alexellis/go-execute/v2
See docs at pkg.go.dev: github.com/alexellis/go-execute
Used by dozens of projects as identified by GitHub, notably:
- alexellis/arkade
- openfaas/faas-cli
- inlets/inletsctl
- inlets/cloud-provision
- alexellis/k3sup
- openfaas/connector-sdk
- openfaas-incubator/ofc-bootstrap
Community examples:
- dokku/lambda-builder
- 027xiguapi/pear-rec
- cnrancher/autok3s
- ainsleydev/hupi
- andiwork/andictl
- tonit/rekind
- lucasrod16/ec2-k3s
- seaweedfs/seaweed-up
- jsiebens/inlets-on-fly
- jsiebens/hashi-up
- edgego/ecm
- ministryofjustice/cloud-platform-terraform-upgrade
- mattcanty/go-ffmpeg-transcode
- Popoola-Opeyemi/meeseeks
- aidun/minicloud
Feel free to add a link to your own projects in a PR.
DisableStdioBuffer
- Discard Stdio, rather than buffering into memoryStreamStdio
- Stream stderr and stdout to the console, useful for debugging and testingShell
- Use bash as a shell to execute the command, rather than exec a binary directlyStdOutWriter
- an additional writer for stdout, useful for mutating or filtering the outputStdErrWriter
- an additional writer for stderr, useful for mutating or filtering the outputPrintCommand
- print the command to stdout before executing it
This example captures the values from stdout and stderr without relaying to the console. This means the values can be inspected and used for automation.
package main
import (
"fmt"
execute "github.com/alexellis/go-execute/v2"
)
func main() {
cmd := execute.ExecTask{
Command: "docker",
Args: []string{"version"},
StreamStdio: false,
}
res, err := cmd.Execute()
if err != nil {
panic(err)
}
if res.ExitCode != 0 {
panic("Non-zero exit code: " + res.Stderr)
}
fmt.Printf("stdout: %s, stderr: %s, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}
package main
import (
"fmt"
execute "github.com/alexellis/go-execute/v2"
)
func main() {
ls := execute.ExecTask{
Command: "ls",
Args: []string{"-l"},
Shell: true,
}
res, err := ls.Execute()
if err != nil {
panic(err)
}
fmt.Printf("stdout: %q, stderr: %q, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}
package main
import (
"fmt"
execute "github.com/alexellis/go-execute/v2"
)
func main() {
ls := execute.ExecTask{
Command: "exit 1",
Shell: true,
}
res, err := ls.Execute()
if err != nil {
panic(err)
}
fmt.Printf("stdout: %q, stderr: %q, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}
Commits must be signed off with git commit -s
License: MIT