@@ -2,48 +2,55 @@ package ui
22
33import (
44 "fmt"
5+ "os"
56
67 "github.com/andrearcaina/goforge/internal/spec"
78 "github.com/charmbracelet/lipgloss"
89)
910
10- func OutputSuccess ( cfg * spec. Config ) {
11- successStyle : = lipgloss .NewStyle ().
12- Foreground (lipgloss .Color ("205" )).
13- Bold (true ).
14- Padding (1 , 0 )
11+ var (
12+ successStyle = lipgloss .NewStyle ().
13+ Foreground (lipgloss .Color ("205" )).
14+ Bold (true ).
15+ Padding (1 , 0 )
1516
16- cmdStyle := lipgloss .NewStyle ().
17- Foreground (lipgloss .Color ("63" )).
18- PaddingLeft (2 )
17+ cmdStyle = lipgloss .NewStyle ().
18+ Foreground (lipgloss .Color ("63" )).
19+ PaddingLeft (2 )
20+ )
1921
22+ func OutputSuccess (cfg * spec.Config ) {
2023 fmt .Println (successStyle .Render ("🔥 Generated successfully!" ))
2124 fmt .Println ("Make sure to run the following commands:" )
2225
2326 // base commands to run
2427 commands := []string {
2528 fmt .Sprintf ("cd %s" , cfg .OutputPath ),
26- "go mod tidy" ,
2729 }
2830
31+ if cfg .Form .MakefileFlag {
32+ if cfg .Form .DatabaseFlag {
33+ commands = appendDatabaseCommands (commands )
34+ }
35+
36+ commands = append (commands , "make" )
37+
38+ printCommands (commands )
39+ }
40+
41+ commands = append (commands , "go mod tidy" )
42+
2943 // add commands based on selected options
3044 if cfg .Form .ServerTypeFlag == spec .REST {
3145 commands = append (commands , "swag init -g ./cmd/server/main.go # install swag if you haven't already" )
3246 }
3347
3448 // if database is selected, add sqlc generate and server run commands
3549 if cfg .Form .DatabaseFlag {
36- commands = append (commands ,
37- "sqlc generate ./... # install sqlc if you haven't already" ,
38- "goose up -dir ./db/migrations postgres \" your_db_connection_string\" # install goose and DB is running" ,
39- )
50+ commands = appendDatabaseCommands (commands )
4051 }
4152
42- if cfg .Form .MakefileFlag {
43- commands = append (commands , "make" )
44- } else {
45- commands = append (commands , "go run ./cmd/server/main.go" )
46- }
53+ commands = append (commands , "go run ./cmd/server/main.go" )
4754
4855 // if REST server is selected, add command to view API docs
4956 if cfg .Form .ServerTypeFlag == spec .REST {
@@ -52,7 +59,21 @@ func OutputSuccess(cfg *spec.Config) {
5259 )
5360 }
5461
62+ printCommands (commands )
63+ }
64+
65+ func appendDatabaseCommands (commands []string ) []string {
66+ return append (commands ,
67+ "sqlc generate ./... # install sqlc if you haven't already" ,
68+ "goose up -dir ./db/migrations postgres \" your_db_connection_string\" # install goose and DB is running" ,
69+ )
70+ }
71+
72+ func printCommands (commands []string ) {
5573 for _ , cmd := range commands {
5674 fmt .Println (cmdStyle .Render (cmd ))
5775 }
76+
77+ // exit without error
78+ os .Exit (0 )
5879}
0 commit comments