Skip to content

Commit

Permalink
fix: making read config file optional and add compass env namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed May 23, 2022
1 parent c083ffc commit 0698446
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cli/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -60,12 +61,16 @@ func loadConfig(cmd *cobra.Command) (Config, error) {
opts = append(opts,
config.WithPath("./"),
config.WithName("compass"),
config.WithEnvKeyReplacer(".", "_"),
config.WithEnvPrefix("COMPASS"),
)
}

var cfg Config
err := config.NewLoader(opts...).Load(&cfg)
if err != nil {
if err := config.NewLoader(opts...).Load(&cfg); err != nil {
if errors.As(err, &config.ConfigFileNotFoundError{}) {
return cfg, nil
}
return cfg, err
}
return cfg, nil
Expand Down

0 comments on commit 0698446

Please sign in to comment.