#!/bin/bash

function is_in_git_repo() {
    [ -d .git ] && true || git rev-parse --git-dir > /dev/null 2>&1
}


if [ -z $1 ]; then
    echo "Missing an argument!"
elif [ $1 == "run" ] && [ -z $2 ] && is_in_git_repo; then
    REPO=`git config --get remote.origin.url | cut -d':' -f 2- | cut -d'.' -f 1`
    FLASK_APP=reviewington.app.py GITHUB_ORG_REPO=$REPO python3 -m flask run
elif [ $1 == "run" ] && [ -z $2 ]; then
    echo "Missing Github Organization and Repository name! Example: HomeXLabs/reviewington"
elif [ $1 == "run" ] && [ $2 ]; then
    FLASK_APP=reviewington.app.py GITHUB_ORG_REPO=$2 python3 -m flask run
elif [ $1 == "about" ]; then
    python3 -m reviewington.about_reader
elif [ $1 == "configure" ]; then
    python3 -m reviewington.configurator
else
    echo "Command not supported! Please check our documentation."
fi
