-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
45 lines (39 loc) · 1000 Bytes
/
common.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
package main
import (
"github.com/mateothegreat/go-multilog/multilog"
"github.com/polyrepopro/api/config"
)
type SetupResult struct {
Config *config.Config
Workspace *config.Workspace
}
func Setup(group string, workspaceName string, configPath string) (SetupResult, error) {
cfg, err := config.GetConfig(configPath)
if err != nil {
multilog.Fatal(group, "failed to get config", map[string]interface{}{
"error": err,
})
}
if workspaceName == "" && cfg.Default != "" {
workspaceName = cfg.Default
} else {
if len(*cfg.Workspaces) > 0 {
workspaceName = (*cfg.Workspaces)[0].Name
} else {
multilog.Fatal(group, "no workspaces found in config", map[string]interface{}{
"error": err,
})
}
}
workspace, err := cfg.GetWorkspace(workspaceName)
if err != nil {
multilog.Fatal(group, "failed to get workspace", map[string]interface{}{
"name": workspaceName,
"error": err,
})
}
return SetupResult{
Config: cfg,
Workspace: workspace,
}, nil
}