Skip to content

Instantly share code, notes, and snippets.

@thehowl
Created January 26, 2024 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehowl/9f3437d81b7c5dc48cc78182353ec7ea to your computer and use it in GitHub Desktop.
Save thehowl/9f3437d81b7c5dc48cc78182353ec7ea to your computer and use it in GitHub Desktop.
//go:build ignore
package main
import (
"fmt"
"go/doc"
"go/parser"
"go/token"
"io/fs"
"os"
"strings"
)
func main() {
if err := _main(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
func _main() error {
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, ".", func(fi fs.FileInfo) bool {
return !strings.HasSuffix(fi.Name(), "_test.go")
}, parser.ParseComments)
if err != nil {
return err
}
pkg := pkgs["gnoclient"]
if pkg == nil {
return fmt.Errorf("gnoclient pkg does not exist in current dir")
}
p := doc.New(pkg, "github.com/gnolang/gno/gno.land/pkg/gnoclient", 0)
fmt.Printf("# %s\n\n```\nimport %q\n```\n\n%s\n\n", p.Name, p.ImportPath, p.Markdown(p.Doc))
// TODO CONSTANTS
// TODO VARIABLES
fmt.Printf("## Functions\n\n")
for _, fn := range p.Funcs {
fmt.Printf("### `%s`\n\n%s\n\n", fn.Name, p.Markdown(fn.Doc))
}
fmt.Printf("## Types\n\n")
for _, typ := range p.Types {
fmt.Printf("### `%s`\n\n%s\n\n", typ.Name, p.Markdown(typ.Doc))
// TODO METHODS
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment