diff --git README.txt README.txt
index f7604da..b6100c5 100644
--- README.txt
+++ README.txt
@@ -2,24 +2,25 @@ $Id: README.txt,v 1.1 2010/03/04 05:38:42 ceardach Exp $
 
 ENVIRONMENT
 
-Creates a drush command line interface for setting an environment for a site
-instance.  Other modules may then change their logic depending upon the current
-active environment.  The 'drush env switch' command also invokes a hook to allow
-each module to run additional required actions when switching environments.
+Creates an api for specifying an environment for a site instance.  Other modules
+may then change their logic depending upon the current active environment. When
+switching environments a hook is invoked to allow each module to run additional
+required actions.
 
 The environment states are completely customizable and may be arbitrarily set
-to any value that makes sense for the project at hand.  The recommended set of
-environment states are 'development', 'production', and 'readonly'.
+to any value that makes sense for the project at hand. Predefined environments
+are 'development' and 'production'.
 
 
 Example
 -------
 
- drush env switch development              Switch the environment to
+ drush env-switch development              Switch the environment to
                                            development
- drush env switch production force         Force the environment to switch to
+ drush env-switch --force production       Force the environment to switch to
                                            production even if the current
                                            environment already is production
+ drush env                                 Shows current environment
 
 
 Hooks Invoked
@@ -32,5 +33,7 @@ Additional Behaviors
 --------------------
 
 Drush:
-  - drush env switch
+  - drush env-switch
     Invokes switching the environment
