Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --profile arg for lazydocker command #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"github.com/docker/docker/client"
"github.com/go-errors/errors"
"github.com/integrii/flaggy"
"github.com/jesseduffield/yaml"
"github.com/samber/lo"

"github.com/jesseduffield/lazydocker/pkg/app"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/jesseduffield/lazydocker/pkg/utils"
"github.com/jesseduffield/yaml"
"github.com/samber/lo"
)

const DEFAULT_VERSION = "unversioned"
Expand All @@ -29,6 +30,7 @@ var (
configFlag = false
debuggingFlag = false
composeFiles []string
profiles []string
)

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

flaggy.Parse()
Expand All @@ -71,7 +74,7 @@ func main() {
log.Fatal(err.Error())
}

appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir)
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag, composeFiles, projectDir, profiles)
if err != nil {
log.Fatal(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cheatsheet/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Generate() {
}

func generateAtDir(dir string) {
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "")
mConfig, err := config.NewAppConfig("lazydocker", "", "", "", "", true, nil, "", nil)
if err != nil {
panic(err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ type AppConfig struct {
}

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

if len(profiles) > 0 {
userConfig.CommandTemplates.DockerCompose += " --profile " + strings.Join(profiles, " --profile ")
}

appConfig := &AppConfig{
Name: name,
Version: version,
Expand Down
21 changes: 17 additions & 4 deletions pkg/config/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

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

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

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

func TestDockerComposeProfiles(t *testing.T) {
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, nil, "projectDir", []string{"profile1", "profile2"})
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}

actual := conf.UserConfig.CommandTemplates.DockerCompose
expected := "docker compose --profile profile1 --profile profile2"
if actual != expected {
t.Fatalf("Expected %s but got %s", expected, actual)
}
}

func TestWritingToConfigFile(t *testing.T) {
// init the AppConfig
emptyComposeFiles := []string{}
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir")
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir", nil)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
Expand Down
16 changes: 16 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ services:
dockerfile: Dockerfile
context: .
command: /app/print-random-stuff.sh

my-service4:
build:
dockerfile: Dockerfile
context: .
command: /app/print-random-stuff.sh
profiles:
- foo

my-service5:
build:
dockerfile: Dockerfile
context: .
command: /app/print-random-stuff.sh
profiles:
- bar
blwsh marked this conversation as resolved.
Show resolved Hide resolved