-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
location.go
55 lines (47 loc) · 1.29 KB
/
location.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
package manifest
import (
"fmt"
"path/filepath"
"runtime"
homedir "github.com/mitchellh/go-homedir"
)
// Path returns the manifest path
func Path(browser, libpath string, globalInstall bool) (string, error) {
location, err := getLocation(browser, libpath, globalInstall)
if err != nil {
return "", err
}
expanded, err := homedir.Expand(location)
if err != nil {
return "", err
}
return filepath.Join(expanded, Name+".json"), nil
}
func getLocation(browser, libpath string, globalInstall bool) (string, error) {
if globalInstall {
return getGlobalLocation(browser, libpath)
}
pm, found := manifestPath[runtime.GOOS]
if !found {
return "", fmt.Errorf("platform %s is currently not supported", runtime.GOOS)
}
path, found := pm[browser]
if !found {
return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS)
}
return path, nil
}
func getGlobalLocation(browser, libpath string) (string, error) {
pm, found := globalManifestPath[runtime.GOOS]
if !found {
return "", fmt.Errorf("platform %s is currently not supported", runtime.GOOS)
}
path, found := pm[browser]
if !found {
return "", fmt.Errorf("browser %s on %s is currently not supported", browser, runtime.GOOS)
}
if browser == "firefox" {
path = libpath + "/" + path
}
return path, nil
}