#compdef rqbit

autoload -U is-at-least

_rqbit() {
    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[@]}" : \
'-v+[The console loglevel]:LOG_LEVEL:(trace debug info warn error)' \
'--log-file=[The log filename to also write to in addition to the console]:LOG_FILE:_default' \
'--log-file-rust-log=[The value for RUST_LOG in the log file]:LOG_FILE_RUST_LOG:_default' \
'-i+[The interval to poll trackers, e.g. 30s. Trackers send the refresh interval when we connect to them. Often this is pretty big, e.g. 30 minutes. This can force a certain value]:FORCE_TRACKER_INTERVAL:_default' \
'--tracker-refresh-interval=[The interval to poll trackers, e.g. 30s. Trackers send the refresh interval when we connect to them. Often this is pretty big, e.g. 30 minutes. This can force a certain value]:FORCE_TRACKER_INTERVAL:_default' \
'--http-api-listen-addr=[The listen address for HTTP API]:HTTP_API_LISTEN_ADDR:_default' \
'--http-api-max-upload-size=[Upload body size limit in bytes]:HTTP_API_MAX_UPLOAD_SIZE:_default' \
'--dht-bootstrap-addrs=[Set DHT bootstrap addrs A comma separated list of host\:port or ip\:port]:DHT_BOOTSTRAP_ADDRS:_default' \
'--peer-connect-timeout=[The connect timeout, e.g. 1s, 1.5s, 100ms etc]:PEER_CONNECT_TIMEOUT:_default' \
'--peer-read-write-timeout=[The timeout for read() and write() operations, e.g. 1s, 1.5s, 100ms etc]:PEER_READ_WRITE_TIMEOUT:_default' \
'--peer-limit=[The maximum number of connected peers per torrent]:PEER_LIMIT:_default' \
'-t+[How many threads to spawn for the executor]:WORKER_THREADS:_default' \
'--worker-threads=[How many threads to spawn for the executor]:WORKER_THREADS:_default' \
'--listen-port=[The port to listen for incoming connections (applies to both TCP and uTP)]:LISTEN_PORT:_default' \
'--announce-port=[The port to advertise to trackers and DHT]:ANNOUNCE_PORT:_default' \
'--listen-ip=[What'\''s the IP to listen on. Default is to listen on all interfaces on IPv4 and IPv6]:LISTEN_IP:_default' \
'--upnp-server-friendly-name=[UPnP server name that would be displayed on devices in your network]:UPNP_SERVER_FRIENDLY_NAME:_default' \
'--bind-device=[What network device to bind to for DHT, BT-UDP, BT-TCP, trackers and LSD. On OSX will use IP(V6)_BOUND_IF, on Linux will use SO_BINDTODEVICE]:BIND_DEVICE_NAME:_default' \
'--max-blocking-threads=[How many maximum blocking tokio threads to spawn to process disk reads/writes. This will indicate how many parallel reads/writes can happen at a moment in time. The higher the number, the more the memory usage]:MAX_BLOCKING_THREADS:_default' \
'--socks-url=[If set will use socks5 proxy for all outgoing connections. The format is socks5\://\[username\:password\]@host\:port]:SOCKS_URL:_default' \
'--concurrent-init-limit=[How many torrents can be initializing (rehashing) at the same time]:CONCURRENT_INIT_LIMIT:_default' \
'--umask=[Set the process umask to this value]:UMASK:_default' \
'--ratelimit-download=[Limit download speed to bytes-per-second]:RATELIMIT_DOWNLOAD_BPS:_default' \
'--ratelimit-upload=[Limit upload speed to bytes-per-second]:RATELIMIT_UPLOAD_BPS:_default' \
'--blocklist-url=[Downloads a p2p blocklist from this url and blocks connections from/to those peers. Supports file\:/// and http(s)\:// URLs. Format is newline-delimited "name\:start_ip-end_ip" E.g. https\://github.com/Naunter/BT_BlockLists/raw/refs/heads/master/bt_blocklists.gz]:BLOCKLIST_URL:_default' \
'--allowlist-url=[Downloads a p2p allowlist from this url and blocks ALL connections BUT from/to those peers. Supports file\:/// and http(s)\:// URLs. Format is newline-delimited "name\:start_ip-end_ip" E.g. https\://github.com/Naunter/BT_BlockLists/raw/refs/heads/master/bt_blocklists.gz]:ALLOWLIST_URL:_default' \
'--trackers-filename=[The filename with tracker URLs to always use for each torrent. Newline-delimited]:TRACKERS_FILENAME:_default' \
'--log-file-json[]' \
'--http-api-allow-create[Allow creating torrents via HTTP API]' \
'--enable-mdns[Advertise the HTTP API on the local network via mDNS/DNS-SD, so it can be reached at http\://rqbit.local\:PORT from other devices on your LAN]' \
'-s[Set this flag if you want to use tokio'\''s single threaded runtime. It MAY perform better, but the main purpose is easier debugging, as time profilers work better with this one]' \
'--single-thread-runtime[Set this flag if you want to use tokio'\''s single threaded runtime. It MAY perform better, but the main purpose is easier debugging, as time profilers work better with this one]' \
'--disable-dht[]' \
'--disable-dht-persistence[Set this to disable DHT reading and storing it'\''s state. For now this is a useful workaround if you want to launch multiple rqbit instances, otherwise DHT port will conflict]' \
'--disable-tcp-listen[Disable listening for incoming connections over TCP. Note that outgoing connections can still be made (--disable-tcp-connect to disable)]' \
'--disable-tcp-connect[Disable outgoing connections over TCP. Note that listening over TCP for incoming connections is enabled by default (--disable-tcp-listen to disable)]' \
'--experimental-enable-utp-listen[Enable to listen and connect over uTP]' \
'--disable-upnp-port-forward[By default, rqbit will try to publish LISTEN_PORT through UPnP on your router. This can disable it]' \
'--enable-upnp-server[If set, will run a UPnP Media server on RQBIT_HTTP_API_LISTEN_ADDR]' \
'--ipv4-only[Force IPv4 only]' \
'--disable-lsd[Disable local peer discovery (LSD). By default rqbit will announce torrents to LAN]' \
'--disable-trackers[Disable trackers (for debugging DHT, LSD and --initial-peers)]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_rqbit_commands" \
"*::: :->rqbit" \
&& ret=0
    case $state in
    (rqbit)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rqbit-command-$line[1]:"
        case $line[1] in
            (server)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
