_rustnet() {
    local i cur prev opts cmd
    COMPREPLY=()
    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
        cur="$2"
    else
        cur="${COMP_WORDS[COMP_CWORD]}"
    fi
    prev="$3"
    cmd=""
    opts=""

    for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="rustnet"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        rustnet)
            opts="-i -r -l -f -h -V --interface --no-localhost --show-localhost --refresh-interval --no-dpi --log-level --json-log --pcap-export --bpf-filter --no-resolve-dns --show-ptr-lookups --no-color --theme --geoip-country --geoip-asn --geoip-city --no-geoip --no-sandbox --sandbox-strict --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --interface)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -i)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --refresh-interval)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -r)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --log-level)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -l)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --json-log)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pcap-export)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --bpf-filter)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -f)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --theme)
                    COMPREPLY=($(compgen -W "muted classic" -- "${cur}"))
                    return 0
                    ;;
                --geoip-country)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --geoip-asn)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --geoip-city)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -F _rustnet -o nosort -o bashdefault -o default rustnet
else
    complete -F _rustnet -o bashdefault -o default rustnet
fi
