Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/podman/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type listFlagType struct {
format string
noHeading bool
noTrunc bool
quiet bool
}

type artifactListOutput struct {
Expand Down Expand Up @@ -76,6 +77,7 @@ func init() {
_ = listCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&artifactListOutput{}))
flags.BoolVarP(&listFlag.noHeading, "noheading", "n", false, "Do not print column headings")
flags.BoolVar(&listFlag.noTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVarP(&listFlag.quiet, "quiet", "q", false, "Display only artifact digests")
}

func list(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -137,6 +139,13 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
})
}

if listFlag.quiet && !cmd.Flags().Changed("format") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --quiet + --format interaction silently ignores --quiet (format wins). Should end with an error: quiet and format flags cannot be used together.

for _, a := range artifacts {
fmt.Println(a.Digest)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for a clean approach, I would split code into two functions: quietOut(listed) and outputTemplate(cmd, listed).

}
return nil
}

headers := report.Headers(artifactListOutput{}, map[string]string{
"REPOSITORY": "REPOSITORY",
"Tag": "TAG",
Expand Down
11 changes: 11 additions & 0 deletions docs/source/markdown/podman-artifact-ls.1.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Print results with a Go template.

@@option noheading

#### **--quiet**, **-q**

Lists only the artifact digests.

## EXAMPLES

List artifacts in the local store
Expand Down Expand Up @@ -62,6 +66,13 @@ ab609fad386d 2.097GB
cd734b558ceb 12.58MB
```

List only artifact digests
```
$ podman artifact ls --quiet
ab609fad386d
cd734b558ceb
```



## SEE ALSO
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ var _ = Describe("Podman artifact", func() {
Expect(noHeaderOutput).To(HaveLen(2))
Expect(noHeaderOutput).ToNot(ContainElement("REPOSITORY"))

// check with --quiet and verify only the (truncated) digests are printed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add coverage for the --quiet --no-trunc combination.

quietSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--quiet")
quietOutput := quietSession.OutputToStringArray()
Expect(quietOutput).To(HaveLen(2))
Expect(quietOutput).ToNot(ContainElement("REPOSITORY"))
Expect(quietOutput).To(ContainElement(defaultOutput))
for _, digest := range quietOutput {
Expect(digest).To(HaveLen(12))
}

// Check if .VirtualSize is reported correctly
virtualSizeFormatSession := podmanTest.PodmanExitCleanly("artifact", "ls", "--format", "{{.VirtualSize}}")
virtualSizes := virtualSizeFormatSession.OutputToStringArray()
Expand Down