#compdef cut

autoload -U is-at-least

_cut() {
    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+[cut-help-bytes]:LIST:_default' \
'*--bytes=[cut-help-bytes]:LIST:_default' \
'*-c+[cut-help-characters]:LIST:_default' \
'*--characters=[cut-help-characters]:LIST:_default' \
'-d+[cut-help-delimiter]:DELIM:_default' \
'--delimiter=[cut-help-delimiter]:DELIM:_default' \
'*-f+[cut-help-fields]:LIST:_default' \
'*--fields=[cut-help-fields]:LIST:_default' \
'--output-delimiter=[cut-help-output-delimiter]:NEW_DELIM:_default' \
'-w[cut-help-whitespace-delimited]' \
'--complement[cut-help-complement]' \
'-s[cut-help-only-delimited]' \
'--only-delimited[cut-help-only-delimited]' \
'-z[cut-help-zero-terminated]' \
'--zero-terminated[cut-help-zero-terminated]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_cut" ]; then
    _cut "$@"
else
    compdef _cut cut
fi
