Files
alda-mirror/client/text/interaction.go
Dave Yarwood 1839e93bb7 Implement a (hopefully!) robust alda update mechanism
I haven't yet implemented the part where use the Alda API to check for versions
newer than the one installed. This commit is just the actual update mechanism.
`alda update` takes a flag that lets you specify which version you want to
install. That works, as of this commit, and hopefully I've done it in a way that
will work on Windows, macOS, and Linux. CI will tell me whether or not this is
the case when I push this commit.
2021-03-06 15:36:11 -05:00

36 lines
521 B
Go

package text
import (
"bufio"
"fmt"
"os"
"strings"
)
func PromptForConfirmation(prompt string, defaultToYes bool) bool {
options := "[yN]"
if defaultToYes {
options = "[Yn]"
}
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("%s %s ", prompt, options)
response, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
switch strings.ToLower(strings.TrimSpace(response)) {
case "":
return defaultToYes
case "y", "yes":
return true
case "n", "no":
return false
}
}
}