#compdef nl

autoload -U is-at-least

_nl() {
    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+[nl-help-body-numbering]:STYLE:_default' \
'--body-numbering=[nl-help-body-numbering]:STYLE:_default' \
'-d+[nl-help-section-delimiter]:CC:_default' \
'--section-delimiter=[nl-help-section-delimiter]:CC:_default' \
'-f+[nl-help-footer-numbering]:STYLE:_default' \
'--footer-numbering=[nl-help-footer-numbering]:STYLE:_default' \
'-h+[nl-help-header-numbering]:STYLE:_default' \
'--header-numbering=[nl-help-header-numbering]:STYLE:_default' \
'-i+[nl-help-line-increment]:NUMBER:_default' \
'--line-increment=[nl-help-line-increment]:NUMBER:_default' \
'-l+[nl-help-join-blank-lines]:NUMBER:_default' \
'--join-blank-lines=[nl-help-join-blank-lines]:NUMBER:_default' \
'-n+[nl-help-number-format]:FORMAT:(ln rn rz)' \
'--number-format=[nl-help-number-format]:FORMAT:(ln rn rz)' \
'-s+[nl-help-number-separator]:STRING:_default' \
'--number-separator=[nl-help-number-separator]:STRING:_default' \
'-v+[nl-help-starting-line-number]:NUMBER:_default' \
'--starting-line-number=[nl-help-starting-line-number]:NUMBER:_default' \
'-w+[nl-help-number-width]:NUMBER:_default' \
'--number-width=[nl-help-number-width]:NUMBER:_default' \
'--help[nl-help-help]' \
'-p[nl-help-no-renumber]' \
'--no-renumber[nl-help-no-renumber]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_nl" ]; then
    _nl "$@"
else
    compdef _nl nl
fi
