Merge pull request #5582 from kunalkushwaha/bugfix-5001

Improved readability in image json output
This commit is contained in:
Daniel J Walsh 2020-03-22 17:40:20 -04:00 committed by GitHub
commit 31d14457a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 23 deletions

View File

@ -13,8 +13,8 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/adapter"
"github.com/docker/go-units"
"github.com/opencontainers/go-digest"
units "github.com/docker/go-units"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -34,14 +34,15 @@ type imagesTemplateParams struct {
}
type imagesJSONParams struct {
ID string `json:"id"`
Name []string `json:"names"`
Digest digest.Digest `json:"digest"`
Digests []digest.Digest `json:"digests"`
Created time.Time `json:"created"`
Size *uint64 `json:"size"`
ReadOnly bool `json:"readonly"`
History []string `json:"history"`
ID string `json:"ID"`
Name []string `json:"Names"`
Created string `json:"Created"`
Digest digest.Digest `json:"Digest"`
Digests []digest.Digest `json:"Digests"`
CreatedAt time.Time `json:"CreatedAt"`
Size *uint64 `json:"Size"`
ReadOnly bool `json:"ReadOnly"`
History []string `json:"History"`
}
type imagesOptions struct {
@ -344,14 +345,15 @@ func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage)
size = nil
}
params := imagesJSONParams{
ID: img.ID(),
Name: img.Names(),
Digest: img.Digest(),
Digests: img.Digests(),
Created: img.Created(),
Size: size,
ReadOnly: img.IsReadOnly(),
History: img.NamesHistory(),
ID: img.ID(),
Name: img.Names(),
Digest: img.Digest(),
Digests: img.Digests(),
Created: units.HumanDuration(time.Since(img.Created())) + " ago",
CreatedAt: img.Created(),
Size: size,
ReadOnly: img.IsReadOnly(),
History: img.NamesHistory(),
}
imagesOutput = append(imagesOutput, params)
}

View File

@ -27,11 +27,11 @@ load helpers
@test "podman images - json" {
# 'created': podman includes fractional seconds, podman-remote does not
tests="
names[0] | $PODMAN_TEST_IMAGE_FQN
id | [0-9a-f]\\\{64\\\}
digest | sha256:[0-9a-f]\\\{64\\\}
created | [0-9-]\\\+T[0-9:.]\\\+Z
size | [0-9]\\\+
Names[0] | $PODMAN_TEST_IMAGE_FQN
ID | [0-9a-f]\\\{64\\\}
Digest | sha256:[0-9a-f]\\\{64\\\}
CreatedAt | [0-9-]\\\+T[0-9:.]\\\+Z
Size | [0-9]\\\+
"
run_podman images -a --format json