#!/usr/bin/env bash

# This checks whether the script was executed or sourced
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] || 
[[ -n $KSH_VERSION && $(cd "$(dirname -- "$0")" &&
printf '%s' "${PWD%/}/")$(basename -- "$0") != "${.sh.file}" ]] || 
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && sourced=1 || sourced=0

# This script should only be sourced
if [[ "${sourced}" == "0" ]]
then
    echo "You must source this script to use it, not execute it:"
    echo "source cosmosis-configure"
    exit
fi

cmds=$(python -m cosmosis.configure "$@")
retval=$?
if [ $retval -ne 0 ]
then
    return
fi

eval $cmds

echo "Your shell is now configured to build the CosmoSIS standard library"