generator

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(g Generator)

Register adds a generator to the global registry. Call this from each generator package's init() or explicitly in main.

Types

type Context

type Context struct {
	// Name is the file or project name passed as the first argument.
	Name string
	// Template is the --template flag value (empty for file generation).
	Template string
	// OutputDir is where output should be written (defaults to cwd).
	OutputDir string
	// Vars holds any additional key=value pairs passed via --var flags.
	Vars map[string]string
}

Context holds all input parsed from the CLI for a generation request.

type Generator

type Generator interface {
	// Name returns the unique identifier for this generator.
	Name() string
	// Detect returns true if this generator should handle the given Context.
	Detect(ctx *Context) bool
	// Generate executes the generation and returns any error.
	Generate(ctx *Context) error
}

Generator is implemented by anything that can produce files from a Context.

func Resolve

func Resolve(ctx *Context) (Generator, error)

Resolve walks the registry in order and returns the first Generator whose Detect method returns true for the given Context. Returns an error if no generator matches.

Jump to

Keyboard shortcuts

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