mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 07:11:01 +00:00
Support -p flag and DRY up code
This commit is contained in:
parent
697cd441aa
commit
3974f6fec1
4 changed files with 27 additions and 17 deletions
|
|
@ -154,9 +154,25 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
|
|||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
// When the user passes -p outside of a compose directory, treat it as the
|
||||
// local project so the project/services panels still appear and filtering
|
||||
// is applied. Inside a compose dir, LocalProjectName is derived from
|
||||
// container labels later in RefreshContainersAndServices.
|
||||
if !dockerCommand.InDockerComposeProject && config.ProjectName != "" {
|
||||
dockerCommand.LocalProjectName = config.ProjectName
|
||||
}
|
||||
|
||||
return dockerCommand, nil
|
||||
}
|
||||
|
||||
// IsProjectScoped reports whether lazydocker should be scoped to a single
|
||||
// compose project — either because we're inside a compose directory or
|
||||
// because the user passed -p. When false, the project/services panels are
|
||||
// hidden and all containers are shown in a flat list.
|
||||
func (c *DockerCommand) IsProjectScoped() bool {
|
||||
return c.InDockerComposeProject || c.Config.ProjectName != ""
|
||||
}
|
||||
|
||||
func (c *DockerCommand) setDockerComposeCommand(config *config.AppConfig) {
|
||||
if config.UserConfig.CommandTemplates.DockerCompose != "docker compose" {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -87,11 +87,10 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container]
|
|||
return false
|
||||
}
|
||||
|
||||
// Only apply project and standalone filtering when we are inside a
|
||||
// docker-compose project. Outside of a compose project all
|
||||
// containers are shown in a flat list regardless of which compose
|
||||
// project they belong to.
|
||||
if gui.DockerCommand.InDockerComposeProject {
|
||||
// When project-scoped, apply project and standalone filtering.
|
||||
// Otherwise all containers are shown in a flat list regardless
|
||||
// of which compose project they belong to.
|
||||
if gui.DockerCommand.IsProjectScoped() {
|
||||
// This check must be inside the InDockerComposeProject guard:
|
||||
// outside a compose project, services are still derived from
|
||||
// container labels, so compose-managed containers from other
|
||||
|
|
|
|||
|
|
@ -59,12 +59,7 @@ func (gui *Gui) getProjectPanel() *panels.SideListPanel[*commands.Project] {
|
|||
return gui.renderContainersAndServices()
|
||||
},
|
||||
Hide: func() bool {
|
||||
// Only show the project panel when we are inside a docker-compose
|
||||
// project directory. When launched outside of a compose project
|
||||
// there is no meaningful local project to display, so we hide the
|
||||
// panel and let the containers panel show all containers in a flat
|
||||
// list (matching the behaviour from before v0.25).
|
||||
return !gui.DockerCommand.InDockerComposeProject
|
||||
return !gui.DockerCommand.IsProjectScoped()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +190,11 @@ func (gui *Gui) renderAllLogs(project *commands.Project) tasks.TaskFunc {
|
|||
}
|
||||
|
||||
func (gui *Gui) renderDockerComposeConfig(project *commands.Project) tasks.TaskFunc {
|
||||
if !gui.DockerCommand.InDockerComposeProject {
|
||||
return gui.NewSimpleRenderStringTask(func() string {
|
||||
return "Compose config is only available when launched from a docker-compose project directory"
|
||||
})
|
||||
}
|
||||
if project != nil && project.Name != gui.DockerCommand.LocalProjectName {
|
||||
return gui.NewSimpleRenderStringTask(func() string {
|
||||
return "Compose config is not available for non-local projects"
|
||||
|
|
|
|||
|
|
@ -90,12 +90,7 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] {
|
|||
return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service)
|
||||
},
|
||||
Hide: func() bool {
|
||||
// Only show the services panel when we are inside a docker-compose
|
||||
// project directory. When launched outside of a compose project
|
||||
// there is no local project context, so the panel is hidden and
|
||||
// all containers are shown in a flat list (matching pre-v0.25
|
||||
// behaviour).
|
||||
return !gui.DockerCommand.InDockerComposeProject
|
||||
return !gui.DockerCommand.IsProjectScoped()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue