Documentation
¶
Overview ¶
Package config provides application configuration management.
Package config provides application configuration management.
Package config provides application configuration management.
Index ¶
- Variables
- type Config
- func (c *Config) GetDisplayWidth() int
- func (c *Config) GetEngine() string
- func (c *Config) GetExportDirectory() string
- func (c *Config) GetExportFormat() string
- func (c *Config) GetExportTemplate() string
- func (c *Config) GetFormat() string
- func (c *Config) GetLoggingFormat() string
- func (c *Config) GetLoggingLevel() string
- func (c *Config) GetSections() []string
- func (c *Config) GetTemplate() string
- func (c *Config) GetTheme() string
- func (c *Config) GetWrapWidth() int
- func (c *Config) IsDisplayPager() bool
- func (c *Config) IsDisplaySyntaxHighlighting() bool
- func (c *Config) IsExportBackup() bool
- func (c *Config) IsJSONOutput() bool
- func (c *Config) IsMinimal() bool
- func (c *Config) IsNoProgress() bool
- func (c *Config) IsQuiet() bool
- func (c *Config) IsUseTemplate() bool
- func (c *Config) IsValidationSchemaValidation() bool
- func (c *Config) IsValidationStrict() bool
- func (c *Config) IsVerbose() bool
- func (c *Config) Validate() error
- func (c *Config) ValidateV2() *MultiValidationError
- type DisplayConfig
- type ErrorFormatter
- type ErrorStyles
- type ExportConfig
- type FieldValidationError
- func ValidateDirectoryPath(field, path string, mustExist bool) *FieldValidationError
- func ValidateEnumField(field, value string, validOptions []string, suggestion string) *FieldValidationError
- func ValidateFilePath(field, path string, mustExist bool) *FieldValidationError
- func ValidateRangeField(field string, value, minVal, maxVal int, allowSpecial []int, suggestion string) *FieldValidationError
- type LoggingConfig
- type MultiValidationError
- type ValidationConfig
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ValidEngines = []string{"programmatic", "template", ""}
ValidEngines defines the allowed generation engines.
var ValidExportFormats = []string{"markdown", "md", "json", "yaml", "yml", ""}
ValidExportFormats defines the allowed export formats.
var ValidFormats = []string{"markdown", "md", "json", "yaml", "yml", ""}
ValidFormats defines the allowed output formats.
var ValidLogFormats = []string{"text", "json"}
ValidLogFormats defines the allowed logging formats.
var ValidLogLevels = []string{"debug", "info", "warn", "error"}
ValidLogLevels defines the allowed logging levels.
var ValidThemes = []string{"light", "dark", "auto", "none", "custom", ""}
ValidThemes defines the allowed theme values.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Flat fields (backward compatible)
InputFile string `mapstructure:"input_file"`
OutputFile string `mapstructure:"output_file"`
Verbose bool `mapstructure:"verbose"`
Quiet bool `mapstructure:"quiet"`
Theme string `mapstructure:"theme"`
Format string `mapstructure:"format"`
Template string `mapstructure:"template"`
Sections []string `mapstructure:"sections"`
WrapWidth int `mapstructure:"wrap"`
Engine string `mapstructure:"engine"` // Generation engine (programmatic, template)
UseTemplate bool `mapstructure:"use_template"` // Explicitly enable template mode
JSONOutput bool `mapstructure:"json_output"` // Output errors in JSON format
Minimal bool `mapstructure:"minimal"` // Minimal output mode
NoProgress bool `mapstructure:"no_progress"` // Disable progress indicators
// Nested configuration sections
Display DisplayConfig `mapstructure:"display"`
Export ExportConfig `mapstructure:"export"`
Logging LoggingConfig `mapstructure:"logging"`
Validation ValidationConfig `mapstructure:"validation"`
}
Config holds the configuration for the opnDossier application.
func LoadConfig ¶
LoadConfig loads application configuration from the specified YAML file, environment variables, and defaults. If cfgFile is empty, it attempts to load from a default config file location. LoadConfig loads application configuration from a YAML file, environment variables, and defaults using a new Viper instance. Returns a populated Config struct or an error if loading or validation fails.
func LoadConfigWithFlags ¶
LoadConfigWithFlags loads configuration with CLI flag binding for proper precedence. LoadConfigWithFlags loads configuration using a config file and a set of CLI flags, ensuring that flag values take precedence over other sources. Returns the populated Config struct or an error if loading or validation fails.
func LoadConfigWithViper ¶
LoadConfigWithViper loads application configuration using the provided Viper instance. It merges values from a config file, environment variables with the "OPNDOSSIER" prefix, and defaults. Precedence order: CLI flags > environment variables > config file > defaults. If cfgFile is specified, that file is used; otherwise, .opnDossier.yaml in the home directory is attempted. If the config file is missing, environment variables and defaults are used instead. Returns a validated Config struct or an error if loading or validation fails.
func (*Config) GetDisplayWidth ¶ added in v1.1.0
GetDisplayWidth returns the configured display width.
func (*Config) GetExportDirectory ¶ added in v1.1.0
GetExportDirectory returns the configured export directory.
func (*Config) GetExportFormat ¶ added in v1.1.0
GetExportFormat returns the configured export format.
func (*Config) GetExportTemplate ¶ added in v1.1.0
GetExportTemplate returns the configured export template.
func (*Config) GetLoggingFormat ¶ added in v1.1.0
GetLoggingFormat returns the configured logging format.
func (*Config) GetLoggingLevel ¶ added in v1.1.0
GetLoggingLevel returns the configured logging level.
func (*Config) GetSections ¶
GetSections returns the configured sections to include.
func (*Config) GetTemplate ¶
GetTemplate returns the configured template name.
func (*Config) GetWrapWidth ¶
GetWrapWidth returns the configured wrap width.
func (*Config) IsDisplayPager ¶ added in v1.1.0
IsDisplayPager returns true if pager is enabled.
func (*Config) IsDisplaySyntaxHighlighting ¶ added in v1.1.0
IsDisplaySyntaxHighlighting returns true if syntax highlighting is enabled.
func (*Config) IsExportBackup ¶ added in v1.1.0
IsExportBackup returns true if backup is enabled for exports.
func (*Config) IsJSONOutput ¶ added in v1.1.0
IsJSONOutput returns true if JSON output mode is enabled.
func (*Config) IsMinimal ¶ added in v1.1.0
IsMinimal returns true if minimal output mode is enabled.
func (*Config) IsNoProgress ¶ added in v1.1.0
IsNoProgress returns true if progress indicators should be disabled.
func (*Config) IsUseTemplate ¶ added in v1.1.0
IsUseTemplate returns true if template mode is explicitly enabled.
func (*Config) IsValidationSchemaValidation ¶ added in v1.1.0
IsValidationSchemaValidation returns true if schema validation is enabled.
func (*Config) IsValidationStrict ¶ added in v1.1.0
IsValidationStrict returns true if strict validation is enabled.
func (*Config) Validate ¶
Validate validates the configuration for consistency and correctness. It uses the comprehensive Validator for all validation checks including nested configuration sections.
func (*Config) ValidateV2 ¶ added in v1.1.0
func (c *Config) ValidateV2() *MultiValidationError
ValidateV2 validates the configuration and returns detailed MultiValidationError with suggestions and context for better error reporting.
type DisplayConfig ¶ added in v1.1.0
type DisplayConfig struct {
Width int `mapstructure:"width"` // Terminal width (-1 = auto-detect)
Pager bool `mapstructure:"pager"` // Enable pager for output
SyntaxHighlighting bool `mapstructure:"syntax_highlighting"` // Enable syntax highlighting
}
DisplayConfig holds display-related settings.
type ErrorFormatter ¶ added in v1.1.0
type ErrorFormatter struct {
// contains filtered or unexported fields
}
ErrorFormatter provides styled formatting for validation errors.
func NewErrorFormatter ¶ added in v1.1.0
func NewErrorFormatter() *ErrorFormatter
NewErrorFormatter creates a new ErrorFormatter with default styles. It writes to stderr by default.
func NewErrorFormatterWithWriter ¶ added in v1.1.0
func NewErrorFormatterWithWriter(w io.Writer) *ErrorFormatter
NewErrorFormatterWithWriter creates a new ErrorFormatter writing to the specified writer.
func (*ErrorFormatter) FormatError ¶ added in v1.1.0
func (f *ErrorFormatter) FormatError(err *FieldValidationError)
FormatError formats a single validation error with styling.
func (*ErrorFormatter) FormatErrors ¶ added in v1.1.0
func (f *ErrorFormatter) FormatErrors(errs *MultiValidationError)
FormatErrors formats multiple validation errors with styling.
type ErrorStyles ¶ added in v1.1.0
type ErrorStyles struct {
ErrorLabel lipgloss.Style
FieldLabel lipgloss.Style
FieldValue lipgloss.Style
Suggestion lipgloss.Style
ValidOption lipgloss.Style
Separator lipgloss.Style
LineNumber lipgloss.Style
InvalidValue lipgloss.Style
Bullet lipgloss.Style
Header lipgloss.Style
Count lipgloss.Style
SectionDivider lipgloss.Style
}
ErrorStyles contains lipgloss styles for error formatting.
type ExportConfig ¶ added in v1.1.0
type ExportConfig struct {
Format string `mapstructure:"format"` // Output format (markdown, json, yaml)
Directory string `mapstructure:"directory"` // Output directory
Template string `mapstructure:"template"` // Template name
Backup bool `mapstructure:"backup"` // Create backups before overwriting
}
ExportConfig holds export-related settings.
type FieldValidationError ¶ added in v1.1.0
type FieldValidationError struct {
Field string // The configuration field that failed validation
Message string // Description of what went wrong
Suggestion string // Helpful suggestion for fixing the error
LineNumber int // Line number in config file (0 if unknown)
Value string // The invalid value provided (for context)
ValidItems []string // Valid options for enum fields
}
FieldValidationError represents an enhanced configuration validation error with detailed context for user-friendly error reporting.
func ValidateDirectoryPath ¶ added in v1.1.0
func ValidateDirectoryPath(field, path string, mustExist bool) *FieldValidationError
ValidateDirectoryPath validates that a directory exists or is writable. Returns a FieldValidationError if invalid, or nil if valid.
func ValidateEnumField ¶ added in v1.1.0
func ValidateEnumField(field, value string, validOptions []string, suggestion string) *FieldValidationError
ValidateEnumField validates that a field value is in a list of valid options. Returns a FieldValidationError if invalid, or nil if valid.
func ValidateFilePath ¶ added in v1.1.0
func ValidateFilePath(field, path string, mustExist bool) *FieldValidationError
ValidateFilePath validates that a file exists at the given path. Returns a FieldValidationError if invalid, or nil if valid.
func ValidateRangeField ¶ added in v1.1.0
func ValidateRangeField( field string, value, minVal, maxVal int, allowSpecial []int, suggestion string, ) *FieldValidationError
ValidateRangeField validates that a numeric field is within a valid range. Returns a FieldValidationError if invalid, or nil if valid.
func (*FieldValidationError) Error ¶ added in v1.1.0
func (e *FieldValidationError) Error() string
Error returns a formatted string describing the validation error, including field name, message, and optional suggestion.
type LoggingConfig ¶ added in v1.1.0
type LoggingConfig struct {
Level string `mapstructure:"level"` // Log level (debug, info, warn, error)
Format string `mapstructure:"format"` // Log format (text, json)
}
LoggingConfig holds logging-related settings.
type MultiValidationError ¶ added in v1.1.0
type MultiValidationError struct {
Errors []FieldValidationError
}
MultiValidationError represents a collection of validation errors.
func ConvertToV2Errors ¶ added in v1.1.0
func ConvertToV2Errors(legacyErrors []ValidationError) *MultiValidationError
ConvertToV2Errors converts legacy ValidationError slice to MultiValidationError.
func (*MultiValidationError) Add ¶ added in v1.1.0
func (e *MultiValidationError) Add(err FieldValidationError)
Add appends a validation error to the collection.
func (*MultiValidationError) Count ¶ added in v1.1.0
func (e *MultiValidationError) Count() int
Count returns the number of validation errors.
func (*MultiValidationError) Error ¶ added in v1.1.0
func (e *MultiValidationError) Error() string
Error returns all validation errors joined as a semicolon-separated string.
func (*MultiValidationError) HasErrors ¶ added in v1.1.0
func (e *MultiValidationError) HasErrors() bool
HasErrors returns true if there are any validation errors.
type ValidationConfig ¶ added in v1.1.0
type ValidationConfig struct {
Strict bool `mapstructure:"strict"` // Enable strict validation
SchemaValidation bool `mapstructure:"schema_validation"` // Enable XML schema validation
}
ValidationConfig holds validation-related settings.
type ValidationError ¶
ValidationError represents a configuration validation error.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error returns a formatted string describing the validation error, including the field name and message.
type Validator ¶ added in v1.1.0
type Validator struct {
// contains filtered or unexported fields
}
Validator provides comprehensive configuration validation.
func NewValidator ¶ added in v1.1.0
NewValidator creates a new Validator for the given configuration.
func (*Validator) Validate ¶ added in v1.1.0
func (v *Validator) Validate() *MultiValidationError
Validate performs all validation checks and returns any errors.