diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-08-24 17:39:37 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-08-27 14:47:41 +0000 |
commit | 2bc6427302eb6bcbd613d7ee767080d278968490 (patch) | |
tree | f2cac916ff7557bc604d4ad7874a0933e042b56c | |
parent | 663ee91eec01706008046c1df2c307716f9288db (diff) | |
download | podman-2bc6427302eb6bcbd613d7ee767080d278968490.tar.gz podman-2bc6427302eb6bcbd613d7ee767080d278968490.tar.bz2 podman-2bc6427302eb6bcbd613d7ee767080d278968490.zip |
Fix handling of multiple filters in podman ps
Docker expects multiple filters to be passed with multiple uses
of the --filter flag (e.g. --filter=label=a=b --filter=label=c=d)
and not a single comma-separated list of filters as we expected.
Convert to the Docker format, and make some small cleanups to our
handling of filters along the way.
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #1345
Approved by: umohnani8
-rw-r--r-- | cmd/podman/ps.go | 9 | ||||
-rw-r--r-- | cmd/podman/shared/container.go | 1 | ||||
-rw-r--r-- | test/e2e/ps_test.go | 19 |
3 files changed, 23 insertions, 6 deletions
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index 82309c2ef..0b59b24b7 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -134,7 +134,7 @@ var ( Name: "all, a", Usage: "Show all the containers, default is only running containers", }, - cli.StringFlag{ + cli.StringSliceFlag{ Name: "filter, f", Usage: "Filter output based on conditions given", }, @@ -222,7 +222,6 @@ func psCmd(c *cli.Context) error { opts := shared.PsOptions{ All: c.Bool("all"), - Filter: c.String("filter"), Format: format, Last: c.Int("last"), Latest: c.Bool("latest"), @@ -246,8 +245,8 @@ func psCmd(c *cli.Context) error { }) } - if opts.Filter != "" { - filters := strings.Split(opts.Filter, ",") + filters := c.StringSlice("filter") + if len(filters) > 0 { for _, f := range filters { filterSplit := strings.SplitN(f, "=", 2) if len(filterSplit) < 2 { @@ -317,7 +316,7 @@ func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Ru return strings.Contains(c.ID(), filterValue) }, nil case "label": - var filterArray []string = strings.Split(filterValue, "=") + var filterArray []string = strings.SplitN(filterValue, "=", 2) var filterKey string = filterArray[0] if len(filterArray) > 1 { filterValue = filterArray[1] diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index 7a5455046..f44d0f7c9 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -20,7 +20,6 @@ import ( // PsOptions describes the struct being formed for ps type PsOptions struct { All bool - Filter string Format string Last int Latest bool diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index f5d79193b..a873b57bb 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -181,6 +181,25 @@ var _ = Describe("Podman ps", func() { Expect(result.OutputToStringArray()[0]).To(Equal(fullCid)) }) + It("podman ps multiple filters", func() { + session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", "--label", "key1=value1", ALPINE, "top"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + fullCid := session.OutputToString() + + session2 := podmanTest.Podman([]string{"run", "-d", "--name", "test2", "--label", "key1=value1", ALPINE, "top"}) + session2.WaitWithDefaultTimeout() + Expect(session2.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1", "--filter", "label=key1=value1"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + + output := result.OutputToStringArray() + Expect(len(output)).To(Equal(1)) + Expect(output[0]).To(Equal(fullCid)) + }) + It("podman ps mutually exclusive flags", func() { session := podmanTest.Podman([]string{"ps", "-aqs"}) session.WaitWithDefaultTimeout() |