-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
32 lines (27 loc) · 908 Bytes
/
get.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
package main
import (
"fmt"
"github.com/codegangsta/cli"
keychain "github.com/okdas/go-keychain"
)
func RunGet(c *cli.Context) error {
bucket := c.String("bucket")
environmentVariables, err := getEnvListByBucket(bucket)
if err != nil {
return cli.NewExitError("Can't load virtual environments for bucket "+bucket+".\n", 1)
}
for i := 0; i < len(environmentVariables); i++ {
name := environmentVariables[i]
secret, err := keychain.Find("evk", "evk_"+bucket+"_"+name)
if err != nil {
return cli.NewExitError("Can't load secret from a keychain.\n", 1)
}
fmt.Printf("export %s=\"%s\"\n", name, secret)
}
command := "eval $(evk get)"
if bucket != "main" {
command = "eval $(evk get " + bucket + ")"
}
fmt.Printf("# You can cope and paste those variables to your shell or run: \n# %s\n# you also can add it to your .profile to load vars automatically.\n", command)
return nil
}