":: :_rqbit__subcmd__server_commands" \
"*::: :->server" \
&& ret=0

    case $state in
    (server)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rqbit-server-command-$line[1]:"
        case $line[1] in
            (start)
_arguments "${_arguments_options[@]}" : \
'--persistence-location=[The folder to store session data in. By default uses OS specific folder. If starts with postgres\://, will use postgres as the backend instead of JSON file]:PERSISTENCE_LOCATION:_default' \
'--watch-folder=[The folder to watch for added .torrent files. All files in this folder will be automatically added to the session]:WATCH_FOLDER:_default' \
'--disable-persistence[Disable server persistence. It will not read or write its state to disk.]' \
'--fastresume[\[Experimental\] if set, will try to resume quickly after restart and skip checksumming]' \
'-h[Print help]' \
'--help[Print help]' \
':output_folder -- The output folder to write to. If not exists, it will be created:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_rqbit__subcmd__server__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rqbit-server-help-command-$line[1]:"
        case $line[1] in
            (start)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(share)
_arguments "${_arguments_options[@]}" : \
'-n+[Optional torrent name to use in the torrent file and magnet]:NAME:_default' \
'--name=[Optional torrent name to use in the torrent file and magnet]:NAME:_default' \
'-h[Print help]' \
'--help[Print help]' \
':path -- The path to create and share a torrent from:_default' \
'*::trackers -- Tracker URLs to share to (comma separated). Will append these to trackers from RQBIT_TRACKERS_FILENAME:_default' \
&& ret=0
;;
(download)
_arguments "${_arguments_options[@]}" : \
'-o+[The output folder to write to. Defaults to current folder]:OUTPUT_FOLDER:_default' \
'--output-folder=[The output folder to write to. Defaults to current folder]:OUTPUT_FOLDER:_default' \
'-s+[The sub folder within output folder to write to. Useful when you have a server running with output_folder configured, and don'\''t want to specify the full path every time]:SUB_FOLDER:_default' \
'--sub-folder=[The sub folder within output folder to write to. Useful when you have a server running with output_folder configured, and don'\''t want to specify the full path every time]:SUB_FOLDER:_default' \
'-r+[If set, only the file whose filename matching this regex will be downloaded]:ONLY_FILES_MATCHING_REGEX:_default' \
'--filename-re=[If set, only the file whose filename matching this regex will be downloaded]:ONLY_FILES_MATCHING_REGEX:_default' \
'--initial-peers=[A comma-separated list of initial peers]:INITIAL_PEERS:_default' \
'-l[Only list the torrent metadata contents, don'\''t do anything else]' \
'--list[Only list the torrent metadata contents, don'\''t do anything else]' \
'--overwrite[Set if you are ok to write on top of existing files]' \
'-e[Exit the program once the torrents complete download]' \
'--exit-on-finish[Exit the program once the torrents complete download]' \
'--disable-http-api[Disable HTTP API entirely]' \
'--upnp-port-forward[Forward the listen port through UPnP on your router]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::torrent_path -- The filename or URL of the torrent. If URL, http/https/magnet are supported:_default' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell -- The shell to generate completions for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_rqbit__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rqbit-help-command-$line[1]:"
        case $line[1] in
            (server)
