#compdef od

autoload -U is-at-least

_od() {
    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[@]}" : \
'-A+[od-help-address-radix]:RADIX:_default' \
'--address-radix=[od-help-address-radix]:RADIX:_default' \
'-j+[od-help-skip-bytes]:BYTES:_default' \
'--skip-bytes=[od-help-skip-bytes]:BYTES:_default' \
'-N+[od-help-read-bytes]:BYTES:_default' \
'--read-bytes=[od-help-read-bytes]:BYTES:_default' \
'--endian=[od-help-endian]:big|little:(big little)' \
'-S+[NotImplemented\: output strings of at least BYTES graphic chars. 3 is assumed when BYTES is not specified.]:BYTES:_default' \
'--strings=[NotImplemented\: output strings of at least BYTES graphic chars. 3 is assumed when BYTES is not specified.]:BYTES:_default' \
'*-t+[od-help-format]:TYPE:_default' \
'*--format=[od-help-format]:TYPE:_default' \
'-w+[od-help-width]' \
'--width=[od-help-width]' \
'--help[od-help-help]' \
'-a[od-help-a]' \
'-b[od-help-b]' \
'-c[od-help-c]' \
'-d[od-help-d]' \
'-D[od-help-d4]' \
'-o[octal 2-byte units]' \
'-I[decimal 8-byte units]' \
'-L[decimal 8-byte units]' \
'-i[decimal 4-byte units]' \
'-l[decimal 8-byte units]' \
'-x[hexadecimal 2-byte units]' \
'-h[hexadecimal 2-byte units]' \
'-O[octal 4-byte units]' \
'-s[decimal 2-byte units]' \
'-X[hexadecimal 4-byte units]' \
'-H[hexadecimal 4-byte units]' \
'-e[floating point double precision (64-bit) units]' \
'-f[floating point double precision (32-bit) units]' \
'-F[floating point double precision (64-bit) units]' \
'-v[od-help-output-duplicates]' \
'--output-duplicates[od-help-output-duplicates]' \
'--traditional[od-help-traditional]' \
'-V[Print version]' \
'--version[Print version]' \
'::FILENAME:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_od" ]; then
    _od "$@"
else
    compdef _od od
fi
