()
| 48 | } |
| 49 | |
| 50 | func LoadConfig() (*Config, error) { |
| 51 | config := DefaultConfig() |
| 52 | |
| 53 | home, err := homedir.Dir() |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("failed to find home directory: %w", err) |
| 56 | } |
| 57 | |
| 58 | configDir := filepath.Join(home, ".config", "tagTonic") |
| 59 | viper.AddConfigPath(configDir) |
| 60 | viper.AddConfigPath(home) |
| 61 | viper.AddConfigPath(".") |
| 62 | viper.SetConfigName("config") |
| 63 | viper.SetConfigType("yaml") |
| 64 | |
| 65 | viper.SetConfigName("config") |
| 66 | |
| 67 | viper.AutomaticEnv() |
| 68 | |
| 69 | if err := viper.ReadInConfig(); err == nil { |
| 70 | if err := viper.Unmarshal(config); err != nil { |
| 71 | return nil, fmt.Errorf("failed to unmarshal config: %w", err) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return config, nil |
| 76 | } |
| 77 | |
| 78 | func SaveConfig(config *Config) error { |
| 79 | home, err := homedir.Dir() |
no test coverage detected