_arguments "${_arguments_options[@]}" : \
":: :_rqbit__subcmd__help__subcmd__server_commands" \
"*::: :->server" \
&& ret=0

    case $state in
    (server)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rqbit-help-server-command-$line[1]:"
        case $line[1] in
            (start)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
(share)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(download)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_rqbit_commands] )) ||
_rqbit_commands() {
    local commands; commands=(
'server:Start rqbit server with HTTP API' \
'share:Create a torrent from a given path and announce it. Stateless' \
'download:Download a single torrent, stateless' \
'completions:Shell completions. eval "\$(rqbit completions bash)"' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__completions_commands] )) ||
_rqbit__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit completions commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__download_commands] )) ||
_rqbit__subcmd__download_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit download commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help_commands] )) ||
_rqbit__subcmd__help_commands() {
    local commands; commands=(
'server:Start rqbit server with HTTP API' \
'share:Create a torrent from a given path and announce it. Stateless' \
'download:Download a single torrent, stateless' \
'completions:Shell completions. eval "\$(rqbit completions bash)"' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit help commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__completions_commands] )) ||
_rqbit__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help completions commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__download_commands] )) ||
_rqbit__subcmd__help__subcmd__download_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help download commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__help_commands] )) ||
_rqbit__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help help commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__server_commands] )) ||
_rqbit__subcmd__help__subcmd__server_commands() {
    local commands; commands=(
'start:Start the server' \
    )
    _describe -t commands 'rqbit help server commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__server__subcmd__start_commands] )) ||
_rqbit__subcmd__help__subcmd__server__subcmd__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help server start commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__help__subcmd__share_commands] )) ||
_rqbit__subcmd__help__subcmd__share_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help share commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__server_commands] )) ||
_rqbit__subcmd__server_commands() {
    local commands; commands=(
'start:Start the server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit server commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__server__subcmd__help_commands] )) ||
_rqbit__subcmd__server__subcmd__help_commands() {
    local commands; commands=(
'start:Start the server' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit server help commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__server__subcmd__help__subcmd__help_commands] )) ||
_rqbit__subcmd__server__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server help help commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__server__subcmd__help__subcmd__start_commands] )) ||
_rqbit__subcmd__server__subcmd__help__subcmd__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server help start commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__server__subcmd__start_commands] )) ||
_rqbit__subcmd__server__subcmd__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server start commands' commands "$@"
}
(( $+functions[_rqbit__subcmd__share_commands] )) ||
_rqbit__subcmd__share_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit share commands' commands "$@"
}

if [ "$funcstack[1]" = "_rqbit" ]; then
    _rqbit "$@"
else
    compdef _rqbit rqbit
fi
