#compdef sort

autoload -U is-at-least

_sort() {
    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[@]}" : \
'--sort=[]: :(general-numeric human-numeric month numeric version random)' \
'--random-source=[sort-help-random-source]:FILE:_files' \
'-c+[sort-help-check]:: :(silent quiet diagnose-first)' \
'--check=[sort-help-check]:: :(silent quiet diagnose-first)' \
'*-o+[sort-help-output]:FILENAME:_files' \
'*--output=[sort-help-output]:FILENAME:_files' \
'*-k+[sort-help-key]: :_default' \
'*--key=[sort-help-key]: :_default' \
'-t+[sort-help-separator]: :_default' \
'--field-separator=[sort-help-separator]: :_default' \
'--parallel=[sort-help-parallel]:NUM_THREADS:_default' \
'-S+[sort-help-buf-size]:SIZE:_default' \
'--buffer-size=[sort-help-buf-size]:SIZE:_default' \
'-T+[sort-help-tmp-dir]:DIR:_files -/' \
'--temporary-directory=[sort-help-tmp-dir]:DIR:_files -/' \
'--compress-program=[sort-help-compress-prog]:PROG:_command_names -e' \
'--batch-size=[sort-help-batch-size]:N_MERGE:_default' \
'--files0-from=[sort-help-files0-from]:NUL_FILE:_files' \
'--help[sort-help-help]' \
'--version[sort-help-version]' \
'-h[sort-help-human-numeric]' \
'--human-numeric-sort[sort-help-human-numeric]' \
'-M[sort-help-month]' \
'--month-sort[sort-help-month]' \
'-n[sort-help-numeric]' \
'--numeric-sort[sort-help-numeric]' \
'-g[sort-help-general-numeric]' \
'--general-numeric-sort[sort-help-general-numeric]' \
'-V[sort-help-version-sort]' \
'--version-sort[sort-help-version-sort]' \
'-R[sort-help-random]' \
'--random-sort[sort-help-random]' \
'-d[sort-help-dictionary-order]' \
'--dictionary-order[sort-help-dictionary-order]' \
'-m[sort-help-merge]' \
'--merge[sort-help-merge]' \
'-C[sort-help-check-silent]' \
'--check-silent[sort-help-check-silent]' \
'-f[sort-help-ignore-case]' \
'--ignore-case[sort-help-ignore-case]' \
'-i[sort-help-ignore-nonprinting]' \
'--ignore-nonprinting[sort-help-ignore-nonprinting]' \
'-b[sort-help-ignore-leading-blanks]' \
'--ignore-leading-blanks[sort-help-ignore-leading-blanks]' \
'-r[sort-help-reverse]' \
'--reverse[sort-help-reverse]' \
'-s[sort-help-stable]' \
'--stable[sort-help-stable]' \
'-u[sort-help-unique]' \
'--unique[sort-help-unique]' \
'-z[sort-help-zero-terminated]' \
'--zero-terminated[sort-help-zero-terminated]' \
'--debug[sort-help-debug]' \
'::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_sort" ]; then
    _sort "$@"
else
    compdef _sort sort
fi
