Skip to content

Commit

Permalink
Print notification when failing to load .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
suttod committed Aug 8, 2023
1 parent 8071763 commit 84573bf
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cobrautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ func SyncViperPreRunE(prefix string) CobraRunFunc {
// If empty, envfilePath defaults to ".env".
// The .dotenv file is loaded first before any additional Viper behavior.
func SyncViperDotEnvPreRunE(prefix string, envfilePath string) CobraRunFunc {
return func(cmd *cobra.Command, args []string) error {
if err := godotenv.Load(stringz.DefaultEmpty(envfilePath, ".env")); err != nil {
return err
}
return SyncViperPreRunE(prefix)(cmd, args)
if err := godotenv.Load(stringz.DefaultEmpty(envfilePath, ".env")); err != nil {
fmt.Printf("Info: attempt to load env vars from config file at path: %s failed due to error: %s. Continue without loading it.\n", envfilePath, err)
}
return SyncViperPreRunE(prefix)
}

// CobraRunFunc is the signature of cobra.Command RunFuncs.
Expand Down

0 comments on commit 84573bf

Please sign in to comment.