#compdef arc

autoload -U is-at-least

_arc() {
    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]' \
":: :_arc_commands" \
"*::: :->arc" \
&& ret=0
    case $state in
    (arc)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:arc-command-$line[1]:"
        case $line[1] in
            (install)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':app_id:_default' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':app_id:_default' \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':query:_default' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(refresh-cache)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_arc__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:arc-help-command-$line[1]:"
        case $line[1] in
            (install)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(refresh-cache)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_arc_commands] )) ||
_arc_commands() {
    local commands; commands=(
'install:' \
'remove:' \
'update:' \
'search:' \
'list:' \
'refresh-cache:' \
'completions:Print shell completion script' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'arc commands' commands "$@"
}
(( $+functions[_arc__subcmd__completions_commands] )) ||
_arc__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'arc completions commands' commands "$@"
}
(( $+functions[_arc__subcmd__help_commands] )) ||
_arc__subcmd__help_commands() {
    local commands; commands=(
'install:' \
'remove:' \
'update:' \
'search:' \
'list:' \
'refresh-cache:' \
'completions:Print shell completion script' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'arc help commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__completions_commands] )) ||
_arc__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'arc help completions commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__help_commands] )) ||
_arc__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'arc help help commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__install_commands] )) ||
_arc__subcmd__help__subcmd__install_commands() {
    local commands; commands=()
    _describe -t commands 'arc help install commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__list_commands] )) ||
_arc__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'arc help list commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__refresh-cache_commands] )) ||
_arc__subcmd__help__subcmd__refresh-cache_commands() {
    local commands; commands=()
    _describe -t commands 'arc help refresh-cache commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__remove_commands] )) ||
_arc__subcmd__help__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'arc help remove commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__search_commands] )) ||
_arc__subcmd__help__subcmd__search_commands() {
    local commands; commands=()
    _describe -t commands 'arc help search commands' commands "$@"
}
(( $+functions[_arc__subcmd__help__subcmd__update_commands] )) ||
_arc__subcmd__help__subcmd__update_commands() {
    local commands; commands=()
    _describe -t commands 'arc help update commands' commands "$@"
}
(( $+functions[_arc__subcmd__install_commands] )) ||
_arc__subcmd__install_commands() {
    local commands; commands=()
    _describe -t commands 'arc install commands' commands "$@"
}
(( $+functions[_arc__subcmd__list_commands] )) ||
_arc__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'arc list commands' commands "$@"
}
(( $+functions[_arc__subcmd__refresh-cache_commands] )) ||
_arc__subcmd__refresh-cache_commands() {
    local commands; commands=()
    _describe -t commands 'arc refresh-cache commands' commands "$@"
}
(( $+functions[_arc__subcmd__remove_commands] )) ||
_arc__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'arc remove commands' commands "$@"
}
(( $+functions[_arc__subcmd__search_commands] )) ||
_arc__subcmd__search_commands() {
    local commands; commands=()
    _describe -t commands 'arc search commands' commands "$@"
}
(( $+functions[_arc__subcmd__update_commands] )) ||
_arc__subcmd__update_commands() {
    local commands; commands=()
    _describe -t commands 'arc update commands' commands "$@"
}

if [ "$funcstack[1]" = "_arc" ]; then
    _arc "$@"
else
    compdef _arc arc
fi
