#!/bin/bash

# HERE BEGINS THE SCRIPT
SCRIPTNAME=$(basename $0)
SCRIPTBASE=$(dirname $0)/..
#make SCRIPTBASE fully qualified
SCRIPTBASE=$( cd $SCRIPTBASE && pwd )

RETVALUE=0
source $SCRIPTBASE/bin/env.sh

# Just do a simple log to get traces
echo "$(date) : $SCRIPTNAME starts $*" >> $SCRIPTBASE/log/yoga.log

methodName="$1"
shift 1
methodArgs="$*"

# try to launch script of associated methodName or generated help message
if test -n "$methodName"
then
    script=$SCRIPTBASE/bin/${methodName}.sh
    if ! eval $script $methodArgs 2> /dev/null
    then
        RETVALUE=1
    fi
else
   for f in $(ls $SCRIPTBASE/bin/*.sh)
   do
       tmp=$(basename $f)
       c=${tmp%%.sh}
       list="$list $(echo $c | grep "^get")  $(echo $c | grep "^run")" 
   done
    echoPre "\nusage: $SCRIPTNAME cmd\ncmd is one of : $list\n"
    RETVALUE=1
fi
# HERE ENDS THE SCRIPT
echo "$(date) : $SCRIPTNAME stops ($RETVALUE)" >> $SCRIPTBASE/log/yoga.log
exit $RETVALUE
