-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (41 loc) · 831 Bytes
/
main.go
File metadata and controls
50 lines (41 loc) · 831 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
48
49
50
package main
import (
"flag"
"fmt"
"log"
"os"
"text/template"
)
func main() {
var (
schemaPath = flag.String("schema", "", "Path to the JSON Schema")
templatePath = flag.String("template", "", "Path to a template")
)
flag.Parse()
if *schemaPath == "" {
fmt.Println("no path to schema")
os.Exit(1)
}
f, err := os.Open(*schemaPath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
schema, err := newSchema(f, ".")
if err != nil {
log.Fatal(err)
}
tpl, err := getOrDefaultTemplate(*templatePath)
if err != nil {
log.Fatal(err)
}
if err := tpl.Execute(os.Stdout, schema); err != nil {
log.Fatal(err)
}
}
func getOrDefaultTemplate(path string) (*template.Template, error) {
if path == "" {
return template.New("docs").Parse(`{{ .Markdown 1 }}`)
}
return template.ParseFiles(path)
}