@@ -45,6 +45,7 @@ var newCmd = &cobra.Command{
4545var projectType string
4646var projectPort string
4747var projectRouter string
48+ var DBType string
4849
4950func init () {
5051 // Add the new command to the rootCmd
@@ -54,6 +55,7 @@ func init() {
5455 newCmd .Flags ().StringVar (& projectType , "type" , "" , "type of the project" )
5556 newCmd .Flags ().StringVar (& projectPort , "port" , "" , "port of the project" )
5657 newCmd .Flags ().StringVar (& projectRouter , "router" , "" , "router of the project" )
58+ newCmd .Flags ().StringVar (& DBType , "db" , "" , "data type of the project" )
5759}
5860
5961func createNewProject (projectName string , projectRouter string , template string , out io.Writer ) {
@@ -73,19 +75,37 @@ func createNewProject(projectName string, projectRouter string, template string,
7375 renderTemplateDir ("rest" + "/" + projectRouter , projectName , TemplateData {
7476 ModuleName : projectName ,
7577 PortName : projectPort ,
78+ DBType : DBType ,
7679 })
7780
7881 if err != nil {
7982 fmt .Fprintf (out , "Error rendering templates: %v\n " , err )
8083 return
8184 }
8285
83- fmt .Fprintf (out , "Created '%s' successfully\n " , projectName )
86+ if DBType != "" {
87+ dbTemplatePath := "db/" + DBType
88+ err := renderTemplateDir (dbTemplatePath , filepath .Join (projectName , "internal" , "db" ), TemplateData {
89+ ModuleName : projectName ,
90+ PortName : projectPort ,
91+ DBType : DBType ,
92+ })
93+ if err != nil {
94+
95+ fmt .Fprintf (out , "Error rendering DB templates: %v\n " , err )
96+ return
97+ }
98+
99+ fmt .Fprintf (out , "✓ Added database support for '%s'\n " , DBType )
100+ }
101+
102+ fmt .Fprintf (out , "✓ Created '%s' successfully\n " , projectName )
84103}
85104
86105type TemplateData struct {
87106 ModuleName string
88107 PortName string
108+ DBType string
89109}
90110
91111func renderTemplateDir (templatePath , destinationPath string , data TemplateData ) error {
0 commit comments