-
Notifications
You must be signed in to change notification settings - Fork 23
/
platform.go
43 lines (37 loc) · 979 Bytes
/
platform.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
package tldr
import (
"strings"
)
// CommonPlatform is the common platform.
const CommonPlatform = "common"
// CurrentPlatform returns the platform name of the current system.
func CurrentPlatform(current string) string {
var os string = current
if strings.ToLower(current) == "darwin" {
os = "osx"
}
return strings.ToLower(os)
}
// AvailablePlatforms returns all the available platforms that are supported.
func AvailablePlatforms(r Repository, current string) ([]string, error) {
platforms, err := r.AvailablePlatforms()
if err != nil {
return nil, err
}
currentPlattform := CurrentPlatform(current)
var currentFound, commonFound bool
for _, p := range platforms {
if p == currentPlattform {
currentFound = true
} else if p == CommonPlatform {
commonFound = true
}
}
if !currentFound {
platforms = append(platforms, CurrentPlatform(current))
}
if !commonFound {
platforms = append(platforms, CommonPlatform)
}
return platforms, nil
}