#compdef tr

autoload -U is-at-least

_tr() {
    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[@]}" : \
'-c[tr-help-complement]' \
'-C[tr-help-complement]' \
'--complement[tr-help-complement]' \
'-d[tr-help-delete]' \
'--delete[tr-help-delete]' \
'-s[tr-help-squeeze]' \
'--squeeze-repeats[tr-help-squeeze]' \
'-t[tr-help-truncate-set1]' \
'--truncate-set1[tr-help-truncate-set1]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::sets:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_tr" ]; then
    _tr "$@"
else
    compdef _tr tr
fi
