diff --git a/kayobe-env b/kayobe-env index 949e99b..c0203c1 100644 --- a/kayobe-env +++ b/kayobe-env @@ -36,6 +36,23 @@ export KOLLA_SOURCE_PATH=${KOLLA_SOURCE_PATH:-${base_path}/src/kolla-ansible} # issues with symlinks on Windows hosts. export KOLLA_VENV_PATH=~/kolla-venv +function check_and_export_env { + # Look for existing Kayobe environments + if [ -d "${KAYOBE_CONFIG_PATH}/environments" ]; then + if [ -d "${KAYOBE_CONFIG_PATH}/environments/${kayobe_env}" ]; then + export KAYOBE_ENVIRONMENT="${kayobe_env}" + echo "Using Kayobe environment ${KAYOBE_ENVIRONMENT}" + return 0 + else + echo "Unable to find Kayobe environment ${kayobe_env} in ${KAYOBE_CONFIG_PATH}/environments" + return 1 + fi + else + echo "Cannot find environments folder in ${KAYOBE_CONFIG_PATH}" + return 1 + fi +} + function usage { echo "usage: ${BASH_SOURCE[0]:-${(%):-%x}} [--environment ]" return 1 @@ -44,21 +61,14 @@ function usage { if [ "$#" -ge 1 ]; then if [ "$1" = "--environment" -a "$#" -eq 2 ]; then kayobe_env="$2" - # Look for existing Kayobe environments - if [ -d "${KAYOBE_CONFIG_PATH}/environments" ]; then - if [ -d "${KAYOBE_CONFIG_PATH}/environments/${kayobe_env}" ]; then - export KAYOBE_ENVIRONMENT="${kayobe_env}" - echo "Using Kayobe environment ${KAYOBE_ENVIRONMENT}" - return 0 - else - echo "Unable to find Kayobe environment ${kayobe_env} in ${KAYOBE_CONFIG_PATH}/environments" - return 1 - fi - else - echo "Cannot find environments folder in ${KAYOBE_CONFIG_PATH}" - return 1 - fi + check_and_export_env else usage fi + return $? +fi + +if [[ -f "$KAYOBE_CONFIG_ROOT/.environment" ]]; then + kayobe_env=$(cat "$KAYOBE_CONFIG_ROOT/.environment") + check_and_export_env fi