#!/bin/bash

WAKEBOARD_TITLE="Wakeboard"
PORT=8000

while [[ $# -gt 0 ]]; do
  key="$1"
  case $key in
  -h|--help)
    HELP=1
    shift
    ;;
  -p|--port)
    PORT="$2"
    shift
    shift
    ;;
  -t|--title)
    WAKEBOARD_TITLE="$2"
    shift
    shift
    ;;
  esac
done

if [ "$HELP" ]; then
  echo "Usage: $0 [-h|--help] [-t|--title <title>] [-p|--port <port>]"
  echo "  -h | --help: Show this help"
  echo "  -t | --title: Title to give to the served page (defaults to Wakeboard)"
  echo "  -p | --port <port>: Port number to use (default 8000)"
  exit 0
fi

if [ ! -d "status" ]; then
  mkdir "status"
fi

# Ensure variable can be read by the get handler
export WAKEBOARD_TITLE

./bashserv/bashserv.sh -s "./static" -g "./handle_get.sh" --post "./handle_post.sh" -p "$PORT"

