/
glide.go
65 lines (51 loc) · 1.27 KB
/
glide.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
package discover
import (
"io/ioutil"
"os"
"path"
yaml "gopkg.in/yaml.v2"
)
const glideFilePath = "glide.yaml"
// Glide is a discoverer for glide Go package manager.
type Glide struct{}
// Name returns name of Glide discoverer.
func (g Glide) Name() string {
return "glide"
}
// InUse checks whether project is using glide as a package manager.
func (g Glide) InUse(projectPath string) (bool, error) {
_, err := os.Stat(path.Join(projectPath, glideFilePath))
if err != nil {
return false, err
}
return true, nil
}
// Repositories discovers repositories belonging to packages imported inside a project managed by Glide.
func (g Glide) Repositories(projectPath string) (RepoMap, error) {
list, err := packageListGlide(projectPath)
if err != nil {
return nil, err
}
repoMap := RepoMap{}
for _, p := range list.Import {
repoMap.add(p.Package)
}
return repoMap, nil
}
type glideList struct {
Import []struct {
Package string `yaml:"package"`
} `yaml:"import"`
}
func packageListGlide(projectPath string) (glideList, error) {
content, err := ioutil.ReadFile(path.Join(projectPath, glideFilePath))
if err != nil {
return glideList{}, err
}
list := glideList{}
err = yaml.Unmarshal(content, &list)
if err != nil {
return glideList{}, err
}
return list, err
}