#!/bin/sh
APPPATH="${0%/*}"
APPFULLPATH="`cd \"$APPPATH\" 2>/dev/null && pwd`"
RUNPATH="$@"

if [ "$1" = "--ruby" ]; then
  $APPFULLPATH/#{NAME}-bin "$@"
  exit
fi

while getopts mhv OPTION
do
  case $OPTION in
    h)  printf "Usage: #{NAME} [options] (app.rb or app.shy)\n"
        printf "\t-m\tOpen the built-in manual.\n"
        printf "\t-v\tDisplay version info.\n"
        exit
        ;;
    m)  RUNPATH="$APPFULLPATH/command-manual.rb"
        ;;
    v)  cat "$APPFULLPATH/VERSION.txt"
        exit
        ;;
  esac
done

if [ "$1" = "" ]; then
  open -a "$APPFULLPATH/../../../#{APPNAME}.app"
else
  open -a "$APPFULLPATH/../../../#{APPNAME}.app" "$RUNPATH"
fi
