-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathloader.go
More file actions
45 lines (36 loc) · 1.24 KB
/
loader.go
File metadata and controls
45 lines (36 loc) · 1.24 KB
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 loader provides common utility functions and helper methods for the workflow CLI.
package loader
import (
"fmt"
"github.com/drycc/workflow-cli/pkg/git"
"github.com/drycc/workflow-cli/pkg/settings"
)
// LoadAppSettings loads settings file, validates workspace, and looks up the app name
func LoadAppSettings(cf string, appID string) (string, *settings.Settings, error) {
s, err := settings.Load(cf)
if err != nil {
return "", nil, err
}
if s.Workspace == "" {
return "", nil, fmt.Errorf("no workspace specified, set a default workspace with 'drycc workspaces switch'")
}
if appID == "" {
appID, err = git.DetectAppName(git.DefaultCmd, s.Client.ControllerURL.Host)
if err != nil {
return "", nil, err
}
}
return appID, s, nil
}
// LoadWorkspace resolves the workspace name from the default workspace in settings.
// If no default workspace is set, it returns an error prompting the user to use "drycc workspaces switch".
func LoadWorkspace(cf string) (string, *settings.Settings, error) {
s, err := settings.Load(cf)
if err != nil {
return "", nil, err
}
if s.Workspace == "" {
return "", nil, fmt.Errorf("no workspace specified, set a default workspace with 'drycc workspaces switch'")
}
return s.Workspace, s, nil
}