Permalink
Browse files

[api] More work on several apps commands

  • Loading branch information...
1 parent f2d51cf commit 3258b2a54def365184f2204e90043e7a05bfcc94 @indexzero indexzero committed Mar 5, 2011
Showing with 50 additions and 9 deletions.
  1. +5 −0 lib/jitsu.js
  2. +2 −2 lib/jitsu/api/apps.js
  3. +23 −4 lib/jitsu/commands/apps.js
  4. +3 −3 lib/jitsu/commands/config.js
  5. +17 −0 lib/jitsu/prompt.js
View
@@ -85,6 +85,11 @@ jitsu.exec = function (command, callback) {
if (err && !/403/.test(err.message)) {
winston.error('Error running command ' + command.magenta);
winston.error(err.message);
+ if (err.stack) {
+ err.stack.split('\n').forEach(function (trace) {
+ winston.error(trace);
+ })
+ }
return
}
View
@@ -41,8 +41,8 @@ Apps.prototype.list = function (callback) {
// Creates an application with the specified package.json manifest in `app`.
//
Apps.prototype.create = function (app, callback) {
- this._request('POST', ['apps', app.name], app, callback, function (err, res, body) {
-
+ this._request('POST', ['apps', jitsu.config.username, app.name], app, callback, function (res, result) {
+ callback();
});
};
View
@@ -18,10 +18,10 @@ apps.list = function (callback) {
apps.forEach(function (app) {
rows.push([
app.name,
- app.state,
+ app.state || 'stopped',
app.subdomain,
- app.scripts.start,
- app.snapshots[0].filename
+ app.scripts.start || '---',
+ app.snapshots && app.snapshots.length > 0 ? app.snapshots[0].filename : '---'
]);
});
@@ -30,7 +30,26 @@ apps.list = function (callback) {
};
apps.create = function (name, callback) {
-
+ jitsu.utils.readPackage(process.cwd(), function (err, pkg) {
+ if (!callback) {
+ callback = name;
+ name = null;
+ }
+
+ pkg.name = name || pkg.name;
+ //
+ // TODO (indexzero): Configure this default value in nodejitsu APIs
+ //
+ pkg.state = 'stopped';
+ winston.info('Validating package.json for ' + pkg.name.magenta);
+ jitsu.prompt.addProperties(pkg, ['subdomain'], function (updated) {
+ winston.info('Creating app ' + pkg.name.magenta);
+ jitsu.apps.create(updated, function (err, res, result) {
+ winston.silly('Done creating app ' + pkg.name.magenta);
+ return err ? callback(err) : callback();
+ });
+ });
+ });
};
apps.update = function (name, callback) {
@@ -21,7 +21,7 @@ config.get = function (key, callback) {
return winston.error('No configuration value for ' + key.yellow);
}
- winston.info([key.yellow, jitsu.config.settings[key].magenta].join(' '));
+ winston.data([key.yellow, jitsu.config.settings[key].magenta].join(' '));
callback();
};
@@ -44,10 +44,10 @@ config.list = function (callback) {
prefix = prefix || '';
Object.keys(obj).forEach(function (key) {
if (Array.isArray(obj[key])) {
- winston.info((prefix + key).yellow + ' ' + obj[key].join(' ').magenta);
+ winston.data((prefix + key).yellow + ' ' + obj[key].join(' ').magenta);
}
else {
- winston.info((prefix + key).yellow + ' ' + obj[key].toString().magenta);
+ winston.data((prefix + key).yellow + ' ' + obj[key].toString().magenta);
}
});
}
View
@@ -130,4 +130,21 @@ prompt.getInput = function (msg, validator, callback) {
linereader.prompt();
prompt.resume();
return prompt;
+};
+
+prompt.addProperties = function (obj, properties, callback) {
+ properties = properties.filter(function (prop) {
+ return typeof obj[prop] === 'undefined';
+ });
+
+ if (properties.length === 0) {
+ return callback(obj);
+ }
+
+ prompt.get(properties, function (results) {
+ Object.keys(results).forEach(function (key) {
+ obj[key] = results[key];
+ callback(obj);
+ });
+ });
};

0 comments on commit 3258b2a

Please sign in to comment.