#!/usr/bin/env bash

. lib.bash || exit

os=$(. /etc/os-release && echo "$ID")

if [[ "$os" != "arch" ]]; then
	vdie "unsupported distribution '$os'"
fi

if (( DEBUG )); then
	export AURACLE_DEBUG="/dev/stderr"
fi

mode=

while getopts ":dimsu" OPT; do
	case $OPT in
	d) mode=download;;
	i) mode=info;;
	m) mode=maintainer;;
	s) mode=search;;
	u) mode=update;;
	*) lib:die_getopts;;
	esac
done; shift $((OPTIND-1))

case $mode in
	download)
		auracle clone "$@" ;;
	info)
		auracle info "$@" ;;
	maintainer)
		auracle search --searchby=maintainer "$@" ;;
	search)
		auracle search "$@" ;;
	update)
		auracle sync "$@" ;;
	*)
		vdie "operation not specified" ;;
esac
