-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
93 lines (74 loc) · 2.22 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"github.com/Obsinqsob01/echo-cli/strs"
"github.com/Obsinqsob01/echo-cli/utils"
)
type FileParse struct {
name string
appName string
subFolder string
fileName string
strName string
}
//Parse parse the files
func (f *FileParse) Parse() {
path := f.subFolder + f.fileName + ".go"
strParse := strings.Replace(strs.Paths[path], "appName", f.appName, -1)
d1 := []byte(strParse)
os.MkdirAll(f.appName, os.ModePerm)
if utils.CheckNil(f.subFolder) {
fmt.Println("\tCreando...", path)
os.MkdirAll(f.appName+"/"+f.subFolder, os.ModePerm)
err := ioutil.WriteFile(f.appName+"/"+f.subFolder+f.fileName+".go", d1, 0644)
utils.CheckErr(err)
} else {
err := ioutil.WriteFile(f.appName+"/"+f.fileName+".go", d1, 0644)
utils.CheckErr(err)
}
}
func main() {
//Initializa the Path map to get the string data
strs.Init()
stream := io.Reader(os.Stdin)
reader := bufio.NewReader(stream)
newApp := flag.String("new", "", "Generate de folder structure of an app")
generate := flag.String("generate", "", "Generate something such as action, controller, model, route")
flag.Parse()
if !utils.CheckNil(*newApp) && !utils.CheckNil(*generate) {
fmt.Println("Echo Framework CLI")
fmt.Println("\n\tUsage: -<command>=<value>")
fmt.Println("\tExample: -new polls\n ")
flag.PrintDefaults()
}
if utils.CheckNil(*newApp) {
fMain := FileParse{"Main File", *newApp, "", "main", "MainFile"}
fMain.Parse()
fActions := FileParse{"Actions folder and file", *newApp, "actions/", "HomeActions", "HomeActionsFile"}
fActions.Parse()
fRoutes := FileParse{"Routes folder and file", *newApp, "routes/", "Routes", "RoutesFile"}
fRoutes.Parse()
fUtils := FileParse{"Util function such as checkErr", *newApp, "utils/", "utils", "UtilsFile"}
fUtils.Parse()
fDB := FileParse{"DB open", *newApp, "db/", "db", "DBFile"}
fDB.Parse()
}
//Check if the generate flag is null or not
if utils.CheckNil(*generate) {
switch *generate {
case "action":
fmt.Println("Escribe el nombre del action: ")
name, err := reader.ReadString('\n')
utils.CheckErr(err)
af := FileParse{"Action", name, "actions/", name, "Action"}
af.Parse()
break
}
}
}