From ac549c9207d667956626b12613b01eebb53e9f43 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Fri, 5 Aug 2016 22:14:28 -0700 Subject: [PATCH] Make sqlboiler respect environment - Stop failing on config file load, use the validation in the test config stuff. --- main.go | 4 +++- templates_test/main_test/postgres_main.tpl | 3 ++- templates_test/singleton/boil_main_helpers.tpl | 13 ++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ea91e39..28917bd 100644 --- a/main.go +++ b/main.go @@ -64,8 +64,10 @@ func main() { rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to") rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package") - viper.SetDefault("postgres.sslmode", "required") + viper.SetDefault("postgres.sslmode", "require") + viper.SetDefault("postgres.port", "5432") viper.BindPFlags(rootCmd.PersistentFlags()) + viper.AutomaticEnv() if err := rootCmd.Execute(); err != nil { if e, ok := err.(commandFailure); ok { diff --git a/templates_test/main_test/postgres_main.tpl b/templates_test/main_test/postgres_main.tpl index 5e67df6..f0c0758 100644 --- a/templates_test/main_test/postgres_main.tpl +++ b/templates_test/main_test/postgres_main.tpl @@ -115,7 +115,8 @@ func setup() error { return fmt.Errorf("Unable to load config file: %s", err) } - viper.SetDefault("postgres.sslmode", "required") + viper.SetDefault("postgres.sslmode", "require") + viper.SetDefault("postgres.port", "5432") // Create a randomized test configuration object. testCfg.Postgres.Host = viper.GetString("postgres.host") diff --git a/templates_test/singleton/boil_main_helpers.tpl b/templates_test/singleton/boil_main_helpers.tpl index 0e27bc4..d05a20a 100644 --- a/templates_test/singleton/boil_main_helpers.tpl +++ b/templates_test/singleton/boil_main_helpers.tpl @@ -15,8 +15,8 @@ func InitViper() error { if err != nil { wd = "../" } else { - wd = wd + "/.." - } + wd = wd + "/.." + } configPaths := []string{wd} if len(configHome) > 0 { @@ -29,10 +29,9 @@ func InitViper() error { viper.AddConfigPath(p) } - err = viper.ReadInConfig() - if err != nil { - return err - } + // Ignore errors here, fall back to defaults and validation to provide errs + _ = viper.ReadInConfig() + viper.AutomaticEnv() - return nil + return nil }