Skip to content
This repository
Browse code

Merge pull request #335 from yawnt/fix-334

UX Fix
  • Loading branch information...
commit 9113403ce814a2756ae04a92904c4b4f9030f454 2 parents dfd2b68 + 424fbd2
Farrin Reid blakmatrix authored

Showing 1 changed file with 34 additions and 17 deletions. Show diff stats Hide diff stats

  1. +34 17 lib/jitsu/commands/databases.js
51 lib/jitsu/commands/databases.js
@@ -113,32 +113,49 @@ databases.create = function (requestedDatabaseType, requestedDatabaseName, callb
113 113 }
114 114
115 115 function promptForDatabase (callback) {
116   - var getProperties = [];
  116 +
  117 + var funcs = [
  118 + function getDBName(cb) {
  119 + if(database.name) {
  120 + return cb();
  121 + }
117 122
118   - if (!database.name || !database.type) {
119   - if (!database.name) {
120 123 jitsu.log.error('Database name is required');
121   - getProperties.push({
  124 + jitsu.prompt.get({
122 125 name: 'database name',
123 126 default: database.type
  127 + }, function(e, res) {
  128 + database.name = res['database name'] || database.name;
  129 + cb();
124 130 });
125   - }
  131 + },
126 132
127   - if (!database.type) {
128   - jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ', or ' + 'mongo'.magenta);
129   - getProperties.push('database type');
  133 + function getDBType(cb) {
  134 + if(database.type) {
  135 + return cb();
  136 + }
  137 +
  138 + jitsu.log.warn('Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta +', or ' + 'mongo'.magenta);
  139 + jitsu.prompt.get('database type', function(e, res) {
  140 + database.type = res['database type'] || database.type;
  141 + cb();
  142 + });
  143 + }
  144 + ];
  145 +
  146 +
  147 + (function iterate(keys) {
  148 + var elem = funcs[--keys];
  149 +
  150 + if(!elem) {
  151 + return createDatabase(database, callback);
130 152 }
131   - }
132 153
133   - if (!getProperties.length) {
134   - return createDatabase(database, callback);
135   - }
  154 + elem(function dbIterator() {
  155 + iterate(keys);
  156 + });
136 157
137   - jitsu.prompt.get(getProperties, function (err, result) {
138   - database.type = result['database type'] || database.type;
139   - database.name = result['database name'] || database.name;
140   - createDatabase(database, callback);
141   - });
  158 + })(funcs.length);
142 159 }
143 160
144 161 promptForDatabase(callback);

0 comments on commit 9113403

Please sign in to comment.
Something went wrong with that request. Please try again.