#!/bin/bash

while [[ $# -gt 1 ]]
do
key="$1"

case $key in
    -s|--secret)
    SECRET="$2"
    shift # past argument
    ;;
    -q|--queue)
    QUEUE="$2"
    shift # past argument
    ;;
esac
done

if [ -z "$SECRET" ] ; then
	echo "-s --secret argument required!"
	exit
fi
if [ -z "$QUEUE" ] ; then
	echo "Queue name is 'queue'"
	QUEUE="queue"
fi

>queue.js
sed 's/<SECRET>/$SECRET/g' queue-api.js > $QUEUE.js
wt create $QUEUE.js --meta wt-compiler=webtask-tools/express
rm $QUEUE.js