-
Notifications
You must be signed in to change notification settings - Fork 90
/
main.go
63 lines (51 loc) · 1.51 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
package main
import (
"flag"
"fmt"
"os"
"github.com/sipin/gorazor/pkg/razorcore"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: gorazor [-debug] <input dir or file> <output dir or file>\n")
flag.PrintDefaults()
os.Exit(1)
}
func main() {
flag.Usage = usage
isDebug := flag.Bool("debug", false, "use debug mode")
noLine := flag.Bool("noline", false, "skip line number hint in generated code")
version := flag.Bool("version", false, "show gorazor version info")
quick := flag.Bool("q", false, "enable quick mode; skip template render optimzation")
namespacePrefix := flag.String("prefix", "", "tpl namespace prefix")
nameNotChange := flag.Bool("nameNotChange", false, "do not change name of the template")
flag.Parse()
if *version {
fmt.Println("gorazor version: " + razorcore.VERSION)
os.Exit(0)
}
options := razorcore.Option{}
options.IsDebug = *isDebug
options.NameNotChange = *nameNotChange
options.NoLineNumber = *noLine
if len(flag.Args()) != 2 {
flag.Usage()
}
input, output := flag.Arg(0), flag.Arg(1)
stat, err := os.Stat(input)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
razorcore.TemplateNamespacePrefix = *namespacePrefix
razorcore.QuickMode = *quick
if stat.IsDir() {
fmt.Printf("gorazor processing dir: %s -> %s\n", input, output)
err := razorcore.GenFolder(input, output, options)
if err != nil {
fmt.Println(err)
}
} else if stat.Mode().IsRegular() {
fmt.Printf("gorazor processing file: %s -> %s\n", input, output)
razorcore.GenFile(input, output, options)
}
}