From b1f168286f083129533e4053f79af1c7aee95a2d Mon Sep 17 00:00:00 2001 From: Matthieu 'JP' DERASSE Date: Fri, 11 Nov 2022 17:52:44 +0000 Subject: [PATCH] feat(generate): Prepare general generate command --- cmd/generate.go | 24 ++++++++++++++++++++---- cmd/generateAPI.go | 10 +++++----- cmd/generateDB.go | 10 +++++----- cmd/generateDocker.go | 6 +++--- cmd/generateHelm.go | 10 +++++----- cmd/generateLauncher.go | 6 +++--- cmd/generateMakefile.go | 6 +++--- cmd/generateReadme.go | 4 ++-- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 7efb28a..e56727d 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -20,16 +20,32 @@ var generateCmd = &cobra.Command{ Use: "generate", Short: "Generate all the files (API, DB, ...)", Long: `Generate will automatically create all the files of the Project. -You can also generate files for each 'modules' by using the command bellows`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("generate called") - }, +You can also generate files for each 'module' by using the command bellows`, + Run: runGenerate, } func init() { rootCmd.AddCommand(generateCmd) } +// runGenerate will launch sub generate function for the current project. +func runGenerate(cmd *cobra.Command, args []string) { + runGenerateAPI(cmd, args) + runGenerateDocker(cmd, args) + runGenerateHelm(cmd, args) + runGenerateLauncher(cmd, args) + + // Load config to check if we need to generat DB + _, config, err := loadProjectAndConfig() + if err != nil { + return + } + + if config.Features.DatabaseModels.Enabled { + runGenerateDB(cmd, args) + } +} + func loadProjectAndConfig() (string, *models.Config, error) { log.Debugf("Checking dependencies") diff --git a/cmd/generateAPI.go b/cmd/generateAPI.go index ca2e9ea..3bce698 100644 --- a/cmd/generateAPI.go +++ b/cmd/generateAPI.go @@ -5,8 +5,6 @@ Copyright © 2022 Matthieu Derasse package cmd import ( - "fmt" - "github.com/spf13/cobra" ) @@ -14,11 +12,13 @@ import ( var apiCmd = &cobra.Command{ Use: "api", Short: "Generate Go-Swagger Files and Controllers", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("api called") - }, + Run: runGenerateAPI, } func init() { generateCmd.AddCommand(apiCmd) } + +// runGenerateAPI will generate api files such as controllers, server, unit test, ... for the current project. +func runGenerateAPI(cmd *cobra.Command, args []string) { +} diff --git a/cmd/generateDB.go b/cmd/generateDB.go index ee3b308..d0e52ff 100644 --- a/cmd/generateDB.go +++ b/cmd/generateDB.go @@ -5,8 +5,6 @@ Copyright © 2022 Matthieu Derasse package cmd import ( - "fmt" - "github.com/spf13/cobra" ) @@ -14,11 +12,13 @@ import ( var dbCmd = &cobra.Command{ Use: "db", Short: "Generate Database Struct from pkg/dbmodels/schema.yaml", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("db called") - }, + Run: runGenerateDB, } func init() { generateCmd.AddCommand(dbCmd) } + +// runGenerateDB will generate database models, db connector, ... for the current project. +func runGenerateDB(cmd *cobra.Command, args []string) { +} diff --git a/cmd/generateDocker.go b/cmd/generateDocker.go index ed0c980..04a9f6a 100644 --- a/cmd/generateDocker.go +++ b/cmd/generateDocker.go @@ -15,15 +15,15 @@ import ( var dockerCmd = &cobra.Command{ Use: "docker", Short: "Generate Dockerfile & co for API, Crons and Workers", - Run: runGenerateDockerAction, + Run: runGenerateDocker, } func init() { generateCmd.AddCommand(dockerCmd) } -// runGenerateDockerAction will generate the Dockerfile & co for the current project. -func runGenerateDockerAction(cmd *cobra.Command, args []string) { +// runGenerateDocker will generate the Dockerfile & co for the current project. +func runGenerateDocker(cmd *cobra.Command, args []string) { log.Debugf("Starting command GenerateDocker") currentPath, config, err := loadProjectAndConfig() diff --git a/cmd/generateHelm.go b/cmd/generateHelm.go index ac55c98..762b521 100644 --- a/cmd/generateHelm.go +++ b/cmd/generateHelm.go @@ -5,8 +5,6 @@ Copyright © 2022 Matthieu Derasse package cmd import ( - "fmt" - "github.com/spf13/cobra" ) @@ -14,11 +12,13 @@ import ( var helmCmd = &cobra.Command{ Use: "helm", Short: "Generate Kubernetes Helm chart for API & Workers", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("helm called") - }, + Run: runGenerateHelm, } func init() { generateCmd.AddCommand(helmCmd) } + +// runGenerateHekm will generate k8s helm chart for the current project. +func runGenerateHelm(cmd *cobra.Command, args []string) { +} diff --git a/cmd/generateLauncher.go b/cmd/generateLauncher.go index 3e870c7..f6bcc7f 100644 --- a/cmd/generateLauncher.go +++ b/cmd/generateLauncher.go @@ -15,15 +15,15 @@ import ( var launcherCmd = &cobra.Command{ Use: "launcher", Short: "Generate Launcher entrypoint bash script", - Run: runGenerateLauncherAction, + Run: runGenerateLauncher, } func init() { generateCmd.AddCommand(launcherCmd) } -// runGenerateLauncherAction will generate the entrypoint for the current project. -func runGenerateLauncherAction(cmd *cobra.Command, args []string) { +// runGenerateLauncher will generate the entrypoint for the current project. +func runGenerateLauncher(cmd *cobra.Command, args []string) { log.Debugf("Starting command GenerateLauncher") currentPath, config, err := loadProjectAndConfig() diff --git a/cmd/generateMakefile.go b/cmd/generateMakefile.go index fd39606..a49953f 100644 --- a/cmd/generateMakefile.go +++ b/cmd/generateMakefile.go @@ -15,15 +15,15 @@ import ( var makefileCmd = &cobra.Command{ Use: "makefile", Short: "Generate Makefile", - Run: runGenerateMakefileAction, + Run: runGenerateMakefile, } func init() { generateCmd.AddCommand(makefileCmd) } -// runGenerateMakefileAction will generate the Makefile for the current project. -func runGenerateMakefileAction(cmd *cobra.Command, args []string) { +// runGenerateMakefile will generate the Makefile for the current project. +func runGenerateMakefile(cmd *cobra.Command, args []string) { log.Debugf("Starting command GenerateMakefile") currentPath, config, err := loadProjectAndConfig() diff --git a/cmd/generateReadme.go b/cmd/generateReadme.go index 3b2be1f..45353a9 100644 --- a/cmd/generateReadme.go +++ b/cmd/generateReadme.go @@ -15,7 +15,7 @@ import ( var readmeCmd = &cobra.Command{ Use: "readme", Short: "Generate Readme", - Run: runGenerateReadmeAction, + Run: runGenerateReadme, } func init() { @@ -23,7 +23,7 @@ func init() { } // runGenerateReadmeAction will generate the Readme for the current project. -func runGenerateReadmeAction(cmd *cobra.Command, args []string) { +func runGenerateReadme(cmd *cobra.Command, args []string) { log.Debugf("Starting command GenerateReadme") currentPath, config, err := loadProjectAndConfig() if err != nil {