59 lines
1019 B
Go
59 lines
1019 B
Go
|
package helpers
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
// YesOrNoInput
|
||
|
func YesOrNoInput() bool {
|
||
|
|
||
|
var userInput string
|
||
|
for {
|
||
|
|
||
|
_, err := fmt.Scanf("%s", &userInput)
|
||
|
if err != nil {
|
||
|
log.Infof("failed to read input, try again (%s)", err.Error())
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
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")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// IsValidPathInput
|
||
|
func IsValidPathInput() string {
|
||
|
var userInput string
|
||
|
for {
|
||
|
|
||
|
_, err := fmt.Scanf("%s", &userInput)
|
||
|
if err != nil {
|
||
|
log.Infof("failed to read input, try again (%s)", err.Error())
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
err = CheckAndCreateDir(userInput)
|
||
|
if err != nil {
|
||
|
log.Warnf("please, try again")
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
return userInput
|
||
|
}
|
||
|
}
|