diff options
author | Jefferson Julio <[email protected]> | 2022-05-15 18:34:34 -0300 |
---|---|---|
committer | Jefferson Julio <[email protected]> | 2022-05-15 18:34:34 -0300 |
commit | c03c8444ee71433c70e7fadf19bc1fd78fe2f78c (patch) | |
tree | ed723fa86651a5618a0e8b4100140231cd01bb9e | |
parent | 339b18db1b5f1d45367640221753bd4085909070 (diff) | |
download | rest-run-c03c8444ee71433c70e7fadf19bc1fd78fe2f78c.tar.bz2 rest-run-c03c8444ee71433c70e7fadf19bc1fd78fe2f78c.zip |
Read response file passed as parameter.
-rwxr-xr-x | rest-run | 62 |
1 files changed, 37 insertions, 25 deletions
@@ -26,28 +26,30 @@ 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 - history - pick from the request history - stdin - reads from piped input - -r|--response Request response handling, must be one of the following options: - default - store the request on cache - last - read last request, skip request - history - pick from the response history, skip request - -ne|--no-edit Skip request editting. Ignored when --body is set to default - -h|--header Header string. Ex: "Authorization: Bearer 123" - -p|--paginate Paginate request response - -e|--extract Only output one part of the response or request, must be one of the following options: - default - whole request and response, headers and body - body - only response body (default when output is piped to another process) - headers - only response headers - rbody - only request body - rheaders - only request headers - --no-metadata Hide request metadata. For now, only "Elapsed time" is hidden by this option. - --no-color Disable ANSI color scape codes. Default when output is piped to another process. - --color Enable ANSI color scape codes, even when output is piped to another process. + -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 + history - pick from the request history + stdin - reads from piped input + -r|--response Request response handling, must be one of the following options: + default - store the request on cache + last - read last request, skip request + history - pick from the response history, skip request + -rr|--read-response Provide a response file from history and read it. + -ne|--no-edit Skip request editting. Ignored when --body is set to default + -h|--header Header string. Ex: "Authorization: Bearer 123" + -p|--paginate Paginate request response + -e|--extract Only output one part of the response or request, must be one of the + following options: + default - whole request and response, headers and body + body - only response body (default when output is piped) + headers - only response headers + rbody - only request body + rheaders - only request headers + --no-metadata Hide request metadata. For now, only "Elapsed time" is hidden by this option. + --no-color Disable ANSI color scape codes. Default when output is piped to another process. + --color Enable ANSI color scape codes, even when output is piped to another process. rest-run parses your request body with a simple template engine called esh. You can embed shell scripts/commands in your request file surrouning it @@ -148,17 +150,17 @@ rest_method="POST" rest_body="default" rest_body_options=("default" "last" "stdin" "history") rest_response="default" -rest_response_options=("default" "history" "last") +rest_response_options=("default" "history" "last" "select") last_request_file="" last_request_file_checksum="" is_new_request=true edit_rest_request=true paginate_response=false ignore_body=false -rest_output_extract=default enable_color=true force_enable_color=false enable_metadata=true +rest_output_extract=default rest_output_extract_options=("default" "body" "headers" "rbody" "rheaders") httpie_print_options="HBhbm" @@ -182,6 +184,7 @@ while (( "$#" )); do -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 ;; -e|--extract) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_output_extract="$2" && shift 2 || opt-fail $1 ;; + -rr|--read-response) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_response_file="$2" && rest_response="select" && shift 2 || opt-fail $1 ;; -*|--*=) fail "Unkown option $1" ;; *) PARAMS="$PARAMS $1" && shift ;; esac @@ -226,7 +229,10 @@ mkdir -p "$CACHE_DIR_CONTEXT_REQUEST" > /dev/null rest_timestamp="$(date +"%s")" rest_request_file="$CACHE_DIR_CONTEXT_REQUEST/request-$rest_timestamp.json" last_request_file="$(find "$CACHE_DIR_CONTEXT_REQUEST" -type f | sort -n | tail -1)" -rest_response_file="$CACHE_DIR_CONTEXT_RESPONSE/response-$rest_timestamp.log" + +if [ ${#rest_response_file} -lt 1 ]; then + rest_response_file="$CACHE_DIR_CONTEXT_RESPONSE/response-$rest_timestamp.log" +fi if ! [[ -z "$last_request_file" || "${#last_request_file}" = "0" ]]; then last_request_file_checksum="$(cat "$last_request_file" | sha1sum | awk '{print $1}')" @@ -242,6 +248,7 @@ fi if ! [ -t 1 ]; then edit_rest_request=false + rest_output_extract="body" [ $force_enable_color = false ] && enable_color=false fi @@ -298,6 +305,11 @@ case "$rest_response" in rm "$tmp_file" exit ;; + select) + rest_response_file="$CACHE_DIR/$rest_response_file" + output-response + exit + ;; esac if [ $ignore_body = false ]; then |