From 37a6dbf97715cafe21b882ec4d4e71e375d3770a Mon Sep 17 00:00:00 2001 From: Craig Jackson Date: Tue, 21 Aug 2018 14:21:48 -0600 Subject: [PATCH] Allow multiple projects to have different values for same env var --- realize/projects.go | 17 +++++++++++------ realize/projects_test.go | 12 ------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index 41c3040..b97f13e 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -116,12 +116,6 @@ func (p *Project) Before() { } // setup go tools p.Tools.Setup() - // set env const - for key, item := range p.Env { - if err := os.Setenv(key, item); err != nil { - p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""}) - } - } // global commands before p.cmd(p.stop, "before", true) // indexing files and dirs @@ -563,6 +557,13 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { }() } +func (p Project) buildEnvs() (envs []string) { + for k, v := range p.Env { + envs = append(envs, fmt.Sprintf("%s=%s", strings.Replace(k, "=", "", -1), v)) + } + return +} + // Run a project func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err error) { var args []string @@ -625,6 +626,10 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err return errors.New("project not found") } } + appendEnvs := p.buildEnvs() + if len(appendEnvs) > 0 { + build.Env = append(build.Env, appendEnvs...) + } // scan project stream stdout, err := build.StdoutPipe() stderr, err := build.StderrPipe() diff --git a/realize/projects_test.go b/realize/projects_test.go index ae24f27..2305e31 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -44,18 +44,6 @@ func TestProject_Before(t *testing.T) { if !strings.Contains(buf.String(), input) { t.Error("Unexpected error") } - - r = Realize{} - r.Projects = append(r.Projects, Project{ - parent: &r, - Env: map[string]string{ - input: input, - }, - }) - r.Projects[0].Before() - if os.Getenv(input) != input { - t.Error("Unexpected error expected", input, "instead", os.Getenv(input)) - } } func TestProject_Err(t *testing.T) {