#compdef fmt

autoload -U is-at-least

_fmt() {
    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[@]}" : \
'-p+[fmt-prefix-help]:PREFIX:_default' \
'--prefix=[fmt-prefix-help]:PREFIX:_default' \
'-P+[fmt-skip-prefix-help]:PSKIP:_default' \
'--skip-prefix=[fmt-skip-prefix-help]:PSKIP:_default' \
'-w+[fmt-width-help]:WIDTH:_default' \
'--width=[fmt-width-help]:WIDTH:_default' \
'-g+[fmt-goal-help]:GOAL:_default' \
'--goal=[fmt-goal-help]:GOAL:_default' \
'-T+[fmt-tab-width-help]:TABWIDTH:_default' \
'--tab-width=[fmt-tab-width-help]:TABWIDTH:_default' \
'-c[fmt-crown-margin-help]' \
'--crown-margin[fmt-crown-margin-help]' \
'-t[fmt-tagged-paragraph-help]' \
'--tagged-paragraph[fmt-tagged-paragraph-help]' \
'-m[fmt-preserve-headers-help]' \
'--preserve-headers[fmt-preserve-headers-help]' \
'-s[fmt-split-only-help]' \
'--split-only[fmt-split-only-help]' \
'-u[fmt-uniform-spacing-help]' \
'--uniform-spacing[fmt-uniform-spacing-help]' \
'-x[fmt-exact-prefix-help]' \
'--exact-prefix[fmt-exact-prefix-help]' \
'-X[fmt-exact-skip-prefix-help]' \
'--exact-skip-prefix[fmt-exact-skip-prefix-help]' \
'-q[fmt-quick-help]' \
'--quick[fmt-quick-help]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_fmt" ]; then
    _fmt "$@"
else
    compdef _fmt fmt
fi
