diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2022-08-03 17:23:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 17:23:07 +0000 |
commit | 5fc7339aa1f383828a2f4949b0d9b8a7553374d7 (patch) | |
tree | f71f3f817d04cae5a51373264e8eda84863f28a7 /cmd/podman | |
parent | c1a38eb773af07b1f84a2b3f1780b216c4278e15 (diff) | |
parent | 53ec479685a7636a1bcc75bf3a88fbf7d95ba72a (diff) | |
download | podman-5fc7339aa1f383828a2f4949b0d9b8a7553374d7.tar.gz podman-5fc7339aa1f383828a2f4949b0d9b8a7553374d7.tar.bz2 podman-5fc7339aa1f383828a2f4949b0d9b8a7553374d7.zip |
Merge pull request #15084 from sstosh/rm-filter
Add rm --filter option
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/containers/kill.go | 7 | ||||
-rw-r--r-- | cmd/podman/containers/rm.go | 24 | ||||
-rw-r--r-- | cmd/podman/containers/stop.go | 7 |
3 files changed, 27 insertions, 11 deletions
diff --git a/cmd/podman/containers/kill.go b/cmd/podman/containers/kill.go index 5a5379389..c08b3abb6 100644 --- a/cmd/podman/containers/kill.go +++ b/cmd/podman/containers/kill.go @@ -49,7 +49,8 @@ var ( ) var ( - killOptions = entities.KillOptions{} + killOptions = entities.KillOptions{} + killCidFiles = []string{} ) func killFlags(cmd *cobra.Command) { @@ -61,7 +62,7 @@ func killFlags(cmd *cobra.Command) { flags.StringVarP(&killOptions.Signal, signalFlagName, "s", "KILL", "Signal to send to the container") _ = cmd.RegisterFlagCompletionFunc(signalFlagName, common.AutocompleteStopSignal) cidfileFlagName := "cidfile" - flags.StringArrayVar(&cidFiles, cidfileFlagName, []string{}, "Read the container ID from the file") + flags.StringArrayVar(&killCidFiles, cidfileFlagName, nil, "Read the container ID from the file") _ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault) } @@ -94,7 +95,7 @@ func kill(_ *cobra.Command, args []string) error { if sig < 1 || sig > 64 { return errors.New("valid signals are 1 through 64") } - for _, cidFile := range cidFiles { + for _, cidFile := range killCidFiles { content, err := ioutil.ReadFile(cidFile) if err != nil { return fmt.Errorf("error reading CIDFile: %w", err) diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go index 056e32651..1e3976389 100644 --- a/cmd/podman/containers/rm.go +++ b/cmd/podman/containers/rm.go @@ -52,8 +52,10 @@ var ( ) var ( - rmOptions = entities.RmOptions{} - cidFiles = []string{} + rmOptions = entities.RmOptions{ + Filters: make(map[string][]string), + } + rmCidFiles = []string{} ) func rmFlags(cmd *cobra.Command) { @@ -69,9 +71,13 @@ func rmFlags(cmd *cobra.Command) { flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") cidfileFlagName := "cidfile" - flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file") + flags.StringArrayVar(&rmCidFiles, cidfileFlagName, nil, "Read the container ID from the file") _ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault) + filterFlagName := "filter" + flags.StringSliceVar(&filters, filterFlagName, []string{}, "Filter output based on conditions given") + _ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters) + if !registry.IsRemote() { // This option is deprecated, but needs to still exists for backwards compatibility flags.Bool("storage", false, "Remove container from storage library") @@ -101,7 +107,7 @@ func rm(cmd *cobra.Command, args []string) error { } rmOptions.Timeout = &stopTimeout } - for _, cidFile := range cidFiles { + for _, cidFile := range rmCidFiles { content, err := ioutil.ReadFile(cidFile) if err != nil { return fmt.Errorf("error reading CIDFile: %w", err) @@ -110,6 +116,14 @@ func rm(cmd *cobra.Command, args []string) error { args = append(args, id) } + for _, f := range filters { + split := strings.SplitN(f, "=", 2) + if len(split) < 2 { + return fmt.Errorf("invalid filter %q", f) + } + rmOptions.Filters[split[0]] = append(rmOptions.Filters[split[0]], split[1]) + } + if rmOptions.All { logrus.Debug("--all is set: enforcing --depend=true") rmOptions.Depend = true @@ -147,7 +161,7 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit } errs = append(errs, r.Err) } else { - fmt.Println(r.Id) + fmt.Println(r.RawInput) } } return errs.PrintErrors() diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go index 261f441c3..b0f449266 100644 --- a/cmd/podman/containers/stop.go +++ b/cmd/podman/containers/stop.go @@ -52,7 +52,8 @@ var ( stopOptions = entities.StopOptions{ Filters: make(map[string][]string), } - stopTimeout uint + stopCidFiles = []string{} + stopTimeout uint ) func stopFlags(cmd *cobra.Command) { @@ -62,7 +63,7 @@ func stopFlags(cmd *cobra.Command) { flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing") cidfileFlagName := "cidfile" - flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file") + flags.StringArrayVar(&stopCidFiles, cidfileFlagName, nil, "Read the container ID from the file") _ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault) timeFlagName := "time" @@ -103,7 +104,7 @@ func stop(cmd *cobra.Command, args []string) error { if cmd.Flag("time").Changed { stopOptions.Timeout = &stopTimeout } - for _, cidFile := range cidFiles { + for _, cidFile := range stopCidFiles { content, err := ioutil.ReadFile(cidFile) if err != nil { return fmt.Errorf("error reading CIDFile: %w", err) |