2021-10-16 03:58:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-10-16 14:21:05 +00:00
|
|
|
"path/filepath"
|
|
|
|
"go/ast"
|
2021-10-16 03:58:56 +00:00
|
|
|
"go/doc"
|
|
|
|
"go/parser"
|
|
|
|
"go/token"
|
2021-10-16 14:21:05 +00:00
|
|
|
"strings"
|
|
|
|
"os"
|
2021-10-16 03:58:56 +00:00
|
|
|
)
|
|
|
|
|
2021-10-16 16:38:46 +00:00
|
|
|
// feel free to clean this up
|
|
|
|
// it works, dont really care about the code
|
2021-10-16 03:58:56 +00:00
|
|
|
func main() {
|
|
|
|
fset := token.NewFileSet()
|
|
|
|
|
2021-10-16 14:21:05 +00:00
|
|
|
dirs := []string{"./"}
|
|
|
|
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
|
|
|
if !info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dirs = append(dirs, "./" + path)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
pkgs := make(map[string]*ast.Package)
|
|
|
|
for _, path := range dirs {
|
|
|
|
d, err := parser.ParseDir(fset, path, nil, parser.ParseComments)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for k, v := range d {
|
|
|
|
pkgs[k] = v
|
|
|
|
}
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 14:21:05 +00:00
|
|
|
prefix := map[string]string{
|
|
|
|
"main": "hsh",
|
2021-10-16 16:38:46 +00:00
|
|
|
"hilbish": "hl",
|
2021-10-16 14:21:05 +00:00
|
|
|
"fs": "f",
|
|
|
|
"commander": "c",
|
|
|
|
"bait": "b",
|
2021-10-17 20:10:57 +00:00
|
|
|
"terminal": "term",
|
2021-10-16 14:21:05 +00:00
|
|
|
}
|
2021-10-16 16:38:46 +00:00
|
|
|
docs := make(map[string][]string)
|
2021-10-16 03:58:56 +00:00
|
|
|
|
2021-10-16 14:21:05 +00:00
|
|
|
for l, f := range pkgs {
|
|
|
|
p := doc.New(f, "./", doc.AllDecls)
|
2021-10-16 03:58:56 +00:00
|
|
|
for _, t := range p.Funcs {
|
2021-10-16 16:38:46 +00:00
|
|
|
mod := l
|
|
|
|
if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
|
|
|
|
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
|
2021-10-16 14:21:05 +00:00
|
|
|
parts := strings.Split(t.Doc, "\n")
|
|
|
|
funcsig := parts[0]
|
2021-10-16 16:38:46 +00:00
|
|
|
doc := parts[1:]
|
2021-10-16 14:21:05 +00:00
|
|
|
|
2021-10-16 16:38:46 +00:00
|
|
|
docs[mod] = append(docs[mod], funcsig + " > " + strings.Join(doc, "\n"))
|
2021-10-16 14:21:05 +00:00
|
|
|
}
|
|
|
|
for _, t := range p.Types {
|
|
|
|
for _, m := range t.Methods {
|
|
|
|
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
|
|
|
|
parts := strings.Split(m.Doc, "\n")
|
|
|
|
funcsig := parts[0]
|
2021-10-16 16:38:46 +00:00
|
|
|
doc := parts[1:]
|
2021-10-16 14:21:05 +00:00
|
|
|
|
2021-10-16 16:38:46 +00:00
|
|
|
docs[l] = append(docs[l], funcsig + " > " + strings.Join(doc, "\n"))
|
2021-10-16 14:21:05 +00:00
|
|
|
}
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-16 16:38:46 +00:00
|
|
|
|
|
|
|
for mod, v := range docs {
|
|
|
|
if mod == "main" { mod = "global" }
|
2021-10-16 19:38:17 +00:00
|
|
|
os.Mkdir("docs", 0777)
|
2021-10-16 16:38:46 +00:00
|
|
|
f, _ := os.Create("docs/" + mod + ".txt")
|
|
|
|
f.WriteString(strings.Join(v, "\n") + "\n")
|
|
|
|
}
|
2021-10-16 03:58:56 +00:00
|
|
|
}
|