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) DeprecationWarnings() []string
- func (c *Config) GetDisplayWidth() int
- func (c *Config) GetExportDirectory() string
- func (c *Config) GetExportFormat() string
- func (c *Config) GetFormat() string
- func (c *Config) GetLoggingFormat() string
- func (c *Config) GetLoggingLevel() string
- func (c *Config) GetSections() []string
- func (c *Config) GetTheme() string
- func (c *Config) GetWrapWidth() int
- func (c *Config) IsDebug() bool
- 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) 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 ValidExportFormats = []string{"markdown", "md", "json", "yaml", "yml", ""}
ValidExportFormats defines the allowed export formats for structured data interchange. Text and HTML are excluded because they are human-readable output formats incompatible with programmatic consumption (automation, integration, tooling).
var ValidFormats = append( slices.Clone(converter.DefaultRegistry.ValidFormatsWithAliases()), "", ) //nolint:gochecknoglobals // derived from registry
ValidFormats defines the allowed output formats, sourced from the converter registry with an empty string appended to allow unset values.
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; see deprecation notes per field)
InputFile string `mapstructure:"input_file"`
OutputFile string `mapstructure:"output_file"`
// Deprecated: Verbose will be removed in v2.0. There is no direct nested
// boolean replacement; set Logging.Level = "debug" for verbose runtime
// logging. This field is still read by cmd/root.go and config_show.go for
// backward compatibility with v1.x YAML configs. When both this field and
// Logging.Level are set, Logging.Level wins.
Verbose bool `mapstructure:"verbose"`
// Deprecated: Debug will be removed in v2.0. Use Logging.Level = "debug"
// instead. This field is still read by cmd/root.go for backward
// compatibility with v1.x YAML configs. When both this field and
// Logging.Level are set, Logging.Level wins.
Debug bool `mapstructure:"debug"`
// Deprecated: Quiet will be removed in v2.0. There is no direct nested
// boolean replacement; set Logging.Level = "error" to suppress info/warn
// output. This field is still read by cmd/root.go, cmd/audit.go,
// cmd/validate.go, cmd/display.go, cmd/convert.go, cmd/diff.go, and
// cmd/config_show.go for backward compatibility with v1.x YAML configs.
Quiet bool `mapstructure:"quiet"`
// Deprecated: Theme will be removed in v2.0. A nested Display.Theme field
// has not yet been introduced — when it is added, it will supersede this
// flat field. Until then, this remains the canonical location for theme
// selection and is read by cmd/display.go, cmd/convert.go, and
// internal/processor/report.go.
Theme string `mapstructure:"theme"`
// Deprecated: Format will be removed in v2.0. Use Export.Format for the
// programmatic output format (markdown, json, yaml). This field is still
// read by cmd/convert.go and cmd/config_show.go for backward compatibility
// with v1.x YAML configs. When both this field and Export.Format are set,
// callers should prefer Export.Format.
Format string `mapstructure:"format"`
Sections []string `mapstructure:"sections"`
WrapWidth int `mapstructure:"wrap"`
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"`
// contains filtered or unexported fields
}
Config holds the configuration for the opnDossier application.
NOTE: Several top-level fields (Verbose, Debug, Quiet, Theme, Format) are marked Deprecated and kept for backward compatibility with v1.x YAML config files. They will be removed in v2.0. Migration guidance for end users lives in GOTCHAS.md §21 "Config Flat→Nested Deprecation"; migration guidance for Go API consumers is in the per-field Deprecated comments below.
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) DeprecationWarnings ¶ added in v1.5.0
DeprecationWarnings returns user-facing guidance for every deprecated flat config key the user explicitly set during load. Callers (e.g. cmd/root.go) should log each entry at WARN level once during startup. Returns nil when no deprecated fields are in use.
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) GetFormat ¶
GetFormat returns the configured output format.
Reads the deprecated Config.Format field. This accessor will be updated or removed alongside Config.Format in v2.0. Callers wanting the programmatic output format should prefer Export.Format.
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) GetTheme ¶
GetTheme returns the configured theme.
Reads the deprecated Config.Theme field. This accessor will be updated or removed alongside Config.Theme in v2.0.
func (*Config) GetWrapWidth ¶
GetWrapWidth returns the configured wrap width.
func (*Config) IsDebug ¶ added in v1.3.0
IsDebug returns true if debug logging is enabled.
Reads the deprecated Config.Debug field. This accessor will be updated or removed alongside Config.Debug in v2.0.
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) IsQuiet ¶
IsQuiet returns true if quiet mode is enabled.
Reads the deprecated Config.Quiet field. This accessor will be updated or removed alongside Config.Quiet in v2.0.
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) IsVerbose ¶
IsVerbose returns true if verbose logging is enabled.
Reads the deprecated Config.Verbose field. This accessor will be updated or removed alongside Config.Verbose in v2.0.
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
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.