package input import ( "fmt" "path/filepath" "strings" "git.home.m-and-m.ovh/mderasse/gouick/helpers" "git.home.m-and-m.ovh/mderasse/gouick/models" ) // Path ask user for a path string and try until we get a possible answer. func Path(mandatory bool) string { value := Ask(mandatory, func(in string) (string, error) { path := filepath.Clean(in) _, err := helpers.CheckAndCreateDir(path) if err != nil { return "", fmt.Errorf("please try again") } return path, nil }) return value } // APITypeName ask user for a string that is a valid API Type name and try until we get a possible answer. func APITypeName(mandatory bool) models.APITypeName { possibleAPITypes := make([]string, 0) for _, apiType := range models.GetListOfAPITypeName() { possibleAPITypes = append(possibleAPITypes, string(apiType)) } value := Ask(mandatory, func(in string) (string, error) { apiTypeName, err := models.NewAPITypeNameFromInput(in) if err != nil { return "", fmt.Errorf("invalid API type (possible values: %s)", strings.Join(possibleAPITypes, ", ")) } return string(apiTypeName), nil }) apiTypeName, _ := models.NewAPITypeName(value) return apiTypeName }