aboutsummaryrefslogtreecommitdiff
path: root/auth/input.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-06 13:24:54 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-07-06 13:24:54 +0530
commit34d9dcbfc608ed97e28a2069f759518ba484fbab (patch)
treefd1da923f5a546755e7e31452e6b809553fa3364 /auth/input.go
parentcfe513e4ad4db4f0de8e616c02216c9ed5a69058 (diff)
added confirmation messages when re-logging in, etc
Diffstat (limited to 'auth/input.go')
-rw-r--r--auth/input.go12
1 files changed, 9 insertions, 3 deletions
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
}