gouick/helpers/input/other.go
Matthieu 'JP' DERASSE 3d878c050d
All checks were successful
continuous-integration/drone/push Build is passing
fix(path): Fix package name after git server migration
2022-11-26 22:36:00 +00:00

52 lines
1.2 KiB
Go

package input
import (
"fmt"
"path/filepath"
"strings"
"git.dev.m-and-m.ovh/mderasse/gouick/helpers"
"git.dev.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
}