Loop header ask on bad project nums

This commit is contained in:
2024-08-04 17:43:34 -04:00
parent e8b8905c8b
commit 544a03442c

View File

@@ -263,7 +263,7 @@ ask_pn() {
fi fi
fi fi
done done
[[ -z ${ADD_PROJECTS[*]} ]] [[ ${#ADD_PROJECTS[@]} -gt 0 ]]
} }
debug() { (( DEBUG )) && echo "Debug: $*"; } debug() { (( DEBUG )) && echo "Debug: $*"; }
# Not super portable but nice to have # Not super portable but nice to have
@@ -525,22 +525,29 @@ interactive_header() {
echo "" echo ""
# Let user choose or add project(s) # Let user choose or add project(s)
if [[ -z ${PROJECTS[*]} ]]; then if [[ ${#PROJECTS[@]} -eq 0 ]]; then
num=$((${#projects[@]})) num=$((${#projects[@]}))
if [[ $num -eq 0 ]]; then if [[ $num -eq 0 ]]; then
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
else else
for ((c=0; c<=1; c++)); do # safe loop that only runs once
echo "Enter a comma-separated list of project numbers to analyze" echo "Enter a comma-separated list of project numbers to analyze"
((YES)) || read -r -p "Enter \"new\" to add a new project or hit Enter for default ($num): " response ((YES)) || read -r -p "Enter 0 to add a new project or hit Enter for default project ($num): " response
if [[ $response == "new" ]]; then if [[ $response == 0 ]]; then
ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}")
else else
[[ -z $response ]] && response=$num [[ -z $response ]] && response=$num
IFS=',' read -ra arr <<< "$response" IFS=',' read -ra arr <<< "$response"
for i in "${arr[@]}"; do for i in "${arr[@]}"; do
if [[ -n ${projects[$((i-1))]} ]]; then
PROJECTS+=("${projects[$((i-1))]}") PROJECTS+=("${projects[$((i-1))]}")
else
err "Project number $i is invalid"
fi
done done
fi fi
[[ ${#PROJECTS[@]} -eq 0 ]] && c=0 # repeat the loop
done
fi fi
unset response arr i unset response arr i
fi fi
@@ -553,7 +560,7 @@ interactive_header() {
fi fi
done done
if [[ -z ${MODULES[*]} && -z ${EXCLUDE_MODULES[*]} ]]; then if [[ ${#MODULES[@]} -eq 0 && ${#EXCLUDE_MODULES[@]} -eq 0 ]]; then
echo "Enter a comma-separated list of modules to run" echo "Enter a comma-separated list of modules to run"
((YES)) || read -r -p "Hit Enter for all (default) or '0' for none: " response ((YES)) || read -r -p "Hit Enter for all (default) or '0' for none: " response
if [[ -z $response ]]; then if [[ -z $response ]]; then
@@ -569,7 +576,7 @@ interactive_header() {
unset response arr i unset response arr i
fi fi
if [[ -z ${MODULES[*]} && -z ${EXCLUDE_MODULES[*]} && -z ${SUBMODULES[*]} ]]; then if [[ ${#MODULES[@]} -eq 0 && ${#EXCLUDE_MODULES[@]} -eq 0 && ${#SUBMODULES[@]} -eq 0 ]]; then
while :; do while :; do
echo "Enter a submodule followed by its arguments as a comma-separated string" echo "Enter a submodule followed by its arguments as a comma-separated string"
echo "Quote your string if there are any whitespaces" echo "Quote your string if there are any whitespaces"