Skip to content

Commit

Permalink
fix(cfg): don't load config from file and flags unless required
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyvgy committed Nov 16, 2024
1 parent 0aeb8e2 commit 9b4fbcc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cfg/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func LoadConfig(o interface{}, opt LoadOptions) error {
var finalErr error

// Read from YAML file
if err := k.Load(file.Provider(opt.Filename), yaml.Parser()); err != nil {
finalErr = err
if opt.Filename != "" {
if err := k.Load(file.Provider(opt.Filename), yaml.Parser()); err != nil {
finalErr = err
}
}

// Read from environment variables
Expand All @@ -43,8 +45,10 @@ func LoadConfig(o interface{}, opt LoadOptions) error {
}

// Read from command-line flags
if err := k.Load(posflag.Provider(opt.Flags, ".", k), nil); err != nil {
finalErr = err
if opt.Flags != nil {
if err := k.Load(posflag.Provider(opt.Flags, ".", k), nil); err != nil {
finalErr = err
}
}

// Unmarshal config
Expand Down

0 comments on commit 9b4fbcc

Please sign in to comment.