diff --git a/helpers/api_types/base/check_initialize.go b/helpers/api_types/base/check_initialize.go index b7bc321..01f6366 100644 --- a/helpers/api_types/base/check_initialize.go +++ b/helpers/api_types/base/check_initialize.go @@ -2,9 +2,11 @@ package base import ( "github.com/juju/errors" + + "git.home.m-and-m.ovh/mderasse/gouick/helpers" ) // CheckInitialize will do preliminary check before initializing a new project. func (a APIType) CheckInitialize() error { - return errors.NotImplementedf("CheckInitialize not implemented for %s", a.GetName()) + return errors.NotImplementedf("%s not implemented for %s", helpers.GetCurrentFuncName(), a.GetName()) } diff --git a/helpers/api_types/base/get_user_input.go b/helpers/api_types/base/get_user_input.go index 6200244..a8a5607 100644 --- a/helpers/api_types/base/get_user_input.go +++ b/helpers/api_types/base/get_user_input.go @@ -1,12 +1,13 @@ package base import ( - "git.home.m-and-m.ovh/mderasse/gouick/models" - "github.com/juju/errors" + + "git.home.m-and-m.ovh/mderasse/gouick/helpers" + "git.home.m-and-m.ovh/mderasse/gouick/models" ) // GetInitializeUserInput will ask user to provide information that allow initialization of a project. func (a APIType) GetInitializeUserInput(params *models.Config) (*models.Config, error) { - return nil, errors.NotImplementedf("GetInitializeUserInput not implemented for %s", a.GetName()) + return nil, errors.NotImplementedf("%s not implemented for %s", helpers.GetCurrentFuncName(), a.GetName()) } diff --git a/helpers/api_types/go_swagger/check_initialize.go b/helpers/api_types/go_swagger/check_initialize.go index 78e9138..a4a528b 100644 --- a/helpers/api_types/go_swagger/check_initialize.go +++ b/helpers/api_types/go_swagger/check_initialize.go @@ -12,7 +12,7 @@ import ( // CheckInitialize will do preliminary check before initializing a new project. func (a APIType) CheckInitialize() error { - log.Debugf("Starting %s check initialize", string(a.GetName())) + log.Debugf("Starting %s - %s", a.GetName(), helpers.GetCurrentFuncName()) // Get current path log.Debug("Getting current location") diff --git a/helpers/api_types/go_swagger/get_user_input.go b/helpers/api_types/go_swagger/get_user_input.go index b625985..7f5875c 100644 --- a/helpers/api_types/go_swagger/get_user_input.go +++ b/helpers/api_types/go_swagger/get_user_input.go @@ -13,7 +13,7 @@ import ( // GetInitializeUserInput will ask user to provide information that allow initialization of a project. func (a APIType) GetInitializeUserInput(params *models.Config) (*models.Config, error) { - log.Debugf("Starting %s user input", a.GetName()) + log.Debugf("Starting %s - %s", a.GetName(), helpers.GetCurrentFuncName()) // Get current path log.Debug("Getting current location") diff --git a/helpers/debug.go b/helpers/debug.go new file mode 100644 index 0000000..a571fa0 --- /dev/null +++ b/helpers/debug.go @@ -0,0 +1,12 @@ +package helpers + +import ( + "runtime" +) + +// GetCurrentFuncName will return the current function's name. +// It can be used for a better log debug system. +func GetCurrentFuncName() string { + pc, _, _, _ := runtime.Caller(1) + return runtime.FuncForPC(pc).Name() +} diff --git a/helpers/input.go b/helpers/input.go index 102ec2b..a501907 100644 --- a/helpers/input.go +++ b/helpers/input.go @@ -54,6 +54,32 @@ func AlphanumericalInput() string { if !is_alphanumeric { log.Warn("Please use a-z, A-Z, 0-9 and - or _ characters only.") + continue + } + + return userInput + } +} + +// AlphanumericalAndSpaceInput ask user for a alphanumerical+space string and try until we get a possible answer. +func AlphanumericalAndSpaceInput() string { + + scanner := bufio.NewScanner(os.Stdin) + for { + + scanner.Scan() + userInput := scanner.Text() + + if userInput == "" { + log.Warn("Empty input, try again") + continue + } + + is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9\-\_\s]*$`).MatchString(userInput) + + if !is_alphanumeric { + log.Warn("Please use a-z, A-Z, 0-9, - , space or _ characters only.") + continue } return userInput