Improve handling some edge cases in the ask utlity
This commit is contained in:
parent
91c4f6be4c
commit
e0e1920b0b
1 changed files with 9 additions and 2 deletions
|
@ -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
|
||||||
|
answer="$(echo "$read_answer" | xargs)"
|
||||||
|
|
||||||
|
if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then
|
||||||
echo "$answer"
|
echo "$answer"
|
||||||
|
else
|
||||||
|
log debug "[ask] Invalid choice"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_opts() {
|
set_opts() {
|
||||||
|
|
Loading…
Reference in a new issue