docgen

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(structName, path string, w io.Writer, format OutputFormat) error

Generate generates documentation for the specified struct in the given path.

func PrintDefaultYAML

func PrintDefaultYAML(docs []StructDoc, w io.Writer, withComments bool) error

PrintDefaultYAML writes a plain YAML config file with default values for all fields across the given struct docs.

func PrintEnvFile

func PrintEnvFile(docs []StructDoc, w io.Writer) error

PrintEnvFile writes a .env.example-style file with comments showing descriptions, types, and YAML paths for each env-tagged field.

func PrintEnvSummary

func PrintEnvSummary(docs []StructDoc, w io.Writer) error

PrintEnvSummary writes a formatted table of all env-tagged fields across all parsed structs.

Types

type ASCIIPrinter

type ASCIIPrinter struct {
	// contains filtered or unexported fields
}

ASCIIPrinter generates terminal-friendly documentation with adaptive colors. Colors automatically adjust for light/dark backgrounds and degrade gracefully across TrueColor, ANSI 256, and basic ANSI color profiles via lipgloss CompleteAdaptiveColor.

func NewASCIIPrinter

func NewASCIIPrinter(w io.Writer) *ASCIIPrinter

NewASCIIPrinter creates a new ASCIIPrinter.

func (*ASCIIPrinter) Print

func (a *ASCIIPrinter) Print(structName string, doc string, fields []FieldInfo)

Print generates terminal-friendly documentation.

type FieldInfo

type FieldInfo = docutil.FieldInfo

FieldInfo is an alias for docutil.FieldInfo provided for backwards compatibility so existing code in this package can use the unqualified name.

type MarkdownPrinter

type MarkdownPrinter struct {
	// contains filtered or unexported fields
}

MarkdownPrinter handles markdown output generation.

func NewMarkdownPrinter

func NewMarkdownPrinter(w io.Writer) *MarkdownPrinter

NewMarkdownPrinter creates a new MarkdownPrinter that writes to the given writer.

func (*MarkdownPrinter) Print

func (p *MarkdownPrinter) Print(structName string, doc string, fields []FieldInfo)

Print generates Markdown documentation for the given fields.

type OutputFormat

type OutputFormat int

OutputFormat specifies the documentation output format.

const (
	// FormatMarkdown outputs Markdown documentation.
	FormatMarkdown OutputFormat = iota
	// FormatASCII outputs terminal-friendly documentation with ANSI colors.
	FormatASCII
)

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser handles parsing of Go source files.

func NewParser

func NewParser() *Parser

NewParser creates a new Parser.

func (*Parser) FindAllStructs

func (p *Parser) FindAllStructs(pkg *ast.Package) []*ast.TypeSpec

FindAllStructs returns all exported struct type declarations in the package. Doc comments are propagated from GenDecl to TypeSpec where needed.

func (*Parser) FindStruct

func (p *Parser) FindStruct(pkg *ast.Package, structName string) *ast.TypeSpec

FindStruct finds a struct definition by name in the package. It propagates doc comments from the enclosing GenDecl to the TypeSpec when the TypeSpec's own Doc field is nil (standard Go AST behaviour for top-level type declarations).

func (*Parser) ParsePackage

func (p *Parser) ParsePackage(path string) (*ast.Package, error)

ParsePackage parses the directory containing the Go files.

func (*Parser) ProcessStruct

func (p *Parser) ProcessStruct(ts *ast.TypeSpec, pkg *ast.Package) ([]FieldInfo, error)

ProcessStruct extracts field information from a struct type.

type StructDoc

type StructDoc struct {
	Name   string      // struct name
	Doc    string      // struct-level godoc comment
	Fields []FieldInfo // recursive field tree
}

StructDoc holds parsed documentation data for a single struct.

func ParseAll

func ParseAll(structName, path string) ([]StructDoc, error)

ParseAll discovers every exported struct in the given path and returns their documentation data. When structName is non-empty only that struct is returned; when empty all exported structs are included.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL