UX Fix #335

Merged
merged 5 commits into from Oct 8, 2012
View
51 lib/jitsu/commands/databases.js
@@ -113,32 +113,49 @@ databases.create = function (requestedDatabaseType, requestedDatabaseName, callb
}
function promptForDatabase (callback) {
- var getProperties = [];
+
+ var funcs = [
+ function getDBName(cb) {
+ if(database.name) {
+ return cb();
+ }
- if (!database.name || !database.type) {
- if (!database.name) {
jitsu.log.error('Database name is required');
- getProperties.push({
+ jitsu.prompt.get({
name: 'database name',
default: database.type
+ }, function(e, res) {
+ database.name = res['database name'] || database.name;
+ cb();
});
- }
+ },
- if (!database.type) {
- jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ', or ' + 'mongo'.magenta);
- getProperties.push('database type');
+ 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 = funcs[--keys];
+
+ if(!elem) {
+ return createDatabase(database, callback);
}
- }
- if (!getProperties.length) {
- return createDatabase(database, callback);
- }
+ elem(function dbIterator() {
+ iterate(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);
- });
+ })(funcs.length);
}
promptForDatabase(callback);