mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
Add --no-trunc to artifact ls
added a --no-trunc flag to artifact ls, which follows what images has done. by default now, the ls output will have the shortened 12 character digest. the --no-trunc will output the full digest. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -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,
|
||||
|
1
docs/source/markdown/.gitignore
vendored
1
docs/source/markdown/.gitignore
vendored
@ -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
|
||||
|
7
docs/source/markdown/options/no-trunc.md
Normal file
7
docs/source/markdown/options/no-trunc.md
Normal file
@ -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*).
|
@ -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
|
||||
```
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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() {
|
||||
|
Reference in New Issue
Block a user