#compdef split

autoload -U is-at-least

_split() {
    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[@]}" : \
'-b+[split-help-bytes]:SIZE:_default' \
'--bytes=[split-help-bytes]:SIZE:_default' \
'-C+[split-help-line-bytes]:SIZE:_default' \
'--line-bytes=[split-help-line-bytes]:SIZE:_default' \
'-l+[split-help-lines]:NUMBER:_default' \
'--lines=[split-help-lines]:NUMBER:_default' \
'-n+[split-help-number]:CHUNKS:_default' \
'--number=[split-help-number]:CHUNKS:_default' \
'--additional-suffix=[split-help-additional-suffix]:SUFFIX:_default' \
'--filter=[split-help-filter]:COMMAND:_command_names -e' \
'--numeric-suffixes=[split-help-numeric-suffixes]' \
'--hex-suffixes=[split-help-hex-suffixes]' \
'-a+[split-help-suffix-length]:N:_default' \
'--suffix-length=[split-help-suffix-length]:N:_default' \
'*-t+[split-help-separator]:SEP:_default' \
'*--separator=[split-help-separator]:SEP:_default' \
'--io-blksize=[]: :_default' \
'-e[split-help-elide-empty-files]' \
'--elide-empty-files[split-help-elide-empty-files]' \
'-d[split-help-numeric-suffixes-short]' \
'-x[split-help-hex-suffixes-short]' \
'--verbose[split-help-verbose]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::input:_files' \
'::prefix:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_split" ]; then
    _split "$@"
else
    compdef _split split
fi
