add cli runner to info

pull/7862/head
Medya Gh 2020-04-22 22:34:11 -07:00
parent fad745f607
commit c6895c2058
No known key found for this signature in database
GPG Key ID: 7CF7792C6DF3245C
2 changed files with 11 additions and 13 deletions

View File

@ -216,15 +216,12 @@ type podmanSysInfo struct {
// dockerSystemInfo returns docker system info --format '{{json .}}'
func dockerSystemInfo() (dockerSysInfo, error) {
var ds dockerSysInfo
cmd := exec.Command(Docker, "system", "info", "--format", "{{json .}}")
out, err := cmd.CombinedOutput()
rr, err := cli.RunCmd(exec.Command(Docker, "system", "info", "--format", "{{json .}}"))
if err != nil {
return ds, errors.Wrap(err, "get docker system info")
}
if err := json.Unmarshal([]byte(strings.TrimSpace(string(out))), &ds); err != nil {
if err := json.Unmarshal([]byte(strings.TrimSpace(string(rr.Stdout.Bytes()))), &ds); err != nil {
return ds, errors.Wrapf(err, "unmarshal docker system info")
}
@ -234,12 +231,11 @@ func dockerSystemInfo() (dockerSysInfo, error) {
// podmanSysInfo returns podman system info --format '{{json .}}'
func podmanSystemInfo() (podmanSysInfo, error) {
var ps podmanSysInfo
cmd := exec.Command(Podman, "system", "info", "--format", "'{{json .}}'")
out, err := cmd.CombinedOutput()
rr, err := cli.RunCmd(exec.Command(Podman, "system", "info", "--format", "'{{json .}}'"))
if err != nil {
return ps, errors.Wrap(err, "get podman system info")
}
if err := json.Unmarshal([]byte(strings.TrimSpace(string(out))), &ps); err != nil {
if err := json.Unmarshal([]byte(strings.TrimSpace(string(rr.Stdout.Bytes()))), &ps); err != nil {
return ps, errors.Wrapf(err, "unmarshal podman system info")
}
return ps, nil

View File

@ -27,8 +27,10 @@ import (
"github.com/golang/glog"
)
//runner runs commands using the os/exec package.
type runner struct {
var cli = newRunner()
//cliRunner runs commands using the os/exec package.
type cliRunner struct {
}
// RunResult holds the results of a Runner
@ -66,12 +68,12 @@ func (rr RunResult) Output() string {
}
// newRunner returns an oci runner
func newRunner() *runner {
return &runner{}
func newRunner() *cliRunner {
return &cliRunner{}
}
// RunCmd implements the Command Runner interface to run a exec.Cmd object
func (*runner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
func (*cliRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
rr := &RunResult{Args: cmd.Args}
glog.Infof("Run: %v", rr.Command())