diff --git a/boilingcore/boilingcore.go b/boilingcore/boilingcore.go index e396994..cf33e0e 100644 --- a/boilingcore/boilingcore.go +++ b/boilingcore/boilingcore.go @@ -213,6 +213,11 @@ func (s *State) initTemplates() error { // processReplacements loads any replacement templates func (s *State) processReplacements() error { + basePath, err := getBasePath(s.Config.BaseDir) + if err != nil { + return err + } + for _, replace := range s.Config.Replacements { splits := strings.Split(replace, ":") if len(splits) != 2 { @@ -222,7 +227,7 @@ func (s *State) processReplacements() error { var toReplaceFname string toReplace, replaceWith := splits[0], splits[1] - inf, err := os.Stat(toReplace) + inf, err := os.Stat(filepath.Join(basePath, toReplace)) if err != nil { return errors.Errorf("cannot stat %q", toReplace) } diff --git a/boilingcore/imports.go b/boilingcore/imports.go index ec2752e..3ad8411 100644 --- a/boilingcore/imports.go +++ b/boilingcore/imports.go @@ -144,22 +144,22 @@ func removeDuplicates(dedup []string) []string { type mapImports map[string]imports type importer struct { - standard imports - testStandard imports + Standard imports + TestStandard imports - singleton mapImports - testSingleton mapImports + Singleton mapImports + TestSingleton mapImports - testMain mapImports + TestMain mapImports - basedOnType mapImports + BasedOnType mapImports } // newImporter returns an importer struct with default import values func newImporter() importer { var imp importer - imp.standard = imports{ + imp.Standard = imports{ standard: importList{ `"bytes"`, `"database/sql"`, @@ -178,7 +178,7 @@ func newImporter() importer { }, } - imp.singleton = mapImports{ + imp.Singleton = mapImports{ "boil_queries": { thirdParty: importList{ `"github.com/vattle/sqlboiler/boil"`, @@ -194,7 +194,7 @@ func newImporter() importer { }, } - imp.testStandard = imports{ + imp.TestStandard = imports{ standard: importList{ `"bytes"`, `"reflect"`, @@ -207,7 +207,7 @@ func newImporter() importer { }, } - imp.testSingleton = mapImports{ + imp.TestSingleton = mapImports{ "boil_main_test": { standard: importList{ `"database/sql"`, @@ -246,7 +246,7 @@ func newImporter() importer { }, } - imp.testMain = mapImports{ + imp.TestMain = mapImports{ "postgres": { standard: importList{ `"bytes"`, @@ -290,7 +290,7 @@ func newImporter() importer { // basedOnType imports are only included in the template output if the // database requires one of the following special types. Check // TranslateColumnType to see the type assignments. - imp.basedOnType = mapImports{ + imp.BasedOnType = mapImports{ "null.Float32": { thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, }, diff --git a/boilingcore/imports_test.go b/boilingcore/imports_test.go index 411408b..6f2cde4 100644 --- a/boilingcore/imports_test.go +++ b/boilingcore/imports_test.go @@ -267,7 +267,7 @@ func TestCombineTypeImports(t *testing.T) { imps := newImporter() - res1 := combineTypeImports(imports1, imps.basedOnType, cols) + res1 := combineTypeImports(imports1, imps.BasedOnType, cols) if !reflect.DeepEqual(res1, importsExpected) { t.Errorf("Expected res1 to match importsExpected, got:\n\n%#v\n", res1) @@ -285,7 +285,7 @@ func TestCombineTypeImports(t *testing.T) { }, } - res2 := combineTypeImports(imports2, imps.basedOnType, cols) + res2 := combineTypeImports(imports2, imps.BasedOnType, cols) if !reflect.DeepEqual(res2, importsExpected) { t.Errorf("Expected res2 to match importsExpected, got:\n\n%#v\n", res1) diff --git a/boilingcore/output.go b/boilingcore/output.go index e7192f1..64f28b5 100644 --- a/boilingcore/output.go +++ b/boilingcore/output.go @@ -38,7 +38,7 @@ func generateOutput(state *State, data *templateData) error { state: state, data: data, templates: state.Templates, - importSet: state.Importer.standard, + importSet: state.Importer.Standard, combineImportsOnType: true, fileSuffix: ".go", }) @@ -50,7 +50,7 @@ func generateTestOutput(state *State, data *templateData) error { state: state, data: data, templates: state.TestTemplates, - importSet: state.Importer.testStandard, + importSet: state.Importer.TestStandard, combineImportsOnType: false, fileSuffix: "_test.go", }) @@ -63,7 +63,7 @@ func generateSingletonOutput(state *State, data *templateData) error { state: state, data: data, templates: state.SingletonTemplates, - importNamedSet: state.Importer.singleton, + importNamedSet: state.Importer.Singleton, fileSuffix: ".go", }) } @@ -75,7 +75,7 @@ func generateSingletonTestOutput(state *State, data *templateData) error { state: state, data: data, templates: state.SingletonTestTemplates, - importNamedSet: state.Importer.testSingleton, + importNamedSet: state.Importer.TestSingleton, fileSuffix: ".go", }) } @@ -106,7 +106,7 @@ func executeTemplates(e executeTemplateData) error { imps.standard = e.importSet.standard imps.thirdParty = e.importSet.thirdParty if e.combineImportsOnType { - imps = combineTypeImports(imps, e.state.Importer.basedOnType, e.data.Table.Columns) + imps = combineTypeImports(imps, e.state.Importer.BasedOnType, e.data.Table.Columns) } writeFileDisclaimer(out) @@ -170,8 +170,8 @@ func generateTestMainOutput(state *State, data *templateData) error { out.Reset() var imps imports - imps.standard = state.Importer.testMain[state.Config.DriverName].standard - imps.thirdParty = state.Importer.testMain[state.Config.DriverName].thirdParty + imps.standard = state.Importer.TestMain[state.Config.DriverName].standard + imps.thirdParty = state.Importer.TestMain[state.Config.DriverName].thirdParty writeFileDisclaimer(out) writePackageName(out, state.Config.PkgName)