#!/bin/bash
# Multiple shebangs are fine :-)

#UTIL
# error function checks?

export contate_cmd="${BASH_SOURCE}"
if [ -z "${BASH_SOURCE}" ]; then
	err "However you're running this script, ssh or somethign, we don't support that yet. Maybe main should be an actual contate function that then exports it and calls contate, that way we cab avoid knowing where we are."
	exit 1
fi

function contate {
	${contate_cmd} "${@}"
}

if [ -z "$CONTATE_DEBUG" ]; then
	export CONTATE_DEBUG=false
fi

if $CONTATE_DEBUG; then
	export CoC="c"
	export CoS="s"
	export CoE="e"
	export CoP="p"
	export CoI="i"
	export DEBUGINDENT+="."
else
	unset CoC CoS CoE CoP CoI
fi

dbg(){
	if $CONTATE_DEBUG; then
		>&2 echo "${DEBUGINDENT}DEBUG: ${@}"
	fi
}

# must will fail the last exit code isn't true
must(){
	dbg "must passed $1 for $2"
	if [ $1 -ne 0 ]; then
		err $2
		exit 1
	fi
}

# should will dbg if the last exit code isn't true
should(){
	if [ $1 -ne 0 ]; then
		dbg $2
	fi
}

dbg "defining utils"
err(){
	if ! $CONTATE_QUIET; then
		>&2 echo "ERR: ${@}"
	fi
}

usage(){
	if ! $CONTATE_QUIET; then
		>&2 echo "USAGE: " # TODO
	fi
}
dbg "util defined"

export -f dbg should must err contate
