'use strict';

// load db models
var db = require( '../models' );

// command prompt aid
var readline = require( 'readline' );
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

// regex to validate email is real
var emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

// output script banner
var banner = '\n\nSet administrator by email.\n\n' +
             'You will be repeatedly prompted for emails until a blank \n' +
             'line is detected indicating no more emails to be provided.\n' +
             '----------------------------------------------------------\n';
console.log( banner );

// get email(s) and set them as admins
(function getEmail() {
  rl.question( 'Email to set as admin: ', function( email ) {
    if( emailRegex.test( email ) ) {
      return db.User.find({
        where: {
          email: email
        }
      }).done( function( error, user ) {
        if( !user ) {
          console.log( '%s is not currently a user. Cannot set as admin.\n', email );

          return getEmail();
        }

        user.updateAttributes({
          isAdmin: true
        }).success( function( user ) {
          console.log( '%s was set as admin.\n', user.email );

          return getEmail();
        });
      });
    }

    // check if empty response (indicating exit)
    if( email === '' ) {
      rl.close();
      return;
    }

    console.log( '%s did not validate as an email address.\n', email );

    return getEmail();
  });
}());

@@ -8,16 +8,106 @@
 rict';%0A%0A
+// laod env%0Avar Habitat = require( 'habitat' );%0Avar env = new Habitat();%0AHabitat.load();%0A%0A
 // load 
@@ -145,16 +145,23 @@
 /models'
+ )( env
  );%0A%0A// 

Update setAdmin tool