#compdef pkgsite

autoload -U is-at-least

_pkgsite() {
    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]' \
":: :_pkgsite_commands" \
"*::: :->pkgsite-tools" \
&& ret=0
    case $state in
    (pkgsite-tools)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:pkgsite-command-$line[1]:"
        case $line[1] in
            (depends)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(dep)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(rdepends)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(rdep)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(info)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::packages:_default' \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
'-s[]' \
'--search-only[]' \
'--no-redir[]' \
'-h[Print help]' \
'--help[Print help]' \
':pattern:_default' \
&& ret=0
;;
(updates)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(files)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':arch:_default' \
':repo:_default' \
':package:_default' \
':version:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_pkgsite__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:pkgsite-help-command-$line[1]:"
        case $line[1] in
            (depends)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(rdepends)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(updates)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(files)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_pkgsite_commands] )) ||
_pkgsite_commands() {
    local commands; commands=(
'depends:Query dependencies of packages' \
'dep:Query dependencies of packages' \
'rdepends:Query reverse dependencies of packages' \
'rdep:Query reverse dependencies of packages' \
'show:Get package information' \
'info:Get package information' \
'search:Search for packages' \
'updates:List 100 latest source updates' \
'files:List files for a package' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'pkgsite commands' commands "$@"
}
(( $+functions[_pkgsite__depends_commands] )) ||
_pkgsite__depends_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite depends commands' commands "$@"
}
(( $+functions[_pkgsite__files_commands] )) ||
_pkgsite__files_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite files commands' commands "$@"
}
(( $+functions[_pkgsite__help_commands] )) ||
_pkgsite__help_commands() {
    local commands; commands=(
'depends:Query dependencies of packages' \
'rdepends:Query reverse dependencies of packages' \
'show:Get package information' \
'search:Search for packages' \
'updates:List 100 latest source updates' \
'files:List files for a package' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'pkgsite help commands' commands "$@"
}
(( $+functions[_pkgsite__help__depends_commands] )) ||
_pkgsite__help__depends_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help depends commands' commands "$@"
}
(( $+functions[_pkgsite__help__files_commands] )) ||
_pkgsite__help__files_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help files commands' commands "$@"
}
(( $+functions[_pkgsite__help__help_commands] )) ||
_pkgsite__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help help commands' commands "$@"
}
(( $+functions[_pkgsite__help__rdepends_commands] )) ||
_pkgsite__help__rdepends_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help rdepends commands' commands "$@"
}
(( $+functions[_pkgsite__help__search_commands] )) ||
_pkgsite__help__search_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help search commands' commands "$@"
}
(( $+functions[_pkgsite__help__show_commands] )) ||
_pkgsite__help__show_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help show commands' commands "$@"
}
(( $+functions[_pkgsite__help__updates_commands] )) ||
_pkgsite__help__updates_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite help updates commands' commands "$@"
}
(( $+functions[_pkgsite__rdepends_commands] )) ||
_pkgsite__rdepends_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite rdepends commands' commands "$@"
}
(( $+functions[_pkgsite__search_commands] )) ||
_pkgsite__search_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite search commands' commands "$@"
}
(( $+functions[_pkgsite__show_commands] )) ||
_pkgsite__show_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite show commands' commands "$@"
}
(( $+functions[_pkgsite__updates_commands] )) ||
_pkgsite__updates_commands() {
    local commands; commands=()
    _describe -t commands 'pkgsite updates commands' commands "$@"
}

if [ "$funcstack[1]" = "_pkgsite" ]; then
    _pkgsite "$@"
else
    compdef _pkgsite pkgsite
fi
