#compdef rolr

__rolr_all_roles() {
    local roles=("${(@f)$(rolr complete -qqq all-roles)}")
    _describe -t roles 'role' roles "$@"
}

__rolr_inactive_roles() {
    local roles=("${(@f)$(rolr complete -qqq inactive-roles)}")
    _describe -t roles 'role' roles "$@"
}

# everything below was generated by clap_complete
# with minor modifications to add role completions
# and hide the "complete" subcommand

autoload -U is-at-least

_rolr() {
    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[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_rolr_commands" \
"*::: :->rolr" \
&& ret=0
    case $state in
    (rolr)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rolr-command-$line[1]:"
        case $line[1] in
            (add)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::roles:__rolr_inactive_roles' \
&& ret=0
;;
(select)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(list)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::roles:__rolr_all_roles' \
&& ret=0
;;
(complete)
_arguments "${_arguments_options[@]}" : \
'*-v[Increase logging verbosity]' \
'*--verbose[Increase logging verbosity]' \
'(-v --verbose)*-q[Decrease logging verbosity]' \
'(-v --verbose)*--quiet[Decrease logging verbosity]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':kind:(all-roles active-roles inactive-roles)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_rolr__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_rolr_commands] )) ||
_rolr_commands() {
    local commands; commands=(
'add:Activate roles' \
'select:Activate roles in a TUI menu' \
'update:Update all active roles' \
'list:List available roles' \
'run:Run roles without activating them' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rolr commands' commands "$@"
}
(( $+functions[_rolr__add_commands] )) ||
_rolr__add_commands() {
    local commands; commands=()
    _describe -t commands 'rolr add commands' commands "$@"
}
(( $+functions[_rolr__complete_commands] )) ||
_rolr__complete_commands() {
    local commands; commands=()
    _describe -t commands 'rolr complete commands' commands "$@"
}
(( $+functions[_rolr__help_commands] )) ||
_rolr__help_commands() {
    local commands; commands=(
'add:Activate roles' \
'select:Activate roles in a TUI menu' \
'update:Update all active roles' \
'list:List available roles' \
'run:Run roles without activating them' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rolr help commands' commands "$@"
}
(( $+functions[_rolr__help__add_commands] )) ||
_rolr__help__add_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help add commands' commands "$@"
}
(( $+functions[_rolr__help__complete_commands] )) ||
_rolr__help__complete_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help complete commands' commands "$@"
}
(( $+functions[_rolr__help__help_commands] )) ||
_rolr__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help help commands' commands "$@"
}
(( $+functions[_rolr__help__list_commands] )) ||
_rolr__help__list_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help list commands' commands "$@"
}
(( $+functions[_rolr__help__run_commands] )) ||
_rolr__help__run_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help run commands' commands "$@"
}
(( $+functions[_rolr__help__select_commands] )) ||
_rolr__help__select_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help select commands' commands "$@"
}
(( $+functions[_rolr__help__update_commands] )) ||
_rolr__help__update_commands() {
    local commands; commands=()
    _describe -t commands 'rolr help update commands' commands "$@"
}
(( $+functions[_rolr__list_commands] )) ||
_rolr__list_commands() {
    local commands; commands=()
    _describe -t commands 'rolr list commands' commands "$@"
}
(( $+functions[_rolr__run_commands] )) ||
_rolr__run_commands() {
    local commands; commands=()
    _describe -t commands 'rolr run commands' commands "$@"
}
(( $+functions[_rolr__select_commands] )) ||
_rolr__select_commands() {
    local commands; commands=()
    _describe -t commands 'rolr select commands' commands "$@"
}
(( $+functions[_rolr__update_commands] )) ||
_rolr__update_commands() {
    local commands; commands=()
    _describe -t commands 'rolr update commands' commands "$@"
}

if [ "$funcstack[1]" = "_rolr" ]; then
    _rolr "$@"
else
    compdef _rolr rolr
fi
