refactor: make command argument checking into guard claus.
This commit is contained in:
14
mc
14
mc
@@ -99,8 +99,12 @@ function main() {
|
|||||||
if [[ ! $(which curl) ]]; then echo "curl is required"; exit 1; fi
|
if [[ ! $(which curl) ]]; then echo "curl is required"; exit 1; fi
|
||||||
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
||||||
|
|
||||||
for command in "${!commands[@]}"; do
|
# Check if key does NOT exists in command array
|
||||||
if [[ "$1" == "${command}" ]]; then
|
if [[ ! -v commands[$1] ]]; then
|
||||||
|
printf "${0}: invalid option -- $1\n"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
local endpoint method body
|
local endpoint method body
|
||||||
read -r endpoint method body <<<"${commands[$1]}"
|
read -r endpoint method body <<<"${commands[$1]}"
|
||||||
@@ -124,12 +128,6 @@ function main() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "${0}: invalid option -- $1\n"
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user