-
Notifications
You must be signed in to change notification settings - Fork 10
/
gcloud.go
43 lines (39 loc) · 882 Bytes
/
gcloud.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
package main
import (
"fmt"
"log"
"os/exec"
"github.com/emicklei/tre"
)
func gcloudConfigList() {
log.Println("checking gcloud config list ...")
cmd := exec.Command("gcloud", "config", "list")
out, _ := cmd.CombinedOutput()
fmt.Println(string(out))
}
func gcloudConfigSetProject(cfg Config) error {
for _, each := range []struct {
Key, Value string
}{
{"core/project", cfg.Project},
{"compute/region", cfg.Region},
{"compute/zone", cfg.Zone},
} {
k := each.Key
v := each.Value
if len(v) > 0 { // skip optional values
if cfg.verbose {
log.Printf("setting gcloud config [%s] to [%s]\n", k, v)
}
cmd := exec.Command("gcloud", "config", "set", k, v)
data, err := runCommand(cmd)
if cfg.verbose {
log.Println(string(data))
}
if err != nil {
return tre.New(err, "error changing gcloud config", k, v)
}
}
}
return nil
}