#compdef chcon

autoload -U is-at-least

_chcon() {
    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[@]}" : \
'(-u --user -r --role -t --type -l --range)--reference=[chcon-help-reference]:RFILE:_files' \
'-u+[chcon-help-user]:USER:_users' \
'--user=[chcon-help-user]:USER:_users' \
'-r+[chcon-help-role]:ROLE:_default' \
'--role=[chcon-help-role]:ROLE:_default' \
'-t+[chcon-help-type]:TYPE:_default' \
'--type=[chcon-help-type]:TYPE:_default' \
'-l+[chcon-help-range]:RANGE:_default' \
'--range=[chcon-help-range]:RANGE:_default' \
'--dereference[chcon-help-dereference]' \
'-h[chcon-help-no-dereference]' \
'--no-dereference[chcon-help-no-dereference]' \
'--help[help]' \
'--preserve-root[chcon-help-preserve-root]' \
'--no-preserve-root[chcon-help-no-preserve-root]' \
'-R[chcon-help-recursive]' \
'--recursive[chcon-help-recursive]' \
'-H[chcon-help-follow-arg-dir-symlink]' \
'-L[chcon-help-follow-dir-symlinks]' \
'-P[chcon-help-no-follow-symlinks]' \
'-v[chcon-help-verbose]' \
'--verbose[chcon-help-verbose]' \
'-V[Print version]' \
'--version[Print version]' \
'*::FILE:_files' \
&& ret=0
}

(( $+functions[_chcon_commands] )) ||
_chcon_commands() {
    local commands; commands=()
    _describe -t commands 'chcon commands' commands "$@"
}

if [ "$funcstack[1]" = "_chcon" ]; then
    _chcon "$@"
else
    compdef _chcon chcon
fi
