#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' \
'--peer-connect-timeout=[The connect timeout, e.g. 1s, 1.5s, 100ms etc]:PEER_CONNECT_TIMEOUT:_default' \
'--peer-read-write-timeout=[The connect timeout, e.g. 1s, 1.5s, 100ms etc]:PEER_READ_WRITE_TIMEOUT:_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' \
'--tcp-min-port=[The minimal port to listen for incoming connections]:TCP_LISTEN_MIN_PORT:_default' \
'--tcp-max-port=[The maximal port to listen for incoming connections]:TCP_LISTEN_MAX_PORT:_default' \
'--upnp-server-friendly-name=[UPNP server name that would be displayed on devices in your network]:UPNP_SERVER_FRIENDLY_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' \
'--defer-writes-up-to=[]:DEFER_WRITES_UP_TO:_default' \
'--socks-url=[Provide a socks5 URL. 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 to bytes-per-second]:RATELIMIT_DOWNLOAD_BPS:_default' \
'--ratelimit-upload=[Limit upload to bytes-per-second]:RATELIMIT_UPLOAD_BPS:_default' \
'--blocklist-url=[Downloads a p2p blocklist from this url and blocks peers from it]:BLOCKLIST_URL:_default' \
'--trackers-filename=[The filename with tracker URLs to always use for each torrent]:TRACKERS_FILENAME:_default' \
'-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-upnp-port-forward[If set, will try to publish the chosen port through upnp on your router]' \
'--enable-upnp-server[If set, will run a UPNP Media server and stream all the torrents through it. Should be set to your hostname/IP as seen by your LAN neighbors]' \
'--experimental-mmap-storage[Use mmap (file-backed) for storage. Any advantages are questionable and unproven. If you use it, you know what you are doing]' \
'-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__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__server__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
;;
(download)
_arguments "${_arguments_options[@]}" : \
'-o+[The output folder to write to. If not exists, it will be created. If not specified, would use the server'\''s output folder. If there'\''s no server running, this is required]:OUTPUT_FOLDER:_default' \
'--output-folder=[The output folder to write to. If not exists, it will be created. If not specified, would use the server'\''s output folder. If there'\''s no server running, this is required]: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=[]:INITIAL_PEERS:_default' \
'--server-url=[]:SERVER_URL:_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-trackers[]' \
'-h[Print help]' \
'--help[Print 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__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__help__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
;;
(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:' \
'download:' \
'completions:' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit commands' commands "$@"
}
(( $+functions[_rqbit__completions_commands] )) ||
_rqbit__completions_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit completions commands' commands "$@"
}
(( $+functions[_rqbit__download_commands] )) ||
_rqbit__download_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit download commands' commands "$@"
}
(( $+functions[_rqbit__help_commands] )) ||
_rqbit__help_commands() {
    local commands; commands=(
'server:' \
'download:' \
'completions:' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit help commands' commands "$@"
}
(( $+functions[_rqbit__help__completions_commands] )) ||
_rqbit__help__completions_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help completions commands' commands "$@"
}
(( $+functions[_rqbit__help__download_commands] )) ||
_rqbit__help__download_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help download commands' commands "$@"
}
(( $+functions[_rqbit__help__help_commands] )) ||
_rqbit__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help help commands' commands "$@"
}
(( $+functions[_rqbit__help__server_commands] )) ||
_rqbit__help__server_commands() {
    local commands; commands=(
'start:' \
    )
    _describe -t commands 'rqbit help server commands' commands "$@"
}
(( $+functions[_rqbit__help__server__start_commands] )) ||
_rqbit__help__server__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit help server start commands' commands "$@"
}
(( $+functions[_rqbit__server_commands] )) ||
_rqbit__server_commands() {
    local commands; commands=(
'start:' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit server commands' commands "$@"
}
(( $+functions[_rqbit__server__help_commands] )) ||
_rqbit__server__help_commands() {
    local commands; commands=(
'start:' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rqbit server help commands' commands "$@"
}
(( $+functions[_rqbit__server__help__help_commands] )) ||
_rqbit__server__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server help help commands' commands "$@"
}
(( $+functions[_rqbit__server__help__start_commands] )) ||
_rqbit__server__help__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server help start commands' commands "$@"
}
(( $+functions[_rqbit__server__start_commands] )) ||
_rqbit__server__start_commands() {
    local commands; commands=()
    _describe -t commands 'rqbit server start commands' commands "$@"
}

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