summaryrefslogtreecommitdiff
path: root/cmd/podman/images.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-10-11 21:38:31 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-10-11 21:56:40 +0200
commit71410ff0738f69793cd282b2e9c341d56198cd98 (patch)
tree7296b3b580561c1fbe324275e5f38c93d7c9da8f /cmd/podman/images.go
parentb0b350662173b3456224fa64a241d567943655b7 (diff)
downloadpodman-71410ff0738f69793cd282b2e9c341d56198cd98.tar.gz
podman-71410ff0738f69793cd282b2e9c341d56198cd98.tar.bz2
podman-71410ff0738f69793cd282b2e9c341d56198cd98.zip
images: empty list is valid json with --format=json
similar change to f7d55d64e7040cdad149684234ea150b0a90cf0e with images --format=json, be sure the output is valid json also when it is an empty list. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'cmd/podman/images.go')
-rw-r--r--cmd/podman/images.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index fe7c89b5c..e363fa3bb 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -216,17 +216,18 @@ func (i imagesOptions) setOutputFormat() string {
}
// imagesToGeneric creates an empty array of interfaces for output
-func imagesToGeneric(templParams []imagesTemplateParams, JSONParams []imagesJSONParams) (genericParams []interface{}) {
+func imagesToGeneric(templParams []imagesTemplateParams, JSONParams []imagesJSONParams) []interface{} {
+ genericParams := []interface{}{}
if len(templParams) > 0 {
for _, v := range templParams {
genericParams = append(genericParams, interface{}(v))
}
- return
+ return genericParams
}
for _, v := range JSONParams {
genericParams = append(genericParams, interface{}(v))
}
- return
+ return genericParams
}
func sortImagesOutput(sortBy string, imagesOutput imagesSorted) imagesSorted {
@@ -309,7 +310,8 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma
}
// getImagesJSONOutput returns the images information in its raw form
-func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage) (imagesOutput []imagesJSONParams) {
+func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage) []imagesJSONParams {
+ imagesOutput := []imagesJSONParams{}
for _, img := range images {
size, err := img.Size(ctx)
if err != nil {
@@ -325,7 +327,7 @@ func getImagesJSONOutput(ctx context.Context, images []*adapter.ContainerImage)
}
imagesOutput = append(imagesOutput, params)
}
- return
+ return imagesOutput
}
// generateImagesOutput generates the images based on the format provided
@@ -336,10 +338,6 @@ func generateImagesOutput(ctx context.Context, images []*adapter.ContainerImage,
switch opts.format {
case formats.JSONString:
- // If 0 images are present, print nothing for JSON
- if len(images) == 0 {
- return nil
- }
imagesOutput := getImagesJSONOutput(ctx, images)
out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)}
default: