Default .Repository and .Tag values to <none>

Refactor the processing of Repository and Tag fields to default to <none>
when printing via --format flag. Previously, the default format would
print <none> but --format {{.Tag}} would not in some cases.

Fixes #7123

Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
Jhon Honce
2020-08-05 15:10:12 -07:00
parent da00482ef2
commit c60b695e64
2 changed files with 13 additions and 7 deletions

View File

@ -195,6 +195,7 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
} else { } else {
h.ImageSummary = *e h.ImageSummary = *e
h.Repository = "<none>" h.Repository = "<none>"
h.Tag = "<none>"
imgs = append(imgs, h) imgs = append(imgs, h)
} }
listFlag.readOnly = e.IsReadOnly() listFlag.readOnly = e.IsReadOnly()
@ -205,27 +206,34 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
} }
func tokenRepoTag(ref string) (string, string, error) { func tokenRepoTag(ref string) (string, string, error) {
if ref == "<none>:<none>" { if ref == "<none>:<none>" {
return "<none>", "<none>", nil return "<none>", "<none>", nil
} }
repo, err := reference.Parse(ref) repo, err := reference.Parse(ref)
if err != nil { if err != nil {
return "", "", err return "<none>", "<none>", err
} }
named, ok := repo.(reference.Named) named, ok := repo.(reference.Named)
if !ok { if !ok {
return ref, "", nil return ref, "<none>", nil
}
name := named.Name()
if name == "" {
name = "<none>"
} }
tagged, ok := repo.(reference.Tagged) tagged, ok := repo.(reference.Tagged)
if !ok { if !ok {
return named.Name(), "", nil return name, "<none>", nil
}
tag := tagged.Tag()
if tag == "" {
tag = "<none>"
} }
return named.Name(), tagged.Tag(), nil return name, tag, nil
} }

View File

@ -28,8 +28,6 @@ verify_iid_and_name() {
@test "podman load - by image ID" { @test "podman load - by image ID" {
skip_if_remote "FIXME: pending #7123"
# FIXME: how to build a simple archive instead? # FIXME: how to build a simple archive instead?
get_iid_and_name get_iid_and_name