2022-07-15 11:49:53 +00:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import (
|
2022-07-25 20:19:38 +00:00
|
|
|
"bufio"
|
|
|
|
"os"
|
2022-07-15 11:49:53 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-07-28 22:03:57 +00:00
|
|
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/api_type"
|
2022-07-25 20:57:00 +00:00
|
|
|
|
2022-07-15 11:49:53 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// YesOrNoInput
|
|
|
|
func YesOrNoInput() bool {
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
2022-07-15 11:49:53 +00:00
|
|
|
for {
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
scanner.Scan()
|
|
|
|
userInput := scanner.Text()
|
2022-07-15 11:49:53 +00:00
|
|
|
|
|
|
|
lUserInput := strings.ToLower(userInput)
|
|
|
|
|
|
|
|
for _, positiveAnswer := range []string{"yes", "y", "1", "true"} {
|
|
|
|
if lUserInput == positiveAnswer {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, negativeAnswer := range []string{"no", "n", "0", "false"} {
|
|
|
|
if lUserInput == negativeAnswer {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Expecting a yes or no answer, Try again")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
// PathInput
|
|
|
|
func PathInput() string {
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
2022-07-15 11:49:53 +00:00
|
|
|
for {
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
scanner.Scan()
|
|
|
|
userInput := scanner.Text()
|
|
|
|
|
|
|
|
err := CheckAndCreateDir(userInput)
|
2022-07-15 11:49:53 +00:00
|
|
|
if err != nil {
|
2022-07-25 20:19:38 +00:00
|
|
|
log.Warnf("please, try again")
|
2022-07-15 11:49:53 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
return userInput
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 20:57:00 +00:00
|
|
|
// ApiTypeNameInput
|
|
|
|
func ApiTypeNameInput() api_type.ApiTypeName {
|
2022-07-25 20:19:38 +00:00
|
|
|
|
|
|
|
var possibleApiTypes []string
|
|
|
|
for _, apiType := range api_type.GetListOfApiTypeName() {
|
|
|
|
possibleApiTypes = append(possibleApiTypes, string(apiType))
|
|
|
|
}
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
for {
|
|
|
|
|
|
|
|
scanner.Scan()
|
|
|
|
userInput := scanner.Text()
|
|
|
|
|
2022-07-25 20:57:00 +00:00
|
|
|
apiTypeName, err := api_type.NewApiTypeNameFromInput(userInput)
|
2022-07-15 11:49:53 +00:00
|
|
|
if err != nil {
|
2022-07-25 20:19:38 +00:00
|
|
|
log.Warnf("invalid API type (possible values: %s)", strings.Join(possibleApiTypes, ", "))
|
2022-07-15 11:49:53 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-25 20:19:38 +00:00
|
|
|
return apiTypeName
|
2022-07-15 11:49:53 +00:00
|
|
|
}
|
|
|
|
}
|