feat: add --format flag to artifact inspect

Many commands support the `--format` flag which accept a go template to
allow for formatting for certain values, but it is not
yet implemented for artifact inspect command.

Adding this feature will allow easy formatting in scripts as well as
running it on a terminal.

This feature is implemented for artifact inspect by taking reference
from images and network commands implementation.

Fixes: [#27112](https://github.com/containers/podman/issues/27112)

Signed-off-by: Akash Yadav <akashyadav256526@gmail.com>
This commit is contained in:
Akash Yadav
2025-10-21 16:58:03 +05:30
parent 7fecff5c29
commit 1fbf24b65b
4 changed files with 108 additions and 13 deletions

View File

@@ -636,6 +636,18 @@ var _ = Describe("Podman artifact", func() {
// Verify we have 2 layers
Expect(a.Manifest.Layers).To(HaveLen(2))
})
It("podman artifact inspect with --format", func() {
artifact1File, err := createArtifactFile(4192)
Expect(err).ToNot(HaveOccurred())
artifact1Name := "localhost/test/artifact1"
addArtifact1 := podmanTest.PodmanExitCleanly("artifact", "add", artifact1Name, artifact1File)
artifactDigest := addArtifact1.OutputToString()
podmanTest.PodmanExitCleanly("artifact", "inspect", artifactDigest, "--format", "{{.Digest}}")
podmanTest.PodmanExitCleanly("artifact", "inspect", artifactDigest[:12], "--format", "{{.Name}}")
})
})
func digestToFilename(digest string) string {