diff --git a/forms.go b/forms.go index 97598d3..6aad49b 100644 --- a/forms.go +++ b/forms.go @@ -26,6 +26,7 @@ type FormResponse struct { CreateProfile bool ScaffoldProject bool ProjectName string + Prefix string } func Forms() (formResponse FormResponse) { @@ -81,6 +82,10 @@ You'll need: huh.NewConfirm().Affirmative("Yeah!").Negative("Nope"). Title("Would you like to scaffold a basic dbt project into the output directory?"). Value(&formResponse.ScaffoldProject), + huh.NewInput(). + Title("What prefix do you want to use for your staging files?"). + Value(&formResponse.Prefix). + Placeholder("stg"), ), ) project_name_form := huh.NewForm( diff --git a/main.go b/main.go index 92d5fc8..97aa806 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { } bd = s } - err = WriteFiles(ts, bd) + err = WriteFiles(ts, bd, formResponse.Prefix) if err != nil { log.Fatalf("Error writing files: %v\n", err) } diff --git a/write_files.go b/write_files.go index 01f8034..a8374a7 100644 --- a/write_files.go +++ b/write_files.go @@ -7,7 +7,7 @@ import ( "github.com/gwenwindflower/tbd/shared" ) -func WriteFiles(ts shared.SourceTables, bd string) error { +func WriteFiles(ts shared.SourceTables, bd string, prefix string) error { if len(ts.SourceTables) == 0 { return errors.New("no tables to write") } @@ -19,7 +19,7 @@ func WriteFiles(ts shared.SourceTables, bd string) error { }() go func() { defer wg.Done() - WriteStagingModels(ts, bd) + WriteStagingModels(ts, bd, prefix) }() wg.Wait() return nil diff --git a/write_files_test.go b/write_files_test.go index 6049018..43a7ccf 100644 --- a/write_files_test.go +++ b/write_files_test.go @@ -22,7 +22,7 @@ func TestWriteFiles(t *testing.T) { }, } bd := t.TempDir() - WriteFiles(ts, bd) + WriteFiles(ts, bd, "prefix") } func TestWriteFilesError(t *testing.T) { @@ -31,7 +31,7 @@ func TestWriteFilesError(t *testing.T) { } bd := t.TempDir() - err := WriteFiles(ts, bd) + err := WriteFiles(ts, bd, "prefix") if err == nil { t.Error("expected error, got nil") } else { diff --git a/write_staging_models.go b/write_staging_models.go index 03b437e..b91ba2a 100644 --- a/write_staging_models.go +++ b/write_staging_models.go @@ -15,7 +15,7 @@ import ( //go:embed *.sql var stagingTemplate embed.FS -func WriteStagingModels(tables shared.SourceTables, buildDir string) { +func WriteStagingModels(tables shared.SourceTables, buildDir string, prefix string) { var wg sync.WaitGroup for _, table := range tables.SourceTables { @@ -29,7 +29,7 @@ func WriteStagingModels(tables shared.SourceTables, buildDir string) { log.Fatalf("Failed to parse template %v\n", err) } - filename := fmt.Sprintf(buildDir + "/stg_" + strings.ToLower(table.Name) + ".sql") + filename := fmt.Sprintf(buildDir + "/" + prefix + "_" + strings.ToLower(table.Name) + ".sql") outputFile, err := os.Create(filename) if err != nil { log.Fatalf("Failed to create file %v\n", err)