Permalink
Browse files

[refactor] cleanup

  • Loading branch information...
1 parent a0e7fac commit 424fbd2165b51f9de153f0f3e15af93821e1cdab @yawnt yawnt committed Oct 8, 2012
Showing with 30 additions and 30 deletions.
  1. +30 −30 lib/jitsu/commands/databases.js
@@ -113,39 +113,39 @@ databases.create = function (requestedDatabaseType, requestedDatabaseName, callb
}
function promptForDatabase (callback) {
- var todo = [];
-
- function getDBName(cb) {
- jitsu.log.error('Database name is required');
- jitsu.prompt.get({
- name: 'database name',
- default: database.type
- }, function(e, res) {
- database.name = res['database name'] || database.name;
- cb();
- });
- }
-
- function getDBType(cb) {
- jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta +', or ' + 'mongo'.magenta);
- jitsu.prompt.get('database type', function(e, res) {
- database.type = res['database type'] || database.type;
- cb();
- });
- }
- if (!database.name || !database.type) {
- if (!database.name) {
- todo.push(getDBName);
- }
+ var funcs = [
+ function getDBName(cb) {
+ if(database.name) {
+ return cb();
+ }
- if (!database.type) {
- todo.push(getDBType);
- }
- }
+ jitsu.log.error('Database name is required');
+ jitsu.prompt.get({
+ name: 'database name',
+ default: database.type
+ }, function(e, res) {
+ database.name = res['database name'] || database.name;
+ cb();
+ });
+ },
+
+ function getDBType(cb) {
+ if(database.type) {
+ return cb();
+ }
+ jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta +', or ' + 'mongo'.magenta);
+ jitsu.prompt.get('database type', function(e, res) {
+ database.type = res['database type'] || database.type;
+ cb();
+ });
+ }
+ ];
+
+
(function iterate(keys) {
- var elem = todo[--keys];
+ var elem = funcs[--keys];
if(!elem) {
return createDatabase(database, callback);
@@ -155,7 +155,7 @@ databases.create = function (requestedDatabaseType, requestedDatabaseName, callb
iterate(keys);
});
- })(todo.length);
+ })(funcs.length);
}
promptForDatabase(callback);

0 comments on commit 424fbd2

Please sign in to comment.