forked from sipin/gorazor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gorazor.go
56 lines (45 loc) · 1.04 KB
/
gorazor.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
package main
// considering import fsnotify
import (
"flag"
"fmt"
"os"
"github.com/sipin/gorazor/gorazor"
)
func Usage() {
fmt.Fprintf(os.Stderr, "usage: gorazor [-debug] [-watch] <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")
isWatch := flag.Bool("watch", false, "use watch mode")
flag.Parse()
options := gorazor.Option{}
if *isDebug {
options["Debug"] = *isDebug
}
if *isWatch {
options["Watch"] = *isWatch
}
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)
}
if stat.IsDir() {
fmt.Printf("Gorazor processing dir: %s -> %s\n", input, output)
err := gorazor.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)
gorazor.GenFile(input, output, options)
}
}