#compdef oha

autoload -U is-at-least

_oha() {
    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[@]}" : \
'--completions=[]:COMPLETIONS:(bash elvish fish powershell zsh)' \
'(-z)-n+[Number of requests to run. Accepts plain numbers or suffixes\: k = 1,000, m = 1,000,000 (e.g. 10k, 1m).]:N_REQUESTS:_default' \
'-c+[Number of connections to run concurrently. You may should increase limit to number of open files for larger \`-c\`.]:N_CONNECTIONS:_default' \
'-p+[Number of parallel requests to send on HTTP/2. \`oha\` will run c * p concurrent workers in total.]:N_HTTP2_PARALLEL:_default' \
'(-n)-z+[Duration of application to send requests. On HTTP/1, When the duration is reached, ongoing requests are aborted and counted as "aborted due to deadline" You can change this behavior with \`-w\` option. Currently, on HTTP/2, When the duration is reached, ongoing requests are waited. \`-w\` option is ignored. Examples\: -z 10s -z 3m.]:DURATION:_default' \
'(--burst-delay --burst-rate)-q+[Rate limit for all, in queries per second (QPS)]:QUERY_PER_SECOND:_default' \
'(-q)--burst-delay=[Introduce delay between a predefined number of requests. Note\: If qps is specified, burst will be ignored]:BURST_DURATION:_default' \
'(-q)--burst-rate=[Rates of requests for burst. Default is 1 Note\: If qps is specified, burst will be ignored]:BURST_REQUESTS:_default' \
'--max-repeat=[A parameter for the '\''--rand-regex-url'\''. The max_repeat parameter gives the maximum extra repeat counts the x*, x+ and x{n,} operators will become.]:MAX_REPEAT:_default' \
'--dump-urls=[Dump target Urls <DUMP_URLS> times to debug --rand-regex-url]:DUMP_URLS:_default' \
'--fps=[Frame per second for tui.]:FPS:_default' \
'-m+[HTTP method]:METHOD:_default' \
'--method=[HTTP method]:METHOD:_default' \
'*-H+[Custom HTTP header. Examples\: -H "foo\: bar"]:HEADERS:_default' \
'*--proxy-header=[Custom Proxy HTTP header. Examples\: --proxy-header "foo\: bar"]:PROXY_HEADERS:_default' \
'-t+[Timeout for each request. Default to infinite.]:TIMEOUT:_default' \
'--connect-timeout=[Timeout for establishing a new connection. Default to 5s.]:CONNECT_TIMEOUT:_default' \
'-A+[HTTP Accept Header.]:ACCEPT_HEADER:_default' \
'(-D -Z -F --form)-d+[HTTP request body.]:BODY_STRING:_default' \
'(-d -Z -F --form)-D+[HTTP request body from file.]:BODY_PATH:_files' \
'(-d -D -F --form)-Z+[HTTP request body from file line by line.]:BODY_PATH_LINES:_files' \
'(-d -D -Z)*-F+[Specify HTTP multipart POST data (curl compatible). Examples\: -F '\''name=value'\'' -F '\''file=@path/to/file'\'']:FORM:_default' \
'(-d -D -Z)*--form=[Specify HTTP multipart POST data (curl compatible). Examples\: -F '\''name=value'\'' -F '\''file=@path/to/file'\'']:FORM:_default' \
'-T+[Content-Type.]:CONTENT_TYPE:_default' \
'-a+[Basic authentication (username\:password), or AWS credentials (access_key\:secret_key)]:BASIC_AUTH:_default' \
'--aws-session=[AWS session token]:AWS_SESSION:_default' \
'--aws-sigv4=[AWS SigV4 signing params (format\: aws\:amz\:region\:service)]:AWS_SIGV4:_default' \
'-x+[HTTP proxy]:PROXY:_default' \
'--proxy-http-version=[HTTP version to connect to proxy. Available values 0.9, 1.0, 1.1, 2.]:PROXY_HTTP_VERSION:_default' \
'--http-version=[HTTP version. Available values 0.9, 1.0, 1.1, 2, 3]:HTTP_VERSION:_default' \
'--host=[HTTP Host header]:HOST:_default' \
'-r+[Limit for number of Redirect. Set 0 for no redirection. Redirection isn'\''t supported for HTTP/2.]:REDIRECT:_default' \
'--redirect=[Limit for number of Redirect. Set 0 for no redirection. Redirection isn'\''t supported for HTTP/2.]:REDIRECT:_default' \
'--cacert=[(TLS) Use the specified certificate file to verify the peer. Native certificate store is used even if this argument is specified.]:CACERT:_files' \
'--cert=[(TLS) Use the specified client certificate file. --key must be also specified]:CERT:_files' \
'--key=[(TLS) Use the specified client key file. --cert must be also specified]:KEY:_files' \
'*--connect-to=[Override DNS resolution and default port numbers with strings like '\''example.org\:443\:localhost\:8443'\'' Note\: if used several times for the same host\:port\:target_host\:target_port, a random choice is made]:CONNECT_TO:_default' \
'--unix-socket=[Connect to a unix socket instead of the domain in the URL. Only for non-HTTPS URLs.]:UNIX_SOCKET:_files' \
'--db-url=[Write succeeded requests to sqlite database url E.G test.db]:DB_URL:_default' \
'-o+[Output file to write the results to. If not specified, results are written to stdout.]:OUTPUT:_files' \
'--output=[Output file to write the results to. If not specified, results are written to stdout.]:OUTPUT:_files' \
'--output-format=[Output format]:OUTPUT_FORMAT:(text json csv quiet)' \
'-u+[Time unit to be used. If not specified, the time unit is determined automatically. This option affects only text format.]:TIME_UNIT:(ns us ms s m h)' \
'--time-unit=[Time unit to be used. If not specified, the time unit is determined automatically. This option affects only text format.]:TIME_UNIT:(ns us ms s m h)' \
'--worker-threads=[Number of native OS threads used by the async runtime (tokio). Defaults to the number of physical CPU cores.]:WORKER_THREADS:_default' \
'-w[When the duration is reached, ongoing requests are waited]' \
'--wait-ongoing-requests-after-deadline[When the duration is reached, ongoing requests are waited]' \
'--rand-regex-url[Generate URL by rand_regex crate but dot is disabled for each query e.g. http\://127.0.0.1/\[a-z\]\[a-z\]\[0-9\]. Currently dynamic scheme, host and port with keep-alive do not work well. See https\://docs.rs/rand_regex/latest/rand_regex/struct.Regex.html for details of syntax.]' \
'--urls-from-file[Read the URLs to query from a file]' \
'--latency-correction[Correct latency to avoid coordinated omission problem. It'\''s ignored if neither -q nor --burst-delay is set.]' \
'--no-tui[No realtime tui]' \
'--proxy-http2[Use HTTP/2 to connect to proxy. Shorthand for --proxy-http-version=2]' \
'--http2[Use HTTP/2. Shorthand for --http-version=2]' \
'--disable-compression[Disable compression.]' \
'--disable-keepalive[Disable keep-alive, prevents re-use of TCP connections between different HTTP requests. This isn'\''t supported for HTTP/2.]' \
'--no-pre-lookup[*Not* perform a DNS lookup at beginning to cache it]' \
'--ipv6[Lookup only ipv6.]' \
'--ipv4[Lookup only ipv4.]' \
'--insecure[Accept invalid certs.]' \
'--no-color[Disable the color scheme.]' \
'--stats-success-breakdown[Include a response status code successful or not successful breakdown for the time histogram and distribution statistics]' \
'--debug[Perform a single request and dump the request and response]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::url -- Target URL or file with multiple URLs.:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_oha" ]; then
    _oha "$@"
else
    compdef _oha oha
fi
