refactor: make command argument checking into guard claus.

This commit is contained in:
2025-07-20 02:49:58 -07:00
parent 58c41a708b
commit 1010fb88b4

14
mc
View File

@@ -99,8 +99,12 @@ function main() {
if [[ ! $(which curl) ]]; then echo "curl is required"; exit 1; fi
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
for command in "${!commands[@]}"; do
if [[ "$1" == "${command}" ]]; then
# Check if key does NOT exists in command array
if [[ ! -v commands[$1] ]]; then
printf "${0}: invalid option -- $1\n"
usage
exit 1
fi
local endpoint method body
read -r endpoint method body <<<"${commands[$1]}"
@@ -124,12 +128,6 @@ function main() {
esac
exit 0
fi
done
printf "${0}: invalid option -- $1\n"
usage
exit 1
}