+  - drush env
+    Shows current environment
diff --git environment.admin.inc environment.admin.inc
new file mode 100644
index 0000000..a1f7680
--- /dev/null
+++ environment.admin.inc
@@ -0,0 +1,57 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Settings for Environment module
+ */
+
+function environment_admin_settings() {
+  $form = array();
+
+  $env_override = variable_get('environment_override', NULL);
+  if ($env_override) {
+    $form['environment'] = array(
+      '#type'  => 'item',
+      '#title' => t('Current Environment'),
+      '#value' => check_plain(variable_get('environment', 'none')),
+    );
+    $form['environment_override'] = array(
+      '#type'  => 'item',
+      '#title' => t('Environment Override'),
+      '#value' => t('Active'),
+    );
+  }
+  else {
+    $form['environment'] = array(
+      '#type'          => 'select',
+      '#title'         => t('Environment'),
+      '#options'       => drupal_map_assoc(array_keys(environment_get())),
+      '#default_value' => variable_get('environment', NULL),
+    );
+  }
+
+  $form['environment_require_override'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Require environment override'),
+    '#description'   => t('Used to require that an environment is set in the settings.php file.'),
+    '#default_value' => variable_get('environment_require_override', FALSE),
+  );
+
+  $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
+
+  return $form;
+}
+
+function environment_admin_settings_submit($form, &$form_state) {
+  $values = $form_state['values'];
+
+  variable_set('environment_require_override', $values['environment_require_override']);
+
+  $result = environment_switch($values['environment']);
+  foreach ($result['messages'] as $message) {
+    drupal_set_message(t(check_plain($message)));
+  }
+
+  drupal_set_message(t('The configuration options have been saved.'));
+}
diff --git environment.drush.inc environment.drush.inc
index 8ba3d14..89fafb5 100644
--- environment.drush.inc
+++ environment.drush.inc
@@ -11,17 +11,26 @@
 function environment_drush_command() {
   $items = array();
 
-  $items['env switch'] = array(
+  $items['environment'] = array(
+    'description' => 'Show the environment mode',
+    'drupal dependencies' => array('environment'),
+    'aliases' => array('env'),
+  );
+
+  $items['environment-switch'] = array(
     'description' => 'Switch the environment to the given mode',
-    'callback' => 'environment_switch',
+    'drupal dependencies' => array('environment'),
     'arguments' => array(
       'target_env' => 'The target environment to switch to',
-      'force' => 'Whether or not the environment switch should be forced if the target enviornment is the same as the current environment.',
+    ),
+    'options' => array(
+      '--force' => 'Whether an environment switch should be forced if the target enviornment is the same as the current environment.',
     ),
     'examples' => array(
-      'drush env switch development' => 'Switch the environment to development',
-      'drush env switch production force' => 'Force the environment to switch to production even if the current environment already is production',
+      'drush env-switch development' => 'Switch the environment to development',
+      'drush env-switch --force production' => 'Force the environment to switch to production even if the current environment already is production',
     ),
+    'aliases' => array('env-switch'),
   );
 
   return $items;
@@ -32,7 +41,10 @@ function environment_drush_command() {
  */
 function environment_drush_help($section) {
   switch ($section) {
-    case 'drush:env switch':
+    case 'drush:environment':
+      $help = dt("Shows the current environment.");
+      break;
+    case 'drush:environment-switch':
       $help = dt("Switches the environment to the target environment.");
       break;
   }
@@ -40,62 +52,52 @@ function environment_drush_help($section) {
 }
 
 /**
- * Drush callback function to switch an environment
+ * Drush callback function to show environment
  */
-function environment_switch() {
-  $args = func_get_args();
-
-  // Figure out if the user set the force flag
-  $force = FALSE;
-  if (in_array('force', $args)) {
-    $force = TRUE;
-    // Remove the flag from the args and reset the array
-    foreach ($args as $key => $arg) {
-      if ($arg == 'force') {
-        unset($args[$key]);
-      }
-    }
-    sort($args);
-  }
+function drush_environment() {
+  $current_env = variable_get('environment', NULL);
 
-  // Warn the user if  no environment arg was set
-  if (count($args) < 1) {
-    drush_print("ERROR: You must provide the environment to switch to.\n");
-    drush_print(environment_drush_help('drush:env_switch'));
-    return;
-  }
+  drush_print($current_env === NULL ? 'None' : $current_env);
+}
 
-  $target_env = $args[0];
+/**
+ * Drush callback function to switch an environment
+ */
+function drush_environment_switch() {
+  if ($args = func_get_args()) {
+    $force = drush_get_option('force');
 
-  $current_env = variable_get('environment', 'unset');
-  if ($current_env == $target_env && !$force) {
-    drush_print("WARNING: The current environment is already set to '{$current_env}'.\n");
-    drush_print("To force the environment switch to run, use the 'force' flag.\n");
-    return;
-  }
+    $target_env   = $args[0];
+    $current_env  = variable_get('environment', NULL);
+    $env_override = variable_get('environment_override', NULL);
 
-  drush_print("Switching the environment to {$target_env}...\n");
+    if (!$force && $current_env == $target_env) {
+      drush_print("WARNING: The current environment is already set to '{$current_env}'.");
+      drush_print("To force the environment switch to run anyway, use the '--force' flag.");
+    }
+    else if (!$force && $env_override && $target_env != $env_override) {
+      drush_print("WARNING: The current environment is overriden with '{$env_override}'.");
+      drush_print("To force the environment switch to run anyway, use the '--force' flag.");
+    }
+    else {
+      drush_print("Switching the environment to {$target_env}...");
 
-  // Register the new environment
-  variable_set('environment', $target_env);
+      $result   = environment_switch($target_env, $force);
+      $messages = $result['messages'];
 
-  // In many cases, simply clearing the cache will work
-  drupal_flush_all_caches();;
-  drush_print("- Cleared cache");
+      foreach ($messages as $message) {
+        drush_print('- ' . $message);
+      }
 
-  // Some settings will require special handling.  Allow other modules to
-  // run their own logic to properly switch the mode.
-  // Invokes hook_environment_switch().
-  $messages = array();
-  $messages = module_invoke_all('environment_switch', $target_env, $current_env);
-  foreach ($messages as $message) {
-    drush_print($message);
+      if ($result['result']) {
+        drush_print("Done.");
+      }
+      else {
+        drush_print("Failed.");
+      }
+    }
   }
-
-  // Clearing the cache one last time
-  if (count($messages) > 0) {
-    drupal_flush_all_caches();
+  else {
+    return drush_set_error('DRUSH_ENVIRONMENT_ERROR', dt('You must provide the environment to switch to.'));
   }
-
-  drush_print("\nDone.\n");
 }
diff --git environment.info environment.info
index 63d753f..636dd50 100644
--- environment.info
+++ environment.info
@@ -1,6 +1,4 @@
 ; $Id: environment.info,v 1.1 2010/03/04 05:38:42 ceardach Exp $
 name = Environment
 description = Sets the environment variable for a site instance
-
-version = "6.x-1.0"
-core = "6.x"
+core = 6.x 
\ No newline at end of file
diff --git environment.install environment.install
new file mode 100644
index 0000000..f368ae7
--- /dev/null
+++ environment.install
@@ -0,0 +1,40 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Handles installation of the Environment module.
+ */
+
+/**
+ * Implementation of hook_install().
+ */
+function environment_install() {
+  // New module weights in core: put environment as the very last in the chain.
+  db_query("UPDATE {system} SET weight = -100 WHERE name = 'environment'");
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function environment_uninstall() {
+  variable_del('environment');
+}
+
+/**
+ * Implementation of hook_requirements().
+ */
+function environment_requirements($phase) {
+  if ($phase == 'runtime') {
+    if (variable_get('environment_require_override', FALSE)) {
+      $t = get_t();
+      $requirements['environment_require_override'] = array(
+        'title'       => $t('Environment Override'),
+        'description' => $t("You should override the 'environment_override' variable in your settings.php file to indicate the server environment this site is in."),
+        'value'       => $t('Missing'),
+        'severity'    => REQUIREMENT_ERROR,
+      );
+      return $requirements;
+    }
+  }
+}
diff --git environment.module environment.module
index 0182eb4..09cfabd 100644
--- environment.module
+++ environment.module
@@ -2,5 +2,161 @@
 // $Id: environment.module,v 1.1 2010/03/04 05:38:42 ceardach Exp $
 
 /**
- * @file Placeholder file.  All functionality exists in the drush command.
+ * @file
+ * Module for handling changes in server environments
  */
+
+/**
+ * Implementation of hook_init().
+ */
+function environment_init() {
+  $env_override = variable_get('environment_override', NULL);
+  if ($env_override) {
+    $current_env  = variable_get('environment', NULL);
+    if ($current_env != $env_override) {
+      environment_switch($env_override);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function environment_menu() {
+  $items = array();
+
+  $base = array(
+    'access arguments' => array('administer site configuration'),
+    'file'             => 'environment.admin.inc',
+  );
+
+  $items['admin/settings/environment'] = array(
+    'title'            => 'Environment',
+    'description'      => 'Settings for Environment.',
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('environment_admin_settings'),
+    'access arguments' => array('administer filters'),
+  ) + $base;
+
+  return $items;
+}
+
+/**
+ * Implementation of hook_environments().
+ */
+function environment_environments() {
+  return array(
+    'production' => array(
+      'default' => TRUE,
+    ),
+    'development' => array(
+      'default' => FALSE,
+    ),
+  );
+}
+
+/**
+ * Check if something is allowed in the current environment.
+ *
+ * @param $name
+ *   Name of the thing to check if allowed, eg. function.
+ * @param $category
+ *   (optional) Category of the thing to check for, eg. name of module. Defaults to 'other'.
+ * @param $default
+ *   (optional) What the default should be if no environment value is found. Defaults to FALSE.
+ *
+ * @return
+ *   TRUE or FALSE for whether the thing is allowed.
+ */
+function environment_allowed($name, $category = 'other', $default = FALSE) {
+  $env = variable_get('environment', NULL);
+
+  if ($env) {
+    $env = environment_get($env);
+  }
+
+  if (!empty($env)) {
+    if (!empty($env[$category])) {
+      if (isset($env[$category][$name])) {
+        $result = $env[$category][$name];
+      }
+      elseif (isset($env[$category]['default'])) {
+        $result = $env[$category]['default'];
+      }
+    }
+    if (!isset($result) && isset($env['default'])) {
+      $result = $env['default'];
+    }
+  }
+
+  if (!isset($result)) {
+    $result = $default;
+  }
+
+  return $result;
+}
+
+/**
+ * Fetches all available environments.
+ *
+ * @param $env
+ *   (optional) Name of the environment.
+ *
+ * @return
+ *   Return all environments or the specified environment.
+ */
+function environment_get($env = NULL) {
+  static $environments;
+
+  if (!isset($environments)) {
+    $environments  = module_invoke_all('environments');
+    $environments += variable_get('environment_definitions', array());
+  }
+
+  if ($env) {
+    return isset($environments[$env]) ? $environments[$env] : FALSE;
+  }
+  else {
+    return $environments;
+  }
+}
+
+/**
+ * Switches between two environments.
+ *
+ * @param $target_env
+ *   Name of the environment to change to.
+ * @param $force
+ *   (optional) Whether to trigger a change even if the environment is the currently set one. Defaults to FALSE.
+ *
+ * @return
+ *   Return messages telling what has happened.
+ */
+function environment_switch($target_env, $force = FALSE) {
+  $result = FALSE;
+  $messages = array();
+
+  $current_env = variable_get('environment', NULL);
+
+  if ($current_env != $target_env || $force) {
+    if (!environment_get($target_env)) {
+      $messages[] = "Environment {$target_env} doesn't exists.";
+    }
+    else {
+      variable_set('environment', $target_env);
+
+      $messages += module_invoke_all('environment_switch', $target_env, $current_env);
+
+      drupal_flush_all_caches();
+
+      $messages[] = 'Cleared cache';
+
+      $result = TRUE;
+    }
+  }
+
+  return array(
+    'result'   => $result,
+    'messages' => $messages,
+  );
+}
