package helpers
import (
"fmt"
"github.com/manifoldco/promptui"
"os"
"strings"
)
const (
promptMessage = "Do you wish to continue"
)
var (
affirmativeOptions = []string{"y", "yes"}
)
func isAffirmative(result string) bool {
result = strings.ToLower(strings.TrimSpace(result))
for _, opt := range affirmativeOptions {
if opt == result {
return true
}
}
return false
}
func PromptToContinue() (bool, error) {
prompt := promptui.Prompt{
Label: promptMessage,
IsConfirm: true,
Default: "No",
}
res, err := prompt.Run()
if err != nil {
return false, err
}
return isAffirmative(res), nil
}
func ExitWithAbort() {
fmt.Println("Aborting...")
os.Exit(0)
}
func ExitWithMessage(message string) {
fmt.Println(message)
os.Exit(0)
}
|
The pages are generated with Golds v0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |