-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (64 loc) · 1.51 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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"bytes"
"flag"
"io/ioutil"
"os"
"text/template"
"github.com/hyperledger/fabric/common/metrics/gendoc"
"golang.org/x/tools/go/packages"
)
// Gendoc can be used used to discover the metrics options declared at the
// package level in the fabric tree and output a table that can be used in the
// documentation.
var templatePath = flag.String(
"template",
"docs/source/metrics_reference.rst.tmpl",
"The documentation template.",
)
func main() {
flag.Parse()
patterns := flag.Args()
if len(patterns) == 0 {
patterns = []string{"github.com/hyperledger/fabric/..."}
}
pkgs, err := packages.Load(&packages.Config{Mode: packages.LoadSyntax}, patterns...)
if err != nil {
panic(err)
}
options, err := gendoc.Options(pkgs)
if err != nil {
panic(err)
}
cells, err := gendoc.NewCells(options)
if err != nil {
panic(err)
}
funcMap := template.FuncMap{
"PrometheusTable": func() string {
buf := &bytes.Buffer{}
gendoc.NewPrometheusTable(cells).Generate(buf)
return buf.String()
},
"StatsdTable": func() string {
buf := &bytes.Buffer{}
gendoc.NewStatsdTable(cells).Generate(buf)
return buf.String()
},
}
docTemplate, err := ioutil.ReadFile(*templatePath)
if err != nil {
panic(err)
}
tmpl, err := template.New("metrics_reference").Funcs(funcMap).Parse(string(docTemplate))
if err != nil {
panic(err)
}
if err := tmpl.Execute(os.Stdout, ""); err != nil {
panic(err)
}
}