fix: don't export from within function
Also, don't explode on command function which has "export" in the name! See coop-cloud/organising#498
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/Autonomic-Cooperative/godotenv"
|
||||
@ -149,22 +150,32 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
|
||||
}
|
||||
return envVars, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
exportRegex, err := regexp.Compile(`^export\s+(\w+=\w+)`)
|
||||
if err != nil {
|
||||
return envVars, err
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.Contains(line, "export") {
|
||||
splitVals := strings.Split(line, "export ")
|
||||
txt := scanner.Text()
|
||||
if exportRegex.MatchString(txt) {
|
||||
splitVals := strings.Split(txt, "export ")
|
||||
envVarDef := splitVals[len(splitVals)-1]
|
||||
keyVal := strings.Split(envVarDef, "=")
|
||||
if len(keyVal) != 2 {
|
||||
return envVars, fmt.Errorf("couldn't parse %s", line)
|
||||
return envVars, fmt.Errorf("couldn't parse %s", txt)
|
||||
}
|
||||
envVars[keyVal[0]] = keyVal[1]
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("read %s from %s", envVars, abraSh)
|
||||
if len(envVars) > 0 {
|
||||
logrus.Debugf("read %s from %s", envVars, abraSh)
|
||||
} else {
|
||||
logrus.Debugf("read 0 env var exports from %s", abraSh)
|
||||
}
|
||||
|
||||
return envVars, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user