2022-07-15 11:49:53 +00:00
|
|
|
/*
|
2022-07-16 15:46:09 +00:00
|
|
|
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
2022-07-15 11:49:53 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-09-20 21:49:37 +00:00
|
|
|
"os"
|
2022-07-15 11:49:53 +00:00
|
|
|
|
2022-09-20 21:49:37 +00:00
|
|
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
|
|
|
|
"git.home.m-and-m.ovh/mderasse/gouick/models"
|
2022-07-15 11:49:53 +00:00
|
|
|
"github.com/spf13/cobra"
|
2022-09-20 21:49:37 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-07-15 11:49:53 +00:00
|
|
|
)
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// generateCmd represents the generate command.
|
2022-07-15 11:49:53 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-09-20 21:49:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|