// initSQLMigrator reads in config file and ENV variables if set.
initSQLMigrator reads in config file and ENV variables if set.
// initSQLMigrator reads in config file and ENV variables if set .
func initSQLMigrator() {
	var config api.Configuration
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		viper.AddConfigPath(home)
		viper.SetConfigName(".dbmigrator")
	}
	viper.AutomaticEnv() 
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	} else if _, ok := err.(viper.ConfigFileNotFoundError); ok {
		fmt.Println("Default config file not found:", viper.ConfigFileUsed())
	}
	err := viper.Unmarshal(&config)
	if err != nil {
		fmt.Println("\n Error: expected arguments \"dsn\" and \"dir\" was not set\n", rootCmd.Help())
		os.Exit(1)
	}
	config.ExpandEnv()
	err = dbmigrator.InitTool(ctx, config, nil)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func initSQLMigrator ( ) { var config api . Configuration if cfgFile != " " { viper . SetConfigFile ( cfgFile ) } else { home , err := homedir . Dir ( ) if err != nil { fmt . Println ( err ) os . Exit ( 1 ) } viper . AddConfigPath ( home ) viper . SetConfigName ( " " ) } viper . AutomaticEnv ( ) if err := viper . ReadInConfig ( ) ; err == nil { fmt . Println ( " " , viper . ConfigFileUsed ( ) ) } else if _ , ok := err . ( viper . ConfigFileNotFoundError ) ; ok { fmt . Println ( " " , viper . ConfigFileUsed ( ) ) } err := viper . Unmarshal ( & config ) if err != nil { fmt . Println ( " \n \" \" \" \" \n " , rootCmd . Help ( ) ) os . Exit ( 1 ) } config . ExpandEnv ( ) err = dbmigrator . InitTool ( ctx , config , nil ) if err != nil { fmt . Println ( err ) os . Exit ( 1 ) } }
initSQLMigrator reads in config file and ENV variables if set.
initSQLMigrator reads in config file and ENV variables if set .
// Use config file from the flag. // Find home directory. // Search config in home directory with name ".dbmigrator" (without extension). // read in environment variables that match // If a config file is found, read it in. //err = dbmigrator.Init(ctx, config, nil)