qemush : remplacement du if précédent par un case POSIX

This commit is contained in:
Ahurac 2024-03-25 11:43:20 +01:00
parent 7c4e645fa0
commit 50fba776c8

View file

@ -193,23 +193,17 @@ public_spice() {
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
}
function_exists() {
declare -F \
| cut -d \ -f 3- \
| grep '^public_' \
| sed 's/^public_//' \
| grep -q "^${1}\$"
}
case "$1" in
"")
public_running
;;
running|ls|add|edit|start|attach|rm|diskls|diskadd|diskrm|shell|do|spice|help)
function=$1
shift
# Defauts to `active` if no function is supplied; else checks for a public
# function named after the argument; else fails
if [ -z "$1" ]; then
public_running
elif function_exists "$1"; then
function=$1
shift
"public_${function}" "$@"
else
error_usage
fi
"public_${function}" "$@"
;;
*)
error_usage
;;
esac