update
This commit is contained in:
37
mc
37
mc
@@ -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,6 +101,8 @@ function usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args=("$@")
|
args=("$@")
|
||||||
|
|
||||||
|
function main() {
|
||||||
# remove command from arg list while preserving quoted strings.
|
# remove command from arg list while preserving quoted strings.
|
||||||
args=("${args[@]:1}")
|
args=("${args[@]:1}")
|
||||||
|
|
||||||
@@ -93,13 +110,13 @@ if [[ ! $(which jq) ]]; then echo "jq is required"; exit 1; fi
|
|||||||
|
|
||||||
for command in "${!commands[@]}"; do
|
for command in "${!commands[@]}"; do
|
||||||
if [[ "$1" == "${command}" ]]; then
|
if [[ "$1" == "${command}" ]]; then
|
||||||
if [[ "$(first $(rest ${commands[$1]}))" == "POST" ]]; then
|
if [[ "$(second ${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[@]}")"
|
curl -sS "${headers[@]}" -X "$(second ${commands[$1]})" "${base_url}$(first "${commands[$1]}")" -d "$(printf "$(rest $(rest ${commands[$1]}))\n" "${args[@]}")"
|
||||||
echo ""
|
echo ""
|
||||||
elif [[ "$(first $(rest ${commands[$1]}))" == "FUNC" ]]; then
|
elif [[ "$(second ${commands[$1]})" == "FUNC" ]]; then
|
||||||
eval "$(first ${commands[$1]})"
|
eval "$(first ${commands[$1]})"
|
||||||
else
|
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 ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -110,3 +127,9 @@ done
|
|||||||
printf "${0}: invalid option -- $1\n"
|
printf "${0}: invalid option -- $1\n"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "$(basename "$0")" == "mc" ]]; then
|
||||||
|
main "${args[@]}"
|
||||||
|
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