-
Notifications
You must be signed in to change notification settings - Fork 57
/
detect.go
90 lines (70 loc) · 2.36 KB
/
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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"bufio"
"fmt"
"github.com/cloud66-oss/starter/common"
"github.com/cloud66-oss/starter/packs"
"github.com/cloud66-oss/starter/packs/compose-to-service-yml"
"github.com/cloud66-oss/starter/packs/node"
"github.com/cloud66-oss/starter/packs/php"
"github.com/cloud66-oss/starter/packs/ruby"
"github.com/cloud66-oss/starter/packs/service-yml-to-kubes"
"os"
"strings"
)
func Detect(rootDir string) ([]packs.Pack, error) {
ruby := ruby.Pack{}
node := node.Pack{}
php := php.Pack{}
dockercompose := compose_to_service_yml.Pack{}
serviceyml := service_yml_to_kubes.Pack{}
detectors := []packs.Detector{dockercompose.Detector(), ruby.Detector(), node.Detector(), php.Detector(), serviceyml.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())
}
}
return packs, nil
}
func choosePack(detectedPacks []packs.Pack, noPrompt bool) (packs.Pack, error) {
if len(detectedPacks) == 0 {
return nil, fmt.Errorf("Could not detect any of the supported frameworks")
} else if len(detectedPacks) > 1 {
if noPrompt == false {
common.PrintlnTitle("More than one framework detected. Please choose which of the following should be used:")
for i := 0; i < len(detectedPacks); i++ {
common.PrintlnTitle(strings.ToUpper(detectedPacks[i].Name()))
}
reader := bufio.NewReader(os.Stdin)
var answer string
answer, _ = reader.ReadString('\n')
answer = strings.ToUpper(answer)
for i := 0; i < len(detectedPacks); i++ {
temp := strings.ToUpper(detectedPacks[i].Name()) + "\n"
if answer == temp {
return detectedPacks[i], nil
}
}
return nil, fmt.Errorf("Starter was unable to match your answer")
} else {
common.PrintlnTitle("More than one framework detected! NoPrompt flag value is set to true.")
for i := 0; i < len(detectedPacks); i++ {
if detectedPacks[i].Name() == "docker-compose" {
return detectedPacks[i], nil
}
}
for i := 0; i < len(detectedPacks); i++ {
if detectedPacks[i].Name() == "service.yml" {
return detectedPacks[i], nil
}
}
return nil, fmt.Errorf("Multiple frameworks detected. Unable to generate.")
}
} else {
common.PrintlnTitle(detectedPacks[0].Name())
return detectedPacks[0], nil
}
return detectedPacks[0], nil
}