Documentation
¶
Overview ¶
Package adder provides a documentation-driven CLI generator for Go applications. It processes markdown files with YAML frontmatter to generate type-safe command interfaces, request/response structures, and handler interfaces for Cobra CLI applications.
Index ¶
- Constants
- Variables
- func GenerateFromDirectory(_, inputDir string) error
- func TemplateFunctions() template.FuncMap
- func Version() string
- type Adder
- func (a *Adder) Clean() error
- func (a *Adder) Generate() error
- func (a *Adder) GenerateFromFS(ctx context.Context, inputFS fs.FS) error
- func (a *Adder) GenerateWithContext(ctx context.Context) error
- func (a *Adder) GetCommand(name string) *Command
- func (a *Adder) GetCommands() []*Command
- func (a *Adder) GetConfig() *Config
- func (a *Adder) GetStats() map[string]int
- func (a *Adder) SetConfig(config *Config)
- func (a *Adder) Validate() error
- type Argument
- type Command
- type Config
- type Flag
- type Generator
- type GeneratorInterface
- type HandlerInterface
- type HandlerMethod
- type Parser
- func (p *Parser) GetCommandPath(filePath string) string
- func (p *Parser) GetFunctionName(cmd *Command) string
- func (p *Parser) GetHandlerName(cmd *Command) string
- func (p *Parser) GetMethodName(cmd *Command) string
- func (p *Parser) GetPackageName(_ *Command) string
- func (p *Parser) GetStructName(cmd *Command) string
- func (p *Parser) ParseContent(content, filePath string) (*Command, error)
- func (p *Parser) ParseDirectory(fsys fs.FS) ([]*Command, error)
- func (p *Parser) ParseFile(fsys fs.FS, path string) (*Command, error)
Constants ¶
const ( TypeString = "string" TypeBool = "bool" TypeInt = "int" TypeStringArray = "stringArray" NilValue = "nil" )
Type constants for common data types
Variables ¶
var Templates = struct { Command string Package string }{ Command: commandTemplate, Package: packageTemplate, }
Templates contains all code generation templates
Functions ¶
func GenerateFromDirectory ¶
GenerateFromDirectory is a convenience function to generate from a directory path
func TemplateFunctions ¶
TemplateFunctions returns the template functions
Types ¶
type Adder ¶
type Adder struct {
// contains filtered or unexported fields
}
Adder is the main interface for the code generator
func NewWithDefaults ¶
func NewWithDefaults() *Adder
NewWithDefaults creates a new Adder instance with default configuration
func (*Adder) GenerateFromFS ¶
GenerateFromFS generates code from the provided filesystem
func (*Adder) GenerateWithContext ¶
GenerateWithContext processes the input directory and generates command stubs with context
func (*Adder) GetCommand ¶
GetCommand returns a specific command by name
func (*Adder) GetCommands ¶
GetCommands returns all parsed commands (requires Generate to be called first)
type Argument ¶
type Argument struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Type string `yaml:"type"`
}
Argument represents a command argument
func (*Argument) GetValidationTag ¶
GetValidationTag returns the validation tag for the argument
type Command ¶
type Command struct {
Title string `yaml:"title"`
Name string `yaml:"name"`
Aliases []string `yaml:"aliases"`
Hidden bool `yaml:"hidden"`
Arguments []Argument `yaml:"arguments"`
Flags []Flag `yaml:"flags"`
Description string // Markdown content
FilePath string // Source file path
}
Command represents a command definition from markdown
type Config ¶
type Config struct {
InputDir string `yaml:"input_dir"`
OutputDir string `yaml:"output_dir"`
Package string `yaml:"package"`
FileSuffix string `yaml:"file_suffix"`
}
Config represents the generator configuration
type Flag ¶
type Flag struct {
Name string `yaml:"name"`
Shorthand string `yaml:"shorthand"`
Description string `yaml:"description"`
Type string `yaml:"type"`
Default interface{} `yaml:"default"`
Required bool `yaml:"required"`
Enum []string `yaml:"enum"`
}
Flag represents a command flag
func (*Flag) GetCobraFlagMethod ¶
GetCobraFlagMethod returns the cobra flag method name
func (*Flag) GetCobraFlagMethodP ¶
GetCobraFlagMethodP returns the cobra flag method name with shorthand
func (*Flag) GetDefaultValue ¶
GetDefaultValue returns the default value as a Go literal
func (*Flag) GetValidationTag ¶
GetValidationTag returns the validation tag for the field
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator handles code generation from parsed commands
func NewGenerator ¶
NewGenerator creates a new generator instance
func (*Generator) GetCommand ¶
GetCommand returns a command by name
func (*Generator) ListCommands ¶
ListCommands returns a list of all parsed commands
func (*Generator) ValidateCommands ¶
ValidateCommands validates all parsed commands
type GeneratorInterface ¶
GeneratorInterface defines the interface for code generators
type HandlerInterface ¶
type HandlerInterface struct {
Name string
Methods []HandlerMethod
}
HandlerInterface represents a handler interface to be generated
type HandlerMethod ¶
HandlerMethod represents a method in a handler interface
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing markdown files with YAML frontmatter
func (*Parser) GetCommandPath ¶
GetCommandPath returns the command path from the file path
func (*Parser) GetFunctionName ¶
GetFunctionName returns the command constructor function name
func (*Parser) GetHandlerName ¶
GetHandlerName returns the handler interface name for the command
func (*Parser) GetMethodName ¶
GetMethodName returns the handler method name for the command
func (*Parser) GetPackageName ¶
GetPackageName returns the Go package name for the command
func (*Parser) GetStructName ¶
GetStructName returns the request struct name for the command
func (*Parser) ParseContent ¶
ParseContent parses markdown content with YAML frontmatter
func (*Parser) ParseDirectory ¶
ParseDirectory parses all markdown files in the input directory