logic changes

This commit is contained in:
2025-08-26 09:58:22 +02:00
parent bc53a6c0dd
commit 9e78e1acb2

33
helper
View File

@@ -43,8 +43,15 @@ must_be_in_dir() {
line() { printf "%0.s$1" $(seq 1 $2); printf '\n'; } line() { printf "%0.s$1" $(seq 1 $2); printf '\n'; }
# #
# Checks if a service is running or not and react accordingly # Capitalize first letter of each service name
# #
_capitalize_services() {
local result=()
for svc in "$@"; do
result+=("$(echo "$svc" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')")
done
echo "${result[*]}"
}
# #
# Service(s) must be running # Service(s) must be running
@@ -58,10 +65,13 @@ must_be_running() {
done done
if (( ${#bad_services[@]} > 0 )); then if (( ${#bad_services[@]} > 0 )); then
echo "The following service(s) appear not to be running, cannot continue..." local services_cap
for svc in "${bad_services[@]}"; do services_cap=$(_capitalize_services "${bad_services[@]}")
echo " - $svc" if (( ${#bad_services[@]} == 1 )); then
done echo "The service $services_cap is not running! Cannot continue..."
else
echo "The services $services_cap are not running! Cannot continue..."
fi
exit 1 exit 1
fi fi
} }
@@ -78,16 +88,19 @@ must_not_be_running() {
done done
if (( ${#bad_services[@]} > 0 )); then if (( ${#bad_services[@]} > 0 )); then
echo "The following service(s) appear already to be running, cannot continue..." local services_cap
for svc in "${bad_services[@]}"; do services_cap=$(_capitalize_services "${bad_services[@]}")
echo " - $svc" if (( ${#bad_services[@]} == 1 )); then
done echo "The service $services_cap is already running! Cannot continue..."
else
echo "The services $services_cap are already running! Cannot continue..."
fi
exit 1 exit 1
fi fi
} }
# #
# Detect input mode: "flags" or "positional" this will detect whether $1 or getopts is beeing used. # Detect input mode: "flags" or "positional" this will detect whether $1 or getopts is being used.
# #
detect_mode() { detect_mode() {
for arg in "$@"; do for arg in "$@"; do