-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
46 lines (37 loc) · 1004 Bytes
/
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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
)
var TempioVersion string
func main() {
var config *map[string]interface{}
configFile := flag.String("conf", "", "Config json file, can be omitted if used in a pipe")
templateFile := flag.String("template", "", "Template file")
outFile := flag.String("out", "", "Output file, if not defined output will be to console")
flag.Usage = func() {
writer := flag.CommandLine.Output()
fmt.Fprintf(writer, "Version: %s\n", TempioVersion)
fmt.Fprintf(writer, "Documentation: https:/home-assistant/tempio\n\n")
flag.PrintDefaults()
}
// parse command lines
flag.Parse()
if *templateFile == "" {
log.Fatal("Missing template argument")
}
// Get config
config = readConfig(*configFile)
// create & write corefile
data := renderTemplateFile(config, *templateFile)
if *outFile == "" {
fmt.Println(string(data))
} else {
err := ioutil.WriteFile(*outFile, data, 0644)
if err != nil {
log.Fatal(err)
}
}
}