#compdef porthole

autoload -U is-at-least

_porthole() {
    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[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_porthole_commands" \
"*::: :->porthole" \
&& ret=0
    case $state in
    (porthole)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:porthole-command-$line[1]:"
        case $line[1] in
            (open)
_arguments "${_arguments_options[@]}" : \
'--proto=[Protocol\: tcp or udp]:PROTO:_default' \
'(--until-reboot)--for=[How long to keep it open\: 15m, 1h, 4h. Maximum 8h. Defaults to 1h]:duration:_default' \
'--to=[Who to open towards\: subnet, any, a CIDR, an IP address, or the name of a device saved with \`porthole devices add\`]:TO:_default' \
'--until-reboot[Keep it open until the machine reboots]' \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
':port -- Port to open, 1-65535:_default' \
&& ret=0
;;
(forward)
_arguments "${_arguments_options[@]}" : \
'--as=[The port the local network connects to. Defaults to the port being forwarded]:PORT:_default' \
'--for=[How long to keep it open\: 15m, 1h, 4h. Maximum 8h. Defaults to 1h]:DURATION:_default' \
'--to=[Who to forward towards\: subnet, any, a CIDR, an IP address, or the name of a device saved with \`porthole devices add\`]:TO:_default' \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':port -- The port to forward, as `porthole listen` shows it\: the one Docker published on this machine:_default' \
&& ret=0
;;
(close)
_arguments "${_arguments_options[@]}" : \
'--proto=[Protocol of the port to close]:PROTO:_default' \
'(--all)--id=[Close the rule with this id, as shown by \`porthole list --json\`]:ID:_default' \
'(--id)--all[Close every port porthole has open]' \
'--from-timer[Set when the expiry timer invokes the close. Not for humans]' \
'--forget[Drop the record of a rule without touching any firewall]' \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'::port -- Port to close:_default' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(listen)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(devices)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
":: :_porthole__subcmd__devices_commands" \
"*::: :->devices" \
&& ret=0

    case $state in
    (devices)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:porthole-devices-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(rm)
_arguments "${_arguments_options[@]}" : \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help]' \
'--help[Print help]' \
':name -- The device'\''s name, as shown by `devices list`:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_porthole__subcmd__devices__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:porthole-devices-help-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rm)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(update)
_arguments "${_arguments_options[@]}" : \
'(--disable)--enable[Let porthole ask the local package manager, once a day, whether a newer porthole is available. Nothing leaves this machine]' \
'--disable[Stop the daily check. \`porthole update\` on its own still answers when you ask it]' \
'--json[Print machine-readable JSON instead of text]' \
'--dry-run[Show what would happen without changing anything. Needs no privileges, except for \`forward\`\: that one reads Docker'\''s own rules itself, which needs root, and exits 10 without it]' \
'--session[Talk to a helper on the session bus instead of the system bus. For tests\: the real helper serves the system bus]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_porthole__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:porthole-help-command-$line[1]:"
        case $line[1] in
            (open)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(forward)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(close)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(listen)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(devices)
_arguments "${_arguments_options[@]}" : \
":: :_porthole__subcmd__help__subcmd__devices_commands" \
"*::: :->devices" \
&& ret=0

    case $state in
    (devices)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:porthole-help-devices-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rm)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
