Skip to content

Commit

Permalink
Merge pull request #25182 from baude/artifactnotrunc
Browse files Browse the repository at this point in the history
Add --no-trunc to artifact ls
  • Loading branch information
openshift-merge-bot[bot] authored Jan 31, 2025
2 parents c131c9d + d575ae1 commit b06d786
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
15 changes: 11 additions & 4 deletions cmd/podman/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var (
)

type listFlagType struct {
format string
format string
noTrunc bool
}

type artifactListOutput struct {
Expand All @@ -54,6 +55,7 @@ func init() {
formatFlagName := "format"
flags.StringVar(&listFlag.format, formatFlagName, defaultArtifactListOutputFormat, "Format volume output using JSON or a Go template")
_ = listCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&artifactListOutput{}))
flags.BoolVar(&listFlag.noTrunc, "no-trunc", false, "Do not truncate output")
}

func list(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -95,10 +97,15 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
if err != nil {
return err
}
// TODO when we default to shorter ids, i would foresee a switch
// like images that will show the full ids.

artifactHash := artifactDigest.Encoded()[0:12]
// If the user does not want truncated hashes
if listFlag.noTrunc {
artifactHash = artifactDigest.Encoded()
}

artifacts = append(artifacts, artifactListOutput{
Digest: artifactDigest.Encoded(),
Digest: artifactHash,
Repository: named.Name(),
Size: units.HumanSize(float64(lr.Artifact.TotalSizeBytes())),
Tag: tag,
Expand Down
1 change: 1 addition & 0 deletions docs/source/markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
podman-artifact-add.1.md
podman-artifact-ls.1.md
podman-artifact-pull.1.md
podman-artifact-push.1.md
podman-attach.1.md
Expand Down
7 changes: 7 additions & 0 deletions docs/source/markdown/options/no-trunc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
####> This option file is used in:
####> podman artifact ls, images
####> If file is edited, make sure the changes
####> are applicable to all of those.
#### **--no-trunc**

Do not truncate the output (default *false*).
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ Print results with a Go template.
| .Tag | Tag of the artifact name |


@@option no-trunc

## EXAMPLES

List artifacts in the local store
```
$ podman artifact ls
REPOSITORY TAG DIGEST SIZE
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 12.58MB
REPOSITORY TAG DIGEST SIZE
quay.io/artifact/foobar1 latest ab609fad386d 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb 12.58MB
```

List artifacts in the local store without truncating the digest
```
REPOSITORY TAG DIGEST SIZE
quay.io/artifact/foobar1 latest ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 2.097GB
quay.io/artifact/foobar2 special cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 12.58MB
```

List artifact digests and size using a --format
```
$ podman artifact ls --format "{{.Digest}} {{.Size}}"
ab609fad386df1433f461b0643d9cf575560baf633809dcc9c190da6cc3a3c29 2.097GB
cd734b558ceb8ccc0281ca76530e1dea1eb479407d3163f75fb601bffb6f73d0 12.58MB
ab609fad386d 2.097GB
cd734b558ceb 12.58MB
```


Expand Down
4 changes: 1 addition & 3 deletions docs/source/markdown/podman-images.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ Valid placeholders for the Go template are listed below:

Display the history of image names. If an image gets re-tagged or untagged, then the image name history gets prepended (latest image first). This is especially useful when undoing a tag operation or an image does not contain any name because it has been untagged.

#### **--no-trunc**

Do not truncate the output (default *false*).
@@option no-trunc

@@option noheading

Expand Down
14 changes: 13 additions & 1 deletion test/e2e/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Podman artifact", func() {
artifact1File, err := createArtifactFile(4192)
Expect(err).ToNot(HaveOccurred())
artifact1Name := "localhost/test/artifact1"
podmanTest.PodmanExitCleanly([]string{"artifact", "add", artifact1Name, artifact1File}...)
add1 := podmanTest.PodmanExitCleanly([]string{"artifact", "add", artifact1Name, artifact1File}...)

artifact2File, err := createArtifactFile(10240)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -43,6 +43,18 @@ var _ = Describe("Podman artifact", func() {
// Make sure the names are what we expect
Expect(output).To(ContainElement(artifact1Name))
Expect(output).To(ContainElement(artifact2Name))

// Check default digest length (should be 12)
defaultFormatSession := podmanTest.PodmanExitCleanly([]string{"artifact", "ls", "--format", "{{.Digest}}"}...)
defaultOutput := defaultFormatSession.OutputToStringArray()[0]
Expect(defaultOutput).To(HaveLen(12))

// Check with --no-trunc and verify the len of the digest is the same as the len what was returned when the artifact
// was added
noTruncSession := podmanTest.PodmanExitCleanly([]string{"artifact", "ls", "--no-trunc", "--format", "{{.Digest}}"}...)
truncOutput := noTruncSession.OutputToStringArray()[0]
Expect(truncOutput).To(HaveLen(len(add1.OutputToString())))

})

It("podman artifact simple add", func() {
Expand Down

0 comments on commit b06d786

Please sign in to comment.