#compdef trip

autoload -U is-at-least

_trip() {
    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[@]}" \
'-c+[Config file]:CONFIG_FILE:_files' \
'--config-file=[Config file]:CONFIG_FILE:_files' \
'-m+[Output mode \[default\: tui\]]:MODE:((tui\:"Display interactive TUI"
stream\:"Display a continuous stream of tracing data"
pretty\:"Generate an pretty text table report for N cycles"
markdown\:"Generate a markdown text table report for N cycles"
csv\:"Generate a CSV report for N cycles"
json\:"Generate a JSON report for N cycles"
dot\:"Generate a Graphviz DOT file for N cycles"
flows\:"Display all flows"
silent\:"Do not generate any tracing output for N cycles"))' \
'--mode=[Output mode \[default\: tui\]]:MODE:((tui\:"Display interactive TUI"
stream\:"Display a continuous stream of tracing data"
pretty\:"Generate an pretty text table report for N cycles"
markdown\:"Generate a markdown text table report for N cycles"
csv\:"Generate a CSV report for N cycles"
json\:"Generate a JSON report for N cycles"
dot\:"Generate a Graphviz DOT file for N cycles"
flows\:"Display all flows"
silent\:"Do not generate any tracing output for N cycles"))' \
'-p+[Tracing protocol \[default\: icmp\]]:PROTOCOL:((icmp\:"Internet Control Message Protocol"
udp\:"User Datagram Protocol"
tcp\:"Transmission Control Protocol"))' \
'--protocol=[Tracing protocol \[default\: icmp\]]:PROTOCOL:((icmp\:"Internet Control Message Protocol"
udp\:"User Datagram Protocol"
tcp\:"Transmission Control Protocol"))' \
'-P+[The target port (TCP & UDP only) \[default\: 80\]]:TARGET_PORT: ' \
'--target-port=[The target port (TCP & UDP only) \[default\: 80\]]:TARGET_PORT: ' \
'-S+[The source port (TCP & UDP only) \[default\: auto\]]:SOURCE_PORT: ' \
'--source-port=[The source port (TCP & UDP only) \[default\: auto\]]:SOURCE_PORT: ' \
'(-I --interface)-A+[The source IP address \[default\: auto\]]:SOURCE_ADDRESS: ' \
'(-I --interface)--source-address=[The source IP address \[default\: auto\]]:SOURCE_ADDRESS: ' \
'-I+[The network interface \[default\: auto\]]:INTERFACE: ' \
'--interface=[The network interface \[default\: auto\]]:INTERFACE: ' \
'-i+[The minimum duration of every round \[default\: 1s\]]:MIN_ROUND_DURATION: ' \
'--min-round-duration=[The minimum duration of every round \[default\: 1s\]]:MIN_ROUND_DURATION: ' \
'-T+[The maximum duration of every round \[default\: 1s\]]:MAX_ROUND_DURATION: ' \
'--max-round-duration=[The maximum duration of every round \[default\: 1s\]]:MAX_ROUND_DURATION: ' \
'-g+[The period of time to wait for additional ICMP responses after the target has responded \[default\: 100ms\]]:GRACE_DURATION: ' \
'--grace-duration=[The period of time to wait for additional ICMP responses after the target has responded \[default\: 100ms\]]:GRACE_DURATION: ' \
'--initial-sequence=[The initial sequence number \[default\: 33000\]]:INITIAL_SEQUENCE: ' \
'-R+[The Equal-cost Multi-Path routing strategy (UDP only) \[default\: classic\]]:MULTIPATH_STRATEGY:((classic\:"The src or dest port is used to store the sequence number"
paris\:"The UDP \`checksum\` field is used to store the sequence number"
dublin\:"The IP \`identifier\` field is used to store the sequence number"))' \
'--multipath-strategy=[The Equal-cost Multi-Path routing strategy (UDP only) \[default\: classic\]]:MULTIPATH_STRATEGY:((classic\:"The src or dest port is used to store the sequence number"
paris\:"The UDP \`checksum\` field is used to store the sequence number"
dublin\:"The IP \`identifier\` field is used to store the sequence number"))' \
'-U+[The maximum number of in-flight ICMP echo requests \[default\: 24\]]:MAX_INFLIGHT: ' \
'--max-inflight=[The maximum number of in-flight ICMP echo requests \[default\: 24\]]:MAX_INFLIGHT: ' \
'-f+[The TTL to start from \[default\: 1\]]:FIRST_TTL: ' \
'--first-ttl=[The TTL to start from \[default\: 1\]]:FIRST_TTL: ' \
'-t+[The maximum number of TTL hops \[default\: 64\]]:MAX_TTL: ' \
'--max-ttl=[The maximum number of TTL hops \[default\: 64\]]:MAX_TTL: ' \
'--packet-size=[The size of IP packet to send (IP header + ICMP header + payload) \[default\: 84\]]:PACKET_SIZE: ' \
'--payload-pattern=[The repeating pattern in the payload of the ICMP packet \[default\: 0\]]:PAYLOAD_PATTERN: ' \
'-Q+[The TOS (i.e. DSCP+ECN) IP header value (TCP and UDP only) \[default\: 0\]]:TOS: ' \
'--tos=[The TOS (i.e. DSCP+ECN) IP header value (TCP and UDP only) \[default\: 0\]]:TOS: ' \
'--read-timeout=[The socket read timeout \[default\: 10ms\]]:READ_TIMEOUT: ' \
'-r+[How to perform DNS queries \[default\: system\]]:DNS_RESOLVE_METHOD:((system\:"Resolve using the OS resolver"
resolv\:"Resolve using the \`/etc/resolv.conf\` DNS configuration"
google\:"Resolve using the Google \`8.8.8.8\` DNS service"
cloudflare\:"Resolve using the Cloudflare \`1.1.1.1\` DNS service"))' \
'--dns-resolve-method=[How to perform DNS queries \[default\: system\]]:DNS_RESOLVE_METHOD:((system\:"Resolve using the OS resolver"
resolv\:"Resolve using the \`/etc/resolv.conf\` DNS configuration"
google\:"Resolve using the Google \`8.8.8.8\` DNS service"
cloudflare\:"Resolve using the Cloudflare \`1.1.1.1\` DNS service"))' \
'--dns-timeout=[The maximum time to wait to perform DNS queries \[default\: 5s\]]:DNS_TIMEOUT: ' \
'-a+[How to render addresses \[default\: host\]]:TUI_ADDRESS_MODE:((ip\:"Show IP address only"
host\:"Show reverse-lookup DNS hostname only"
both\:"Show both IP address and reverse-lookup DNS hostname"))' \
'--tui-address-mode=[How to render addresses \[default\: host\]]:TUI_ADDRESS_MODE:((ip\:"Show IP address only"
host\:"Show reverse-lookup DNS hostname only"
both\:"Show both IP address and reverse-lookup DNS hostname"))' \
'--tui-as-mode=[How to render AS information \[default\: asn\]]:TUI_AS_MODE:((asn\:"Show the ASN"
prefix\:"Display the AS prefix"
country-code\:"Display the country code"
registry\:"Display the registry name"
allocated\:"Display the allocated date"
name\:"Display the AS name"))' \
'--tui-icmp-extension-mode=[How to render ICMP extensions \[default\: off\]]:TUI_ICMP_EXTENSION_MODE:((off\:"Do not show \`icmp\` extensions"
mpls\:"Show MPLS label(s) only"
full\:"Show full \`icmp\` extension data for all known extensions"
all\:"Show full \`icmp\` extension data for all classes"))' \
'--tui-geoip-mode=[How to render GeoIp information \[default\: short\]]:TUI_GEOIP_MODE:((off\:"Do not display GeoIp data"
short\:"Show short format"
long\:"Show long format"
location\:"Show latitude and Longitude format"))' \
'-M+[The maximum number of addresses to show per hop \[default\: auto\]]:TUI_MAX_ADDRS: ' \
'--tui-max-addrs=[The maximum number of addresses to show per hop \[default\: auto\]]:TUI_MAX_ADDRS: ' \
'-s+[The maximum number of samples to record per hop \[default\: 256\]]:TUI_MAX_SAMPLES: ' \
'--tui-max-samples=[The maximum number of samples to record per hop \[default\: 256\]]:TUI_MAX_SAMPLES: ' \
'--tui-max-flows=[The maximum number of flows to show \[default\: 64\]]:TUI_MAX_FLOWS: ' \
'--tui-refresh-rate=[The Tui refresh rate \[default\: 100ms\]]:TUI_REFRESH_RATE: ' \
'--tui-privacy-max-ttl=[The maximum ttl of hops which will be masked for privacy \[default\: 0\]]:TUI_PRIVACY_MAX_TTL: ' \
'*--tui-theme-colors=[The TUI theme colors \[item=color,item=color,..\]]:TUI_THEME_COLORS: ' \
'*--tui-key-bindings=[The TUI key bindings \[command=key,command=key,..\]]:TUI_KEY_BINDINGS: ' \
'-C+[The number of report cycles to run \[default\: 10\]]:REPORT_CYCLES: ' \
'--report-cycles=[The number of report cycles to run \[default\: 10\]]:REPORT_CYCLES: ' \
'-G+[The MaxMind City GeoLite2 mmdb file]:GEOIP_MMDB_FILE:_files' \
'--geoip-mmdb-file=[The MaxMind City GeoLite2 mmdb file]:GEOIP_MMDB_FILE:_files' \
'--generate=[Generate shell completion]:GENERATE:(bash elvish fish powershell zsh)' \
'--log-format=[The debug log format \[default\: pretty\]]:LOG_FORMAT:((compact\:"Display log data in a compact format"
pretty\:"Display log data in a pretty format"
json\:"Display log data in a json format"
chrome\:"Display log data in Chrome trace format"))' \
'--log-filter=[The debug log filter \[default\: trippy=debug\]]:LOG_FILTER: ' \
'--log-span-events=[The debug log format \[default\: off\]]:LOG_SPAN_EVENTS:((off\:"Do not display event spans"
active\:"Display enter and exit event spans"
full\:"Display all event spans"))' \
'-u[Trace without requiring elevated privileges on supported platforms \[default\: false\]]' \
'--unprivileged[Trace without requiring elevated privileges on supported platforms \[default\: false\]]' \
'(-p --protocol --tcp --icmp)--udp[Trace using the UDP protocol]' \
'(-p --protocol --udp --icmp)--tcp[Trace using the TCP protocol]' \
'(-p --protocol --udp --tcp)--icmp[Trace using the ICMP protocol]' \
'(-6 --ipv6)-4[Use IPv4 only]' \
'(-6 --ipv6)--ipv4[Use IPv4 only]' \
'(-4 --ipv4)-6[Use IPv6 only]' \
'(-4 --ipv4)--ipv6[Use IPv6 only]' \
'-e[Parse ICMP extensions]' \
'--icmp-extensions[Parse ICMP extensions]' \
'-y[Trace to all IPs resolved from DNS lookup \[default\: false\]]' \
'--dns-resolve-all[Trace to all IPs resolved from DNS lookup \[default\: false\]]' \
'-z[Lookup autonomous system (AS) information during DNS queries \[default\: false\]]' \
'--dns-lookup-as-info[Lookup autonomous system (AS) information during DNS queries \[default\: false\]]' \
'--tui-preserve-screen[Preserve the screen on exit \[default\: false\]]' \
'--print-tui-theme-items[Print all TUI theme items and exit]' \
'--print-tui-binding-commands[Print all TUI commands that can be bound and exit]' \
'--print-config-template[Print a template toml config file and exit]' \
'-v[Enable verbose debug logging]' \
'--verbose[Enable verbose debug logging]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'*::targets -- A space delimited list of hostnames and IPs to trace:' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_trip" ]; then
    _trip "$@"
else
    compdef _trip trip
fi
