Skip to content

Commit

Permalink
Only complete removable containers if --force is not given
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Albers <[email protected]>
(cherry picked from commit 147630a)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
albers authored and thaJeztah committed Oct 17, 2024
1 parent e283128 commit b018e55
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cli/command/container/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
Expand Down Expand Up @@ -38,7 +39,9 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{
"aliases": "docker container rm, docker container remove, docker rm",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true),
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool {
return opts.force || ctr.State == "exited" || ctr.State == "created"
}),
}

flags := cmd.Flags()
Expand Down

0 comments on commit b018e55

Please sign in to comment.