Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images: accept multiple filter with logical AND between them. #3651

Merged
Merged
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
8 changes: 4 additions & 4 deletions cmd/buildah/images.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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