Parcourir la Source

put commands to run in detect as well.

Lucas Stadler 11 ans auparavant
Parent
commit
6109056749
1 fichiers modifiés avec 29 ajouts et 31 suppressions
  1. 29 31
      go/detect.go

+ 29 - 31
go/detect.go

@ -12,35 +12,32 @@ import (
12 12
	detect - guess the project type from files present
13 13
*/
14 14
15
type Detection struct {
16
	Language string
17
	Type     string
18
}
19
20
type detectorFunc func(string) bool
21
22
type Detector struct {
23
	Detection Detection
24
	Detector  detectorFunc
25
}
26
27
var Detectors = []Detector{
28
	{Detection{"clojure", "leiningen"}, clojureLeiningen},
29
	{Detection{"docker", "fig"}, dockerFig},
30
	{Detection{"docker", "default"}, dockerDefault},
31
	{Detection{"executable", "default"}, executableDefault},
32
	{Detection{"go", "default"}, goDefault},
33
	{Detection{"java", "maven"}, javaMaven},
34
	{Detection{"javascript", "npm"}, javascriptNpm},
35
	{Detection{"javascript", "meteor"}, javascriptMeteor},
36
	{Detection{"javascript", "default"}, javascriptDefault},
37
	{Detection{"make", "default"}, makeDefault},
38
	{Detection{"procfile", "default"}, procfileDefault},
39
	{Detection{"python", "django"}, pythonDjango},
40
	{Detection{"python", "default"}, pythonDefault},
41
	{Detection{"ruby", "rails"}, rubyRails},
42
	{Detection{"ruby", "rake"}, rubyRake},
43
	{Detection{"ruby", "default"}, rubyDefault},
15
type Project struct {
16
	Id       string
17
	Commands Commands
18
	Detect   func(string) bool
19
}
20
21
type Commands map[string]string
22
23
var ProjectTypes = []Project{
24
	Project{"clojure/leiningen", Commands{"run": "lein run", "test": "lein test"}, clojureLeiningen},
25
	Project{"docker/fig", Commands{"run": "fig up"}, dockerFig},
26
	Project{"docker/default", Commands{}, dockerDefault},
27
	Project{"executable/default", Commands{"run": "{file}"}, executableDefault},
28
	Project{"go/default", Commands{"build": "go build {file}", "run": "go build {file} && $(basename {file} .go)"},
29
		goDefault},
30
	Project{"java/maven", Commands{"build": "mvn compile", "test": "mvn compile test"}, javaMaven},
31
	Project{"javascript/npm", Commands{}, javascriptNpm},
32
	Project{"javascript/meteor", Commands{"run": "meteor"}, javascriptMeteor},
33
	Project{"javascript/default", Commands{"run": "node {file}"}, javascriptDefault},
34
	Project{"make/default", Commands{"run": "make"}, makeDefault},
35
	Project{"procfile/default", Commands{}, procfileDefault},
36
	Project{"python/django", Commands{}, pythonDjango},
37
	Project{"python/default", Commands{"run": "python {file}"}, pythonDefault},
38
	Project{"ruby/rails", Commands{"run": "rails server", "test": "bundle exec rake test"}, rubyRails},
39
	Project{"ruby/rake", Commands{"run": "rake"}, rubyRake},
40
	Project{"ruby/default", Commands{"run": "ruby {file}"}, rubyDefault},
44 41
}
45 42
46 43
func main() {
@ -51,8 +48,9 @@ func main() {
51 48
52 49
	file := os.Args[1]
53 50
54
	for _, detector := range Detectors {
55
		fmt.Println(detector.Detection, detector.Detector(file))
51
	for _, project := range ProjectTypes {
52
		runCmd := project.Commands["run"]
53
		fmt.Printf("%v (%v): %v\n", project.Id, runCmd, project.Detect(file))
56 54
	}
57 55
}
58 56