#!/bin/bash
if [ -z "$GVM_ROOT" ]; then
	if [ command -v tput >/dev/null 2>&1 ]; then
		tput sgr0
		tput setaf 1
	fi
	echo 'ERROR: $GVM_ROOT is not set! Please add the following line to your .bashrc or .profile

	[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
' >&2
	if [ command -v tput >/dev/null 2>&1 ]; then
		tput sgr0
	fi
	exit 1
fi

. $GVM_ROOT/scripts/functions

command=$1
if [[ $command == "implode" ]]; then
	rm -rf $GVM_ROOT
	exit 0
fi

$GVM_ROOT/scripts/gvm-check
if [[ "$?" != "0" ]]; then
	display_error "Missing requirements."
fi

if [[ $command == "version" ]]; then
	display_message "Go Version Manager v$GVM_VERSION installed at $GVM_ROOT"
else
	if [ -f $GVM_ROOT/scripts/$command ]; then
		shift
		$GVM_ROOT/scripts/$command $@
	elif [[ -n $command ]]; then
		display_error "Unrecognized command line argument: '$command'"
	else
		echo "Usage: gvm [command]

Description:
  GVM is the Go Version Manager

Commands:
  version    - print the gvm version number
  get        - gets the latest code (for debugging)
  use        - select a go version to use
  diff       - view changes to Go root
  implode    - completely remove gvm
  install    - install go versions
  uninstall  - uninstall go versions
  list       - list installed go versions
  listall    - list available versions
  pkgset     - manage go packages sets
"
	fi
fi
