Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,18 @@ func getImages(fillNameWithID bool) ([]podman.Image, error) {
func listOutput(images []podman.Image, containers []podman.Container) {
if len(images) != 0 {
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(writer, "%s\t%s\t%s\n", "IMAGE ID", "IMAGE NAME", "CREATED")
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\n", "IMAGE ID", "IMAGE NAME", "CREATED", "SIZE")

for _, image := range images {
if len(image.Names) != 1 {
panic("cannot list unflattened Image")
}

fmt.Fprintf(writer, "%s\t%s\t%s\n",
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\n",
utils.ShortID(image.ID),
image.Names[0],
image.Created)
image.Created,
image.Size)
}

writer.Flush()
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

type Image struct {
Created string
Size string
ID string
Labels map[string]string
Names []string
Expand Down Expand Up @@ -84,6 +85,7 @@ func (image *Image) FlattenNames(fillNameWithID bool) []Image {
func (image *Image) UnmarshalJSON(data []byte) error {
var raw struct {
Created interface{}
Size float64
ID string
Labels map[string]string
Names []string
Expand All @@ -102,6 +104,7 @@ func (image *Image) UnmarshalJSON(data []byte) error {
case float64:
image.Created = utils.HumanDuration(int64(value))
}
image.Size = utils.HumanSize(int64(raw.Size))

image.ID = raw.ID
image.Labels = raw.Labels
Expand Down
10 changes: 10 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"syscall"
"time"
"unicode"
"unicode/utf8"

"github.com/acobaugh/osrelease"
Expand Down Expand Up @@ -588,6 +589,15 @@ func HumanDuration(duration int64) string {
return units.HumanDuration(time.Since(time.Unix(duration, 0))) + " ago"
}

// HumanSize accepts a bytes value and converts it into a human readable string.
//
// Examples: "500 MB", "1.23 GB"
func HumanSize(size int64) string {
s := units.HumanSizeWithPrecision(float64(size), 3)
j := strings.LastIndexFunc(s, unicode.IsNumber)
return s[:j+1] + " " + s[j+1:]
}

// ImageReferenceCanBeID checks if 'image' might be the ID of an image
func ImageReferenceCanBeID(image string) bool {
matched, err := regexp.MatchString("^[a-f0-9]{6,64}$", image)
Expand Down