#!/bin/bash
OPEN_PROJECT_NAME="frosted"

if [ "$PROJECT_NAME" = "$OPEN_PROJECT_NAME" ]; then
    return
fi

export PROJECT_NAME=$OPEN_PROJECT_NAME
export PROJECT_DIR="$PWD"

# Let's make sure this is a hubflow enabled repo
yes | git hf init >/dev/null 2>/dev/null

# Quick directory switching
alias root="cd $PROJECT_DIR"
alias project="root; cd $PROJECT_NAME"
alias tests="project; cd test"
alias scripts="project; cd scripts"

# Commands
alias test="_test_project"
alias install="_install_project"
alias distribute="python setup.py sdist upload; python setup.py bdist_wheel upload"
alias leave="_leave_project"

function _install_project()
{
    CURRENT_DIRECTORY="$PWD"
    root
    sudo python setup.py install
    cd $CURRENT_DIRECTORY
}

function _test_project()
{
    CURRENT_DIRECTORY="$PWD"
    tests
    py.test -s
    cd $CURRENT_DIRECTORY
}

function _leave_project()
{
    export PROJECT_NAME=""
    export PROJECT_DIR=""

    unalias root
    unalias project
    unalias tests
    unalias test
    unalias install
    unalias distribute
    unalias leave
}
