@@ -12,6 +12,7 @@ import (
1212 "github.com/bartekpacia/fhome/highlevel"
1313 "github.com/knadh/koanf"
1414 "github.com/knadh/koanf/parsers/toml"
15+ "github.com/knadh/koanf/providers/env"
1516 "github.com/knadh/koanf/providers/file"
1617 "github.com/lmittmann/tint"
1718 "github.com/urfave/cli/v3"
@@ -81,21 +82,34 @@ func main() {
8182func loadConfig () * highlevel.Config {
8283 k := koanf .New ("." )
8384
85+ // Attempt to load configuration from /etc/fhome/config.toml
8486 p := "/etc/fhome/config.toml"
85- if err := k .Load (file .Provider (p ), toml .Parser ()); err != nil {
87+ err := k .Load (file .Provider (p ), toml .Parser ())
88+ if err != nil {
8689 slog .Debug ("failed to load config file" , slog .Any ("error" , err ))
8790 } else {
8891 slog .Debug ("loaded config file" , slog .String ("path" , p ))
8992 }
9093
94+ // Attempt to load configuration from ~/.config/fhome/config.toml
9195 homeDir , _ := os .UserHomeDir ()
9296 p = fmt .Sprintf ("%s/.config/fhome/config.toml" , homeDir )
93- if err := k .Load (file .Provider (p ), toml .Parser ()); err != nil {
97+ err = k .Load (file .Provider (p ), toml .Parser ())
98+ if err != nil {
9499 slog .Debug ("failed to load config file" , slog .Any ("error" , err ))
95100 } else {
96101 slog .Debug ("loaded config file" , slog .String ("path" , p ))
97102 }
98103
104+ // Attempt to load configuration from environment variables.
105+ // This will override any values from config files.
106+ err = k .Load (env .Provider ("" , "." , nil ), nil )
107+ if err != nil {
108+ slog .Debug ("failed to load environment variables" , slog .Any ("error" , err ))
109+ } else {
110+ slog .Debug ("loaded configuration from environment variables" )
111+ }
112+
99113 return & highlevel.Config {
100114 Email : k .MustString ("FHOME_EMAIL" ),
101115 Password : k .MustString ("FHOME_CLOUD_PASSWORD" ),
0 commit comments