/
component_config.go
89 lines (78 loc) · 2.13 KB
/
component_config.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package core
import "gopkg.in/yaml.v2"
type ModeList []string
func (s ModeList) contains(v string) bool {
for _, item := range s {
if item == v {
return true
}
}
return false
}
type ComponentConfig struct {
Alias string `yaml:"alias"`
ComposeFile string `yaml:"compose_file"`
Dependencies map[string]ModeList `yaml:"dependencies"`
ExecPath string `yaml:"exec_path"`
Extends string `yaml:"extends"`
HostedIn string `yaml:"hosted_in"`
Hostname string `yaml:"hostname"`
IsTemplate bool `yaml:"is_template"`
Path string `yaml:"path"`
Replace bool `yaml:"replace"`
Variables yaml.MapSlice `yaml:"variables"`
Repository string `yaml:"repository"`
Tags []string `yaml:"tags"`
AfterCloneHook string `yaml:"after_clone_hook"`
}
func (cc ComponentConfig) merge(cc2 ComponentConfig) ComponentConfig {
if cc2.Replace {
return cc2
}
if cc2.Path != "" {
cc.Path = cc2.Path
}
if cc2.ComposeFile != "" {
cc.ComposeFile = cc2.ComposeFile
}
if cc2.Extends != "" {
cc.Extends = cc2.Extends
}
if cc2.HostedIn != "" {
cc.HostedIn = cc2.HostedIn
}
if cc2.ExecPath != "" {
cc.ExecPath = cc2.ExecPath
}
if cc2.Alias != "" {
cc.Alias = cc2.Alias
}
if cc2.Repository != "" {
cc.Repository = cc2.Repository
}
if cc2.AfterCloneHook != "" {
cc.AfterCloneHook = cc2.AfterCloneHook
}
cc.Variables = append(cc.Variables, cc2.Variables...)
cc.Tags = append(cc.Tags, cc2.Tags...)
for depSvc, modes := range cc2.Dependencies {
if cc.Dependencies[depSvc] == nil {
cc.Dependencies[depSvc] = make([]string, 1)
}
for _, mode := range modes {
if !cc.Dependencies[depSvc].contains(mode) {
cc.Dependencies[depSvc] = append(cc.Dependencies[depSvc], mode)
}
}
}
return cc
}
func (cc *ComponentConfig) GetDeps(mode string) []string {
var result []string
for key, modes := range cc.Dependencies {
if modes.contains(mode) {
result = append(result, key)
}
}
return result
}