Manager: Check if no operation is selected, improve error formatting
This commit is contained in:
+24
-7
@@ -25,7 +25,7 @@ red="$(tput setf 4)"
|
|||||||
n="$(tput sgr0)"
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
if [ "$(dirname "$0")" != "." ]; then
|
if [ "$(dirname "$0")" != "." ]; then
|
||||||
echo "${b}${red}Error: Please run this script from the directory it resides.${n}" >&2
|
echo "${b}${red}Error:${n} please run this script from the directory it resides." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ osDetect()
|
|||||||
elif echo "$idLike" | grep -q 'ubuntu'; then
|
elif echo "$idLike" | grep -q 'ubuntu'; then
|
||||||
os="debian"
|
os="debian"
|
||||||
else
|
else
|
||||||
echo "Unsupported operating system." >&2
|
echo "${b}${red}Error:${n} unsupported operating system." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ osDependencies()
|
|||||||
binary="$(echo "$pair" | cut -d ':' -f 1)"
|
binary="$(echo "$pair" | cut -d ':' -f 1)"
|
||||||
if ! command -v "$binary" > /dev/null; then
|
if ! command -v "$binary" > /dev/null; then
|
||||||
dependency="$(echo "$pair" | cut -d ':' -f 2)"
|
dependency="$(echo "$pair" | cut -d ':' -f 2)"
|
||||||
echo "Please install the '$dependency' dependency before running this option." >&2
|
echo "${b}${red}Error:${n} required dependency '$dependency' is missing." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -344,12 +344,18 @@ eval set -- "$parsed"
|
|||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-F | --file)
|
-F | --file)
|
||||||
[ -n "$mode" ] && echo "${b}${red}Error: only one operation may be used at a time." >&2 && exit 1
|
if [ -n "$mode" ]; then
|
||||||
|
echo "${b}${red}Error:${n} only one operation may be used at a time." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
mode="file"
|
mode="file"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-P | --package)
|
-P | --package)
|
||||||
[ -n "$mode" ] && echo "${b}${red}Error: only one operation may be used at a time." >&2 && exit 1
|
if [ -n "$mode" ]; then
|
||||||
|
echo "${b}${red}Error:${n} only one operation may be used at a time." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
mode="package"
|
mode="package"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
@@ -391,13 +397,21 @@ targetsNoHyphen="$(echo "$targets" | sed -E 's/(^-$|\s-|-\s)//g; s/(\s-\s)/ /;')
|
|||||||
|
|
||||||
# Read targets from stdin
|
# Read targets from stdin
|
||||||
if [ "$targets" != "$targetsNoHyphen" ]; then
|
if [ "$targets" != "$targetsNoHyphen" ]; then
|
||||||
[ -t 0 ] && echo "${b}${red}Error: argument '-' specified without input on stdin." >&2 && exit 1
|
if [ -t 0 ]; then
|
||||||
|
echo "${b}${red}Error:${n} argument '-' specified without input on stdin." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
eval set -- "$targetsNoHyphen $(cat /dev/stdin)"
|
eval set -- "$targetsNoHyphen $(cat /dev/stdin)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
if [ -z "$mode" ]; then
|
||||||
|
echo "${b}${red}Error:${n} no operation specified (use -h for help)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$mode" = "file" ]; then
|
if [ "$mode" = "file" ]; then
|
||||||
if [ -z "$options" ]; then
|
if [ -z "$options" ]; then
|
||||||
files "list" "$@"
|
files "list" "$@"
|
||||||
@@ -406,7 +420,10 @@ if [ "$mode" = "file" ]; then
|
|||||||
|
|
||||||
for option in $options; do
|
for option in $options; do
|
||||||
if [ -z "$*" ]; then
|
if [ -z "$*" ]; then
|
||||||
[ "$option" = "add" ] && echo "${b}${red}Error: No files or directories selected to add.${n}" >&2 && exit 1
|
if [ "$option" = "add" ];then
|
||||||
|
echo "${b}${red}Error:${n} no files or directories selected to add." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
files "$option"
|
files "$option"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user