feat: output docs to a docs folder, allow multiline docs

pull/78/head
sammyette 2021-10-16 12:38:46 -04:00
parent 71b72bbdd4
commit a2f54b627b
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 18 additions and 6 deletions

View File

@ -11,6 +11,8 @@ import (
"os" "os"
) )
// feel free to clean this up
// it works, dont really care about the code
func main() { func main() {
fset := token.NewFileSet() fset := token.NewFileSet()
@ -37,31 +39,41 @@ func main() {
prefix := map[string]string{ prefix := map[string]string{
"main": "hsh", "main": "hsh",
"hilbish": "hl",
"fs": "f", "fs": "f",
"commander": "c", "commander": "c",
"bait": "b", "bait": "b",
} }
docs := make(map[string][]string)
for l, f := range pkgs { for l, f := range pkgs {
fmt.Println("------", l)
p := doc.New(f, "./", doc.AllDecls) p := doc.New(f, "./", doc.AllDecls)
for _, t := range p.Funcs { for _, t := range p.Funcs {
if !strings.HasPrefix(t.Name, prefix[l]) || t.Name == "Loader" { continue } mod := l
if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
parts := strings.Split(t.Doc, "\n") parts := strings.Split(t.Doc, "\n")
funcsig := parts[0] funcsig := parts[0]
doc := parts[1] doc := parts[1:]
fmt.Println(funcsig, ">", doc) docs[mod] = append(docs[mod], funcsig + " > " + strings.Join(doc, "\n"))
} }
for _, t := range p.Types { for _, t := range p.Types {
for _, m := range t.Methods { for _, m := range t.Methods {
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue } if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
parts := strings.Split(m.Doc, "\n") parts := strings.Split(m.Doc, "\n")
funcsig := parts[0] funcsig := parts[0]
doc := parts[1] doc := parts[1:]
fmt.Println(funcsig, ">", doc) docs[l] = append(docs[l], funcsig + " > " + strings.Join(doc, "\n"))
} }
} }
} }
for mod, v := range docs {
if mod == "main" { mod = "global" }
os.Mkdir("docs", 0744)
f, _ := os.Create("docs/" + mod + ".txt")
f.WriteString(strings.Join(v, "\n") + "\n")
}
} }