Documentation
¶
Overview ¶
Package config provides centralized configuration management with Viper isolation.
All Viper usage is contained within this package. Other packages must access configuration through this package's functions, never directly via Viper.
Index ¶
- Constants
- func GetConfigPath(appName string) string
- func UpgradeConfig(configPath string, force bool) (string, error)
- func WriteConfigWithHeader(path string, cfg *ExtendedConfig, header string) error
- type Config
- type DirectoriesConfig
- type DoctorConfig
- type DotfileConfig
- type ExperimentalConfig
- type ExtendedConfig
- type IgnoreConfig
- type JSONStrategy
- type Loader
- type LoggingConfig
- type MarshalOptions
- type NetworkConfig
- type OperationsConfig
- type OutputConfig
- type PackagesConfig
- type Strategy
- type SymlinksConfig
- type TOMLStrategy
- type UpdateConfig
- type WriteOptions
- type Writer
- type YAMLStrategy
Constants ¶
const ( // Logging defaults DefaultLogLevel = "INFO" // Default log level (DEBUG, INFO, WARN, ERROR) DefaultLogFormat = "text" // Default log format (text, json) DefaultLogDestination = "stderr" // Default log destination (stderr, stdout, file) // Symlink defaults DefaultSymlinkMode = "relative" // Default symlink mode (relative, absolute) DefaultSymlinkFolding = true // Enable directory folding optimization DefaultSymlinkOverwrite = false // Do not overwrite existing files (safe default) DefaultSymlinkBackup = false // Do not create backups (explicit opt-in) DefaultSymlinkBackupSuffix = ".bak" // Default backup file suffix // Dotfile translation defaults DefaultDotfileTranslate = true // Enable dot- to . translation DefaultDotfilePrefix = "dot-" // Prefix for dotfile translation DefaultDotfilePackageNameMapping = true // Enable package name to target directory mapping (pre-1.0 breaking change) // Output defaults DefaultOutputFormat = "text" // Default output format (text, json, yaml, table) DefaultOutputColor = "auto" // Default color mode (auto, always, never) DefaultOutputProgress = true // Show progress indicators DefaultOutputVerbosity = 1 // Default verbosity (0=quiet, 1=normal, 2=verbose, 3=debug) DefaultOutputWidth = 0 // Terminal width (0 = auto-detect) // Operations defaults DefaultOperationsDryRun = false // Execute operations (not dry-run) DefaultOperationsAtomic = true // Enable atomic operations with rollback DefaultOperationsMaxParallel = 0 // Max parallel operations (0 = auto-detect CPU count) // Packages defaults DefaultPackagesSortBy = "name" // Default sort order (name, links, date) DefaultPackagesAutoDiscover = false // Do not auto-discover packages DefaultPackagesValidateNames = true // Validate package naming conventions // Doctor defaults DefaultDoctorAutoFix = false // Do not auto-fix issues (require explicit action) DefaultDoctorCheckManifest = true // Check manifest integrity DefaultDoctorCheckBrokenLinks = true // Check for broken symlinks DefaultDoctorCheckOrphaned = false // Do not check for orphaned links (opt-in) DefaultDoctorOrphanScanMode = "off" // Orphan scan mode (off, scoped, deep) DefaultDoctorOrphanScanDepth = 0 // Orphan scan depth (0 = unlimited) DefaultDoctorCheckPermissions = false // Do not check file permissions // Ignore defaults DefaultIgnoreUseDefaults = true // Use default ignore patterns // Experimental defaults DefaultExperimentalParallel = false // Experimental parallel operations disabled DefaultExperimentalProfiling = false // Performance profiling disabled )
const ( // Directory configuration keys KeyDirPackage = "directories.package" KeyDirTarget = "directories.target" KeyDirManifest = "directories.manifest" // Logging configuration keys KeyLogLevel = "logging.level" KeyLogFormat = "logging.format" KeyLogDestination = "logging.destination" KeyLogFile = "logging.file" // Symlink configuration keys KeySymlinkMode = "symlinks.mode" KeySymlinkFolding = "symlinks.folding" KeySymlinkOverwrite = "symlinks.overwrite" KeySymlinkBackup = "symlinks.backup" KeySymlinkBackupSuffix = "symlinks.backup_suffix" KeySymlinkBackupDir = "symlinks.backup_dir" // Ignore pattern configuration keys KeyIgnoreUseDefaults = "ignore.use_defaults" KeyIgnorePatterns = "ignore.patterns" KeyIgnoreOverrides = "ignore.overrides" // Dotfile translation configuration keys KeyDotfileTranslate = "dotfile.translate" KeyDotfilePrefix = "dotfile.prefix" // Output configuration keys KeyOutputFormat = "output.format" KeyOutputColor = "output.color" KeyOutputProgress = "output.progress" KeyOutputVerbosity = "output.verbosity" KeyOutputWidth = "output.width" // Operations configuration keys KeyOperationsDryRun = "operations.dry_run" KeyOperationsAtomic = "operations.atomic" KeyOperationsMaxParallel = "operations.max_parallel" // Packages configuration keys KeyPackagesSortBy = "packages.sort_by" KeyPackagesAutoDiscover = "packages.auto_discover" KeyPackagesValidateNames = "packages.validate_names" // Doctor configuration keys KeyDoctorAutoFix = "doctor.auto_fix" KeyDoctorCheckManifest = "doctor.check_manifest" KeyDoctorCheckBrokenLinks = "doctor.check_broken_links" KeyDoctorCheckOrphaned = "doctor.check_orphaned" KeyDoctorCheckPermissions = "doctor.check_permissions" KeyDoctorOrphanScanMode = "doctor.orphan_scan_mode" KeyDoctorOrphanScanDepth = "doctor.orphan_scan_depth" KeyDoctorOrphanSkipPatterns = "doctor.orphan_skip_patterns" )
Variables ¶
This section is empty.
Functions ¶
func GetConfigPath ¶
GetConfigPath returns XDG-compliant configuration directory path. Uses XDG_CONFIG_HOME if set, otherwise falls back to ~/.config on Unix systems.
func UpgradeConfig ¶
UpgradeConfig upgrades the configuration file at configPath to the latest format. It creates a timestamped backup before making changes and merges user values with new defaults. Deprecated fields are automatically migrated.
func WriteConfigWithHeader ¶
func WriteConfigWithHeader(path string, cfg *ExtendedConfig, header string) error
WriteConfigWithHeader writes configuration with a custom header comment.
Types ¶
type Config ¶
type Config struct {
// LogLevel specifies logging level: DEBUG, INFO, WARN, ERROR
LogLevel string `mapstructure:"log_level" json:"log_level" yaml:"log_level" toml:"log_level"`
// LogFormat specifies log output format: json, text
LogFormat string `mapstructure:"log_format" json:"log_format" yaml:"log_format" toml:"log_format"`
}
Config contains all application configuration.
func LoadFromFile ¶
LoadFromFile loads configuration from specified file. Supports YAML, JSON, and TOML formats based on file extension.
func LoadWithEnv ¶
LoadWithEnv loads configuration from file and applies environment variable overrides. Environment variables use DOT_ prefix and replace dots with underscores.
type DirectoriesConfig ¶
type DirectoriesConfig struct {
// Package directory containing packages
Package string `mapstructure:"package" json:"package" yaml:"package" toml:"package"`
// Target directory for symlinks
Target string `mapstructure:"target" json:"target" yaml:"target" toml:"target"`
// Manifest directory for tracking
Manifest string `mapstructure:"manifest" json:"manifest" yaml:"manifest" toml:"manifest"`
}
DirectoriesConfig contains directory path configuration.
type DoctorConfig ¶
type DoctorConfig struct {
// Auto-fix issues when possible
AutoFix bool `mapstructure:"auto_fix" json:"auto_fix" yaml:"auto_fix" toml:"auto_fix"`
// Check manifest integrity
CheckManifest bool `mapstructure:"check_manifest" json:"check_manifest" yaml:"check_manifest" toml:"check_manifest"`
// Check for broken symlinks
CheckBrokenLinks bool `mapstructure:"check_broken_links" json:"check_broken_links" yaml:"check_broken_links" toml:"check_broken_links"`
// Check for orphaned links
CheckOrphaned bool `mapstructure:"check_orphaned" json:"check_orphaned" yaml:"check_orphaned" toml:"check_orphaned"`
// Check file permissions
CheckPermissions bool `mapstructure:"check_permissions" json:"check_permissions" yaml:"check_permissions" toml:"check_permissions"`
}
DoctorConfig contains doctor command configuration.
type DotfileConfig ¶
type DotfileConfig struct {
// Enable dot- to . translation
Translate bool `mapstructure:"translate" json:"translate" yaml:"translate" toml:"translate"`
// Prefix for dotfile translation
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix" toml:"prefix"`
// PackageNameMapping enables package name to target directory mapping.
// When enabled, package "dot-gnupg" targets ~/.gnupg/ instead of ~/.
// Default: true (project is pre-1.0, breaking change acceptable)
PackageNameMapping bool `mapstructure:"package_name_mapping" json:"package_name_mapping" yaml:"package_name_mapping" toml:"package_name_mapping"`
}
DotfileConfig contains dotfile translation configuration.
type ExperimentalConfig ¶
type ExperimentalConfig struct {
// Enable parallel operations
Parallel bool `mapstructure:"parallel" json:"parallel" yaml:"parallel" toml:"parallel"`
// Enable performance profiling
Profiling bool `mapstructure:"profiling" json:"profiling" yaml:"profiling" toml:"profiling"`
}
ExperimentalConfig contains experimental feature flags.
type ExtendedConfig ¶
type ExtendedConfig struct {
Directories DirectoriesConfig `mapstructure:"directories" json:"directories" yaml:"directories" toml:"directories"`
Logging LoggingConfig `mapstructure:"logging" json:"logging" yaml:"logging" toml:"logging"`
Symlinks SymlinksConfig `mapstructure:"symlinks" json:"symlinks" yaml:"symlinks" toml:"symlinks"`
Ignore IgnoreConfig `mapstructure:"ignore" json:"ignore" yaml:"ignore" toml:"ignore"`
Dotfile DotfileConfig `mapstructure:"dotfile" json:"dotfile" yaml:"dotfile" toml:"dotfile"`
Output OutputConfig `mapstructure:"output" json:"output" yaml:"output" toml:"output"`
Operations OperationsConfig `mapstructure:"operations" json:"operations" yaml:"operations" toml:"operations"`
Packages PackagesConfig `mapstructure:"packages" json:"packages" yaml:"packages" toml:"packages"`
Doctor DoctorConfig `mapstructure:"doctor" json:"doctor" yaml:"doctor" toml:"doctor"`
Update UpdateConfig `mapstructure:"update" json:"update" yaml:"update" toml:"update"`
Network NetworkConfig `mapstructure:"network" json:"network" yaml:"network" toml:"network"`
Experimental ExperimentalConfig `mapstructure:"experimental" json:"experimental" yaml:"experimental" toml:"experimental"`
}
ExtendedConfig contains all application configuration with comprehensive settings.
func DefaultExtended ¶
func DefaultExtended() *ExtendedConfig
DefaultExtended returns extended configuration with sensible defaults.
func LoadExtendedFromFile ¶
func LoadExtendedFromFile(path string) (*ExtendedConfig, error)
LoadExtendedFromFile loads extended configuration from specified file.
func (*ExtendedConfig) Validate ¶
func (c *ExtendedConfig) Validate() error
Validate checks configuration for errors.
type IgnoreConfig ¶
type IgnoreConfig struct {
// Use default ignore patterns (.git, .DS_Store, etc.)
UseDefaults bool `mapstructure:"use_defaults" json:"use_defaults" yaml:"use_defaults" toml:"use_defaults"`
// Additional patterns to ignore (glob format, supports !negation)
Patterns []string `mapstructure:"patterns" json:"patterns" yaml:"patterns" toml:"patterns"`
// Patterns to override (DEPRECATED: use !pattern instead)
Overrides []string `mapstructure:"overrides" json:"overrides" yaml:"overrides" toml:"overrides"`
// Enable per-package .dotignore files
PerPackageIgnore bool `mapstructure:"per_package_ignore" json:"per_package_ignore" yaml:"per_package_ignore" toml:"per_package_ignore"`
// Maximum file size in bytes (0 = no limit)
MaxFileSize int64 `mapstructure:"max_file_size" json:"max_file_size" yaml:"max_file_size" toml:"max_file_size"`
// Interactive prompt for large files (TTY mode only)
InteractiveLargeFiles bool `` /* 131-byte string literal not displayed */
}
IgnoreConfig contains ignore pattern configuration.
type JSONStrategy ¶
type JSONStrategy struct{}
JSONStrategy implements Strategy for JSON format.
func NewJSONStrategy ¶
func NewJSONStrategy() *JSONStrategy
NewJSONStrategy creates a new JSON marshaling strategy.
func (*JSONStrategy) Marshal ¶
func (s *JSONStrategy) Marshal(cfg *ExtendedConfig, opts MarshalOptions) ([]byte, error)
Marshal converts configuration to JSON bytes.
func (*JSONStrategy) Unmarshal ¶
func (s *JSONStrategy) Unmarshal(data []byte) (*ExtendedConfig, error)
Unmarshal converts JSON bytes to configuration.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading configuration from multiple sources.
func (*Loader) Load ¶
func (l *Loader) Load() (*ExtendedConfig, error)
Load loads configuration from file with proper precedence. Precedence: file > defaults
func (*Loader) LoadWithEnv ¶
func (l *Loader) LoadWithEnv() (*ExtendedConfig, error)
LoadWithEnv loads configuration from file and applies environment variable overrides. Precedence: env > file > defaults
func (*Loader) LoadWithFlags ¶
func (l *Loader) LoadWithFlags(flags map[string]interface{}) (*ExtendedConfig, error)
LoadWithFlags loads configuration and applies flag overrides. Precedence: flags > env > file > defaults
type LoggingConfig ¶
type LoggingConfig struct {
// Log level: DEBUG, INFO, WARN, ERROR
Level string `mapstructure:"level" json:"level" yaml:"level" toml:"level"`
// Log format: text, json
Format string `mapstructure:"format" json:"format" yaml:"format" toml:"format"`
// Log destination: stderr, stdout, file
Destination string `mapstructure:"destination" json:"destination" yaml:"destination" toml:"destination"`
// Log file path (only used if destination is "file")
File string `mapstructure:"file" json:"file" yaml:"file" toml:"file"`
}
LoggingConfig contains logging configuration.
type MarshalOptions ¶
type MarshalOptions struct {
// IncludeComments adds explanatory comments to output (format-dependent)
IncludeComments bool
// Indent specifies indentation size (spaces)
Indent int
}
MarshalOptions controls marshaling behavior.
func DefaultMarshalOptions ¶
func DefaultMarshalOptions() MarshalOptions
DefaultMarshalOptions returns sensible default marshaling options.
type NetworkConfig ¶
type NetworkConfig struct {
// HTTP proxy URL (overrides environment)
HTTPProxy string `mapstructure:"http_proxy" json:"http_proxy" yaml:"http_proxy" toml:"http_proxy"`
// HTTPS proxy URL (overrides environment)
HTTPSProxy string `mapstructure:"https_proxy" json:"https_proxy" yaml:"https_proxy" toml:"https_proxy"`
// No proxy hosts (comma-separated)
NoProxy string `mapstructure:"no_proxy" json:"no_proxy" yaml:"no_proxy" toml:"no_proxy"`
// HTTP timeout in seconds (0 = use default 10s)
Timeout int `mapstructure:"timeout" json:"timeout" yaml:"timeout" toml:"timeout"`
// Connection timeout in seconds (0 = use default 5s)
ConnectTimeout int `mapstructure:"connect_timeout" json:"connect_timeout" yaml:"connect_timeout" toml:"connect_timeout"`
// TLS handshake timeout in seconds (0 = use default 5s)
TLSTimeout int `mapstructure:"tls_timeout" json:"tls_timeout" yaml:"tls_timeout" toml:"tls_timeout"`
}
NetworkConfig contains network and HTTP configuration.
type OperationsConfig ¶
type OperationsConfig struct {
// Enable dry-run mode by default
DryRun bool `mapstructure:"dry_run" json:"dry_run" yaml:"dry_run" toml:"dry_run"`
// Enable atomic operations with rollback
Atomic bool `mapstructure:"atomic" json:"atomic" yaml:"atomic" toml:"atomic"`
// Maximum number of parallel operations (0 = auto-detect CPU count)
MaxParallel int `mapstructure:"max_parallel" json:"max_parallel" yaml:"max_parallel" toml:"max_parallel"`
}
OperationsConfig contains operation behavior configuration.
type OutputConfig ¶
type OutputConfig struct {
// Default output format: text, json, yaml, table
Format string `mapstructure:"format" json:"format" yaml:"format" toml:"format"`
// Enable colored output: auto, always, never
Color string `mapstructure:"color" json:"color" yaml:"color" toml:"color"`
// Table style: default (modern with borders), simple (legacy plain text)
TableStyle string `mapstructure:"table_style" json:"table_style" yaml:"table_style" toml:"table_style"`
// Show progress indicators
Progress bool `mapstructure:"progress" json:"progress" yaml:"progress" toml:"progress"`
// Verbosity level: 0 (quiet), 1 (normal), 2 (verbose), 3 (debug)
Verbosity int `mapstructure:"verbosity" json:"verbosity" yaml:"verbosity" toml:"verbosity"`
// Terminal width for text wrapping (0 = auto-detect)
Width int `mapstructure:"width" json:"width" yaml:"width" toml:"width"`
}
OutputConfig contains output formatting configuration.
type PackagesConfig ¶
type PackagesConfig struct {
// Default sort order for list command: name, links, date
SortBy string `mapstructure:"sort_by" json:"sort_by" yaml:"sort_by" toml:"sort_by"`
// Automatically scan for new packages
AutoDiscover bool `mapstructure:"auto_discover" json:"auto_discover" yaml:"auto_discover" toml:"auto_discover"`
// Package naming convention validation
ValidateNames bool `mapstructure:"validate_names" json:"validate_names" yaml:"validate_names" toml:"validate_names"`
}
PackagesConfig contains package management configuration.
type Strategy ¶
type Strategy interface {
// Name returns the format name (e.g., "yaml", "json", "toml")
Name() string
// Marshal converts configuration to bytes in the strategy's format
Marshal(cfg *ExtendedConfig, opts MarshalOptions) ([]byte, error)
// Unmarshal converts bytes to configuration from the strategy's format
Unmarshal(data []byte) (*ExtendedConfig, error)
}
Strategy defines the interface for configuration marshaling and unmarshaling. Each format (YAML, JSON, TOML) implements this interface.
func GetStrategy ¶
GetStrategy returns the appropriate strategy for the given format. Format strings are case-insensitive. Supported formats: yaml, yml, json, toml
type SymlinksConfig ¶
type SymlinksConfig struct {
// Link mode: relative, absolute
Mode string `mapstructure:"mode" json:"mode" yaml:"mode" toml:"mode"`
// Enable directory folding optimization
Folding bool `mapstructure:"folding" json:"folding" yaml:"folding" toml:"folding"`
// Overwrite existing files when conflicts occur
Overwrite bool `mapstructure:"overwrite" json:"overwrite" yaml:"overwrite" toml:"overwrite"`
// Create backup of overwritten files
Backup bool `mapstructure:"backup" json:"backup" yaml:"backup" toml:"backup"`
// Backup suffix when backups enabled
BackupSuffix string `mapstructure:"backup_suffix" json:"backup_suffix" yaml:"backup_suffix" toml:"backup_suffix"`
// Directory for backup files (default: <target>/.dot-backup)
BackupDir string `mapstructure:"backup_dir" json:"backup_dir" yaml:"backup_dir" toml:"backup_dir"`
}
SymlinksConfig contains symlink behavior configuration.
type TOMLStrategy ¶
type TOMLStrategy struct{}
TOMLStrategy implements Strategy for TOML format.
func NewTOMLStrategy ¶
func NewTOMLStrategy() *TOMLStrategy
NewTOMLStrategy creates a new TOML marshaling strategy.
func (*TOMLStrategy) Marshal ¶
func (s *TOMLStrategy) Marshal(cfg *ExtendedConfig, opts MarshalOptions) ([]byte, error)
Marshal converts configuration to TOML bytes.
func (*TOMLStrategy) Unmarshal ¶
func (s *TOMLStrategy) Unmarshal(data []byte) (*ExtendedConfig, error)
Unmarshal converts TOML bytes to configuration.
type UpdateConfig ¶
type UpdateConfig struct {
// Enable automatic version checking at startup
CheckOnStartup bool `mapstructure:"check_on_startup" json:"check_on_startup" yaml:"check_on_startup" toml:"check_on_startup"`
// Frequency of version checks in hours (0 = always check, -1 = never check)
CheckFrequency int `mapstructure:"check_frequency" json:"check_frequency" yaml:"check_frequency" toml:"check_frequency"`
// Package manager to use for upgrades: auto, brew, apt, yum, pacman, manual
PackageManager string `mapstructure:"package_manager" json:"package_manager" yaml:"package_manager" toml:"package_manager"`
// Repository URL for GitHub releases
Repository string `mapstructure:"repository" json:"repository" yaml:"repository" toml:"repository"`
// Enable pre-release versions
IncludePrerelease bool `mapstructure:"include_prerelease" json:"include_prerelease" yaml:"include_prerelease" toml:"include_prerelease"`
}
UpdateConfig contains update and upgrade configuration.
type WriteOptions ¶
WriteOptions controls configuration file output.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles writing configuration to files.
func (*Writer) DetectFormat ¶
DetectFormat detects format from file extension.
func (*Writer) Write ¶
func (w *Writer) Write(cfg *ExtendedConfig, opts WriteOptions) error
Write writes configuration to file.
func (*Writer) WriteDefault ¶
func (w *Writer) WriteDefault(opts WriteOptions) error
WriteDefault writes default configuration with comments.
type YAMLStrategy ¶
type YAMLStrategy struct{}
YAMLStrategy implements Strategy for YAML format.
func NewYAMLStrategy ¶
func NewYAMLStrategy() *YAMLStrategy
NewYAMLStrategy creates a new YAML marshaling strategy.
func (*YAMLStrategy) Marshal ¶
func (s *YAMLStrategy) Marshal(cfg *ExtendedConfig, opts MarshalOptions) ([]byte, error)
Marshal converts configuration to YAML bytes.
func (*YAMLStrategy) Unmarshal ¶
func (s *YAMLStrategy) Unmarshal(data []byte) (*ExtendedConfig, error)
Unmarshal converts YAML bytes to configuration.