mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 09:37:22 +01:00
6ad63cae10
* rework menus to work on both flows * add installed package split * remove unused field * Add post install hooks
37 lines
779 B
Go
37 lines
779 B
Go
package exe
|
|
|
|
import (
|
|
"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 {
|
|
if exitErr, isExitError := err.(*exec.ExitError); isExitError {
|
|
stderr = strings.TrimSpace(string(exitErr.Stderr))
|
|
}
|
|
}
|
|
|
|
return stdout, stderr, err
|
|
}
|