With [a fix][1] in [podman v3.4.3][2], these commands now work as
expected in macOS. Potentially, it might make sense to version check
podman to ensure that the minimum version is met, but I'm not sure
that's needed because it's unlikely that people have an older version
installed _and_ wish to use this tool.
I'm unsure whether the commands work on Windows so I left the
unsupported version there compiling with the negation of the supported
flags.
[1]: https://github.com/containers/podman/issues/12402
[2]: 4ba71f955a/RELEASE_NOTES.md (bugfixes-2)
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
// +build linux darwin
|
|
|
|
package podman
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/wagoodman/dive/utils"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// runPodmanCmd runs a given Podman command in the current tty
|
|
func runPodmanCmd(cmdStr string, args ...string) error {
|
|
if !isPodmanClientBinaryAvailable() {
|
|
return fmt.Errorf("cannot find podman client executable")
|
|
}
|
|
|
|
allArgs := utils.CleanArgs(append([]string{cmdStr}, args...))
|
|
|
|
cmd := exec.Command("podman", allArgs...)
|
|
cmd.Env = os.Environ()
|
|
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Stdin = os.Stdin
|
|
|
|
return cmd.Run()
|
|
}
|
|
|
|
func streamPodmanCmd(args ...string) (error, io.Reader) {
|
|
if !isPodmanClientBinaryAvailable() {
|
|
return fmt.Errorf("cannot find podman client executable"), nil
|
|
}
|
|
|
|
cmd := exec.Command("podman", utils.CleanArgs(args)...)
|
|
cmd.Env = os.Environ()
|
|
|
|
reader, writer, err := os.Pipe()
|
|
if err != nil {
|
|
return err, nil
|
|
}
|
|
|
|
cmd.Stdout = writer
|
|
cmd.Stderr = os.Stderr
|
|
|
|
return cmd.Start(), reader
|
|
}
|
|
|
|
func isPodmanClientBinaryAvailable() bool {
|
|
_, err := exec.LookPath("podman")
|
|
return err == nil
|
|
}
|