2021-07-23 11:55:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func run() error {
|
|
|
|
tfb, err := ioutil.ReadFile("./node/config/types.go")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// could use the ast lib, but this is simpler
|
|
|
|
|
|
|
|
type st int
|
|
|
|
const (
|
|
|
|
stGlobal st = iota // looking for typedef
|
|
|
|
stType st = iota // in typedef
|
|
|
|
)
|
|
|
|
|
|
|
|
lines := strings.Split(string(tfb), "\n")
|
|
|
|
state := stGlobal
|
|
|
|
|
|
|
|
type field struct {
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Comment string
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentType string
|
|
|
|
var currentComment []string
|
|
|
|
|
|
|
|
out := map[string][]field{}
|
|
|
|
|
|
|
|
for l := range lines {
|
|
|
|
line := strings.TrimSpace(lines[l])
|
|
|
|
|
|
|
|
switch state {
|
|
|
|
case stGlobal:
|
|
|
|
if strings.HasPrefix(line, "type ") {
|
|
|
|
currentType = line
|
|
|
|
currentType = strings.TrimPrefix(currentType, "type")
|
|
|
|
currentType = strings.TrimSuffix(currentType, "{")
|
|
|
|
currentType = strings.TrimSpace(currentType)
|
|
|
|
currentType = strings.TrimSuffix(currentType, "struct")
|
|
|
|
currentType = strings.TrimSpace(currentType)
|
|
|
|
currentComment = nil
|
|
|
|
state = stType
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
case stType:
|
2022-07-01 20:21:19 +00:00
|
|
|
if strings.HasPrefix(line, "//") {
|
2021-07-23 11:55:50 +00:00
|
|
|
cline := strings.TrimSpace(strings.TrimPrefix(line, "//"))
|
|
|
|
currentComment = append(currentComment, cline)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
comment := currentComment
|
|
|
|
currentComment = nil
|
|
|
|
|
|
|
|
if strings.HasPrefix(line, "}") {
|
|
|
|
state = stGlobal
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
f := strings.Fields(line)
|
|
|
|
if len(f) < 2 { // empty or embedded struct
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := f[0]
|
|
|
|
typ := f[1]
|
|
|
|
|
|
|
|
out[currentType] = append(out[currentType], field{
|
|
|
|
Name: name,
|
|
|
|
Type: typ,
|
|
|
|
Comment: strings.Join(comment, "\n"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var outt []string
|
|
|
|
for t := range out {
|
|
|
|
outt = append(outt, t)
|
|
|
|
}
|
|
|
|
sort.Strings(outt)
|
|
|
|
|
|
|
|
fmt.Print(`// Code generated by github.com/filecoin-project/lotus/node/config/cfgdocgen. DO NOT EDIT.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
type DocField struct {
|
2022-09-14 16:41:47 +00:00
|
|
|
Name string
|
2021-07-23 11:55:50 +00:00
|
|
|
Type string
|
|
|
|
Comment string
|
|
|
|
}
|
|
|
|
|
|
|
|
var Doc = map[string][]DocField{
|
|
|
|
`)
|
|
|
|
|
|
|
|
for _, typeName := range outt {
|
|
|
|
typ := out[typeName]
|
|
|
|
|
|
|
|
fmt.Printf("\t\"%s\": []DocField{\n", typeName)
|
|
|
|
|
|
|
|
for _, f := range typ {
|
|
|
|
fmt.Println("\t\t{")
|
2022-09-14 16:41:47 +00:00
|
|
|
fmt.Printf("\t\t\tName: \"%s\",\n", f.Name)
|
2021-07-23 13:18:20 +00:00
|
|
|
fmt.Printf("\t\t\tType: \"%s\",\n\n", f.Type)
|
2021-07-23 11:55:50 +00:00
|
|
|
fmt.Printf("\t\t\tComment: `%s`,\n", f.Comment)
|
|
|
|
fmt.Println("\t\t},")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("\t},\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(`}`)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
2021-07-23 13:53:22 +00:00
|
|
|
fmt.Println(err.Error())
|
2021-07-23 11:55:50 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|