update
This commit is contained in:
37
mc
37
mc
@@ -65,13 +65,28 @@ function backup() {
|
||||
|
||||
|
||||
function first() {
|
||||
echo "$@" | cut --delimiter=" " --fields="-1"
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
function second() {
|
||||
first $(rest "${@}")
|
||||
}
|
||||
|
||||
function rest() {
|
||||
if (( "${#@}" > 1 )); then
|
||||
echo "$@" | cut --delimiter=" " --fields="2-"
|
||||
drop 1 "$@"
|
||||
}
|
||||
|
||||
function drop() {
|
||||
if (( 1 == "$#" )); then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if (( "$#" < 1 )); then
|
||||
return 1
|
||||
fi
|
||||
|
||||
shift $(( 1 + $1 ))
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
@@ -86,6 +101,8 @@ function usage() {
|
||||
}
|
||||
|
||||
args=("$@")
|
||||
|
||||
function main() {
|
||||
# remove command from arg list while preserving quoted strings.
|
||||
args=("${args[@]:1}")
|
||||
|
||||
@@ -93,13 +110,13 @@ if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
||||
|
||||
for command in "${!commands[@]}"; do
|
||||
if [[ "$1" == "${command}" ]]; then
|
||||
if [[ "$(first $(rest ${commands[$1]}))" == "POST" ]]; then
|
||||
curl -sS "${headers[@]}" -X "$(first $(rest ${commands[$1]}))" "${base_url}$(first "${commands[$1]}")" -d "$(printf "$(rest $(rest ${commands[$1]}))\n" "${args[@]}")"
|
||||
if [[ "$(second ${commands[$1]})" == "POST" ]]; then
|
||||
curl -sS "${headers[@]}" -X "$(second ${commands[$1]})" "${base_url}$(first "${commands[$1]}")" -d "$(printf "$(rest $(rest ${commands[$1]}))\n" "${args[@]}")"
|
||||
echo ""
|
||||
elif [[ "$(first $(rest ${commands[$1]}))" == "FUNC" ]]; then
|
||||
elif [[ "$(second ${commands[$1]})" == "FUNC" ]]; then
|
||||
eval "$(first ${commands[$1]})"
|
||||
else
|
||||
curl -sS "${headers[@]}" -X "$(first $(rest ${commands[$1]}))" "${base_url}$(first "${commands[$1]}")"
|
||||
curl -sS "${headers[@]}" -X "$(second ${commands[$1]})" "${base_url}$(first "${commands[$1]}")"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
@@ -110,3 +127,9 @@ done
|
||||
printf "${0}: invalid option -- $1\n"
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
if [[ "$(basename "$0")" == "mc" ]]; then
|
||||
main "${args[@]}"
|
||||
fi
|
||||
|
@@ -13,12 +13,6 @@ function assert() {
|
||||
return 1
|
||||
}
|
||||
|
||||
function test_assert() {
|
||||
local string="one two three four"
|
||||
assert "$(rest ${string})" "$(rest ${string})"
|
||||
}
|
||||
test_assert
|
||||
|
||||
function first_func_returns_first_item() {
|
||||
local string="one two three four"
|
||||
assert "$(first ${string})" "one"
|
||||
|
Reference in New Issue
Block a user