forked from cloud66-oss/starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect.go
33 lines (29 loc) · 837 Bytes
/
detect.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
package main
import (
"fmt"
"github.com/cloud66/starter/common"
"github.com/cloud66/starter/packs"
"github.com/cloud66/starter/packs/node"
"github.com/cloud66/starter/packs/php"
"github.com/cloud66/starter/packs/ruby"
)
func Detect(rootDir string) (packs.Pack, error) {
ruby := ruby.Pack{}
node := node.Pack{}
php := php.Pack{}
detectors := []packs.Detector{ruby.Detector(), node.Detector(), php.Detector()}
var packs []packs.Pack
for _, d := range detectors {
if d.Detect(rootDir) {
packs = append(packs, d.GetPack())
common.PrintlnL0("Found %s application", d.GetPack().Name())
}
}
if len(packs) == 0 {
return nil, fmt.Errorf("Could not detect any of the supported frameworks")
} else if len(packs) > 1 {
return nil, fmt.Errorf("More than one framework detected")
} else {
return packs[0], nil
}
}