Make sqlboiler respect environment

- Stop failing on config file load, use the validation in the test
  config stuff.
This commit is contained in:
Aaron L 2016-08-05 22:14:28 -07:00
parent 1839b9fa03
commit ac549c9207
3 changed files with 11 additions and 9 deletions

View file

@ -64,8 +64,10 @@ func main() {
rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to") 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") 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.BindPFlags(rootCmd.PersistentFlags())
viper.AutomaticEnv()
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
if e, ok := err.(commandFailure); ok { if e, ok := err.(commandFailure); ok {

View file

@ -115,7 +115,8 @@ func setup() error {
return fmt.Errorf("Unable to load config file: %s", err) 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. // Create a randomized test configuration object.
testCfg.Postgres.Host = viper.GetString("postgres.host") testCfg.Postgres.Host = viper.GetString("postgres.host")

View file

@ -15,8 +15,8 @@ func InitViper() error {
if err != nil { if err != nil {
wd = "../" wd = "../"
} else { } else {
wd = wd + "/.." wd = wd + "/.."
} }
configPaths := []string{wd} configPaths := []string{wd}
if len(configHome) > 0 { if len(configHome) > 0 {
@ -29,10 +29,9 @@ func InitViper() error {
viper.AddConfigPath(p) viper.AddConfigPath(p)
} }
err = viper.ReadInConfig() // Ignore errors here, fall back to defaults and validation to provide errs
if err != nil { _ = viper.ReadInConfig()
return err viper.AutomaticEnv()
}
return nil return nil
} }