feat(init): Get User input for config + small refacto

This commit is contained in:
Matthieu 'JP' DERASSE
2022-08-01 19:47:46 +00:00
parent 13903329c8
commit 9103e7ba60
24 changed files with 314 additions and 86 deletions

View File

@ -8,10 +8,13 @@ import (
"os"
"strings"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/helpers/api_type"
"github.com/juju/errors"
"github.com/spf13/cobra"
"git.home.m-and-m.ovh/mderasse/gouick/helpers"
"git.home.m-and-m.ovh/mderasse/gouick/helpers/api_types"
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
log "github.com/sirupsen/logrus"
)
@ -87,7 +90,7 @@ func runInitAction(cmd *cobra.Command, args []string) {
// ask which API type we want to use
var possibleApiTypes []string
for _, apiType := range api_type.GetListOfApiTypeName() {
for _, apiType := range models.GetListOfApiTypeName() {
possibleApiTypes = append(possibleApiTypes, string(apiType))
}
@ -96,11 +99,21 @@ func runInitAction(cmd *cobra.Command, args []string) {
log.Debugf("Using api type : %s", string(apiTypeName))
_, err = api_type.GetApiType(apiTypeName)
apiType, err := api_types.GetApiType(apiTypeName)
if err != nil {
log.Error("Impossible to load that API Type generator")
}
// XXX: split in to: checkBeforeInitialize + GetInitializeUserInput
// launch GetInitializeUserInput from selected api type
log.Debug("Get user input for the selected API type")
_, err = apiType.GetInitializeUserInput()
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