config

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides application configuration management.

Package config provides application configuration management.

Package config provides application configuration management.

Index

Constants

This section is empty.

Variables

View Source
var ValidEngines = []string{"programmatic", "template", ""}

ValidEngines defines the allowed generation engines.

View Source
var ValidExportFormats = []string{"markdown", "md", "json", "yaml", "yml", ""}

ValidExportFormats defines the allowed export formats.

View Source
var ValidFormats = []string{"markdown", "md", "json", "yaml", "yml", ""}

ValidFormats defines the allowed output formats.

View Source
var ValidLogFormats = []string{"text", "json"}

ValidLogFormats defines the allowed logging formats.

View Source
var ValidLogLevels = []string{"debug", "info", "warn", "error"}

ValidLogLevels defines the allowed logging levels.

View Source
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

func LoadConfig(cfgFile string) (*Config, error)

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

func LoadConfigWithFlags(cfgFile string, flags *pflag.FlagSet) (*Config, error)

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

func LoadConfigWithViper(cfgFile string, v *viper.Viper) (*Config, error)

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

func (c *Config) GetDisplayWidth() int

GetDisplayWidth returns the configured display width.

func (*Config) GetEngine added in v1.1.0

func (c *Config) GetEngine() string

GetEngine returns the configured generation engine.

func (*Config) GetExportDirectory added in v1.1.0

func (c *Config) GetExportDirectory() string

GetExportDirectory returns the configured export directory.

func (*Config) GetExportFormat added in v1.1.0

func (c *Config) GetExportFormat() string

GetExportFormat returns the configured export format.

func (*Config) GetExportTemplate added in v1.1.0

func (c *Config) GetExportTemplate() string

GetExportTemplate returns the configured export template.

func (*Config) GetFormat

func (c *Config) GetFormat() string

GetFormat returns the configured output format.

func (*Config) GetLoggingFormat added in v1.1.0

func (c *Config) GetLoggingFormat() string

GetLoggingFormat returns the configured logging format.

func (*Config) GetLoggingLevel added in v1.1.0

func (c *Config) GetLoggingLevel() string

GetLoggingLevel returns the configured logging level.

func (*Config) GetSections

func (c *Config) GetSections() []string

GetSections returns the configured sections to include.

func (*Config) GetTemplate

func (c *Config) GetTemplate() string

GetTemplate returns the configured template name.

func (*Config) GetTheme

func (c *Config) GetTheme() string

GetTheme returns the configured theme.

func (*Config) GetWrapWidth

func (c *Config) GetWrapWidth() int

GetWrapWidth returns the configured wrap width.

func (*Config) IsDisplayPager added in v1.1.0

func (c *Config) IsDisplayPager() bool

IsDisplayPager returns true if pager is enabled.

func (*Config) IsDisplaySyntaxHighlighting added in v1.1.0

func (c *Config) IsDisplaySyntaxHighlighting() bool

IsDisplaySyntaxHighlighting returns true if syntax highlighting is enabled.

func (*Config) IsExportBackup added in v1.1.0

func (c *Config) IsExportBackup() bool

IsExportBackup returns true if backup is enabled for exports.

func (*Config) IsJSONOutput added in v1.1.0

func (c *Config) IsJSONOutput() bool

IsJSONOutput returns true if JSON output mode is enabled.

func (*Config) IsMinimal added in v1.1.0

func (c *Config) IsMinimal() bool

IsMinimal returns true if minimal output mode is enabled.

func (*Config) IsNoProgress added in v1.1.0

func (c *Config) IsNoProgress() bool

IsNoProgress returns true if progress indicators should be disabled.

func (*Config) IsQuiet

func (c *Config) IsQuiet() bool

IsQuiet returns true if quiet mode is enabled.

func (*Config) IsUseTemplate added in v1.1.0

func (c *Config) IsUseTemplate() bool

IsUseTemplate returns true if template mode is explicitly enabled.

func (*Config) IsValidationSchemaValidation added in v1.1.0

func (c *Config) IsValidationSchemaValidation() bool

IsValidationSchemaValidation returns true if schema validation is enabled.

func (*Config) IsValidationStrict added in v1.1.0

func (c *Config) IsValidationStrict() bool

IsValidationStrict returns true if strict validation is enabled.

func (*Config) IsVerbose

func (c *Config) IsVerbose() bool

IsVerbose returns true if verbose logging is enabled.

func (*Config) Validate

func (c *Config) Validate() error

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

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

type ValidationError struct {
	Field   string
	Message string
}

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

func NewValidator(c *Config) *Validator

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.

Jump to

Keyboard shortcuts

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