Skip to content

Commit 4256a4b

Browse files
committed
Merge pull request jesseduffield#602 from blwsh/support-profiles
Add --profile arg for lazydocker command
2 parents 825f401 + 26671cc commit 4256a4b

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
"github.com/docker/docker/client"
1212
"github.com/go-errors/errors"
1313
"github.com/integrii/flaggy"
14+
"github.com/jesseduffield/yaml"
15+
"github.com/samber/lo"
16+
1417
"github.com/jesseduffield/lazydocker/pkg/app"
1518
"github.com/jesseduffield/lazydocker/pkg/config"
1619
"github.com/jesseduffield/lazydocker/pkg/utils"
17-
"github.com/jesseduffield/yaml"
18-
"github.com/samber/lo"
1920
)
2021

2122
const DEFAULT_VERSION = "unversioned"
@@ -29,6 +30,7 @@ var (
2930
configFlag = false
3031
debuggingFlag = false
3132
composeFiles []string
33+
profiles []string
3234
)
3335

3436
func main() {
@@ -51,6 +53,7 @@ func main() {
5153
flaggy.Bool(&configFlag, "c", "config", "Print the current default config")
5254
flaggy.Bool(&debuggingFlag, "d", "debug", "a boolean")
5355
flaggy.StringSlice(&composeFiles, "f", "file", "Specify alternate compose files")
56+
flaggy.StringSlice(&profiles, "p", "profile", "Specify one or more profiles to use")
5457
flaggy.SetVersion(info)
5558

5659
flaggy.Parse()
@@ -71,7 +74,7 @@ func main() {
7174
log.Fatal(err.Error())
7275
}
7376

74-
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir)
77+
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir, profiles)
7578
if err != nil {
7679
log.Fatal(err.Error())
7780
}

pkg/cheatsheet/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Generate() {
3333
}
3434

3535
func generateAtDir(dir string) {
36-
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "")
36+
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "", nil)
3737
if err != nil {
3838
panic(err)
3939
}

pkg/config/app_config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ type AppConfig struct {
491491
}
492492

493493
// NewAppConfig makes a new app config
494-
func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag bool, composeFiles []string, projectDir string) (*AppConfig, error) {
494+
func NewAppConfig(name, version, commit, date, buildSource string, debuggingFlag bool, composeFiles []string, projectDir string, profiles []string) (*AppConfig, error) {
495495
configDir, err := findOrCreateConfigDir(name)
496496
if err != nil {
497497
return nil, err
@@ -507,6 +507,10 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
507507
userConfig.CommandTemplates.DockerCompose += " -f " + strings.Join(composeFiles, " -f ")
508508
}
509509

510+
if len(profiles) > 0 {
511+
userConfig.CommandTemplates.DockerCompose += " --profile " + strings.Join(profiles, " --profile ")
512+
}
513+
510514
appConfig := &AppConfig{
511515
Name: name,
512516
Version: version,

pkg/config/app_config_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestDockerComposeCommandNoFiles(t *testing.T) {
1111
composeFiles := []string{}
12-
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
12+
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir", nil)
1313
if err != nil {
1414
t.Fatalf("Unexpected error: %s", err)
1515
}
@@ -23,7 +23,7 @@ func TestDockerComposeCommandNoFiles(t *testing.T) {
2323

2424
func TestDockerComposeCommandSingleFile(t *testing.T) {
2525
composeFiles := []string{"one.yml"}
26-
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
26+
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir", nil)
2727
if err != nil {
2828
t.Fatalf("Unexpected error: %s", err)
2929
}
@@ -37,7 +37,7 @@ func TestDockerComposeCommandSingleFile(t *testing.T) {
3737

3838
func TestDockerComposeCommandMultipleFiles(t *testing.T) {
3939
composeFiles := []string{"one.yml", "two.yml", "three.yml"}
40-
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir")
40+
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, composeFiles, "projectDir", nil)
4141
if err != nil {
4242
t.Fatalf("Unexpected error: %s", err)
4343
}
@@ -49,10 +49,23 @@ func TestDockerComposeCommandMultipleFiles(t *testing.T) {
4949
}
5050
}
5151

52+
func TestDockerComposeProfiles(t *testing.T) {
53+
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, nil, "projectDir", []string{"profile1", "profile2"})
54+
if err != nil {
55+
t.Fatalf("Unexpected error: %s", err)
56+
}
57+
58+
actual := conf.UserConfig.CommandTemplates.DockerCompose
59+
expected := "docker compose --profile profile1 --profile profile2"
60+
if actual != expected {
61+
t.Fatalf("Expected %s but got %s", expected, actual)
62+
}
63+
}
64+
5265
func TestWritingToConfigFile(t *testing.T) {
5366
// init the AppConfig
5467
emptyComposeFiles := []string{}
55-
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir")
68+
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir", nil)
5669
if err != nil {
5770
t.Fatalf("Unexpected error: %s", err)
5871
}

test/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,19 @@ services:
2323
dockerfile: Dockerfile
2424
context: .
2525
command: /app/print-random-stuff.sh
26+
27+
my-service4:
28+
build:
29+
dockerfile: Dockerfile
30+
context: .
31+
command: /app/print-random-stuff.sh
32+
profiles:
33+
- foo
34+
35+
my-service5:
36+
build:
37+
dockerfile: Dockerfile
38+
context: .
39+
command: /app/print-random-stuff.sh
40+
profiles:
41+
- bar

0 commit comments

Comments
 (0)