#compdef vnc

_vnc () {
    local curcontext="$curcontext" state line ret=1 expl
    typeset -A opt_args

  _arguments -C -s \
    '*:hosts:->hosts' && ret=0

    if [[ -n "$state" ]]; then
	if compset -P '*@'; then
            _wanted hosts expl host _vnc_all_hosts && ret=0
	else
            _alternative \
		'hosts:: _vnc_all_hosts' \
		'users:: _vnc_users -qS@' && ret=0
	fi
    fi
    return ret
}

_vnc_users () {
  _tags users && _combination -s '@' my-accounts users-hosts users "$@"
}

_vnc_all_hosts () {
  _tags hosts && _combination -s '@' my-accounts users-hosts hosts "$@"
}

_vnc "$@"
