Skip to content

Commit

Permalink
Merge pull request #32 from upsight/feature/envpropagation
Browse files Browse the repository at this point in the history
Fixes parent env merging from parent to child
  • Loading branch information
pkar authored Nov 20, 2017
2 parents 37ef258 + c33bfdf commit d25bcaf
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ or download from [releases](https://github.com/upsight/ron/releases)

### Upgrade

LATEST_URL=https://github.com/upsight/ron/releases/download/v1.1.2/ron-linux-v1.1.2 ron upgrade
LATEST_URL=https://github.com/upsight/ron/releases/download/v1.1.3/ron-linux-v1.1.3 ron upgrade

### Testing

Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Upgrade
Ron can be upgraded if you already have it installed. The easiest way
is to just provide a LATEST_URL to the upgrade command:
$ LATEST_URL=https://github.com/upsight/ron/releases/download/v1.1.2/ron-linux-v1.1.2 ron upgrade
$ LATEST_URL=https://github.com/upsight/ron/releases/download/v1.1.3/ron-linux-v1.1.3 ron upgrade
Version
Expand Down
2 changes: 1 addition & 1 deletion ron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ envs:
- CURDIR: +pwd
- UNAME: +uname | tr '[:upper:]' '[:lower:]'
- PACKAGE_VERSION: +git describe --always --dirty --tags | tr '-' '_'
- TAG: v1.1.2
- TAG: v1.1.3
- LATEST_URL: "https://github.com/upsight/ron/releases/download/$TAG/ron-${UNAME}-latest"
- REPO: github.com/upsight/ron
- RELEASES: linux darwin windows
Expand Down
11 changes: 3 additions & 8 deletions target/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,14 @@ func NewConfigs(configs []*RawConfig, remoteEnv string, stdOut io.Writer, stdErr
return nil, err
}
f.Env = e
if parentFile != nil {
parentFile.Env.MergeTo(f.Env)
}
confs.Files = append(confs.Files, f)
if strings.HasSuffix(config.Filepath, ConfigFileName) {
parentFile = f
}
}
for i := len(confs.Files) - 1; i >= 0; i-- {
curFile := confs.Files[i]
parent := confs.Files[i].Env.parent
for parent != nil {
curFile.Env.Merge(parent.Env)
parent = parent.Env.parent
}
}

if remoteEnv != "" {
// find any remote hosts if set.
Expand Down
4 changes: 2 additions & 2 deletions target/default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion target/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envs:
- CURDIR: +pwd
- UNAME: +uname | tr '[:upper:]' '[:lower:]'
- PACKAGE_VERSION: +git describe --always --dirty --tags | tr '-' '_'
- TAG: v1.1.2
- TAG: v1.1.3
- LATEST_URL: "https://github.com/upsight/ron/releases/download/$TAG/ron-${UNAME}-$TAG"
targets:
_hello:
Expand Down
4 changes: 2 additions & 2 deletions target/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (e *Env) Config() (MSS, error) {
return e.config, nil
}

// Merge the current env into any missing keys for the input node.
func (e *Env) Merge(node *Env) error {
// MergeTo the current env into any missing keys for the input node.
func (e *Env) MergeTo(node *Env) error {
for k, v := range e.config {
if _, ok := node.config[k]; !ok {
node.config[k] = v
Expand Down
15 changes: 8 additions & 7 deletions target/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,24 @@ func TestEnv_PrintRawBadWriter(t *testing.T) {
e.PrintRaw()
}

func TestEnv_Merge(t *testing.T) {
func TestEnv_MergeTo(t *testing.T) {
writer := &bytes.Buffer{}
e1Config := `
- ABC: +pwd
- APP: ron
- HELLO: hello
- ABC: +pwd
`
e2Config := `
- GOOD: bye
- BLAH: +pwd
- GOOD: bye
- HELLO: bye
`
e1, _ := NewEnv(nil, &RawConfig{Envs: e1Config}, ParseOSEnvs([]string{}), writer)
e2, _ := NewEnv(nil, &RawConfig{Envs: e2Config}, ParseOSEnvs([]string{}), writer)
e1.Merge(e2)
e1.MergeTo(e2)
equals(t, e2.config["ABC"], "+pwd")
equals(t, e2.config["APP"], "ron")
equals(t, e2.config["GOOD"], "bye")
equals(t, e2.config["BLAH"], "+pwd")
equals(t, e2.config["ABC"], "+pwd")
equals(t, e2.config["HELLO"], "hello")
equals(t, e2.config["GOOD"], "bye")
equals(t, e2.config["HELLO"], "bye")
}

0 comments on commit d25bcaf

Please sign in to comment.