Skip to content

Commit

Permalink
(#25) Extract default environment generation to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Apr 16, 2020
1 parent 1badb29 commit 47362c1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ func (dc *LocalDockerCompose) Down() ExecError {
panic("Local Docker Compose not found. Is " + dc.Executable + " on the PATH?")
}

environment := map[string]string{
envProjectName: dc.Identifier,
envComposeFile: dc.ComposeFilePath,
}
environment := dc.getDockerComposeEnvironment()

abs, err := filepath.Abs(dc.ComposeFilePath)
pwd, name := filepath.Split(abs)
Expand All @@ -79,18 +76,25 @@ func (dc *LocalDockerCompose) Down() ExecError {
return execErr
}

func (dc *LocalDockerCompose) getDockerComposeEnvironment() map[string]string {
environment := map[string]string{}

environment[envProjectName] = dc.Identifier
environment[envComposeFile] = dc.ComposeFilePath

return environment
}

// Invoke invokes the docker compose
func (dc *LocalDockerCompose) Invoke() ExecError {
if which(dc.Executable) != nil {
panic("Local Docker Compose not found. Is " + dc.Executable + " on the PATH?")
}

environment := map[string]string{}
environment := dc.getDockerComposeEnvironment()
for k, v := range dc.Env {
environment[k] = v
}
environment[envProjectName] = dc.Identifier
environment[envComposeFile] = dc.ComposeFilePath

abs, err := filepath.Abs(dc.ComposeFilePath)
pwd, name := filepath.Split(abs)
Expand Down

0 comments on commit 47362c1

Please sign in to comment.