#!/usr/bin/env bash

EXEC=0

function print_usage {
	str1=$(green "$basename:")
	str2=$(dark_yellow "options $1")
	line
	echo "${str1} ${str2}"
	echo $(light_blue "Required options:")
	echo $(dark_yellow "$2")
	line
	exit 1
}

function error {
	err=$(red "ERROR:")
	logit "${err} $1"
}

function line {
	local sep=$(printf %120s |tr " " ":")
	local line=$(dark_gray "${sep}")
	echo ${line}
}

function logit {
	line
	echo $(dark_yellow "${1}")
	line
}

function runit {
	logit "$1"
	if [[ ${EXEC} == 1 ]]; then
		eval  $1
	fi
}

function usage {
	error "create a usage menu in calling shell script"
}

function is_required {
	varname=$1
	eval var=\$$varname
	if [[ -z ${var} ]]; then
		str1=$(light_blue "${varname}")
		error "[${str1}] is required"
		usage
		exit 1
	fi
}

function set_default {
	varname=$1
	eval var=\$$varname
	if [[ -z ${var} ]]; then
		eval $varname=$2
	fi
}

## file systerm variables
basename=$(basename $0)
perllib="/var/songspace/perllib"
bin="${perllib}/bin"
ingest="${bin}/ingest"

## color formats
function dark_yellow {
	local text="\033[33m${1}\033[0m"; echo ${text}
}

function light_blue {
	local text="\033[36m${1}\033[0m"; echo ${text}
}

function red {
	local text="\033[31m${1}\033[0m"; echo ${text}
}

function green {
	local text="\033[32m${1}\033[0m"; echo ${text}
}

function dark_gray {
	local text="\033[38;5;233m${1}\033[0m"; echo ${text}
}
