-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
79 lines (67 loc) · 2.01 KB
/
main.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
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
)
// Define the supported project types and their respective template files
var ProjectTemplates = map[string]string{
"Django": "templates/django/Dockerfile.tmpl",
"Node.js": "templates/Node.js/Dockerfile.tmpl",
"Go": "templates/Go/Dockerfile.tmpl",
"Flask": "templates/flask/Dockerfile.tmpl",
"Mojo": "templates/Mojo/Dockerfile.tmpl",
// Add more project types as needed
}
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Choose a Project type")
// List of Projects
for projectType := range ProjectTemplates {
fmt.Printf("%s\n", projectType)
}
fmt.Print("Enter the project type: ")
projectType, _ := reader.ReadString('\n')
projectType = strings.TrimSpace(projectType)
templateFile, found := ProjectTemplates[projectType]
if !found {
fmt.Println("Unsupported project type:", projectType)
fmt.Println("Raise an error with the type of Dockerfile you want on the GitHub repo, and we will try to resolve it as soon as possible")
return
}
// Initialize the template engine
tmpl, err := template.ParseFiles(templateFile)
if err != nil {
fmt.Println("Error:", err)
return
}
// Get the target directory from the command-line argument (if provided)
var targetDir string
if len(os.Args) > 1 {
targetDir = os.Args[1]
} else {
// If no target directory is provided,then using current working directory
targetDir, err = os.Getwd()
if err != nil {
fmt.Println("Error getting current working directory:", err)
return
}
}
// Creating or overwriting the Dockerfile in the target directory
outputFile, err := os.Create(filepath.Join(targetDir, "Dockerfile"))
if err != nil {
fmt.Println("Error creating Dockerfile:", err)
return
}
defer outputFile.Close()
// Execute the template and write the Dockerfile content to the file
err = tmpl.Execute(outputFile, nil)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Printf("Dockerfile has been generated in %s.\n", targetDir)
}