-
Notifications
You must be signed in to change notification settings - Fork 1
/
variant.go
151 lines (115 loc) · 3.81 KB
/
variant.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package cask
// A Variant represents a single cask variant.
type Variant struct {
// Version specifies the version stanza.
Version *Version
// SHA256 specifies the SHA256 checksum for the downloaded Variant.URL file.
SHA256 *SHA256
// URL specifies the url stanza.
URL *URL
// Appcast specifies the appcast stanza.
Appcast *Appcast
// Names specify the application names. Each cask can have multiple names.
Names []*Name
// Homepage specifies the application vendor homepage stanza.
Homepage *Homepage
// Artifacts specify artifact stanzas.
Artifacts []*Artifact
// MinimumSupportedMacOS specifies the minimum supported macOS release. By
// default each cask uses the latest stable macOS release.
MinimumSupportedMacOS MacOS
// MaximumSupportedMacOS specifies the maximum supported macOS release. By
// default each cask uses the latest stable macOS release.
MaximumSupportedMacOS MacOS
}
// NewVariant returns a new Variant instance pointer.
func NewVariant() *Variant {
return &Variant{}
}
// AddName adds a new *Name to the Variant.Names slice.
func (v *Variant) AddName(name *Name) {
v.Names = append(v.Names, name)
}
// AddArtifact adds a new Artifact pointer to the Variant.Artifacts slice.
func (v *Variant) AddArtifact(artifact *Artifact) {
v.Artifacts = append(v.Artifacts, artifact)
}
// GetVersion returns the Version struct from the existing Variant.Version
// struct pointer.
func (v *Variant) GetVersion() Version {
if v.Version != nil {
return *(v.Version)
}
return Version{}
}
// GetSHA256 returns the SHA256 struct from the existing Variant.SHA256 struct
// pointer.
func (v *Variant) GetSHA256() SHA256 {
if v.SHA256 != nil {
return *(v.SHA256)
}
return SHA256{}
}
// GetURL returns the URL struct from the existing Variant.URL struct pointer
// and interpolates the version into the Variant.URL.Value if available.
func (v *Variant) GetURL() (u URL) {
if v.URL != nil {
u = *(v.URL)
if v.Version != nil && v.Version.HasVersionStringInterpolation(u.Value) {
u.Value = v.Version.InterpolateIntoString(u.Value)
}
return u
}
return URL{}
}
// GetAppcast returns the Appcast struct from the existing Variant.Appcast
// struct pointer and interpolates the version into the Variant.Appcast.URL if
// available.
func (v *Variant) GetAppcast() (a Appcast) {
if v.Appcast != nil {
a = *(v.Appcast)
if v.Version != nil && v.Version.HasVersionStringInterpolation(a.URL) {
a.URL = v.Version.InterpolateIntoString(a.URL)
}
return a
}
return Appcast{}
}
// GetNames returns the []Name slice from the existing []Variant.Names slice
// pointer and interpolates the version into each name if available.
func (v *Variant) GetNames() (n []Name) {
for _, name := range v.Names {
newName := *name
if v.Version != nil && v.Version.HasVersionStringInterpolation(name.Value) {
newName.Value = v.Version.InterpolateIntoString(name.Value)
}
n = append(n, newName)
}
return n
}
// GetHomepage returns the Homepage struct from the existing Variant.Homepage
// struct pointer and interpolates the version into the Variant.Homepage.Value
// if available.
func (v *Variant) GetHomepage() (h Homepage) {
if v.Homepage != nil {
h = *(v.Homepage)
if v.Version != nil && v.Version.HasVersionStringInterpolation(h.Value) {
h.Value = v.Version.InterpolateIntoString(h.Value)
}
return h
}
return Homepage{}
}
// GetArtifacts returns the []Artifacts slice from the existing
// []Variant.Artifacts slice pointer and interpolates the version into each
// artifact value if available.
func (v *Variant) GetArtifacts() (a []Artifact) {
for _, artifact := range v.Artifacts {
newArtifact := *artifact
if v.Version != nil && v.Version.HasVersionStringInterpolation(artifact.Value) {
newArtifact.Value = v.Version.InterpolateIntoString(artifact.Value)
}
a = append(a, newArtifact)
}
return a
}