#compdef ya

autoload -U is-at-least

_ya() {
    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[Print version]' \
'--version[Print version]' \
'-h[Print help]' \
'--help[Print help]' \
":: :_ya_commands" \
"*::: :->Ya" \
&& ret=0
    case $state in
    (Ya)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ya-command-$line[1]:"
        case $line[1] in
            (emit)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name -- Name of the command:_default' \
'*::args -- Arguments of the command:_default' \
&& ret=0
;;
(emit-to)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':receiver -- Receiver ID:_default' \
':name -- Name of the command:_default' \
'*::args -- Arguments of the command:_default' \
&& ret=0
;;
(pkg)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
":: :_ya__pkg_commands" \
"*::: :->pkg" \
&& ret=0

    case $state in
    (pkg)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ya-pkg-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::ids -- Packages to add:_default' \
&& ret=0
;;
(delete)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::ids -- Packages to delete:_default' \
&& ret=0
;;
(install)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(upgrade)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::ids -- Packages to upgrade, upgrade all if unspecified:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_ya__pkg__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ya-pkg-help-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(delete)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(install)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(upgrade)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
;;
(pub)
_arguments "${_arguments_options[@]}" : \
'--str=[Send the message with a string body]:STR:_default' \
'--json=[Send the message with a JSON body]:JSON:_default' \
'*--list=[Send the message as a list of strings]' \
'-h[Print help]' \
'--help[Print help]' \
':kind -- Kind of message:_default' \
&& ret=0
;;
(pub-to)
_arguments "${_arguments_options[@]}" : \
'--str=[Send the message with a string body]:STR:_default' \
'--json=[Send the message with a JSON body]:JSON:_default' \
'*--list=[Send the message as a list of strings]' \
'-h[Print help]' \
'--help[Print help]' \
':receiver -- Receiver ID:_default' \
':kind -- Kind of message:_default' \
&& ret=0
;;
(sub)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':kinds -- Kind of messages to subscribe to, separated by commas if multiple:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_ya__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ya-help-command-$line[1]:"
        case $line[1] in
            (emit)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(emit-to)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(pkg)
_arguments "${_arguments_options[@]}" : \
":: :_ya__help__pkg_commands" \
"*::: :->pkg" \
&& ret=0

    case $state in
    (pkg)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:ya-help-pkg-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(delete)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(install)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(upgrade)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
(pub)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(pub-to)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(sub)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_ya_commands] )) ||
_ya_commands() {
    local commands; commands=(
'emit:Emit a command to be executed by the current instance' \
'emit-to:Emit a command to be executed by the specified instance' \
'pkg:Manage packages' \
'pub:Publish a message to the current instance' \
'pub-to:Publish a message to the specified instance' \
'sub:Subscribe to messages from all remote instances' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ya commands' commands "$@"
}
(( $+functions[_ya__emit_commands] )) ||
_ya__emit_commands() {
    local commands; commands=()
    _describe -t commands 'ya emit commands' commands "$@"
}
(( $+functions[_ya__emit-to_commands] )) ||
_ya__emit-to_commands() {
    local commands; commands=()
    _describe -t commands 'ya emit-to commands' commands "$@"
}
(( $+functions[_ya__help_commands] )) ||
_ya__help_commands() {
    local commands; commands=(
'emit:Emit a command to be executed by the current instance' \
'emit-to:Emit a command to be executed by the specified instance' \
'pkg:Manage packages' \
'pub:Publish a message to the current instance' \
'pub-to:Publish a message to the specified instance' \
'sub:Subscribe to messages from all remote instances' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ya help commands' commands "$@"
}
(( $+functions[_ya__help__emit_commands] )) ||
_ya__help__emit_commands() {
    local commands; commands=()
    _describe -t commands 'ya help emit commands' commands "$@"
}
(( $+functions[_ya__help__emit-to_commands] )) ||
_ya__help__emit-to_commands() {
    local commands; commands=()
    _describe -t commands 'ya help emit-to commands' commands "$@"
}
(( $+functions[_ya__help__help_commands] )) ||
_ya__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'ya help help commands' commands "$@"
}
(( $+functions[_ya__help__pkg_commands] )) ||
_ya__help__pkg_commands() {
    local commands; commands=(
'add:Add packages' \
'delete:Delete packages' \
'install:Install all packages' \
'list:List all packages' \
'upgrade:Upgrade all packages' \
    )
    _describe -t commands 'ya help pkg commands' commands "$@"
}
(( $+functions[_ya__help__pkg__add_commands] )) ||
_ya__help__pkg__add_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pkg add commands' commands "$@"
}
(( $+functions[_ya__help__pkg__delete_commands] )) ||
_ya__help__pkg__delete_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pkg delete commands' commands "$@"
}
(( $+functions[_ya__help__pkg__install_commands] )) ||
_ya__help__pkg__install_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pkg install commands' commands "$@"
}
(( $+functions[_ya__help__pkg__list_commands] )) ||
_ya__help__pkg__list_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pkg list commands' commands "$@"
}
(( $+functions[_ya__help__pkg__upgrade_commands] )) ||
_ya__help__pkg__upgrade_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pkg upgrade commands' commands "$@"
}
(( $+functions[_ya__help__pub_commands] )) ||
_ya__help__pub_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pub commands' commands "$@"
}
(( $+functions[_ya__help__pub-to_commands] )) ||
_ya__help__pub-to_commands() {
    local commands; commands=()
    _describe -t commands 'ya help pub-to commands' commands "$@"
}
(( $+functions[_ya__help__sub_commands] )) ||
_ya__help__sub_commands() {
    local commands; commands=()
    _describe -t commands 'ya help sub commands' commands "$@"
}
(( $+functions[_ya__pkg_commands] )) ||
_ya__pkg_commands() {
    local commands; commands=(
'add:Add packages' \
'delete:Delete packages' \
'install:Install all packages' \
'list:List all packages' \
'upgrade:Upgrade all packages' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ya pkg commands' commands "$@"
}
(( $+functions[_ya__pkg__add_commands] )) ||
_ya__pkg__add_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg add commands' commands "$@"
}
(( $+functions[_ya__pkg__delete_commands] )) ||
_ya__pkg__delete_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg delete commands' commands "$@"
}
(( $+functions[_ya__pkg__help_commands] )) ||
_ya__pkg__help_commands() {
    local commands; commands=(
'add:Add packages' \
'delete:Delete packages' \
'install:Install all packages' \
'list:List all packages' \
'upgrade:Upgrade all packages' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'ya pkg help commands' commands "$@"
}
(( $+functions[_ya__pkg__help__add_commands] )) ||
_ya__pkg__help__add_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help add commands' commands "$@"
}
(( $+functions[_ya__pkg__help__delete_commands] )) ||
_ya__pkg__help__delete_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help delete commands' commands "$@"
}
(( $+functions[_ya__pkg__help__help_commands] )) ||
_ya__pkg__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help help commands' commands "$@"
}
(( $+functions[_ya__pkg__help__install_commands] )) ||
_ya__pkg__help__install_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help install commands' commands "$@"
}
(( $+functions[_ya__pkg__help__list_commands] )) ||
_ya__pkg__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help list commands' commands "$@"
}
(( $+functions[_ya__pkg__help__upgrade_commands] )) ||
_ya__pkg__help__upgrade_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg help upgrade commands' commands "$@"
}
(( $+functions[_ya__pkg__install_commands] )) ||
_ya__pkg__install_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg install commands' commands "$@"
}
(( $+functions[_ya__pkg__list_commands] )) ||
_ya__pkg__list_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg list commands' commands "$@"
}
(( $+functions[_ya__pkg__upgrade_commands] )) ||
_ya__pkg__upgrade_commands() {
    local commands; commands=()
    _describe -t commands 'ya pkg upgrade commands' commands "$@"
}
(( $+functions[_ya__pub_commands] )) ||
_ya__pub_commands() {
    local commands; commands=()
    _describe -t commands 'ya pub commands' commands "$@"
}
(( $+functions[_ya__pub-to_commands] )) ||
_ya__pub-to_commands() {
    local commands; commands=()
    _describe -t commands 'ya pub-to commands' commands "$@"
}
(( $+functions[_ya__sub_commands] )) ||
_ya__sub_commands() {
    local commands; commands=()
    _describe -t commands 'ya sub commands' commands "$@"
}

if [ "$funcstack[1]" = "_ya" ]; then
    _ya "$@"
else
    compdef _ya ya
fi
