#compdef numfmt

autoload -U is-at-least

_numfmt() {
    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+[numfmt-help-delimiter]:X:_default' \
'--delimiter=[numfmt-help-delimiter]:X:_default' \
'--field=[numfmt-help-field]:FIELDS:_default' \
'--format=[numfmt-help-format]:FORMAT:_default' \
'--from=[numfmt-help-from]:UNIT:_default' \
'--from-unit=[numfmt-help-from-unit]:N:_default' \
'--to=[numfmt-help-to]:UNIT:_default' \
'--to-unit=[numfmt-help-to-unit]:N:_default' \
'--padding=[numfmt-help-padding]:N:_default' \
'--header=[numfmt-help-header]' \
'--round=[numfmt-help-round]:METHOD:(up down from-zero towards-zero nearest)' \
'--suffix=[numfmt-help-suffix]:SUFFIX:_default' \
'--invalid=[numfmt-help-invalid]:INVALID:(abort fail warn ignore)' \
'-z[numfmt-help-zero-terminated]' \
'--zero-terminated[numfmt-help-zero-terminated]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::NUMBER:_default' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_numfmt" ]; then
    _numfmt "$@"
else
    compdef _numfmt numfmt
fi
