replace ugly if statement with case

This commit is contained in:
Heavybullets8 2022-08-10 17:46:01 -06:00
parent c6d0926fc2
commit 665db11d8c

View File

@ -30,41 +30,82 @@ do
containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}')") containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}')")
done done
if [[ "${#containers[@]}" == 0 ]]; then case "${#containers[@]}" in
echo -e "No containers available\nAre you sure the application in running?" 0)
exit echo -e "No containers available\nAre you sure the application in running?"
elif [[ "${#containers[@]}" == 1 ]]; then exit
container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}') ;;
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') 1)
else container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}')
while true container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
do ;;
clear -x
title *)
cont_search=$( while true
for i in "${containers[@]}"
do do
echo "$i" clear -x
done | nl -s ") " | column -t title
) cont_search=$(
echo "$cont_search" for i in "${containers[@]}"
echo do
echo "0) Exit" echo "$i"
read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } done | nl -s ") " | column -t
if [[ $selection == 0 ]]; then )
echo "Exiting.." echo "$cont_search"
exit echo
elif ! echo -e "$cont_search}" | grep -qs ^"$selection)" ; then echo "0) Exit"
echo "Error: \"$selection\" was not an option.. Try again" read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
sleep 3 if [[ $selection == 0 ]]; then
continue echo "Exiting.."
else exit
break elif ! echo -e "$cont_search}" | grep -qs ^"$selection)" ; then
fi echo "Error: \"$selection\" was not an option.. Try again"
done sleep 3
container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') continue
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') else
fi break
fi
done
container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}')
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
;;
esac
# if [[ "${#containers[@]}" == 0 ]]; then
# echo -e "No containers available\nAre you sure the application in running?"
# exit
# elif [[ "${#containers[@]}" == 1 ]]; then
# container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}')
# container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
# else
# while true
# do
# clear -x
# title
# cont_search=$(
# for i in "${containers[@]}"
# do
# echo "$i"
# done | nl -s ") " | column -t
# )
# echo "$cont_search"
# echo
# echo "0) Exit"
# read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
# if [[ $selection == 0 ]]; then
# echo "Exiting.."
# exit
# elif ! echo -e "$cont_search}" | grep -qs ^"$selection)" ; then
# echo "Error: \"$selection\" was not an option.. Try again"
# sleep 3
# continue
# else
# break
# fi
# done
# container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}')
# container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
# fi
while true while true
do do
clear -x clear -x