mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #9409 from rhatdan/size
podman ps --format '{{ .Size }}' requires --size option
This commit is contained in:
@ -22,6 +22,7 @@ import (
|
||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -390,6 +391,11 @@ func (l psReporter) Command() string {
|
||||
// Size returns the rootfs and virtual sizes in human duration in
|
||||
// and output form (string) suitable for ps
|
||||
func (l psReporter) Size() string {
|
||||
if l.ListContainer.Size == nil {
|
||||
logrus.Errorf("Size format requires --size option")
|
||||
return ""
|
||||
}
|
||||
|
||||
virt := units.HumanSizeWithPrecision(float64(l.ListContainer.Size.RootFsSize), 3)
|
||||
s := units.HumanSizeWithPrecision(float64(l.ListContainer.Size.RwSize), 3)
|
||||
return fmt.Sprintf("%s (virtual %s)", s, virt)
|
||||
|
@ -350,6 +350,21 @@ var _ = Describe("Podman ps", func() {
|
||||
Expect(session).To(ExitWithError())
|
||||
})
|
||||
|
||||
It("podman --format by size", func() {
|
||||
session := podmanTest.Podman([]string{"create", "busybox", "ls"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"create", "-t", ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"ps", "-a", "--format", "{{.Size}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.ErrorToString()).To(ContainSubstring("Size format requires --size option"))
|
||||
})
|
||||
|
||||
It("podman --sort by size", func() {
|
||||
session := podmanTest.Podman([]string{"create", "busybox", "ls"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
Reference in New Issue
Block a user