mirror of
https://github.com/containers/podman.git
synced 2026-02-05 06:45:31 +01:00
Add CreatedAt format option to podman artifact ls
This change adds a .CreatedAt format option to the podman artifact ls command to match the behavior of podman images --format CreatedAt. The .Created field continues to display human-readable elapsed time (e.g., '6 hours ago'), while the new .CreatedAt field displays the full timestamp (e.g., '2025-10-23 12:34:56 +0000 UTC'). Changes: - Refactored artifactListOutput struct to store time.Time value - Added CreatedAt() method returning full timestamp string - Added Created() method for human-readable duration - Updated documentation to include .CreatedAt field - Added e2e test for .CreatedAt format option Generated-with: Cursor AI Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@@ -38,12 +38,29 @@ type listFlagType struct {
|
||||
}
|
||||
|
||||
type artifactListOutput struct {
|
||||
Digest string
|
||||
Repository string
|
||||
Size string
|
||||
Tag string
|
||||
Created string
|
||||
VirtualSize string
|
||||
Digest string
|
||||
Repository string
|
||||
Size string
|
||||
Tag string
|
||||
created time.Time
|
||||
VirtualSize string
|
||||
virtualBytes int64
|
||||
}
|
||||
|
||||
// Created returns human-readable elapsed time since artifact was created
|
||||
func (a artifactListOutput) Created() string {
|
||||
if a.created.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return units.HumanDuration(time.Since(a.created)) + " ago"
|
||||
}
|
||||
|
||||
// CreatedAt returns the full timestamp string of when the artifact was created
|
||||
func (a artifactListOutput) CreatedAt() string {
|
||||
if a.created.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return a.created.String()
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -109,23 +126,23 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
|
||||
artifactHash = artifactDigest.Encoded()
|
||||
}
|
||||
|
||||
var created string
|
||||
var createdTime time.Time
|
||||
createdAnnotation, ok := lr.Manifest.Annotations[imgspecv1.AnnotationCreated]
|
||||
if ok {
|
||||
createdTime, err := time.Parse(time.RFC3339Nano, createdAnnotation)
|
||||
createdTime, err = time.Parse(time.RFC3339Nano, createdAnnotation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
created = units.HumanDuration(time.Since(createdTime)) + " ago"
|
||||
}
|
||||
|
||||
artifacts = append(artifacts, artifactListOutput{
|
||||
Digest: artifactHash,
|
||||
Repository: named.Name(),
|
||||
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
|
||||
Tag: tag,
|
||||
Created: created,
|
||||
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
|
||||
Digest: artifactHash,
|
||||
Repository: named.Name(),
|
||||
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
|
||||
Tag: tag,
|
||||
created: createdTime,
|
||||
VirtualSize: fmt.Sprintf("%d", lr.Artifact.TotalSizeBytes()),
|
||||
virtualBytes: lr.Artifact.TotalSizeBytes(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user