/* Copyright © 2022 Matthieu Derasse */ package cmd import ( "fmt" "os" "git.home.m-and-m.ovh/mderasse/gouick/helpers" "git.home.m-and-m.ovh/mderasse/gouick/models" "github.com/spf13/cobra" log "github.com/sirupsen/logrus" ) // generateCmd represents the generate command. 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") }, } func init() { rootCmd.AddCommand(generateCmd) } func loadProjectAndConfig() (string, *models.Config, error) { log.Debugf("Checking dependencies") if !checkDependencies() { return "", nil, fmt.Errorf("failed to check dependencies") } // Get current path currentPath, err := os.Getwd() if err != nil { log.Errorf("Fail to get current path. The following error happen: %s", err.Error()) return "", nil, err } log.Debugf("Working in directory: %s", currentPath) // Check if we are in a gouick project log.Debug("Checking if we are in a gouick project") isGouickProject, err := helpers.IsGouickProject(currentPath) if err != nil { log.Errorf("Fail to check if we are in a gouick project. The following error happen: %s", err.Error()) return "", nil, err } if !isGouickProject { log.Error("That command need to be executed in a Gouick Project Directory") return "", nil, fmt.Errorf("that command need to be executed in a gouick project directory") } // Reading project configuration log.Debug("Reading project configuration") config, err := helpers.ReadConfig(currentPath) if err != nil { log.Errorf("Failed to read configuration file. The following error happen: %s", err.Error()) return "", nil, err } log.Debugf("Using api type : %s", string(config.ProjectType)) return currentPath, config, nil }