#!/usr/bin/env bash

#
# ## project\_initialize()
#
# Initializes paths and environment for the logical concept of a 'project'.
#
# ### Input Parameters
#
# None.
#
# ### Stream Outputs
#
# None.
#
# ### Environmental effects
#
# Environmental variable settings, such as {shared,release}_path, environment,
# etc...
#
# ### Return Codes
#
# 0 for success
#
# ### Failure Scenarios
#
# No failure scenarios currently.
#
# ### Usage Examples
#
#     user$ project_initialize
#     user$ echo $environment
#     production
#
# ### Code Walkthrough
project_initialize()
{
  # If the project_path variable is nonempty
  if variable_is_nonempty project_path
  then
    # then ensure that the shared_path, release_path, environment and vcs
    # varaibles are set.
    : \
      "${shared_path:=${project_path}/shared}" \
      "${release_path:=${project_path}/current}" \
      "${environment:="production"}"

    # Set the project log path into the shared path's log directory
    project_log_path="$shared_path/log"

    # Set the extension_log_path to the project_log_path direcotory
    extension_log_path="${project_log_path}"
  fi

  # If the project variable is nonempty
  if variable_is_nonempty project
  then
    # then ensure the database_name is set
    true "${database_name:="${project}_${environment}"}"

    # And source the project name rc file, if they exist
    source_files ".${project}rc"
  fi
}
