#compdef clyde

autoload -U is-at-least

_clyde() {
    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[@]}" \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_clyde_commands" \
"*::: :->clyde" \
&& ret=0
    case $state in
    (clyde)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:clyde-command-$line[1]:"
        case $line[1] in
            (setup)
_arguments "${_arguments_options[@]}" \
'--url=[URL of the Git repository to use for the store]:STORE_URL: ' \
'-u[Update the activation scripts of an existing installation]' \
'--update-scripts[Update the activation scripts of an existing installation]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(install)
_arguments "${_arguments_options[@]}" \
'-r[Uninstall then reinstall already installed packages]' \
'--reinstall[Uninstall then reinstall already installed packages]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::package_names -- Application name, optionally suffixed with @version:' \
&& ret=0
;;
(uninstall)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
'*::package_names -- Application name:' \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" \
'-l[List application files instead of showing information]' \
'--list[List application files instead of showing information]' \
'-j[Use JSON output]' \
'--json[Use JSON output]' \
'-h[Print help]' \
'--help[Print help]' \
':package_name -- Application name:' \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
':query -- Search query:' \
&& ret=0
;;
(doc)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
':package_name -- Application name:' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" \
'-j[Use JSON output]' \
'--json[Use JSON output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(upgrade)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
":: :_clyde__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:clyde-help-command-$line[1]:"
        case $line[1] in
            (setup)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(install)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(uninstall)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" \
&& ret=0
;;
(doc)
_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
}

(( $+functions[_clyde_commands] )) ||
_clyde_commands() {
    local commands; commands=(
'setup:Setup Clyde' \
'update:Update Clyde store' \
'install:Install applications' \
'uninstall:Uninstall applications (alias\: remove)' \
'show:Show details about an application' \
'search:Search for available applications' \
'doc:Read documentation files provided by an application' \
'list:List installed applications' \
'upgrade:Upgrade all installed applications, enforcing pinning' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'clyde commands' commands "$@"
}
(( $+functions[_clyde__doc_commands] )) ||
_clyde__doc_commands() {
    local commands; commands=()
    _describe -t commands 'clyde doc commands' commands "$@"
}
(( $+functions[_clyde__help__doc_commands] )) ||
_clyde__help__doc_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help doc commands' commands "$@"
}
(( $+functions[_clyde__help_commands] )) ||
_clyde__help_commands() {
    local commands; commands=(
'setup:Setup Clyde' \
'update:Update Clyde store' \
'install:Install applications' \
'uninstall:Uninstall applications (alias\: remove)' \
'show:Show details about an application' \
'search:Search for available applications' \
'doc:Read documentation files provided by an application' \
'list:List installed applications' \
'upgrade:Upgrade all installed applications, enforcing pinning' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'clyde help commands' commands "$@"
}
(( $+functions[_clyde__help__help_commands] )) ||
_clyde__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help help commands' commands "$@"
}
(( $+functions[_clyde__help__install_commands] )) ||
_clyde__help__install_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help install commands' commands "$@"
}
(( $+functions[_clyde__install_commands] )) ||
_clyde__install_commands() {
    local commands; commands=()
    _describe -t commands 'clyde install commands' commands "$@"
}
(( $+functions[_clyde__help__list_commands] )) ||
_clyde__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help list commands' commands "$@"
}
(( $+functions[_clyde__list_commands] )) ||
_clyde__list_commands() {
    local commands; commands=()
    _describe -t commands 'clyde list commands' commands "$@"
}
(( $+functions[_clyde__help__search_commands] )) ||
_clyde__help__search_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help search commands' commands "$@"
}
(( $+functions[_clyde__search_commands] )) ||
_clyde__search_commands() {
    local commands; commands=()
    _describe -t commands 'clyde search commands' commands "$@"
}
(( $+functions[_clyde__help__setup_commands] )) ||
_clyde__help__setup_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help setup commands' commands "$@"
}
(( $+functions[_clyde__setup_commands] )) ||
_clyde__setup_commands() {
    local commands; commands=()
    _describe -t commands 'clyde setup commands' commands "$@"
}
(( $+functions[_clyde__help__show_commands] )) ||
_clyde__help__show_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help show commands' commands "$@"
}
(( $+functions[_clyde__show_commands] )) ||
_clyde__show_commands() {
    local commands; commands=()
    _describe -t commands 'clyde show commands' commands "$@"
}
(( $+functions[_clyde__help__uninstall_commands] )) ||
_clyde__help__uninstall_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help uninstall commands' commands "$@"
}
(( $+functions[_clyde__uninstall_commands] )) ||
_clyde__uninstall_commands() {
    local commands; commands=()
    _describe -t commands 'clyde uninstall commands' commands "$@"
}
(( $+functions[_clyde__help__update_commands] )) ||
_clyde__help__update_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help update commands' commands "$@"
}
(( $+functions[_clyde__update_commands] )) ||
_clyde__update_commands() {
    local commands; commands=()
    _describe -t commands 'clyde update commands' commands "$@"
}
(( $+functions[_clyde__help__upgrade_commands] )) ||
_clyde__help__upgrade_commands() {
    local commands; commands=()
    _describe -t commands 'clyde help upgrade commands' commands "$@"
}
(( $+functions[_clyde__upgrade_commands] )) ||
_clyde__upgrade_commands() {
    local commands; commands=()
    _describe -t commands 'clyde upgrade commands' commands "$@"
}

if [ "$funcstack[1]" = "_clyde" ]; then
    _clyde "$@"
else
    compdef _clyde clyde
fi
