#compdef sping

autoload -U is-at-least

_sping() {
    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[@]}" : \
'-I+[Network interface to bind to (e.g., eth0)]:INTERFACE:_default' \
'--interface=[Network interface to bind to (e.g., eth0)]:INTERFACE:_default' \
'-S+[Source IP address to use]:SOURCE:_default' \
'--source=[Source IP address to use]:SOURCE:_default' \
'-i+[Probe interval in milliseconds]:INTERVAL_MS:_default' \
'--interval-ms=[Probe interval in milliseconds]:INTERVAL_MS:_default' \
'-W+[Per-probe timeout in seconds]:TIMEOUT:_default' \
'--timeout=[Per-probe timeout in seconds]:TIMEOUT:_default' \
'-s+[ICMP payload size in bytes (default 56)]:PAYLOAD_SIZE:_default' \
'--size=[ICMP payload size in bytes (default 56)]:PAYLOAD_SIZE:_default' \
'(-s --size)--tcp=[Probe with a TCP connect to PORT instead of ICMP\: works without ICMP permission and through ICMP filters]:PORT:_default' \
'-t+[IP TTL / IPv6 hop limit for outgoing probes]:TTL:_default' \
'--ttl=[IP TTL / IPv6 hop limit for outgoing probes]:TTL:_default' \
'-c+[Stop after sending N probes (any view; default in batch mode\: 10)]:COUNT:_default' \
'--count=[Stop after sending N probes (any view; default in batch mode\: 10)]:COUNT:_default' \
'-v+[Output view; several targets are shown as the table]:VIEW:(compact extended classic json table)' \
'--view=[Output view; several targets are shown as the table]:VIEW:(compact extended classic json table)' \
'-b+[Batch mode\: read targets from file (one per line)]:BATCH:_default' \
'--batch=[Batch mode\: read targets from file (one per line)]:BATCH:_default' \
'-o+[Output file (batch mode, default\: stdout)]:OUTPUT:_default' \
'--output=[Output file (batch mode, default\: stdout)]:OUTPUT:_default' \
'--wan-probe=[WAN reference probe for diagnostics]:WAN_PROBE:_default' \
'--external=[With --ip\: ask a STUN server over UDP (default stun.cloudflare.com\:3478) which address and port it sees each family come from; at most 3 requests per family within 3 s. It contacts that third party, so only when given]::SERVER[:PORT]:_default' \
'(--tcp)--icmp[Probe with an ICMP echo, what sping does without it until 2.0 changes the default\: keeps this probe for scripts (--diagnose keeps its extra probes)]' \
'-q[Quiet\: suppress per-probe lines, print only the final summary (classic view)]' \
'--quiet[Quiet\: suppress per-probe lines, print only the final summary (classic view)]' \
'(-6)-4[Force IPv4 resolution]' \
'-6[Force IPv6 resolution]' \
'--diagnose[Experimental\: when the target stops answering, find out why (the other address family, TCP 443 and 80, a bounded traceroute) and show what was found. One target only]' \
'--ascii[ASCII-only output (no Unicode glyphs); automatic on non-UTF-8 locales and on the legacy Windows console. SPING_ASCII=0 forces Unicode]' \
'--list-interfaces[List available network interfaces and exit (IPv4; see --ip for every address)]' \
'(-b --batch --diagnose --tcp --list-interfaces)--ip[Show this host'\''s addresses (every interface, IPv4 and IPv6, with prefix, kind and state), the source each family uses and the IPv4 gateway, then exit; --view json for scripts. Sends nothing unless --external]' \
'--debug[Enable debug logging]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::targets -- Target host(s) — IP or hostname; an IPv6 link-local address needs its zone (fe80\:\:1%eth0). Multiple targets enable dashboard mode:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_sping" ]; then
    _sping "$@"
else
    compdef _sping sping
fi
