mirror of
https://github.com/containers/podman.git
synced 2025-12-09 07:09:03 +08:00
Merge pull request #80 from umohnani8/kpod_images
Fix output of kpod images
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
createdByTruncLength = 45
|
createdByTruncLength = 45
|
||||||
idTruncLength = 13
|
idTruncLength = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
// historyTemplateParams stores info about each layer
|
// historyTemplateParams stores info about each layer
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type imagesTemplateParams struct {
|
type imagesTemplateParams struct {
|
||||||
|
Repository string
|
||||||
|
Tag string
|
||||||
ID string
|
ID string
|
||||||
Name string
|
|
||||||
Digest digest.Digest
|
Digest digest.Digest
|
||||||
CreatedAt string
|
Created string
|
||||||
Size string
|
Size string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ type imagesJSONParams struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name []string `json:"names"`
|
Name []string `json:"names"`
|
||||||
Digest digest.Digest `json:"digest"`
|
Digest digest.Digest `json:"digest"`
|
||||||
CreatedAt time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +140,14 @@ func genImagesFormat(quiet, noHeading, digests bool) (format string) {
|
|||||||
if quiet {
|
if quiet {
|
||||||
return formats.IDString
|
return formats.IDString
|
||||||
}
|
}
|
||||||
format = "table {{.ID}}\t{{.Name}}\t"
|
format = "table {{.Repository}}\t{{.Tag}}\t"
|
||||||
if noHeading {
|
if noHeading {
|
||||||
format = "{{.ID}}\t{{.Name}}\t"
|
format = "{{.Repository}}\t{{.Tag}}\t"
|
||||||
}
|
}
|
||||||
if digests {
|
if digests {
|
||||||
format += "{{.Digest}}\t"
|
format += "{{.Digest}}\t"
|
||||||
}
|
}
|
||||||
format += "{{.CreatedAt}}\t{{.Size}}\t"
|
format += "{{.ID}}\t{{.Created}}\t{{.Size}}\t"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ func (i *imagesTemplateParams) headerMap() map[string]string {
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
key := v.Type().Field(i).Name
|
key := v.Type().Field(i).Name
|
||||||
value := key
|
value := key
|
||||||
if value == "ID" || value == "Name" {
|
if value == "ID" {
|
||||||
value = "Image" + value
|
value = "Image" + value
|
||||||
}
|
}
|
||||||
values[key] = strings.ToUpper(splitCamelCase(value))
|
values[key] = strings.ToUpper(splitCamelCase(value))
|
||||||
@@ -191,14 +192,19 @@ func getImagesTemplateOutput(runtime *libpod.Runtime, images []*storage.Image, o
|
|||||||
}
|
}
|
||||||
createdTime := img.Created
|
createdTime := img.Created
|
||||||
|
|
||||||
imageID := img.ID
|
imageID := "sha256:" + img.ID
|
||||||
if !opts.noTrunc {
|
if !opts.noTrunc {
|
||||||
imageID = imageID[:idTruncLength]
|
imageID = img.ID[:idTruncLength]
|
||||||
}
|
}
|
||||||
|
|
||||||
imageName := "<none>"
|
repository := "<none>"
|
||||||
|
tag := "<none>"
|
||||||
if len(img.Names) > 0 {
|
if len(img.Names) > 0 {
|
||||||
imageName = img.Names[0]
|
arr := strings.Split(img.Names[0], ":")
|
||||||
|
repository = arr[0]
|
||||||
|
if len(arr) == 2 {
|
||||||
|
tag = arr[1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info, imageDigest, size, _ := runtime.InfoAndDigestAndSize(*img)
|
info, imageDigest, size, _ := runtime.InfoAndDigestAndSize(*img)
|
||||||
@@ -207,10 +213,11 @@ func getImagesTemplateOutput(runtime *libpod.Runtime, images []*storage.Image, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
params := imagesTemplateParams{
|
params := imagesTemplateParams{
|
||||||
|
Repository: repository,
|
||||||
|
Tag: tag,
|
||||||
ID: imageID,
|
ID: imageID,
|
||||||
Name: imageName,
|
|
||||||
Digest: imageDigest,
|
Digest: imageDigest,
|
||||||
CreatedAt: units.HumanDuration(time.Since((createdTime))) + " ago",
|
Created: units.HumanDuration(time.Since((createdTime))) + " ago",
|
||||||
Size: units.HumanSize(float64(size)),
|
Size: units.HumanSize(float64(size)),
|
||||||
}
|
}
|
||||||
imagesOutput = append(imagesOutput, params)
|
imagesOutput = append(imagesOutput, params)
|
||||||
@@ -232,7 +239,7 @@ func getImagesJSONOutput(runtime *libpod.Runtime, images []*storage.Image) (imag
|
|||||||
ID: img.ID,
|
ID: img.ID,
|
||||||
Name: img.Names,
|
Name: img.Names,
|
||||||
Digest: imageDigest,
|
Digest: imageDigest,
|
||||||
CreatedAt: createdTime,
|
Created: createdTime,
|
||||||
Size: size,
|
Size: size,
|
||||||
}
|
}
|
||||||
imagesOutput = append(imagesOutput, params)
|
imagesOutput = append(imagesOutput, params)
|
||||||
|
|||||||
Reference in New Issue
Block a user