#compdef uniq

autoload -U is-at-least

_uniq() {
    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[@]}" : \
'-D+[uniq-help-all-repeated]' \
'--all-repeated=[uniq-help-all-repeated]' \
'(-d --repeated -D --all-repeated -u --unique -c --count)--group=[uniq-help-group]' \
'-w+[uniq-help-check-chars]:N:_default' \
'--check-chars=[uniq-help-check-chars]:N:_default' \
'-s+[uniq-help-skip-chars]:N:_default' \
'--skip-chars=[uniq-help-skip-chars]:N:_default' \
'-f+[uniq-help-skip-fields]:N:_default' \
'--skip-fields=[uniq-help-skip-fields]:N:_default' \
'-c[uniq-help-count]' \
'--count[uniq-help-count]' \
'-i[uniq-help-ignore-case]' \
'--ignore-case[uniq-help-ignore-case]' \
'-d[uniq-help-repeated]' \
'--repeated[uniq-help-repeated]' \
'-u[uniq-help-unique]' \
'--unique[uniq-help-unique]' \
'-z[uniq-help-zero-terminated]' \
'--zero-terminated[uniq-help-zero-terminated]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_uniq" ]; then
    _uniq "$@"
else
    compdef _uniq uniq
fi
