update
This commit is contained in:
89
mc
89
mc
@@ -26,17 +26,17 @@ declare -rA commands=(
|
|||||||
[status-minecraft]='status/Minecraft GET'
|
[status-minecraft]='status/Minecraft GET'
|
||||||
[status-bedrock]='status/Bedrock GET'
|
[status-bedrock]='status/Bedrock GET'
|
||||||
[status-sftp]='status/SFTP GET'
|
[status-sftp]='status/SFTP GET'
|
||||||
[ban]='ban POST {"username": "%s"}'
|
[ban]='ban POST {"username":"%s"}'
|
||||||
[unban]='unban POST {"username": "%s"}'
|
[unban]='unban POST {"username":"%s"}'
|
||||||
[say]='say POST {"message": "%s"}'
|
[say]='say POST {"message":"%s"}'
|
||||||
[tell]='tell POST {"username": "%s", "message": "%s"}'
|
[tell]='tell POST {"username":"%s","message":"%s"}'
|
||||||
[console]='console POST {"command": "%s"}'
|
[console]='console POST {"command":"%s"}'
|
||||||
[give]='give POST {"username": "%s", "item": "%s", "amount": "%s"}'
|
[give]='give POST {"username":"%s","item":"%s","amount":"%s"}'
|
||||||
[install]='install POST {"mod": "%s"}'
|
[install]='install POST {"mod":"%s"}'
|
||||||
[uninstall]='uninstall POST {"mod": "%s"}'
|
[uninstall]='uninstall POST {"mod":"%s"}'
|
||||||
[search]='search POST {"mod": "%s"}'
|
[search]='search POST {"mod":"%s"}'
|
||||||
[mod-list]='mod-list GET'
|
[mod-list]='mod-list GET'
|
||||||
[backup]='backup FUNC'
|
[backup]='backup FUNC'
|
||||||
)
|
)
|
||||||
|
|
||||||
function backup() {
|
function backup() {
|
||||||
@@ -65,13 +65,28 @@ function backup() {
|
|||||||
|
|
||||||
|
|
||||||
function first() {
|
function first() {
|
||||||
echo "$@" | cut --delimiter=" " --fields="-1"
|
echo "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function second() {
|
||||||
|
first $(rest "${@}")
|
||||||
}
|
}
|
||||||
|
|
||||||
function rest() {
|
function rest() {
|
||||||
if (( "${#@}" > 1 )); then
|
drop 1 "$@"
|
||||||
echo "$@" | cut --delimiter=" " --fields="2-"
|
}
|
||||||
|
|
||||||
|
function drop() {
|
||||||
|
if (( 1 == "$#" )); then
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if (( "$#" < 1 )); then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift $(( 1 + $1 ))
|
||||||
|
echo "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
@@ -86,27 +101,35 @@ function usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args=("$@")
|
args=("$@")
|
||||||
# remove command from arg list while preserving quoted strings.
|
|
||||||
args=("${args[@]:1}")
|
|
||||||
|
|
||||||
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
function main() {
|
||||||
|
# remove command from arg list while preserving quoted strings.
|
||||||
for command in "${!commands[@]}"; do
|
args=("${args[@]:1}")
|
||||||
if [[ "$1" == "${command}" ]]; then
|
|
||||||
if [[ "$(first $(rest ${commands[$1]}))" == "POST" ]]; then
|
if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
||||||
curl -sS "${headers[@]}" -X "$(first $(rest ${commands[$1]}))" "${base_url}$(first "${commands[$1]}")" -d "$(printf "$(rest $(rest ${commands[$1]}))\n" "${args[@]}")"
|
|
||||||
echo ""
|
for command in "${!commands[@]}"; do
|
||||||
elif [[ "$(first $(rest ${commands[$1]}))" == "FUNC" ]]; then
|
if [[ "$1" == "${command}" ]]; then
|
||||||
eval "$(first ${commands[$1]})"
|
if [[ "$(second ${commands[$1]})" == "POST" ]]; then
|
||||||
else
|
curl -sS "${headers[@]}" -X "$(second ${commands[$1]})" "${base_url}$(first "${commands[$1]}")" -d "$(printf "$(rest $(rest ${commands[$1]}))\n" "${args[@]}")"
|
||||||
curl -sS "${headers[@]}" -X "$(first $(rest ${commands[$1]}))" "${base_url}$(first "${commands[$1]}")"
|
echo ""
|
||||||
echo ""
|
elif [[ "$(second ${commands[$1]})" == "FUNC" ]]; then
|
||||||
|
eval "$(first ${commands[$1]})"
|
||||||
|
else
|
||||||
|
curl -sS "${headers[@]}" -X "$(second ${commands[$1]})" "${base_url}$(first "${commands[$1]}")"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "${0}: invalid option -- $1\n"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "${0}: invalid option -- $1\n"
|
if [[ "$(basename "$0")" == "mc" ]]; then
|
||||||
usage
|
main "${args[@]}"
|
||||||
exit 1
|
fi
|
||||||
|
@@ -13,12 +13,6 @@ function assert() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_assert() {
|
|
||||||
local string="one two three four"
|
|
||||||
assert "$(rest ${string})" "$(rest ${string})"
|
|
||||||
}
|
|
||||||
test_assert
|
|
||||||
|
|
||||||
function first_func_returns_first_item() {
|
function first_func_returns_first_item() {
|
||||||
local string="one two three four"
|
local string="one two three four"
|
||||||
assert "$(first ${string})" "one"
|
assert "$(first ${string})" "one"
|
||||||
|
Reference in New Issue
Block a user