#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 crc32b md5 sha1 sha2 sha3 blake2b sm3 sha224 sha256 sha384 sha512 blake3 shake128 shake256)' \
'--algorithm=[select the digest type to use. See DIGEST below]:ALGORITHM:(sysv bsd crc crc32b md5 sha1 sha2 sha3 blake2b sm3 sha224 sha256 sha384 sha512 blake3 shake128 shake256)' \
'-l+[digest length in bits; must not exceed the max size and must be a multiple of 8 for blake2b; must be 224, 256, 384, or 512 for sha2 or sha3]: :_default' \
'--length=[digest length in bits; must not exceed the max size and must be a multiple of 8 for blake2b; must be 224, 256, 384, or 512 for sha2 or sha3]: :_default' \
'--untagged[create a reversed style checksum, without digest type]' \
'--tag[create a BSD style checksum (default)]' \
'--raw[emit a raw binary digest, not hexadecimal]' \
'-c[read checksums from the FILEs and check them]' \
'--check[read checksums from the FILEs and check them]' \
'-w[warn about improperly formatted checksum lines]' \
'--warn[warn about improperly formatted checksum lines]' \
'--status[don'\''t output anything, status code shows success]' \
'--quiet[don'\''t print OK for each successfully verified file]' \
'--ignore-missing[don'\''t fail or report status for missing files]' \
'--strict[exit non-zero for improperly formatted checksum lines]' \
'(--raw)--base64[emit base64-encoded digests, not hexadecimal]' \
'-t[]' \
'--text[]' \
'-b[]' \
'--binary[]' \
'-z[end each output line with NUL, not newline, and disable file name escaping]' \
'--zero[end each output line with NUL, not newline, and disable file name escaping]' \
'--debug[print CPU hardware capability detection info used by cksum]' \
'-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
