Documentation
¶
Index ¶
- Variables
- type Detector
- type Format
- type Formatter
- type FormatterOptions
- type GenerateOptions
- type Generator
- type Handler
- type InterpolationError
- type Options
- type OutputFormat
- type ParseError
- type ParseResult
- type Parser
- type Registry
- func (r *Registry) Generate(format Format, data map[string]string) (string, error)
- func (r *Registry) Get(format Format) (Handler, error)
- func (r *Registry) List() []Format
- func (r *Registry) Parse(format Format, content string) (map[string]string, error)
- func (r *Registry) Register(format Format, handler Handler) error
- type SortOption
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidFormat indicates the format is invalid or unsupported ErrInvalidFormat = errors.New("invalid format") // ErrInvalidKey indicates an invalid key name ErrInvalidKey = errors.New("invalid key") // ErrInvalidValue indicates an invalid value ErrInvalidValue = errors.New("invalid value") // ErrDuplicateKey indicates a duplicate key was found ErrDuplicateKey = errors.New("duplicate key") // ErrUnclosedQuote indicates an unclosed quote in the content ErrUnclosedQuote = errors.New("unclosed quote") // ErrCircularReference indicates a circular variable reference ErrCircularReference = errors.New("circular variable reference") // ErrVariableNotFound indicates a required variable was not found ErrVariableNotFound = errors.New("variable not found") // ErrMaxDepthExceeded indicates maximum interpolation depth was exceeded ErrMaxDepthExceeded = errors.New("maximum interpolation depth exceeded") )
Common errors
var DefaultRegistry = NewRegistry()
DefaultRegistry is the global format registry
Functions ¶
This section is empty.
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector detects file formats
func (*Detector) DetectFormat ¶
DetectFormat detects the format of the content
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter provides formatting options for output
func NewFormatter ¶
func NewFormatter(opts *FormatterOptions) *Formatter
NewFormatter creates a new formatter
type FormatterOptions ¶
type FormatterOptions struct {
// Display options
ShowHeader bool // Show header with metadata
ShowComments bool // Show comments for each key
ShowLineNumbers bool // Show line numbers
ColorOutput bool // Use ANSI colors
MaxValueLength int // Truncate values longer than this
MaskSecrets bool // Mask sensitive values
SecretPatterns []string // Patterns to identify secrets
// Sorting options
SortBy SortOption // How to sort keys
GroupByPrefix bool // Group keys by prefix
PrefixSeparator string // Separator for prefix grouping
// Output format
Format OutputFormat // Output format style
Indent string // Indentation string
KeyValueSep string // Separator between key and value
LineSeparator string // Line separator
}
FormatterOptions configures the formatter
func DefaultFormatterOptions ¶
func DefaultFormatterOptions() *FormatterOptions
DefaultFormatterOptions returns default formatter options
type GenerateOptions ¶
type GenerateOptions struct {
*Options
Header string // File header comment
KeyOrder []string // Specific key order
KeyFilter func(string) bool // Filter keys
}
GenerateOptions provides fine-grained control over generation
type Generator ¶
type Generator interface {
// Generate writes key-value pairs to the writer
Generate(w io.Writer, data map[string]string) error
// GenerateString returns the formatted string
GenerateString(data map[string]string) (string, error)
// GenerateFile writes to a file
GenerateFile(filename string, data map[string]string) error
}
Generator defines the interface for generating different formats
type Handler ¶
type Handler interface {
Parser
Generator
Validator
// Format returns the format type
Format() Format
// Extensions returns file extensions for this format
Extensions() []string
}
Handler combines parser, generator, and validator
type InterpolationError ¶
InterpolationError represents an error during variable interpolation
func (*InterpolationError) Error ¶
func (e *InterpolationError) Error() string
Error implements the error interface
func (*InterpolationError) Unwrap ¶
func (e *InterpolationError) Unwrap() error
Unwrap returns the underlying error
type Options ¶
type Options struct {
// Parsing options
ExpandVariables bool // Expand ${VAR} references
StrictMode bool // Strict parsing mode
PreserveComments bool // Preserve comments (ENV only)
TrimSpace bool // Trim whitespace from values
Variables map[string]string // Variables for interpolation
// Generation options
SortKeys bool // Sort keys alphabetically
QuoteValues bool // Always quote values
IndentSize int // Indent size for structured formats
LineEnding string // Line ending style (\n or \r\n)
IncludeComments bool // Include instructional comments
}
Options for parsing and generation
type OutputFormat ¶
type OutputFormat int
OutputFormat defines the output format style
const ( OutputDefault OutputFormat = iota OutputTable OutputExport OutputShell OutputDockerfile OutputCompact )
type ParseError ¶
ParseError represents a parsing error with line information
func NewParseError ¶
func NewParseError(line int, message string, err error) *ParseError
NewParseError creates a new parse error
type ParseResult ¶
type ParseResult struct {
Data map[string]string
Comments map[string]string // Key -> comment mapping
Order []string // Original key order
Metadata map[string]interface{}
}
ParseResult contains parsed data with metadata
type Parser ¶
type Parser interface {
// Parse reads from the reader and returns key-value pairs
Parse(r io.Reader) (map[string]string, error)
// ParseString parses a string
ParseString(content string) (map[string]string, error)
// ParseFile parses a file
ParseFile(filename string) (map[string]string, error)
}
Parser defines the interface for parsing different formats
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages format handlers
type SortOption ¶
type SortOption int
SortOption defines how to sort keys
const ( SortNone SortOption = iota SortAlphabetical SortAlphabeticalReverse SortByLength SortByCategory )
type ValidationError ¶
ValidationError represents a validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface
type Validator ¶
type Validator interface {
// Validate checks if the content is valid for the format
Validate(content []byte) error
// ValidateKey checks if a key is valid
ValidateKey(key string) error
// ValidateValue checks if a value is valid
ValidateValue(value string) error
}
Validator defines the interface for format validation