-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
46 lines (37 loc) · 843 Bytes
/
output.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
34
35
36
37
38
39
40
41
42
43
44
45
46
package commands
import (
"github.com/dchest/safefile"
"github.com/nlindblad/confidential/environment"
"github.com/urfave/cli"
"fmt"
)
func writeEnvironmentToFile(environment *environment.Environment, envFile *string) (error) {
f, err := safefile.Create(*envFile, 0644)
if err != nil {
return nil
}
defer f.Close()
for _, environmentVariable := range environment.AsStrings() {
_, err := f.WriteString(fmt.Sprintf("%s\n", environmentVariable))
if err != nil {
return err
}
}
err = f.Commit()
if err != nil {
return err
}
return nil
}
func output(c *cli.Context) error {
environment, err := RetrieveEnvironmentVariablesFromContext(c)
if err != nil {
return err
}
envFile, err := GetMandatoryFlag(c, "env-file")
if err != nil {
return err
}
writeEnvironmentToFile(environment, envFile)
return nil
}