-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
93 lines (71 loc) · 2.04 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"os"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/lonnblad/go-service-doc/exporting/golang"
"github.com/lonnblad/go-service-doc/exporting/simple"
"github.com/lonnblad/go-service-doc/parser"
)
func init() {
encoderConf := zap.NewProductionEncoderConfig()
encoderConf.TimeKey = "timestamp"
encoderConf.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format(time.RFC3339))
}
logger := zap.New(
zapcore.NewCore(
zapcore.NewConsoleEncoder(encoderConf),
zapcore.Lock(os.Stdout),
zap.NewAtomicLevel(),
),
)
zap.ReplaceGlobals(logger)
}
func main() {
serviceFilename := flag.String("s", "service.md", "Main Markdown file for the service.")
sourceDir := flag.String("d", "docs", "Directory where to get markdown files.")
outputDir := flag.String("o", "docs", "Directory where to write output.")
basepath := flag.String("p", "/docs", "Base path for the generated documentation.")
flag.Parse()
mdParser := parser.NewParser().
WithSourceDir(*sourceDir).
WithOutputDir(*outputDir).
WithBasepath(*basepath).
ServiceFilename(*serviceFilename)
mdParser.Run()
if err := mdParser.Error(); err != nil {
zap.L().With(zap.Error(err)).
Error("parser returned an error")
return
}
pages := mdParser.Pages()
staticFiles := mdParser.StaticFiles()
searchPage := mdParser.SearchPage()
simpleExporter := simple.NewExporter().
WithSourceDir(*sourceDir).
WithOutputDir(*outputDir).
WithPages(pages).
WithStaticFiles(staticFiles)
simpleExporter.Run()
if err := simpleExporter.Error(); err != nil {
zap.L().With(zap.Error(err)).
Error("exporting simple returned an error")
return
}
goExporter := golang.NewExporter().
WithOutputDir(*outputDir).
WithBasepath(*basepath).
WithPages(pages).
WithStaticFiles(staticFiles).
WithSearchPage(searchPage)
goExporter.Run()
if err := goExporter.Error(); err != nil {
zap.L().With(zap.Error(err)).
Error("exporting golang returned an error")
return
}
zap.L().Info("done")
}