forked from toolshed/abra
feat: final round of hacks for deploy command
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Autonomic-Cooperative/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -109,3 +111,31 @@ func EnsureAbraDirExists() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
|
||||
envVars := make(map[string]string)
|
||||
|
||||
file, err := os.Open(abraSh)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return envVars, fmt.Errorf("'%s' does not exist?", abraSh)
|
||||
}
|
||||
return envVars, err
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.Contains(line, "export") {
|
||||
splitVals := strings.Split(line, "export ")
|
||||
envVarDef := splitVals[len(splitVals)-1]
|
||||
keyVal := strings.Split(envVarDef, "=")
|
||||
if len(keyVal) != 2 {
|
||||
return envVars, fmt.Errorf("couldn't parse %s", line)
|
||||
}
|
||||
envVars[keyVal[0]] = keyVal[1]
|
||||
}
|
||||
}
|
||||
|
||||
return envVars, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user