muldap/lib/cli/cli.go

36 lines
617 B
Go
Raw Normal View History

package lib
import (
"bufio"
"errors"
"fmt"
"os"
"strings"
)
// prompt user for input
func GetUserInput(consoleMsg string, confirm bool) (string, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Print(fmt.Sprintf("%s: ", consoleMsg))
input, err := reader.ReadString('\n')
if err != nil {
return "", err
}
if confirm {
fmt.Print("Confirm: ")
confirm_input, confirm_err := reader.ReadString('\n')
if confirm_err != nil {
return "", confirm_err
}
if input != confirm_input {
return "", errors.New("The passwords provided do not match!")
}
}
return strings.TrimSpace(input), nil
}