2022-03-24 00:49:23 +01:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2022-06-15 17:29:45 +02:00
|
|
|
"bytes"
|
|
|
|
"os/exec"
|
|
|
|
|
2022-03-24 00:49:23 +01:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CheckErr(e error) {
|
|
|
|
if e != nil {
|
|
|
|
panic(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CheckDiags(diag hcl.Diagnostics) {
|
|
|
|
if diag.HasErrors() {
|
|
|
|
panic(diag.Error())
|
|
|
|
}
|
|
|
|
}
|
2022-06-15 17:29:45 +02:00
|
|
|
|
|
|
|
// Execute a system command ...
|
|
|
|
func RunSystemCommand(name string, arg ...string) ([]byte, []byte, error) {
|
|
|
|
var stdOut bytes.Buffer
|
|
|
|
var stdErr bytes.Buffer
|
|
|
|
|
|
|
|
cmd := exec.Command(name, arg...)
|
|
|
|
cmd.Stderr = &stdErr
|
|
|
|
cmd.Stdout = &stdOut
|
|
|
|
err := cmd.Run()
|
|
|
|
return stdOut.Bytes(), stdErr.Bytes(), err
|
|
|
|
}
|