Improve handling some edge cases in the ask utlity

This commit is contained in:
Juno Takano 2024-08-28 09:27:06 -03:00
parent 91c4f6be4c
commit e0e1920b0b

View file

@ -72,8 +72,15 @@ ask() {
printf "%s" "$question" >&2 printf "%s" "$question" >&2
printf "%b" "$dialog_options" >&2 printf "%b" "$dialog_options" >&2
printf "\n%s" "Choose an option [1-$options_count] " >&2 printf "\n%s" "Choose an option [1-$options_count] " >&2
read -r answer read -r read_answer
echo "$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() { set_opts() {