-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
33 lines (28 loc) · 854 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"github.com/bitrise-io/go-utils/command"
"strings"
"os"
)
func exportEnvironmentWithEnvman(keyStr, valueStr string) error {
cmd := command.New("envman", "add", "--key", keyStr)
cmd.SetStdin(strings.NewReader(valueStr))
return cmd.Run()
}
func createExportedEnvironment(variableNames string) []EnvironmentVariableModel {
environmentVariableNames := splitPipeSeparatedStringArray(variableNames)
environments := []EnvironmentVariableModel{}
for _, environmentVariableName := range environmentVariableNames {
environments = append(environments, EnvironmentVariableModel{
MappedTo:environmentVariableName,
Value:os.Getenv(environmentVariableName),
})
}
return environments
}
func splitPipeSeparatedStringArray(input string) []string {
if input == "" {
return []string{}
}
return strings.Split(input, "|")
}