Skip to content

Commit 82be620

Browse files
chore: move logic related to config parsing and initialization to ParseConfig (#16)
1 parent 5af3cc5 commit 82be620

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

cmd/main.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,6 @@ func init() {
5151
return
5252
}
5353
projectConfig = pc
54-
55-
if projectConfig.Environments == nil {
56-
projectConfig.Environments = map[string]*project.Environment{}
57-
}
58-
59-
if projectConfig.Addons == nil {
60-
projectConfig.Addons = map[string]project.Addon{}
61-
}
62-
63-
if projectConfig.ParsedAddons == nil {
64-
projectConfig.ParsedAddons = map[string]template.TemplateManifest{}
65-
}
66-
67-
// load all addons, so we can use them later
68-
for k, v := range projectConfig.Addons {
69-
tm, err := template.LoadManifest(v.Path)
70-
if err != nil {
71-
fmt.Printf("An error occurred while loading the addon [%s] manifest file: %s, %v\n", k, v.Path, err)
72-
os.Exit(1)
73-
return
74-
}
75-
tm.Name = k
76-
tm.BasePath = v.Path
77-
tm.Group = v.Group
78-
projectConfig.ParsedAddons[k] = *tm
79-
}
8054
}
8155

8256
func main() {

internal/project/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/leonsteinhaeuser/openshift-gitops-cli/internal/template"
78
"sigs.k8s.io/yaml"
89
)
910

@@ -20,6 +21,29 @@ func ParseConfig(path string) (*ProjectConfig, error) {
2021
return nil, fmt.Errorf("failed to unmarshal config to ProjectConfig: %w", err)
2122
}
2223

24+
if pc.Environments == nil {
25+
pc.Environments = map[string]*Environment{}
26+
}
27+
28+
if pc.Addons == nil {
29+
pc.Addons = map[string]Addon{}
30+
}
31+
32+
if pc.ParsedAddons == nil {
33+
pc.ParsedAddons = map[string]template.TemplateManifest{}
34+
}
35+
36+
// load all addons, so we can use them later
37+
for k, v := range pc.Addons {
38+
tm, err := template.LoadManifest(v.Path)
39+
if err != nil {
40+
return nil, fmt.Errorf("an error occurred while loading the addon [%s] manifest file: %s, %v", k, v.Path, err)
41+
}
42+
tm.Name = k
43+
tm.BasePath = v.Path
44+
tm.Group = v.Group
45+
pc.ParsedAddons[k] = *tm
46+
}
2347
return pc, nil
2448
}
2549

0 commit comments

Comments
 (0)