summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorJakub Guzik <jakubmguzik@gmail.com>2021-05-12 00:39:01 +0200
committerJakub Guzik <jakubmguzik@gmail.com>2021-05-12 09:05:06 +0200
commit5e6405334c3d0422b5ec7cd09ef9c58d8f558dba (patch)
treecc5ca0e47596bdcb2509a4134b4c8b8178b0549e /cmd/podman
parent3aae34694623cce5f1da4a93c7c1e729c528402c (diff)
downloadpodman-5e6405334c3d0422b5ec7cd09ef9c58d8f558dba.tar.gz
podman-5e6405334c3d0422b5ec7cd09ef9c58d8f558dba.tar.bz2
podman-5e6405334c3d0422b5ec7cd09ef9c58d8f558dba.zip
Add support for cli network prune --filter flag
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/networks/prune.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/cmd/podman/networks/prune.go b/cmd/podman/networks/prune.go
index ebba06db5..bcc55f0f4 100644
--- a/cmd/podman/networks/prune.go
+++ b/cmd/podman/networks/prune.go
@@ -6,6 +6,7 @@ import (
"os"
"strings"
+ "github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/utils"
@@ -31,12 +32,14 @@ var (
var (
networkPruneOptions entities.NetworkPruneOptions
force bool
+ filter = []string{}
)
-func networkPruneFlags(flags *pflag.FlagSet) {
- //TODO: Not implemented but for future reference
- //flags.StringSliceVar(&networkPruneOptions.Filters,"filters", []string{}, "provide filter values (e.g. 'until=<timestamp>')")
+func networkPruneFlags(cmd *cobra.Command, flags *pflag.FlagSet) {
flags.BoolVarP(&force, "force", "f", false, "do not prompt for confirmation")
+ filterFlagName := "filter"
+ flags.StringArrayVar(&filter, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
+ _ = cmd.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
}
func init() {
@@ -46,12 +49,13 @@ func init() {
Parent: networkCmd,
})
flags := networkPruneCommand.Flags()
- networkPruneFlags(flags)
+ networkPruneFlags(networkPruneCommand, flags)
}
func networkPrune(cmd *cobra.Command, _ []string) error {
var (
errs utils.OutputErrors
+ err error
)
if !force {
reader := bufio.NewReader(os.Stdin)
@@ -65,6 +69,10 @@ func networkPrune(cmd *cobra.Command, _ []string) error {
return nil
}
}
+ networkPruneOptions.Filters, err = common.ParseFilters(filter)
+ if err != nil {
+ return err
+ }
responses, err := registry.ContainerEngine().NetworkPrune(registry.Context(), networkPruneOptions)
if err != nil {
setExitCode(err)