-
Notifications
You must be signed in to change notification settings - Fork 6
/
ver_darwin.go
69 lines (64 loc) · 1.37 KB
/
ver_darwin.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
package osinfo
import (
"os/exec"
"runtime"
"strings"
)
// GetVersion Darwin returns version info
// fetching info for this os is fairly simple
// version information is all fetched via `sw_vers`
// Returns:
// - r.Runtime
// - r.Arch
// - r.Name
// - r.Version
// - r.Mac.VersionName
func GetVersion() Release {
info := Release{
Runtime: runtime.GOOS,
Arch: runtime.GOARCH,
Name: "Mac OS X",
Version: "unknown",
MacOs: macOsRelease{
VersionName: "unknown",
},
}
version, err := exec.Command("sw_vers").Output()
if err == nil {
str := strings.Split(string(version), "\n")
for _, s := range str {
if strings.HasPrefix(s, "ProductVersion:\t") {
info.Version = strings.TrimPrefix(s, "ProductVersion:\t")
}
}
}
var name string
switch idx := strings.LastIndex(info.Version, "."); info.Version[0:idx] {
case "10.6":
name = "MacOS - Snow Leopard"
case "10.7":
name = "MacOS - Lion"
case "10.8":
name = "MacOS - Mountain Lion"
case "10.9":
name = "MacOS - Mavericks"
case "10.10":
name = "MacOS - Yosemite"
case "10.11":
name = "MacOS - El Capitan"
case "10.12":
name = "MacOS - Sierra"
case "10.13":
name = "MacOS - High Sierra"
case "10.14":
name = "MacOS - Mojave"
case "10.15":
name = "MacOS - Catalina"
case "11.0":
name = "MacOS - Big Sur"
}
info.MacOs = macOsRelease{
VersionName: name,
}
return info
}