#compdef who

autoload -U is-at-least

_who() {
    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[who-help-all]' \
'--all[who-help-all]' \
'-b[who-help-boot]' \
'--boot[who-help-boot]' \
'-d[who-help-dead]' \
'--dead[who-help-dead]' \
'-H[who-help-heading]' \
'--heading[who-help-heading]' \
'-l[who-help-login]' \
'--login[who-help-login]' \
'--lookup[who-help-lookup]' \
'-m[who-help-only-hostname-user]' \
'-p[who-help-process]' \
'--process[who-help-process]' \
'-q[who-help-count]' \
'--count[who-help-count]' \
'-r[who-help-runlevel]' \
'--runlevel[who-help-runlevel]' \
'-s[who-help-short]' \
'--short[who-help-short]' \
'-t[who-help-time]' \
'--time[who-help-time]' \
'-u[who-help-users]' \
'--users[who-help-users]' \
'-T[who-help-mesg]' \
'-w[who-help-mesg]' \
'--mesg[who-help-mesg]' \
'--message[who-help-mesg]' \
'--writable[who-help-mesg]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::FILE:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_who" ]; then
    _who "$@"
else
    compdef _who who
fi
