Skip to content

Commit aec540b

Browse files
authored
fix: making read config file optional and add compass env namespace (#135)
1 parent c083ffc commit aec540b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cli/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67

@@ -60,12 +61,16 @@ func loadConfig(cmd *cobra.Command) (Config, error) {
6061
opts = append(opts,
6162
config.WithPath("./"),
6263
config.WithName("compass"),
64+
config.WithEnvKeyReplacer(".", "_"),
65+
config.WithEnvPrefix("COMPASS"),
6366
)
6467
}
6568

6669
var cfg Config
67-
err := config.NewLoader(opts...).Load(&cfg)
68-
if err != nil {
70+
if err := config.NewLoader(opts...).Load(&cfg); err != nil {
71+
if errors.As(err, &config.ConfigFileNotFoundError{}) {
72+
return cfg, nil
73+
}
6974
return cfg, err
7075
}
7176
return cfg, nil

0 commit comments

Comments
 (0)