feat(init): Improve check and user input

This commit is contained in:
Matthieu 'JP' DERASSE
2022-08-01 21:55:50 +00:00
parent 397540c1b1
commit fabf8fe1eb
9 changed files with 126 additions and 108 deletions

View File

@ -104,37 +104,46 @@ func runInitAction(cmd *cobra.Command, args []string) {
log.Error("Impossible to load that API Type generator")
}
// XXX: split in to: checkBeforeInitialize + GetInitializeUserInput
log.Debug("Check before init for the selected API type")
err = apiType.CheckInitialize()
if err != nil && !errors.Is(err, errors.NotImplemented) {
log.Errorf("Impossible to initialize the project. The following error happen: %s", err.Error())
return
}
// Initialize a default userInput
userInput := models.UserInputParams{}
// ask project directory
log.Info("Name of the project directory:")
userInput.ProjectDirectory = helpers.AlphanumericalInput()
// ask project name
log.Info("Name of the project:")
userInput.ProjectName = helpers.StringInput()
// ask project description
log.Info("Description of the project:")
userInput.ProjectDescription = helpers.StringInput()
// ask project owner
log.Info("Mail address of the developer team:")
userInput.ProjectOwner = helpers.StringInput()
// launch GetInitializeUserInput from selected api type
log.Debug("Get user input for the selected API type")
_, err = apiType.GetInitializeUserInput()
_, err = apiType.GetInitializeUserInput(&userInput)
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
}
// XXX:
// Check we are in gopath or ask for the gomod name
// Create directory
// Move to dir
// git init
// create .gouick
// move templated file
// if isGoProject, err := helpers.IsGoProject(); err != nil {
// log.Error("An error occured when checking your directory.")
// return
// } else if isGoProject {
// log.Error("Cannot initialize a new project because you are already in a Golang Project Directory.")
// return
// }
// if isStrapProject, err := helpers.IsStrapProject(); err != nil {
// log.Error("An error occured when checking your directory.")
// return
// } else if isStrapProject {
// log.Error("Cannot initialize a new project because you are already in a Strap Project Directory.")
// return
// }
}