Skip to content

Commit

Permalink
Merge pull request #3651 from flouthoc/accept-multiple-filters
Browse files Browse the repository at this point in the history
images: accept multiple filter with logical `AND` between them.
  • Loading branch information
openshift-merge-robot committed Nov 29, 2021
2 parents dc7625a + dcc3fc3 commit 2711b85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/buildah/images.go
Expand Up @@ -58,7 +58,7 @@ type imageOptions struct {

type imageResults struct {
imageOptions
filter string
filter []string
}

var imagesHeader = map[string]string{
Expand Down Expand Up @@ -93,7 +93,7 @@ func init() {
flags.SetInterspersed(false)
flags.BoolVarP(&opts.all, "all", "a", false, "show all images, including intermediate images from a build")
flags.BoolVar(&opts.digests, "digests", false, "show digests")
flags.StringVarP(&opts.filter, "filter", "f", "", "filter output based on conditions provided")
flags.StringSliceVarP(&opts.filter, "filter", "f", []string{}, "filter output based on conditions provided")
flags.StringVar(&opts.format, "format", "", "pretty-print images using a Go template")
flags.BoolVar(&opts.json, "json", false, "output in JSON format")
flags.BoolVarP(&opts.noHeading, "noheading", "n", false, "do not print column headings")
Expand Down Expand Up @@ -135,8 +135,8 @@ func imagesCmd(c *cobra.Command, args []string, iopts *imageResults) error {
ctx := context.Background()

options := &libimage.ListImagesOptions{}
if iopts.filter != "" {
options.Filters = []string{iopts.filter}
if len(iopts.filter) > 0 {
options.Filters = iopts.filter
}
if !iopts.all {
options.Filters = append(options.Filters, "intermediate=false")
Expand Down
5 changes: 5 additions & 0 deletions tests/images.bats
Expand Up @@ -53,6 +53,11 @@ load helpers

run_buildah images --noheading --filter since=k8s.gcr.io/pause
expect_line_count 1

# pause* and u* should only give us pause image not busybox since its a AND between
# two filters
run_buildah images --noheading --filter "reference=pause*" --filter "reference=u*"
expect_line_count 1
}

@test "images format test" {
Expand Down

0 comments on commit 2711b85

Please sign in to comment.