github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/helpers/environment.go (about)

     1  package helpers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  func AddOrReplaceEnvironment(env []string, newEnvName string, newEnvVal string) []string {
     9  	var found bool
    10  	for i, envPair := range env {
    11  		splitENV := strings.Split(envPair, "=")
    12  		if splitENV[0] == newEnvName {
    13  			env[i] = fmt.Sprintf("%s=%s", newEnvName, newEnvVal)
    14  			found = true
    15  		}
    16  	}
    17  
    18  	if !found {
    19  		env = append(env, fmt.Sprintf("%s=%s", newEnvName, newEnvVal))
    20  	}
    21  	return env
    22  }