forked from hellozee/cook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (64 loc) · 1.6 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
package main
import (
"flag"
"fmt"
"os"
lg "github.com/hellozee/cook/logger"
mg "github.com/hellozee/cook/manager"
ps "github.com/hellozee/cook/parser"
wk "github.com/hellozee/cook/worker"
)
var cleanFlag = flag.Bool("clean", false, "To clean the cached data")
var helpFlag = flag.Bool("help", false, "To show this help message")
func main() {
flag.Parse()
help := `Usage: cook [OPTIONS]
--help:
To show this help message
--clean:
To clean the cached data
`
if *helpFlag == true {
fmt.Println(help)
return
}
if *cleanFlag == true {
os.RemoveAll("Cooking/")
return
}
logger := lg.NewLogger()
//Reading the Recipe File
manager, err := mg.NewManager(&logger)
must(err, &logger)
Recipe := string(manager.FileData)
//Parsing the Recipe File
parser := ps.NewParser(Recipe, &logger)
err = parser.Parse()
must(err, &logger)
worker := wk.NewWorker(&logger)
err = manager.GenerateFileList(parser, parser.CompilerDetails.Start)
must(err, &logger)
if _, err := os.Stat("Cooking/details.json"); err == nil {
err = manager.ReadDetails()
must(err, &logger)
worker.CompareAndCompile(parser, &manager)
} else {
_ = os.Mkdir("Cooking", 0755)
err = manager.GenerateList()
must(err, &logger)
worker.CompileFirst(parser, manager)
}
err = manager.WriteDetails()
must(err, &logger)
err = worker.Link(parser)
must(err, &logger)
logger.WriteLog()
fmt.Println("Build finished, logs reported to Cooking/log")
}
func must(err error, log *lg.Logger) {
if err != nil {
fmt.Println("Something went wrong, please check Cooking/log/build.errors")
log.WriteLog()
os.Exit(-1)
}
}