#compdef tee

autoload -U is-at-least

_tee() {
    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[@]}" : \
'--output-error=[tee-help-output-error]' \
'-h[tee-help-help]' \
'--help[tee-help-help]' \
'-a[tee-help-append]' \
'--append[tee-help-append]' \
'-i[tee-help-ignore-interrupts]' \
'--ignore-interrupts[tee-help-ignore-interrupts]' \
'-p[tee-help-ignore-pipe-errors]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_tee" ]; then
    _tee "$@"
else
    compdef _tee tee
fi
