#!/bin/bash
#
# This is the main tig script which acts as a proxy to the lower level tig scripts

set -e

TIG_ROOT="${TIG_HOME-"$HOME/.tig"}"
TIGRC_PATH="$TIG_ROOT/tigrc"
if [ ! -f "$TIGRC_PATH" ] ; then
  tig-install -i
  . "$TIGRC_PATH"
fi
. "$TIGRC_PATH"

usage_short="${BLUE}Usage: tig <command> <opts>"

usage_long="$usage_short\n\tinstall: initializes and installs required / optional tig components"
usage_long="$usage_long\n\tlogin: authorize with the tig api"
usage_long="$usage_long\n\tconfig: configure your tig settings"
usage_long="$usage_long\n\ttrack: control the repos, scripts and dot files you are tracking"
usage_long="$usage_long\n\tmesh: synchronize your tracked repositories on your machine"
usage_long="$usage_long\n\tstatus: get status and version info for your tracked repositories"
usage_long="$usage_long\n\tpublish: publish repositories to GitHub and npm with options for annotated versioning"
usage_long="$usage_long\n\tbuild: Mesh and build one of your tracked repositories"
usage_long="$usage_long\n\trun: Mesh, build, and execute one of your tracked repositories or scripts on your local machine"
usage_long="$usage_long\n\tdeploy: Mesh, build, compress, and deploy artifacts to artifacts directory and cloud services"
usage_long="$usage_long\n\tuse tig <command> -h to get command specific help${NC}"

usage_short="$usage_short\nuse -h to get supported command information${NC}"

OPTIND=1
if [ "$#" == "0" ] ; then
  >&2 echo -e "$usage_short"
  exit 1
fi

command="$1"
shift

if [ "$command" = "-h" ] ; then
  >&2 echo -e "$usage_long"
  exit 0
fi

tig-"${command}" "$@"
