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 .}}' // dockerSystemInfo returns docker system info --format '{{json .}}'
func dockerSystemInfo() (dockerSysInfo, error) { func dockerSystemInfo() (dockerSysInfo, error) {
var ds dockerSysInfo var ds dockerSysInfo
rr, err := cli.RunCmd(exec.Command(Docker, "system", "info", "--format", "{{json .}}"))
cmd := exec.Command(Docker, "system", "info", "--format", "{{json .}}")
out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return ds, errors.Wrap(err, "get docker system info") 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") return ds, errors.Wrapf(err, "unmarshal docker system info")
} }
@ -234,12 +231,11 @@ func dockerSystemInfo() (dockerSysInfo, error) {
// podmanSysInfo returns podman system info --format '{{json .}}' // podmanSysInfo returns podman system info --format '{{json .}}'
func podmanSystemInfo() (podmanSysInfo, error) { func podmanSystemInfo() (podmanSysInfo, error) {
var ps podmanSysInfo var ps podmanSysInfo
cmd := exec.Command(Podman, "system", "info", "--format", "'{{json .}}'") rr, err := cli.RunCmd(exec.Command(Podman, "system", "info", "--format", "'{{json .}}'"))
out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return ps, errors.Wrap(err, "get podman system info") 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, errors.Wrapf(err, "unmarshal podman system info")
} }
return ps, nil return ps, nil

View File

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