From e0e1920b0b193abd9095aa066031c79599c434f2 Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 28 Aug 2024 09:27:06 -0300 Subject: [PATCH] Improve handling some edge cases in the ask utlity --- src/utility.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utility.sh b/src/utility.sh index bb2025f..4ff19c4 100644 --- a/src/utility.sh +++ b/src/utility.sh @@ -72,8 +72,15 @@ ask() { printf "%s" "$question" >&2 printf "%b" "$dialog_options" >&2 printf "\n%s" "Choose an option [1-$options_count] " >&2 - read -r answer - echo "$answer" + read -r read_answer + answer="$(echo "$read_answer" | xargs)" + + if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then + echo "$answer" + else + log debug "[ask] Invalid choice" + return 1 + fi } set_opts() {