2019-06-06 10:29:47 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Field struct {
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Docs string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Struct struct {
|
|
|
|
SourcePath string
|
|
|
|
Name string
|
|
|
|
Filename string
|
2019-06-12 10:25:08 -04:00
|
|
|
Header string
|
2019-06-06 10:29:47 -04:00
|
|
|
Fields []Field
|
|
|
|
}
|
|
|
|
|
|
|
|
var structDocsTemplate = template.Must(template.New("structDocsTemplate").
|
|
|
|
Funcs(template.FuncMap{
|
|
|
|
"indent": indent,
|
|
|
|
}).
|
|
|
|
Parse(`<!-- Code generated from the comments of the {{ .Name }} struct in {{ .SourcePath }}; DO NOT EDIT MANUALLY -->
|
2020-07-13 06:33:16 -04:00
|
|
|
{{ if .Header }}
|
|
|
|
{{ .Header }}
|
|
|
|
{{ end -}}
|
|
|
|
{{ range .Fields }}
|
|
|
|
- ` + "`" + `{{ .Name}}` + "`" + ` ({{ .Type }}) - {{ .Docs | indent 2 }}
|
|
|
|
{{ end }}`))
|
2019-06-06 10:29:47 -04:00
|
|
|
|
|
|
|
func indent(spaces int, v string) string {
|
|
|
|
pad := strings.Repeat(" ", spaces)
|
2020-07-13 06:33:16 -04:00
|
|
|
return strings.TrimSpace(strings.Replace(v, "\n", "\n"+pad, -1))
|
2019-06-06 10:29:47 -04:00
|
|
|
}
|