diff --git a/cmd/podman/artifact/list.go b/cmd/podman/artifact/list.go index e9ad56542b..de15adce91 100644 --- a/cmd/podman/artifact/list.go +++ b/cmd/podman/artifact/list.go @@ -31,7 +31,8 @@ var ( ) type listFlagType struct { - format string + format string + noTrunc bool } type artifactListOutput struct { @@ -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 { @@ -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, diff --git a/docs/source/markdown/.gitignore b/docs/source/markdown/.gitignore index 8e05f6967f..3dd3b2e7d4 100644 --- a/docs/source/markdown/.gitignore +++ b/docs/source/markdown/.gitignore @@ -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 diff --git a/docs/source/markdown/options/no-trunc.md b/docs/source/markdown/options/no-trunc.md new file mode 100644 index 0000000000..887893934d --- /dev/null +++ b/docs/source/markdown/options/no-trunc.md @@ -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*). diff --git a/docs/source/markdown/podman-artifact-ls.1.md b/docs/source/markdown/podman-artifact-ls.1.md.in similarity index 74% rename from docs/source/markdown/podman-artifact-ls.1.md rename to docs/source/markdown/podman-artifact-ls.1.md.in index 720c1dec36..585b51a8d0 100644 --- a/docs/source/markdown/podman-artifact-ls.1.md +++ b/docs/source/markdown/podman-artifact-ls.1.md.in @@ -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 ``` diff --git a/docs/source/markdown/podman-images.1.md.in b/docs/source/markdown/podman-images.1.md.in index fda6af0479..6c26107105 100644 --- a/docs/source/markdown/podman-images.1.md.in +++ b/docs/source/markdown/podman-images.1.md.in @@ -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 diff --git a/test/e2e/artifact_test.go b/test/e2e/artifact_test.go index b54747433c..7c74e89a5b 100644 --- a/test/e2e/artifact_test.go +++ b/test/e2e/artifact_test.go @@ -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()) @@ -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() {