package config import ( "errors" "fmt" "github.com/spf13/viper" ) type Config struct { Source string `mapstructure:"source"` Destination string `mapstructure:"destination"` Workers int `mapstructure:"workers"` KeepIncrementals int `mapstructure:"keep_incrementals"` Verbose bool `mapstructure:"verbose"` } // Load unmarshals the current Viper state into a Config struct and validates it. func Load() (*Config, error) { var cfg Config if err := viper.Unmarshal(&cfg); err != nil { return nil, fmt.Errorf("failed to unmarshal configuration: %w", err) } if cfg.Source == "" { return nil, errors.New("source path must be specified") } if cfg.Destination == "" { return nil, errors.New("destination path must be specified") } if cfg.KeepIncrementals < 0 { cfg.KeepIncrementals = 0 } return &cfg, nil }