From 34d9dcbfc608ed97e28a2069f759518ba484fbab Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 6 Jul 2022 13:24:54 +0530 Subject: added confirmation messages when re-logging in, etc --- auth/input.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'auth/input.go') diff --git a/auth/input.go b/auth/input.go index aa56f52..42b5907 100644 --- a/auth/input.go +++ b/auth/input.go @@ -54,11 +54,12 @@ func secretInput(label, errMessage string) string { os.Exit(1) } - return res + // trim leading and trailing whitespaces + return strings.TrimSpace(res) } // ask yes/no with no as default -func confirmInput(label string) bool { +func confirmInput(label string, def bool) bool { validResponses := []string{"y", "yes", "n", "no", ""} validate := func(input string) error { @@ -89,9 +90,14 @@ func confirmInput(label string) bool { os.Exit(1) } - if res == "y" || res == "yes" { + resp := strings.TrimSpace(strings.ToLower(res)) + if resp == "y" || resp == "yes" { return true } + if resp == "" { + return def + } + return false } -- cgit v1.2.3