#compdef cksum

autoload -U is-at-least

_cksum() {
    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+[select the digest type to use. See DIGEST below]:ALGORITHM:(sysv bsd crc md5 sha1 sha224 sha256 sha384 sha512 blake2b sm3)' \
'--algorithm=[select the digest type to use. See DIGEST below]:ALGORITHM:(sysv bsd crc md5 sha1 sha224 sha256 sha384 sha512 blake2b sm3)' \
'-l+[digest length in bits; must not exceed the max for the blake2 algorithm and must be a multiple of 8]: : ' \
'--length=[digest length in bits; must not exceed the max for the blake2 algorithm and must be a multiple of 8]: : ' \
'--untagged[create a reversed style checksum, without digest type]' \
'--raw[emit a raw binary digest, not hexadecimal]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_cksum" ]; then
    _cksum "$@"
else
    compdef _cksum cksum
fi
