_rqbit() {
    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="rqbit"
                ;;
            rqbit,completions)
                cmd="rqbit__completions"
                ;;
            rqbit,download)
                cmd="rqbit__download"
                ;;
            rqbit,help)
                cmd="rqbit__help"
                ;;
            rqbit,server)
                cmd="rqbit__server"
                ;;
            rqbit__help,completions)
                cmd="rqbit__help__completions"
                ;;
            rqbit__help,download)
                cmd="rqbit__help__download"
                ;;
            rqbit__help,help)
                cmd="rqbit__help__help"
                ;;
            rqbit__help,server)
                cmd="rqbit__help__server"
                ;;
            rqbit__help__server,start)
                cmd="rqbit__help__server__start"
                ;;
            rqbit__server,help)
                cmd="rqbit__server__help"
                ;;
            rqbit__server,start)
                cmd="rqbit__server__start"
                ;;
            rqbit__server__help,help)
                cmd="rqbit__server__help__help"
                ;;
            rqbit__server__help,start)
                cmd="rqbit__server__help__start"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        rqbit)
            opts="-v -i -s -t -h -V --log-file --log-file-rust-log --tracker-refresh-interval --http-api-listen-addr --single-thread-runtime --disable-dht --disable-dht-persistence --peer-connect-timeout --peer-read-write-timeout --worker-threads --disable-tcp-listen --tcp-min-port --tcp-max-port --disable-upnp-port-forward --enable-upnp-server --upnp-server-friendly-name --max-blocking-threads --defer-writes-up-to --experimental-mmap-storage --socks-url --concurrent-init-limit --umask --ratelimit-download --ratelimit-upload --blocklist-url --trackers-filename --help --version server download completions help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                -v)
                    COMPREPLY=($(compgen -W "trace debug info warn error" -- "${cur}"))
                    return 0
                    ;;
                --log-file)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --log-file-rust-log)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --tracker-refresh-interval)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -i)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --http-api-listen-addr)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --peer-connect-timeout)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --peer-read-write-timeout)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --worker-threads)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -t)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --tcp-min-port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --tcp-max-port)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --upnp-server-friendly-name)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --max-blocking-threads)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --defer-writes-up-to)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --socks-url)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --concurrent-init-limit)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --umask)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --ratelimit-download)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --ratelimit-upload)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --blocklist-url)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --trackers-filename)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__completions)
            opts="-h --help bash elvish fish powershell zsh"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__download)
            opts="-o -s -r -l -e -h --output-folder --sub-folder --filename-re --list --overwrite --exit-on-finish --disable-trackers --initial-peers --server-url --help [TORRENT_PATH]..."
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --output-folder)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -o)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --sub-folder)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --filename-re)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -r)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --initial-peers)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --server-url)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help)
            opts="server download completions help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help__completions)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help__download)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help__help)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help__server)
            opts="start"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__help__server__start)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__server)
            opts="-h --help start help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__server__help)
            opts="start help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__server__help__help)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__server__help__start)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        rqbit__server__start)
            opts="-h --disable-persistence --persistence-location --fastresume --watch-folder --help <OUTPUT_FOLDER>"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --persistence-location)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --watch-folder)
                    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 _rqbit -o nosort -o bashdefault -o default rqbit
else
    complete -F _rqbit -o bashdefault -o default rqbit
fi
