-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR doesn't functionally change anything about the internal workings of the app, but greatly alters the structure of the app. It now uses Cobra for a more proper CLI-like experience (version, help, etc work). This is laying the ground work for saving configs for easier reuse of previous runs.
- Loading branch information
1 parent
9112c63
commit c009a81
Showing
37 changed files
with
191 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/fatih/color" | ||
"github.com/gwenwindflower/tbd/internal" | ||
"github.com/gwenwindflower/tbd/sourcerer" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Elapsed struct { | ||
DbStart time.Time | ||
ProcessingStart time.Time | ||
DbElapsed float64 | ||
ProcessingElapsed float64 | ||
} | ||
|
||
var ( | ||
greenBold = color.New(color.FgMagenta).Add(color.Bold).SprintFunc() | ||
rootCmd = &cobra.Command{ | ||
Use: "tbd", | ||
Short: "π A sweet and speedy code generator for dbt projects. ποΈβ¨", | ||
Long: fmt.Sprintf(`π %s ποΈβ¨ | ||
tbd uses your database schema to generate YAML configs and | ||
SQL staging models, including tests and docs via LLM. | ||
It's the easy button for starting a dbt project.`, greenBold("A sweet and speedy code generator for dbt projects.")), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
ps, err := internal.FetchDbtProfiles() | ||
if err != nil { | ||
log.Fatalf("Error fetching dbt profiles: %v\n", err) | ||
} | ||
fr, err := internal.Forms(ps) | ||
if err != nil { | ||
log.Fatalf("Error running form: %v\n", err) | ||
} | ||
if !fr.Confirm { | ||
log.Fatal("β User cancelled.") | ||
} | ||
cd := internal.SetConnectionDetails(fr, ps) | ||
|
||
e := Elapsed{} | ||
e.DbStart = time.Now() | ||
|
||
bd := fr.BuildDir | ||
err = internal.PrepBuildDir(bd) | ||
if err != nil { | ||
log.Fatalf("Error preparing build directory: %v\n", err) | ||
} | ||
dbc, err := sourcerer.GetConn(cd) | ||
if err != nil { | ||
log.Fatalf("Error getting database connection: %v\n", err) | ||
} | ||
err = dbc.ConnectToDb(ctx) | ||
if err != nil { | ||
log.Fatalf("Error connecting to database: %v\n", err) | ||
} | ||
fmt.Println("Connected to database") | ||
ts, err := dbc.GetSourceTables(ctx) | ||
if err != nil { | ||
log.Fatalf("Error getting sources: %v\n", err) | ||
} | ||
fmt.Println("Got source tables") | ||
fmt.Println("Putting columns on tables...") | ||
err = sourcerer.PutColumnsOnTables(ctx, ts, dbc) | ||
if err != nil { | ||
log.Fatalf("Error putting columns on tables: %v\n", err) | ||
} | ||
|
||
e.DbElapsed = time.Since(e.DbStart).Seconds() | ||
// End of database interaction, start of processing | ||
e.ProcessingStart = time.Now() | ||
|
||
if fr.GenerateDescriptions { | ||
llm, err := internal.GetLlm(fr) | ||
if err != nil { | ||
// Using Printf instead of log.Fatalf since the program doesn't | ||
// need to totally fail if the API provider can't be fetched | ||
fmt.Printf("Error getting API provider: %v\n", err) | ||
} | ||
fmt.Println("Generating descriptions and tests...") | ||
internal.InferColumnFields(llm, ts) | ||
if err != nil { | ||
// Using Printf instead of log.Fatalf since the program | ||
// doesn't need to totally fail if there's an error in the column field inference | ||
fmt.Printf("Error inferring column fields: %v\n", err) | ||
} | ||
} | ||
fmt.Println("Writing files...") | ||
if fr.CreateProfile { | ||
internal.WriteProfile(cd, bd) | ||
} | ||
if fr.ScaffoldProject { | ||
s, err := internal.WriteScaffoldProject(cd, bd, fr.ProjectName) | ||
if err != nil { | ||
log.Fatalf("Error scaffolding project: %v\n", err) | ||
} | ||
bd = s | ||
} | ||
err = internal.WriteFiles(ts, bd, fr.Prefix) | ||
if err != nil { | ||
log.Fatalf("Error writing files: %v\n", err) | ||
} | ||
e.ProcessingElapsed = time.Since(e.ProcessingStart).Seconds() | ||
pinkUnderline := color.New(color.FgMagenta).Add(color.Bold, color.Underline).SprintFunc() | ||
fmt.Printf("\nπ Done in %.1fs fetching data and %.1fs writing files!\nYour YAML and SQL files are in the %s directory.", e.DbElapsed, e.ProcessingElapsed, pinkUnderline(fr.BuildDir)) | ||
}, | ||
} | ||
) | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gwenwindflower/tbd/internal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of tbd", | ||
Long: `Wanna know what version of tbd you're running? Well I've got some great news for you.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("tbd v%s\n", internal.VERSION) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"log" | ||
|
2 changes: 1 addition & 1 deletion
2
fetch_dbt_profiles_test.go β internal/fetch_dbt_profiles_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import "time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
llm_infer_column_fields.go β internal/llm_infer_column_fields.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
llm_infer_column_fields_test.go β internal/llm_infer_column_fields_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
2 changes: 1 addition & 1 deletion
2
set_connection_details.go β internal/set_connection_details.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"log" | ||
|
2 changes: 1 addition & 1 deletion
2
set_connection_details_test.go β internal/set_connection_details_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package internal | ||
|
||
const VERSION = "0.0.25" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"strings" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"log" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
2 changes: 1 addition & 1 deletion
2
write_scaffold_project.go β internal/write_scaffold_project.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"log" | ||
|
2 changes: 1 addition & 1 deletion
2
write_scaffold_project_test.go β internal/write_scaffold_project_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"embed" | ||
|
2 changes: 1 addition & 1 deletion
2
write_staging_models_test.go β internal/write_staging_models_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"log" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package internal | ||
|
||
import ( | ||
"os" | ||
|
Oops, something went wrong.