Sanity check message function arguments

This commit is contained in:
the-sane 2020-09-07 20:36:26 -04:00 committed by GitHub
parent e3f3a64fe5
commit 632ce7f506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,8 +50,15 @@ conf_subdir="starcitizen-lug"
# To call this function, use the following format: message [type] "[string]"
# See the message types below for instructions on formatting the string.
message() {
if [ "$has_zen" -eq 1 ]; then
# Sanity check
if [ "$#" -lt 2 ]; then
echo -e "\nScript error: The message function expects two arguments. Aborting."
read -n 1 -s -p "Press any key..."
exit 0
fi
# Use zenity messages if available
if [ "$has_zen" -eq 1 ]; then
case "$1" in
"info")
# info message
@ -69,7 +76,7 @@ message() {
margs=("--question" "--text=")
;;
*)
echo -e "\nInvalid message type passed to the message function. Aborting."
echo -e "\nScript Error: Invalid message type passed to the message function. Aborting."
read -n 1 -s -p "Press any key..."
exit 0
;;
@ -116,7 +123,7 @@ message() {
done
;;
*)
echo -e "\nInvalid message type passed to the message function. Aborting."
echo -e "\nScript Error: Invalid message type passed to the message function. Aborting."
read -n 1 -s -p "Press any key..."
exit 0
;;