Moved the filtering out of containers to the docker.go file

This commit is contained in:
mjarkk 2019-07-07 14:19:35 +02:00
parent b89b02eee5
commit 30a79faa49
No known key found for this signature in database
GPG key ID: 147D0BE9258C6C95
2 changed files with 19 additions and 15 deletions

View file

@ -74,6 +74,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
Config: config,
Client: cli,
ErrorChan: errorChan,
ShowExited: true,
InDockerComposeProject: true,
}
@ -214,10 +215,8 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
c.assignContainersToServices(containers, services)
var displayContainers []*Container
if c.Config.UserConfig.Gui.ShowAllContainers {
displayContainers = containers
} else {
var displayContainers = containers
if !c.Config.UserConfig.Gui.ShowAllContainers {
displayContainers = c.obtainStandaloneContainers(containers, services)
}
@ -236,7 +235,7 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
c.Containers = containers
c.Services = services
c.DisplayContainers = displayContainers
c.DisplayContainers = c.filterOutExited(displayContainers)
return nil
}
@ -254,6 +253,20 @@ L:
}
}
// filterOutExited filters out the exited containers if c.ShowExited is false
func (c *DockerCommand) filterOutExited(containers []*Container) []*Container {
if c.ShowExited {
return containers
}
toReturn := []*Container{}
for _, container := range containers {
if container.Container.State != "exited" {
toReturn = append(toReturn, container)
}
}
return toReturn
}
// obtainStandaloneContainers returns standalone containers. Standalone containers are containers which are either one-off containers, or whose service is not part of this docker-compose context
func (c *DockerCommand) obtainStandaloneContainers(containers []*Container, services []*Service) []*Container {
standaloneContainers := []*Container{}

View file

@ -277,17 +277,8 @@ func (gui *Gui) refreshContainersAndServices() error {
gui.g.Update(func(g *gocui.Gui) error {
containersView.Clear()
isFocused := gui.g.CurrentView().Name() == "containers"
toRender := gui.DockerCommand.DisplayContainers
if !gui.DockerCommand.ShowExited {
toRender = []*commands.Container{}
for _, container := range gui.DockerCommand.DisplayContainers {
if container.Container.State != "exited" {
toRender = append(toRender, container)
}
}
}
list, err := utils.RenderList(toRender, utils.IsFocused(isFocused))
list, err := utils.RenderList(gui.DockerCommand.DisplayContainers, utils.IsFocused(isFocused))
if err != nil {
return err
}