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,13 +30,17 @@ 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
0)
echo -e "No containers available\nAre you sure the application in running?" echo -e "No containers available\nAre you sure the application in running?"
exit exit
elif [[ "${#containers[@]}" == 1 ]]; then ;;
1)
container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}') container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}')
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
else ;;
*)
while true while true
do do
clear -x clear -x
@ -64,7 +68,44 @@ else
done done
container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}')
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}')
fi ;;
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