Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print notification and pass when failing to load .env file #49

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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