#compdef readlink

autoload -U is-at-least

_readlink() {
    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[@]}" : \
'-f[readlink-help-canonicalize]' \
'--canonicalize[readlink-help-canonicalize]' \
'-e[readlink-help-canonicalize-existing]' \
'--canonicalize-existing[readlink-help-canonicalize-existing]' \
'-m[readlink-help-canonicalize-missing]' \
'--canonicalize-missing[readlink-help-canonicalize-missing]' \
'-n[readlink-help-no-newline]' \
'--no-newline[readlink-help-no-newline]' \
'-q[readlink-help-quiet]' \
'--quiet[readlink-help-quiet]' \
'-s[readlink-help-silent]' \
'--silent[readlink-help-silent]' \
'-v[readlink-help-verbose]' \
'--verbose[readlink-help-verbose]' \
'-z[readlink-help-zero]' \
'--zero[readlink-help-zero]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::files:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_readlink" ]; then
    _readlink "$@"
else
    compdef _readlink readlink
fi
