#compdef mqttui

autoload -U is-at-least

_mqttui() {
    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[@]}" \
'-b+[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'--broker=[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'-u+[Username to access the mqtt broker]:STRING:_users' \
'--username=[Username to access the mqtt broker]:STRING:_users' \
'--password=[Password to access the mqtt broker]:STRING:( )' \
'-i+[Specify the client id to connect with]:STRING:( )' \
'--client-id=[Specify the client id to connect with]:STRING:( )' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'--insecure[Allow insecure TLS connections]' \
'::topic -- Topic to watch:( )' \
":: :_mqttui_commands" \
"*::: :->MQTT TUI" \
&& ret=0
    case $state in
    (MQTT TUI)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:mqttui-command-$line[2]:"
        case $line[2] in
            (clean-retained)
_arguments "${_arguments_options[@]}" \
'--timeout=[When there is no message received for the given time the operation is considered done]:SECONDS:( )' \
'-b+[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'--broker=[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'-u+[Username to access the mqtt broker]:STRING:_users' \
'--username=[Username to access the mqtt broker]:STRING:_users' \
'--password=[Password to access the mqtt broker]:STRING:( )' \
'-i+[Specify the client id to connect with]:STRING:( )' \
'--client-id=[Specify the client id to connect with]:STRING:( )' \
'--dry-run[Dont clean topics, only log them]' \
'-h[Print help information]' \
'--help[Print help information]' \
'--insecure[Allow insecure TLS connections]' \
':topic -- Topic which gets cleaned:( )' \
&& ret=0
;;
(log)
_arguments "${_arguments_options[@]}" \
'-b+[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'--broker=[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'-u+[Username to access the mqtt broker]:STRING:_users' \
'--username=[Username to access the mqtt broker]:STRING:_users' \
'--password=[Password to access the mqtt broker]:STRING:( )' \
'-i+[Specify the client id to connect with]:STRING:( )' \
'--client-id=[Specify the client id to connect with]:STRING:( )' \
'-v[Show full MQTT communication]' \
'--verbose[Show full MQTT communication]' \
'-h[Print help information]' \
'--help[Print help information]' \
'--insecure[Allow insecure TLS connections]' \
'*::topic -- Topics to watch:( )' \
&& ret=0
;;
(publish)
_arguments "${_arguments_options[@]}" \
'-b+[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'--broker=[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'-u+[Username to access the mqtt broker]:STRING:_users' \
'--username=[Username to access the mqtt broker]:STRING:_users' \
'--password=[Password to access the mqtt broker]:STRING:( )' \
'-i+[Specify the client id to connect with]:STRING:( )' \
'--client-id=[Specify the client id to connect with]:STRING:( )' \
'-r[Publish the MQTT message retained]' \
'--retain[Publish the MQTT message retained]' \
'-v[Show full MQTT communication]' \
'--verbose[Show full MQTT communication]' \
'-h[Print help information]' \
'--help[Print help information]' \
'--insecure[Allow insecure TLS connections]' \
':topic -- Topic to publish to:( )' \
':payload -- Payload to be published:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-b+[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'--broker=[URL which represents how to connect to the MQTT broker]:URL:_urls' \
'-u+[Username to access the mqtt broker]:STRING:_users' \
'--username=[Username to access the mqtt broker]:STRING:_users' \
'--password=[Password to access the mqtt broker]:STRING:( )' \
'-i+[Specify the client id to connect with]:STRING:( )' \
'--client-id=[Specify the client id to connect with]:STRING:( )' \
'--insecure[Allow insecure TLS connections]' \
'*::subcommand -- The subcommand whose help message to display:' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_mqttui_commands] )) ||
_mqttui_commands() {
    local commands; commands=(
'clean-retained:Clean retained messages from the broker' \
'c:Clean retained messages from the broker' \
'clean:Clean retained messages from the broker' \
'log:Log values from subscribed topics to stdout' \
'l:Log values from subscribed topics to stdout' \
'publish:Publish a value quickly' \
'p:Publish a value quickly' \
'pub:Publish a value quickly' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'mqttui commands' commands "$@"
}
(( $+functions[_mqttui__clean-retained_commands] )) ||
_mqttui__clean-retained_commands() {
    local commands; commands=()
    _describe -t commands 'mqttui clean-retained commands' commands "$@"
}
(( $+functions[_mqttui__help_commands] )) ||
_mqttui__help_commands() {
    local commands; commands=()
    _describe -t commands 'mqttui help commands' commands "$@"
}
(( $+functions[_mqttui__log_commands] )) ||
_mqttui__log_commands() {
    local commands; commands=()
    _describe -t commands 'mqttui log commands' commands "$@"
}
(( $+functions[_mqttui__publish_commands] )) ||
_mqttui__publish_commands() {
    local commands; commands=()
    _describe -t commands 'mqttui publish commands' commands "$@"
}

_mqttui "$@"
