forked from abennett/hashi-releases
/
version.go
56 lines (47 loc) · 1.21 KB
/
version.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
package types
import (
"regexp"
"github.com/gulducat/hashi-bin/util"
"github.com/gulducat/hashi-bin/vars"
)
type Version struct {
product *Product // parent
Product string `json:"name"`
Version string `json:"version"`
SHASums string `json:"shasums"`
SHASumsSig string `json:"shasums_signature"`
Builds []*Build `json:"builds"`
}
func (v *Version) String() string {
return v.Version
}
func (v *Version) GetBuild(os string, arch string) *Build {
// TODO: feels bad, darwin arches for vagrant .dmg downloads...
arches := []string{arch}
if vars.LocalOS == "darwin" {
arches = []string{"amd64", "x86_64"}
}
for _, b := range v.Builds {
for _, a := range arches {
if b.OS == os && b.Arch == a {
return b
}
}
}
return nil
}
func (v *Version) GetBuildForLocal() *Build {
return v.GetBuild(vars.LocalOS, vars.LocalArch)
}
func (v *Version) IsActive() bool {
current, _, _ := util.CurrentActive(v.Product)
return v.Version == current
}
func (v *Version) IsBeta() bool {
re := regexp.MustCompile(`-(alpha|beta|rc)`)
return re.FindStringIndex(v.Version) != nil
}
func (v *Version) IsEnterprise() bool {
re := regexp.MustCompile(`\+ent`)
return re.FindStringIndex(v.Version) != nil
}