(update)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_porthole_commands] )) ||
_porthole_commands() {
    local commands; commands=(
'open:Open a port towards the local network' \
'forward:Redirect a port to a Docker container published only on this machine, so the local network can reach it for a bounded time' \
'close:Close a port porthole opened' \
'list:List the ports porthole currently has open' \
'status:Show the firewall backend, the current network, and what is open' \
'doctor:Diagnose why porthole is not working\: firewall, helper, polkit, network, Docker, and IPv6' \
'listen:List TCP services listening on this machine, so you can pick a port instead of typing one. Marks loopback-only services separately (opening the firewall for those changes nothing) from ones reachable only over IPv6 (porthole manages IPv4 rules only, and can neither open nor close those)' \
'devices:Manage saved devices, so \`--to <name>\` can open towards one instead of typing its address by hand' \
'update:Say whether a newer porthole is available, and turn the daily check on or off' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'porthole commands' commands "$@"
}
(( $+functions[_porthole__subcmd__close_commands] )) ||
_porthole__subcmd__close_commands() {
    local commands; commands=()
    _describe -t commands 'porthole close commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices_commands] )) ||
_porthole__subcmd__devices_commands() {
    local commands; commands=(
'list:List saved devices and whether each resolves on this network right now' \
'add:Save a device, picked from the machines currently seen on this network' \
'rm:Forget a saved device' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'porthole devices commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__add_commands] )) ||
_porthole__subcmd__devices__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices add commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__help_commands] )) ||
_porthole__subcmd__devices__subcmd__help_commands() {
    local commands; commands=(
'list:List saved devices and whether each resolves on this network right now' \
'add:Save a device, picked from the machines currently seen on this network' \
'rm:Forget a saved device' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'porthole devices help commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__help__subcmd__add_commands] )) ||
_porthole__subcmd__devices__subcmd__help__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices help add commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__help__subcmd__help_commands] )) ||
_porthole__subcmd__devices__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices help help commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__help__subcmd__list_commands] )) ||
_porthole__subcmd__devices__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices help list commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__help__subcmd__rm_commands] )) ||
_porthole__subcmd__devices__subcmd__help__subcmd__rm_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices help rm commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__list_commands] )) ||
_porthole__subcmd__devices__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices list commands' commands "$@"
}
(( $+functions[_porthole__subcmd__devices__subcmd__rm_commands] )) ||
_porthole__subcmd__devices__subcmd__rm_commands() {
    local commands; commands=()
    _describe -t commands 'porthole devices rm commands' commands "$@"
}
(( $+functions[_porthole__subcmd__doctor_commands] )) ||
_porthole__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'porthole doctor commands' commands "$@"
}
(( $+functions[_porthole__subcmd__forward_commands] )) ||
_porthole__subcmd__forward_commands() {
    local commands; commands=()
    _describe -t commands 'porthole forward commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help_commands] )) ||
_porthole__subcmd__help_commands() {
    local commands; commands=(
'open:Open a port towards the local network' \
'forward:Redirect a port to a Docker container published only on this machine, so the local network can reach it for a bounded time' \
'close:Close a port porthole opened' \
'list:List the ports porthole currently has open' \
'status:Show the firewall backend, the current network, and what is open' \
'doctor:Diagnose why porthole is not working\: firewall, helper, polkit, network, Docker, and IPv6' \
'listen:List TCP services listening on this machine, so you can pick a port instead of typing one. Marks loopback-only services separately (opening the firewall for those changes nothing) from ones reachable only over IPv6 (porthole manages IPv4 rules only, and can neither open nor close those)' \
'devices:Manage saved devices, so \`--to <name>\` can open towards one instead of typing its address by hand' \
'update:Say whether a newer porthole is available, and turn the daily check on or off' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'porthole help commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__close_commands] )) ||
_porthole__subcmd__help__subcmd__close_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help close commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__devices_commands] )) ||
_porthole__subcmd__help__subcmd__devices_commands() {
    local commands; commands=(
'list:List saved devices and whether each resolves on this network right now' \
'add:Save a device, picked from the machines currently seen on this network' \
'rm:Forget a saved device' \
    )
    _describe -t commands 'porthole help devices commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__devices__subcmd__add_commands] )) ||
_porthole__subcmd__help__subcmd__devices__subcmd__add_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help devices add commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__devices__subcmd__list_commands] )) ||
_porthole__subcmd__help__subcmd__devices__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help devices list commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__devices__subcmd__rm_commands] )) ||
_porthole__subcmd__help__subcmd__devices__subcmd__rm_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help devices rm commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__doctor_commands] )) ||
_porthole__subcmd__help__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help doctor commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__forward_commands] )) ||
_porthole__subcmd__help__subcmd__forward_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help forward commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__help_commands] )) ||
_porthole__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help help commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__list_commands] )) ||
_porthole__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help list commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__listen_commands] )) ||
_porthole__subcmd__help__subcmd__listen_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help listen commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__open_commands] )) ||
_porthole__subcmd__help__subcmd__open_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help open commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__status_commands] )) ||
_porthole__subcmd__help__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help status commands' commands "$@"
}
(( $+functions[_porthole__subcmd__help__subcmd__update_commands] )) ||
_porthole__subcmd__help__subcmd__update_commands() {
    local commands; commands=()
    _describe -t commands 'porthole help update commands' commands "$@"
}
(( $+functions[_porthole__subcmd__list_commands] )) ||
_porthole__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'porthole list commands' commands "$@"
}
(( $+functions[_porthole__subcmd__listen_commands] )) ||
_porthole__subcmd__listen_commands() {
    local commands; commands=()
    _describe -t commands 'porthole listen commands' commands "$@"
}
(( $+functions[_porthole__subcmd__open_commands] )) ||
_porthole__subcmd__open_commands() {
    local commands; commands=()
    _describe -t commands 'porthole open commands' commands "$@"
}
(( $+functions[_porthole__subcmd__status_commands] )) ||
_porthole__subcmd__status_commands() {
    local commands; commands=()
    _describe -t commands 'porthole status commands' commands "$@"
}
(( $+functions[_porthole__subcmd__update_commands] )) ||
_porthole__subcmd__update_commands() {
    local commands; commands=()
    _describe -t commands 'porthole update commands' commands "$@"
}

if [ "$funcstack[1]" = "_porthole" ]; then
    _porthole "$@"
else
    compdef _porthole porthole
fi
