32 lines
785 B
Go
32 lines
785 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
gemlog "git.travisshears.com/travisshears/gemlog-cli/gemlog"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// LoadConfig reads and parses the YAML configuration file from ~/.config/gemlog-cli
|
|
func LoadConfig() (*gemlog.Config, error) {
|
|
homeDir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get user home directory: %w", err)
|
|
}
|
|
|
|
configPath := filepath.Join(homeDir, ".config", "gemlog-cli", "config.yml")
|
|
|
|
data, err := os.ReadFile(configPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file %s: %w", configPath, err)
|
|
}
|
|
|
|
var config gemlog.Config
|
|
if err := yaml.Unmarshal(data, &config); err != nil {
|
|
return nil, fmt.Errorf("failed to parse YAML config: %w", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|