pkg/utils: Add function to prompt the user for confirmation

https://github.com/containers/toolbox/pull/318
This commit is contained in:
Harry Míchal 2020-05-11 16:46:12 +02:00 committed by Debarshi Ray
parent 823fbacea9
commit 936f22ff15

View file

@ -97,6 +97,32 @@ func init() {
ContainerNameDefault = ContainerNamePrefixDefault + "-" + releaseDefault
}
func AskForConfirmation(prompt string) bool {
var retVal bool
for {
fmt.Printf("%s ", prompt)
var response string
fmt.Scanf("%s", &response)
if response == "" {
response = "n"
} else {
response = strings.ToLower(response)
}
if response == "no" || response == "n" {
break
} else if response == "yes" || response == "y" {
retVal = true
break
}
}
return retVal
}
func CallFlatpakSessionHelper() (string, error) {
logrus.Debug("Calling org.freedesktop.Flatpak.SessionHelper.RequestSession")