#compdef kanidm_unix

autoload -U is-at-least

_kanidm_unix() {
    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]' \
":: :_kanidm_unix_commands" \
"*::: :->kanidm_unixd" \
&& ret=0
    case $state in
    (kanidm_unixd)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kanidm_unix-command-$line[1]:"
        case $line[1] in
            (auth-test)
_arguments "${_arguments_options[@]}" : \
'-D+[]:ACCOUNT_ID:_default' \
'--name=[]:ACCOUNT_ID:_default' \
'-d[]' \
'--debug[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(cache-clear)
_arguments "${_arguments_options[@]}" : \
'-d[]' \
'--debug[]' \
'--really[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(cache-invalidate)
_arguments "${_arguments_options[@]}" : \
'-d[]' \
'--debug[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
'-d[]' \
'--debug[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(version)
_arguments "${_arguments_options[@]}" : \
'-d[]' \
'--debug[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_kanidm_unix__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kanidm_unix-help-command-$line[1]:"
        case $line[1] in
            (auth-test)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(cache-clear)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(cache-invalidate)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(version)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_kanidm_unix_commands] )) ||
_kanidm_unix_commands() {
    local commands; commands=(
'auth-test:Test authentication of a user via the unixd resolver "pam" channel. This does not test that your pam configuration is correct - only that unixd is correctly processing and validating authentications' \
'cache-clear:Erase the content of the unixd resolver cache. You should probably use \`invalidate\` instead' \
'cache-invalidate:Invalidate, but don'\''t erase the content of the unixd resolver cache. This will force the unixd daemon to refresh all user and group content immediately. If the connection is offline, entries will still be available and will be refreshed as soon as the daemon is online again' \
'status:Check that the unixd daemon is online and able to connect correctly to the kanidmd server' \
'version:Show the version of this tool' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kanidm_unix commands' commands "$@"
}
(( $+functions[_kanidm_unix__auth-test_commands] )) ||
_kanidm_unix__auth-test_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix auth-test commands' commands "$@"
}
(( $+functions[_kanidm_unix__cache-clear_commands] )) ||
_kanidm_unix__cache-clear_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix cache-clear commands' commands "$@"
}
(( $+functions[_kanidm_unix__cache-invalidate_commands] )) ||
_kanidm_unix__cache-invalidate_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix cache-invalidate commands' commands "$@"
}
(( $+functions[_kanidm_unix__help_commands] )) ||
_kanidm_unix__help_commands() {
    local commands; commands=(
'auth-test:Test authentication of a user via the unixd resolver "pam" channel. This does not test that your pam configuration is correct - only that unixd is correctly processing and validating authentications' \
'cache-clear:Erase the content of the unixd resolver cache. You should probably use \`invalidate\` instead' \
'cache-invalidate:Invalidate, but don'\''t erase the content of the unixd resolver cache. This will force the unixd daemon to refresh all user and group content immediately. If the connection is offline, entries will still be available and will be refreshed as soon as the daemon is online again' \
'status:Check that the unixd daemon is online and able to connect correctly to the kanidmd server' \
'version:Show the version of this tool' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kanidm_unix help commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__auth-test_commands] )) ||
_kanidm_unix__help__auth-test_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help auth-test commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__cache-clear_commands] )) ||
_kanidm_unix__help__cache-clear_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help cache-clear commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__cache-invalidate_commands] )) ||
_kanidm_unix__help__cache-invalidate_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help cache-invalidate commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__help_commands] )) ||
_kanidm_unix__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help help commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__status_commands] )) ||
_kanidm_unix__help__status_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help status commands' commands "$@"
}
(( $+functions[_kanidm_unix__help__version_commands] )) ||
_kanidm_unix__help__version_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix help version commands' commands "$@"
}
(( $+functions[_kanidm_unix__status_commands] )) ||
_kanidm_unix__status_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix status commands' commands "$@"
}
(( $+functions[_kanidm_unix__version_commands] )) ||
_kanidm_unix__version_commands() {
    local commands; commands=()
    _describe -t commands 'kanidm_unix version commands' commands "$@"
}

if [ "$funcstack[1]" = "_kanidm_unix" ]; then
    _kanidm_unix "$@"
else
    compdef _kanidm_unix kanidm_unix
fi
