mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Moved the filtering out of containers to the docker.go file
This commit is contained in:
parent
b89b02eee5
commit
30a79faa49
2 changed files with 19 additions and 15 deletions
|
|
@ -74,6 +74,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
|
||||||
Config: config,
|
Config: config,
|
||||||
Client: cli,
|
Client: cli,
|
||||||
ErrorChan: errorChan,
|
ErrorChan: errorChan,
|
||||||
|
ShowExited: true,
|
||||||
InDockerComposeProject: true,
|
InDockerComposeProject: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,10 +215,8 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
|
||||||
|
|
||||||
c.assignContainersToServices(containers, services)
|
c.assignContainersToServices(containers, services)
|
||||||
|
|
||||||
var displayContainers []*Container
|
var displayContainers = containers
|
||||||
if c.Config.UserConfig.Gui.ShowAllContainers {
|
if !c.Config.UserConfig.Gui.ShowAllContainers {
|
||||||
displayContainers = containers
|
|
||||||
} else {
|
|
||||||
displayContainers = c.obtainStandaloneContainers(containers, services)
|
displayContainers = c.obtainStandaloneContainers(containers, services)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,7 +235,7 @@ func (c *DockerCommand) RefreshContainersAndServices() error {
|
||||||
|
|
||||||
c.Containers = containers
|
c.Containers = containers
|
||||||
c.Services = services
|
c.Services = services
|
||||||
c.DisplayContainers = displayContainers
|
c.DisplayContainers = c.filterOutExited(displayContainers)
|
||||||
|
|
||||||
return nil
|
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
|
// 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 {
|
func (c *DockerCommand) obtainStandaloneContainers(containers []*Container, services []*Service) []*Container {
|
||||||
standaloneContainers := []*Container{}
|
standaloneContainers := []*Container{}
|
||||||
|
|
|
||||||
|
|
@ -277,17 +277,8 @@ func (gui *Gui) refreshContainersAndServices() error {
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
containersView.Clear()
|
containersView.Clear()
|
||||||
isFocused := gui.g.CurrentView().Name() == "containers"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue