Permalink
Browse files

[feature] ui

  • Loading branch information...
1 parent dfd2b68 commit 10c699fe434f90e22e718f447c372977cecbedb6 @yawnt yawnt committed Oct 8, 2012
Showing with 33 additions and 16 deletions.
  1. +33 −16 lib/jitsu/commands/databases.js
@@ -113,32 +113,49 @@ databases.create = function (requestedDatabaseType, requestedDatabaseName, callb
}
function promptForDatabase (callback) {
- var getProperties = [];
+ var todo = [];
+
+ function getDBName(cb) {
+ jitsu.log.error('Database name is required');
+ jitsu.prompt.get({
+ name: 'database name',
+ default: database.name
+ }, function(e, res) {
+ database.name = res['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'];
+ cb();
+ });
+ }
+
if (!database.name || !database.type) {
if (!database.name) {
- jitsu.log.error('Database name is required');
- getProperties.push({
- name: 'database name',
- default: database.type
- });
+ todo.push(getDBName);
}
if (!database.type) {
- jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ', or ' + 'mongo'.magenta);
- getProperties.push('database type');
+ todo.push(getDBType);
}
}
- if (!getProperties.length) {
- return createDatabase(database, callback);
- }
+ (function iterate(keys) {
+ var elem = todo[--keys];
- jitsu.prompt.get(getProperties, function (err, result) {
- database.type = result['database type'] || database.type;
- database.name = result['database name'] || database.name;
- createDatabase(database, callback);
- });
+ if(!elem) {
+ return createDatabase(database, callback);
+ }
+
+ elem(function() {
+ iterate(keys);
+ });
+
+ })(todo.length);
}
promptForDatabase(callback);

0 comments on commit 10c699f

Please sign in to comment.