#! /bin/sh
# This source code is released into the public domain.

# Parse command-line arguments.
args=$(getopt c:v $*)
if [ $? -ne 0 ]; then
	exit 1
fi
set -- $args

_uacme_flags=""

while :; do
	case "$1" in
	-c)
		LFACME_CONFDIR="$2"
		shift; shift;;
	-v)
		LFACME_VERBOSE=1
		# Export this so it's available to hooks.
		export LFACME_VERBOSE
		shift;;
	-y)
		_uacme_flags="$_uacme_flags $1"
		shift;;
	--)
		shift; break;;
	esac
done

# Initialise.
. /usr/local/share/lfacme/init.sh

# Run the command.

_command="$1"; shift
if [ -z "$_command" ]; then
	_fatal "missing command"
fi

_cscript="/usr/local/share/lfacme/command/${_command}.sh"
if ! [ -x "$_cscript" ]; then
	_fatal "unknown command: %s" "$_command"
fi

. "$_cscript"
