#!/bin/zsh

### The main controller for antidote.
# The reason we use `antidote-main` instead putting all of this in `antidote`
# is that this allows the `antidote` function to be overridden via `antidote init`.
# The init command switches antidote from static mode to dynamic mode, but this
# core functionality remains.
#function antidote-main {
  0=${(%):-%x}

  local o_help o_version
  zparseopts ${_adote_zparopt_flags} -- \
    h=o_help    -help=h    \
    v=o_version -version=v ||
    return 1

  if (( ${#o_version} )); then
    __antidote_version

  elif (( ${#o_help} )); then
    antidote-help "$@"

  elif [[ ${#} -eq 0 ]]; then
    antidote-help
    return 2

  elif [[ "${1}" = help ]]; then
    local manpage=${2:-antidote}
    antidote-help $manpage

  elif (( $+functions[antidote-${1}] )); then
    local cmd=${1}; shift
    antidote-${cmd} "$@"
    return $?

  else
    print >&2 "antidote: command not found '${1}'" && return 1
  fi
#}
