Skip to content

Commit

Permalink
Merge pull request #12882 from jmguzik/unify-filters-cmd
Browse files Browse the repository at this point in the history
Unify the method of parsing filters in cmd
  • Loading branch information
openshift-merge-robot authored Jan 17, 2022
2 parents ea2656d + 6bca61e commit 26cf6c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/podman/containers/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/specgenutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -64,7 +64,7 @@ func prune(cmd *cobra.Command, args []string) error {
}
}

pruneOptions.Filters, err = specgenutil.ParseFilters(filter)
pruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filter)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/images/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/specgenutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func prune(cmd *cobra.Command, args []string) error {
return nil
}
}
filterMap, err := specgenutil.ParseFilters(filter)
filterMap, err := parse.FilterArgumentsIntoFilters(filter)
if err != nil {
return err
}
Expand Down
14 changes: 6 additions & 8 deletions cmd/podman/networks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -61,14 +61,12 @@ func init() {
}

func networkList(cmd *cobra.Command, args []string) error {
networkListOptions.Filters = make(map[string][]string)
for _, f := range filters {
split := strings.SplitN(f, "=", 2)
if len(split) == 1 {
return errors.Errorf("invalid filter %q", f)
}
networkListOptions.Filters[split[0]] = append(networkListOptions.Filters[split[0]], split[1])
var err error
networkListOptions.Filters, err = parse.FilterArgumentsIntoFilters(filters)
if err != nil {
return err
}

responses, err := registry.ContainerEngine().NetworkList(registry.Context(), networkListOptions)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/networks/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"strings"

"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/containers/podman/v3/pkg/specgenutil"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -68,7 +68,7 @@ func networkPrune(cmd *cobra.Command, _ []string) error {
return nil
}
}
networkPruneOptions.Filters, err = specgenutil.ParseFilters(filter)
networkPruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filter)
if err != nil {
return err
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/specgenutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ func ReadPodIDFiles(files []string) ([]string, error) {
return ids, nil
}

// ParseFilters transforms one filter format to another and validates input
func ParseFilters(filter []string) (map[string][]string, error) {
// TODO Remove once filter refactor is finished and url.Values done.
filters := map[string][]string{}
for _, f := range filter {
t := strings.SplitN(f, "=", 2)
filters = make(map[string][]string)
if len(t) < 2 {
return map[string][]string{}, errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
filters[t[0]] = append(filters[t[0]], t[1])
}
return filters, nil
}

// CreateExpose parses user-provided exposed port definitions and converts them
// into SpecGen format.
// TODO: The SpecGen format should really handle ranges more sanely - we could
Expand Down

0 comments on commit 26cf6c8

Please sign in to comment.