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

129
pman.sh
View File

@ -45,64 +45,77 @@ if [ "$command" = "" ]; then
fi
# Evaluate the command arguments
if [ "$command_args" = "search" ]; then
command_args="-Ss"
elif [ "$command_args" = "provides" ]; then
# Update the cache
su_needed=true
command_args="-Fy"
execute_command "${@}"
case "$command_args" in
"search")
command_args="-Ss"
;;
"provides")
# Update the cache
su_needed=true
command_args="-Fy"
execute_command "${@}"
su_needed=false
command_args="-F"
elif [ "$command_args" = "installed" ]; then
command_args="-Q"
elif [ "$command_args" = "install" ]; then
command_args="-S"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
elif [ "$command_args" = "update" ]; then
command_args="-Sy"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
elif [ "$command_args" = "upgradable" ]; then
command_args="-Qu"
elif [ "$command_args" = "upgrade" ]; then
command_args="-Syu"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
elif [ "$command_args" = "remove" ]; then
command_args="-Rs"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
elif [ "$command_args" = "purge" ]; then
command_args="-Rns"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
elif [ "$more_arguments" = "true" ]; then
echo "Invalid command: \"$command $command_args\""
echo
echo "Usage: pman <command> [args...]"
echo "Available commands:"
echo " yay (aur) - yay | invoke yay "
echo " (aur packages - all the normal operations except config are available)"
echo " aur (yay) - yay | same as \"yay\""
echo " search - pacman -Ss | search packages"
echo " provides - pacman -F | list packages that provide file"
echo " installed - pacman -Q | list installed packages"
echo " install - pacman -S | install packages"
echo " update - pacman -Sy | updates the repositories"
echo " upgradable - pacman -Qu | list available upgrades"
echo " upgrade - pacman -Syu | upgrades your system"
echo " remove - pacman -Rs | remove packages & dependencies"
echo " purge - pacman -Rns | remove packages, dependencies & conf"
echo " config - /etc/pacman.conf | edits pacman configuration"
exit 1
fi
su_needed=false
command_args="-F"
;;
"installed")
command_args="-Q"
;;
"install")
command_args="-S"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
;;
"update")
command_args="-Sy"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
;;
"upgradable")
command_args="-Qu"
;;
"upgrade")
command_args="-Syu"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
;;
"remove")
command_args="-Rs"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
;;
"purge")
command_args="-Rns"
if [ "$command" = "pacman" ]; then
su_needed=true
fi
;;
*)
if [ "$more_arguments" = "true" ]; then
echo "Invalid command: \"$command $command_args\""
echo
echo "Usage: pman <command> [args...]"
echo "Available commands:"
echo " yay (aur) - yay | invoke yay "
echo " (aur packages - all the normal operations except config are available)"
echo " aur (yay) - yay | same as \"yay\""
echo " search - pacman -Ss | search packages"
echo " provides - pacman -F | list packages that provide file"
echo " installed - pacman -Q | list installed packages"
echo " install - pacman -S | install packages"
echo " update - pacman -Sy | updates the repositories"
echo " upgradable - pacman -Qu | list available upgrades"
echo " upgrade - pacman -Syu | upgrades your system"
echo " remove - pacman -Rs | remove packages & dependencies"
echo " purge - pacman -Rns | remove packages, dependencies & conf"
echo " config - /etc/pacman.conf | edits pacman configuration"
exit 1
fi
;;
esac
execute_command "${@}"