-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 854 Bytes
/
main.go
File metadata and controls
47 lines (39 loc) · 854 Bytes
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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
outDir := flag.String("out", ".", "Path to output directory")
help := flag.Bool("help", false, "Show usage")
watch := flag.Bool("watch", false, "keep watching for modified files and template them")
// Customize usage output
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s <input_file_or_directory> [options]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
}
flag.Parse()
if *help {
flag.Usage()
return
}
args := flag.Args()
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "Error: missing input")
flag.Usage()
return
}
if *watch {
watcher := newWatcher(args[0], *outDir)
watcher.run()
} else {
files, err := getFiles(args[0])
if err != nil {
fmt.Println(err.Error())
return
}
templateFiles(files, *outDir)
}
}