Skip to content

Commit 9b90491

Browse files
committed
Add forceProjectView option to GUI configuration (#800)
1 parent 7e7aadc commit 9b90491

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

docs/Config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ gui:
4646
- blue
4747
returnImmediately: false
4848
wrapMainPanel: true
49+
# Show Projects/Services panels even when not launched from a compose directory
50+
forceProjectView: false
4951
# Side panel width as a ratio of the screen's width
5052
sidePanelWidth: 0.333
5153
# Determines whether we show the bottom line (the one containing keybinding

pkg/commands/docker.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
165165
return dockerCommand, nil
166166
}
167167

168-
// IsProjectScoped reports whether lazydocker should be scoped to a single
169-
// compose project — either because we're inside a compose directory or
170-
// because the user passed -p. When false, the project/services panels are
171-
// hidden and all containers are shown in a flat list.
168+
// IsProjectScoped reports whether lazydocker should show the project/services
169+
// panels and filter containers by project. True when inside a compose
170+
// directory, when -p was passed, or when gui.forceProjectView is enabled.
171+
// When false, the project/services panels are hidden and all containers are
172+
// shown in a flat list.
172173
func (c *DockerCommand) IsProjectScoped() bool {
173-
return c.InDockerComposeProject || c.Config.ProjectName != ""
174+
if c.InDockerComposeProject || c.Config.ProjectName != "" {
175+
return true
176+
}
177+
return c.Config.UserConfig != nil && c.Config.UserConfig.Gui.ForceProjectView
174178
}
175179

176180
func (c *DockerCommand) setDockerComposeCommand(config *config.AppConfig) {

pkg/commands/docker_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,34 @@ func TestNewDockerClientVersionNegotiation(t *testing.T) {
6666
// TestIsProjectScoped covers the predicate that drives whether the
6767
// project/services panels appear and whether the containers panel filters by
6868
// project. The "outside compose dir + -p" case is the regression we fixed
69-
// after PR #776 silently disabled it.
69+
// after PR #776 silently disabled it. forceProjectView restores multi-project
70+
// panels when launched outside a compose directory (issue #800).
7071
func TestIsProjectScoped(t *testing.T) {
7172
cases := []struct {
7273
name string
7374
inDockerComposeProject bool
7475
projectName string
76+
forceProjectView bool
7577
want bool
7678
}{
77-
{"inside compose dir, no -p", true, "", true},
78-
{"inside compose dir, with -p", true, "myproject", true},
79-
{"outside compose dir, no -p", false, "", false},
80-
{"outside compose dir, with -p", false, "myproject", true},
79+
{"inside compose dir, no -p", true, "", false, true},
80+
{"inside compose dir, with -p", true, "myproject", false, true},
81+
{"outside compose dir, no -p", false, "", false, false},
82+
{"outside compose dir, with -p", false, "myproject", false, true},
83+
{"outside compose dir, forceProjectView", false, "", true, true},
84+
{"outside compose dir, forceProjectView and -p", false, "myproject", true, true},
85+
{"inside compose dir, forceProjectView", true, "", true, true},
8186
}
8287
for _, tc := range cases {
8388
t.Run(tc.name, func(t *testing.T) {
8489
c := &DockerCommand{
8590
InDockerComposeProject: tc.inDockerComposeProject,
86-
Config: &config.AppConfig{ProjectName: tc.projectName},
91+
Config: &config.AppConfig{
92+
ProjectName: tc.projectName,
93+
UserConfig: &config.UserConfig{
94+
Gui: config.GuiConfig{ForceProjectView: tc.forceProjectView},
95+
},
96+
},
8797
}
8898
assert.Equal(t, tc.want, c.IsProjectScoped())
8999
})

pkg/config/app_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ type GuiConfig struct {
105105
// of clutter
106106
ShowAllContainers bool `yaml:"showAllContainers,omitempty"`
107107

108+
// ForceProjectView shows the Projects and Services panels even when lazydocker
109+
// is not launched from a docker-compose directory (and -p was not passed).
110+
// Projects/services are discovered from running container compose labels.
111+
ForceProjectView bool `yaml:"forceProjectView,omitempty"`
112+
108113
// ReturnImmediately determines whether you get the 'press enter to return to
109114
// lazydocker' message after a subprocess has completed. You would set this to
110115
// true if you often want to see the output of subprocesses before returning
@@ -369,6 +374,7 @@ func GetDefaultConfig() UserConfig {
369374
OptionsTextColor: []string{"blue"},
370375
},
371376
ShowAllContainers: false,
377+
ForceProjectView: false,
372378
ReturnImmediately: false,
373379
WrapMainPanel: true,
374380
LegacySortContainers: false,

0 commit comments

Comments
 (0)