-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatfruits.go
58 lines (49 loc) · 1.17 KB
/
catfruits.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
package catfruits
// Infomation is a repository infomation.
type Infomation struct {
Frameworks []string `json:"frameworks"`
Packages map[string][]string `json:"packages"`
}
// Scanner is scanner for repository.
type Scanner struct {
dir string
fwFunc map[string]FrameworkFunc
info *Infomation
}
// FrameworkFunc is a function that detects framework
type FrameworkFunc func(*Scanner) (ok bool, err error)
// PackageFunc detects any packages
type PackageFunc func(*Scanner) (pkgs []string, err error)
// NewScanner returns a Scanner
func NewScanner(dir string) *Scanner {
return &Scanner{
dir: dir,
fwFunc: DefaultFrameworkFuncs,
info: &Infomation{
Frameworks: make([]string, 0),
Packages: make(map[string][]string),
},
}
}
// Scan scans a repository.
func (sc *Scanner) Scan() (*Infomation, error) {
info := sc.info
for name, f := range DefaultPakcageFuncs {
pkgs, err := f(sc)
if err != nil {
return nil, err
}
info.Packages[name] = pkgs
}
for name, f := range sc.fwFunc {
ok, err := f(sc)
if err != nil {
return nil, err
}
if !ok {
continue
}
info.Frameworks = append(info.Frameworks, name)
}
return info, nil
}