feat(config): Write and read config + refacto
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
29
cmd/init.go
29
cmd/init.go
@ -89,7 +89,10 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// ask which API type we want to use
|
||||
// let's start to work on project configuration
|
||||
config := &models.Config{}
|
||||
|
||||
// ask which API type we want to use.
|
||||
possibleAPITypes := make([]string, 0)
|
||||
for _, apiType := range models.GetListOfAPITypeName() {
|
||||
possibleAPITypes = append(possibleAPITypes, string(apiType))
|
||||
@ -105,6 +108,8 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
||||
log.Error("Impossible to load that API Type generator")
|
||||
}
|
||||
|
||||
config.ProjectType = apiTypeName
|
||||
|
||||
log.Debug("Check before init for the selected API type")
|
||||
|
||||
err = apiType.CheckInitialize()
|
||||
@ -113,35 +118,32 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Initialize a default userInput
|
||||
userInput := models.UserInputParams{}
|
||||
|
||||
// ask project directory
|
||||
log.Info("Name of the project directory:")
|
||||
userInput.ProjectDirectory = helpers.AlphanumericalInput()
|
||||
projectDirectory := helpers.AlphanumericalInput()
|
||||
|
||||
// ask project name
|
||||
log.Info("Name of the project:")
|
||||
userInput.ProjectName = helpers.StringInput()
|
||||
config.ProjectName = helpers.StringInput()
|
||||
|
||||
// ask project description
|
||||
log.Info("Description of the project:")
|
||||
userInput.ProjectDescription = helpers.StringInput()
|
||||
config.ProjectDescription = helpers.StringInput()
|
||||
|
||||
// ask project owner
|
||||
log.Info("Mail address of the developer team:")
|
||||
userInput.ProjectOwner = helpers.StringInput()
|
||||
config.ProjectOwner = helpers.StringInput()
|
||||
|
||||
// launch GetInitializeUserInput from selected api type
|
||||
log.Debug("Get user input for the selected API type")
|
||||
|
||||
_, err = apiType.GetInitializeUserInput(&userInput)
|
||||
config, err = apiType.GetInitializeUserInput(config)
|
||||
if err != nil && !errors.Is(err, errors.NotImplemented) {
|
||||
log.Errorf("Fail to get all the required input. The following error happen: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
projectDirPath := filepath.Join(currentPath, userInput.ProjectDirectory)
|
||||
projectDirPath := filepath.Join(currentPath, projectDirectory)
|
||||
|
||||
log.Debugf("Our project directory path is: %s", projectDirPath)
|
||||
|
||||
@ -160,7 +162,7 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Move to project directory.
|
||||
log.Infof("Moving to the project directory: %s", userInput.ProjectDirectory)
|
||||
log.Infof("Moving to the project directory: %s", projectDirectory)
|
||||
|
||||
err = os.Chdir(projectDirPath)
|
||||
if err != nil {
|
||||
@ -179,6 +181,11 @@ func runInitAction(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
log.Info("Creating gouick configuration file")
|
||||
err = helpers.WriteConfig(projectDirPath, config)
|
||||
if err != nil {
|
||||
log.Errorf("Fail to write configuration. The following error happen: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("Creating API skeleton")
|
||||
}
|
||||
|
Reference in New Issue
Block a user