yay/pkg/settings/exe/exec.go
Jo b8debd1ae7
chore(yay): fix small linting issues (#1885)
* replace context.TODO() in tests context.Background()

* remove mock TODOs

* prettier

* apply missing linting
2023-01-03 21:43:56 +00:00

39 lines
786 B
Go

package exe
import (
"errors"
"os"
"os/exec"
"strings"
"github.com/Jguer/yay/v11/pkg/text"
)
type Runner interface {
Capture(cmd *exec.Cmd) (stdout string, stderr string, err error)
Show(cmd *exec.Cmd) error
}
type OSRunner struct{}
func (r *OSRunner) Show(cmd *exec.Cmd) error {
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
text.Debugln("running", cmd.String())
return cmd.Run()
}
func (r *OSRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
text.Debugln("capturing", cmd.String())
outbuf, err := cmd.Output()
stdout = strings.TrimSpace(string(outbuf))
if err != nil {
exitErr := &exec.ExitError{}
if errors.As(err, &exitErr) {
stderr = strings.TrimSpace(string(exitErr.Stderr))
}
}
return stdout, stderr, err
}