-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
70 lines (58 loc) · 1.18 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
package main
import (
"flag"
"fmt"
"os"
"github.com/codinl/gotpl/template"
"github.com/codinl/go-logger"
)
func Usage() {
fmt.Fprintf(os.Stderr, "usage: gotpl [-debug] [-watch] <input dir> <output dir>\n")
flag.PrintDefaults()
os.Exit(1)
}
func main() {
err := initLogger()
if err != nil {
panic("initLogger fail")
}
flag.Usage = Usage
isDebug := flag.Bool("debug", false, "use debug mode")
isWatch := flag.Bool("watch", false, "use watch mode")
flag.Parse()
option := gotpl.Option{}
if *isDebug {
option["Debug"] = *isDebug
}
if *isWatch {
option["Watch"] = *isWatch
}
option["Debug"] = false
// option["Debug"] = true
option["Watch"] = true
if len(flag.Args()) != 2 {
flag.Usage()
}
input, output := flag.Arg(0), flag.Arg(1)
// input, output := "./tpl/", "./gen/"
stat, err := os.Stat(input)
if err != nil {
logger.Error(err)
os.Exit(1)
}
if stat.IsDir() {
err := gotpl.Generate(input, output, option)
if err != nil {
logger.Error(err)
}
}
}
func initLogger() error {
err := logger.Init("./log", "gotpl.log", logger.DEBUG)
if err != nil {
fmt.Println("logger init error err=", err)
return err
}
logger.SetConsole(true)
return nil
}