add cli runner to info
parent
fad745f607
commit
c6895c2058
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue