mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-12-22 17:50:42 +00:00
add check for xdg config path and cwd directory config.yaml -- xdg takes presidence if both exist
This commit is contained in:
parent
a1f848d423
commit
55383869d1
2 changed files with 22 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -24,4 +24,5 @@ go.work
|
|||
pomme
|
||||
test.db
|
||||
test.sqlite
|
||||
.dccache
|
||||
.dccache
|
||||
config.yaml
|
|
@ -49,19 +49,30 @@ type Config struct {
|
|||
var config Config
|
||||
|
||||
func ReadConfig() (*Config, error) {
|
||||
configPath := xdg.ConfigHome + "/pomme/config.yaml"
|
||||
var (
|
||||
data []byte
|
||||
err error
|
||||
defaultConfigPath string
|
||||
)
|
||||
|
||||
if configPath != "" {
|
||||
data, err := os.ReadFile(filepath.Clean(configPath))
|
||||
if err != nil {
|
||||
return &Config{}, fmt.Errorf("unable to read config file: %w", err)
|
||||
}
|
||||
defaultConfigPath = xdg.ConfigHome + "/pomme/config.yaml"
|
||||
|
||||
if data, err = os.ReadFile(filepath.Clean(defaultConfigPath)); err == nil {
|
||||
if err = yaml.Unmarshal(data, &config); err != nil {
|
||||
|
||||
err = yaml.Unmarshal(data, &config)
|
||||
if err != nil {
|
||||
return &Config{}, fmt.Errorf("unable to unmarshal config file: %w", err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
if data, err = os.ReadFile(filepath.Clean("./config.yaml")); err == nil {
|
||||
if err = yaml.Unmarshal(data, &config); err != nil {
|
||||
|
||||
return &Config{}, fmt.Errorf("unable to unmarshal config file: %w", err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
return &Config{}, fmt.Errorf("unable to read config file: %w", err)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue