#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=[set write error behavior]:: :((warn\:"produce warnings for errors writing to any output"
warn-nopipe\:"produce warnings for errors that are not pipe errors (ignored on non-unix platforms)"
exit\:"exit on write errors to any output"
exit-nopipe\:"exit on write errors to any output that are not pipe errors (equivalent to exit on non-unix platforms)"))' \
'-h[Print help]' \
'--help[Print help]' \
'-a[append to the given FILEs, do not overwrite]' \
'--append[append to the given FILEs, do not overwrite]' \
'-i[ignore interrupt signals (ignored on non-Unix platforms)]' \
'--ignore-interrupts[ignore interrupt signals (ignored on non-Unix platforms)]' \
'-p[set write error behavior (ignored on non-Unix platforms)]' \
'-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
