#compdef xh

autoload -U is-at-least

_xh() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'--raw=[Pass raw request data without extra processing]:RAW: ' \
'--pretty=[Controls output processing]:STYLE:((all\:"(default) Enable both coloring and formatting"
colors\:"Apply syntax highlighting to output"
format\:"Pretty-print json and sort headers"
none\:"Disable both coloring and formatting"))' \
'*--format-options=[Set output formatting options]:FORMAT_OPTIONS: ' \
'-s+[Output coloring style]:THEME:(auto solarized monokai fruity)' \
'--style=[Output coloring style]:THEME:(auto solarized monokai fruity)' \
'--response-charset=[Override the response encoding for terminal display purposes]:ENCODING: ' \
'--response-mime=[Override the response mime type for coloring and formatting for the terminal]:MIME_TYPE: ' \
'-p+[String specifying what the output should contain]:FORMAT: ' \
'--print=[String specifying what the output should contain]:FORMAT: ' \
'-P+[The same as --print but applies only to intermediary requests/responses]:FORMAT: ' \
'--history-print=[The same as --print but applies only to intermediary requests/responses]:FORMAT: ' \
'-o+[Save output to FILE instead of stdout]:FILE:_files' \
'--output=[Save output to FILE instead of stdout]:FILE:_files' \
'--session=[Create, or reuse and update a session]:FILE: ' \
'(--session)--session-read-only=[Create or read a session without updating it form the request/response exchange]:FILE: ' \
'-A+[Specify the auth mechanism]:AUTH_TYPE:(basic bearer digest)' \
'--auth-type=[Specify the auth mechanism]:AUTH_TYPE:(basic bearer digest)' \
'-a+[Authenticate as USER with PASS (-A basic|digest) or with TOKEN (-A bearer)]:USER[:PASS] | TOKEN: ' \
'--auth=[Authenticate as USER with PASS (-A basic|digest) or with TOKEN (-A bearer)]:USER[:PASS] | TOKEN: ' \
'--bearer=[Authenticate with a bearer token]:TOKEN: ' \
'--max-redirects=[Number of redirects to follow. Only respected if --follow is used]:NUM: ' \
'--timeout=[Connection timeout of the request]:SEC: ' \
'*--proxy=[Use a proxy for a protocol. For example\: --proxy https\:http\://proxy.host\:8080]:PROTOCOL:URL: ' \
'--verify=[If "no", skip SSL verification. If a file path, use it as a CA bundle]:VERIFY: ' \
'--cert=[Use a client side certificate for SSL]:FILE:_files' \
'--cert-key=[A private key file to use with --cert]:FILE:_files' \
'--ssl=[Force a particular TLS version]:VERSION:(auto tls1 tls1.1 tls1.2 tls1.3)' \
'--default-scheme=[The default scheme to use if not specified in the URL]:SCHEME: ' \
'--http-version=[HTTP version to use]:VERSION:(1.0 1.1 2 2-prior-knowledge)' \
'*--resolve=[Override DNS resolution for specific domain to a custom IP]:HOST:ADDRESS: ' \
'--interface=[Bind to a network interface or local IP address]:NAME: ' \
'-j[(default) Serialize data items from the command line as a JSON object]' \
'--json[(default) Serialize data items from the command line as a JSON object]' \
'-f[Serialize data items from the command line as form fields]' \
'--form[Serialize data items from the command line as form fields]' \
'(--raw)--multipart[Like --form, but force a multipart/form-data request even without files]' \
'-h[Print only the response headers. Shortcut for --print=h]' \
'--headers[Print only the response headers. Shortcut for --print=h]' \
'-b[Print only the response body. Shortcut for --print=b]' \
'--body[Print only the response body. Shortcut for --print=b]' \
'-m[Print only the response metadata. Shortcut for --print=m]' \
'--meta[Print only the response metadata. Shortcut for --print=m]' \
'*-v[Print the whole request as well as the response]' \
'*--verbose[Print the whole request as well as the response]' \
'--debug[Print full error stack traces and debug log messages]' \
'--all[Show any intermediary requests/responses while following redirects with --follow]' \
'*-q[Do not print to stdout or stderr]' \
'*--quiet[Do not print to stdout or stderr]' \
'-S[Always stream the response body]' \
'--stream[Always stream the response body]' \
'-d[Download the body to a file instead of printing it]' \
'--download[Download the body to a file instead of printing it]' \
'-c[Resume an interrupted download. Requires --download and --output]' \
'--continue[Resume an interrupted download. Requires --download and --output]' \
'--ignore-netrc[Do not use credentials from .netrc]' \
'--offline[Construct HTTP requests without sending them anywhere]' \
'--check-status[(default) Exit with an error status code if the server replies with an error]' \
'-F[Do follow redirects]' \
'--follow[Do follow redirects]' \
'--native-tls[Use the system TLS library instead of rustls (if enabled at compile time)]' \
'--https[Make HTTPS requests if not specified in the URL]' \
'-4[Resolve hostname to ipv4 addresses only]' \
'--ipv4[Resolve hostname to ipv4 addresses only]' \
'-6[Resolve hostname to ipv6 addresses only]' \
'--ipv6[Resolve hostname to ipv6 addresses only]' \
'-I[Do not attempt to read stdin]' \
'--ignore-stdin[Do not attempt to read stdin]' \
'--curl[Print a translation to a curl command]' \
'--curl-long[Use the long versions of curl'\''s flags]' \
'--help[Print help]' \
'--no-json[]' \
'--no-form[]' \
'--no-multipart[]' \
'--no-raw[]' \
'--no-pretty[]' \
'--no-format-options[]' \
'--no-style[]' \
'--no-response-charset[]' \
'--no-response-mime[]' \
'--no-print[]' \
'--no-headers[]' \
'--no-body[]' \
'--no-meta[]' \
'--no-verbose[]' \
'--no-debug[]' \
'--no-all[]' \
'--no-history-print[]' \
'--no-quiet[]' \
'--no-stream[]' \
'--no-output[]' \
'--no-download[]' \
'--no-continue[]' \
'--no-session[]' \
'--no-session-read-only[]' \
'--no-auth-type[]' \
'--no-auth[]' \
'--no-bearer[]' \
'--no-ignore-netrc[]' \
'--no-offline[]' \
'--no-check-status[]' \
'--no-follow[]' \
'--no-max-redirects[]' \
'--no-timeout[]' \
'--no-proxy[]' \
'--no-verify[]' \
'--no-cert[]' \
'--no-cert-key[]' \
'--no-ssl[]' \
'--no-native-tls[]' \
'--no-default-scheme[]' \
'--no-https[]' \
'--no-http-version[]' \
'--no-resolve[]' \
'--no-interface[]' \
'--no-ipv4[]' \
'--no-ipv6[]' \
'--no-ignore-stdin[]' \
'--no-curl[]' \
'--no-curl-long[]' \
'--no-help[]' \
'-V[Print version]' \
'--version[Print version]' \
':raw_method_or_url -- The request URL, preceded by an optional HTTP method:' \
'*::raw_rest_args -- Optional key-value pairs to be included in the request.:' \
&& ret=0
}

(( $+functions[_xh_commands] )) ||
_xh_commands() {
    local commands; commands=()
    _describe -t commands 'xh commands' commands "$@"
}

if [ "$funcstack[1]" = "_xh" ]; then
    _xh "$@"
else
    compdef _xh xh
fi
