refactored if statements to switch case

This commit is contained in:
Bryan Joshua Pedini 2024-06-10 06:57:55 +02:00
parent e2789d200b
commit b1306a73b4

35
pman.sh
View File

@ -45,9 +45,11 @@ if [ "$command" = "" ]; then
fi fi
# Evaluate the command arguments # Evaluate the command arguments
if [ "$command_args" = "search" ]; then case "$command_args" in
"search")
command_args="-Ss" command_args="-Ss"
elif [ "$command_args" = "provides" ]; then ;;
"provides")
# Update the cache # Update the cache
su_needed=true su_needed=true
command_args="-Fy" command_args="-Fy"
@ -55,36 +57,45 @@ elif [ "$command_args" = "provides" ]; then
su_needed=false su_needed=false
command_args="-F" command_args="-F"
elif [ "$command_args" = "installed" ]; then ;;
"installed")
command_args="-Q" command_args="-Q"
elif [ "$command_args" = "install" ]; then ;;
"install")
command_args="-S" command_args="-S"
if [ "$command" = "pacman" ]; then if [ "$command" = "pacman" ]; then
su_needed=true su_needed=true
fi fi
elif [ "$command_args" = "update" ]; then ;;
"update")
command_args="-Sy" command_args="-Sy"
if [ "$command" = "pacman" ]; then if [ "$command" = "pacman" ]; then
su_needed=true su_needed=true
fi fi
elif [ "$command_args" = "upgradable" ]; then ;;
"upgradable")
command_args="-Qu" command_args="-Qu"
elif [ "$command_args" = "upgrade" ]; then ;;
"upgrade")
command_args="-Syu" command_args="-Syu"
if [ "$command" = "pacman" ]; then if [ "$command" = "pacman" ]; then
su_needed=true su_needed=true
fi fi
elif [ "$command_args" = "remove" ]; then ;;
"remove")
command_args="-Rs" command_args="-Rs"
if [ "$command" = "pacman" ]; then if [ "$command" = "pacman" ]; then
su_needed=true su_needed=true
fi fi
elif [ "$command_args" = "purge" ]; then ;;
"purge")
command_args="-Rns" command_args="-Rns"
if [ "$command" = "pacman" ]; then if [ "$command" = "pacman" ]; then
su_needed=true su_needed=true
fi fi
elif [ "$more_arguments" = "true" ]; then ;;
*)
if [ "$more_arguments" = "true" ]; then
echo "Invalid command: \"$command $command_args\"" echo "Invalid command: \"$command $command_args\""
echo echo
echo "Usage: pman <command> [args...]" echo "Usage: pman <command> [args...]"
@ -103,6 +114,8 @@ elif [ "$more_arguments" = "true" ]; then
echo " purge - pacman -Rns | remove packages, dependencies & conf" echo " purge - pacman -Rns | remove packages, dependencies & conf"
echo " config - /etc/pacman.conf | edits pacman configuration" echo " config - /etc/pacman.conf | edits pacman configuration"
exit 1 exit 1
fi fi
;;
esac
execute_command "${@}" execute_command "${@}"