diff options
-rwxr-xr-x | rest-run | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -17,6 +17,7 @@ Positional arguments: You must provide the API URL. An HTTP verb preceding it is accepted if present. Options: + -x|--method HTTP Method -b|--body Request body source, must be one of the following options: default - create a request body using the default editor last - use the last request @@ -121,6 +122,7 @@ while (( "$#" )); do -b|--body) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_body=$2 && shift 2 || opt-fail $1 ;; -r|--response) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_response=$2 && shift 2 || opt-fail $1 ;; -h|--header) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_headers+=("$2") && shift 2 || opt-fail $1 ;; + -x|--method) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_method="$2" && shift 2 || opt-fail $1 ;; -*|--*=) fail "Unkown option $1" ;; *) PARAMS="$PARAMS $1" && shift ;; esac @@ -139,17 +141,18 @@ IFS=' ' read -r -a ARGS <<< "$PARAMS" if [[ ${#ARGS[@]} -gt 1 ]]; then rest_method="${ARGS[0]}" - case "$rest_method" in - POST|post);; - GET|get);; - PUT|put);; - PATCH|patch);; - DELETE|delete);; - *) fail "Invalid HTTP Verb $rest_method" ;; - esac unset 'ARGS[0]' fi +case "$rest_method" in + POST|post);; + GET|get);; + PUT|put);; + PATCH|patch);; + DELETE|delete);; + *) fail "Invalid HTTP Verb $rest_method" ;; +esac + [[ -z "$PARAMS" || "${#PARAMS}" = "1" ]] && fail "Not enough params" rest_url="${ARGS[*]}" |