mirror of
https://github.com/alda-lang/alda.git
synced 2026-03-03 18:23:36 +01:00
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.
36 lines
521 B
Go
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
|
|
}
|
|
}
|
|
}
|