Skip to content
Browse files

[minor] Small refactor to make `jitsu.setup()` async.

  • Loading branch information...
1 parent e971a29 commit f5121b9c6e3728b0832494aa9c0a865ada709e6f @indexzero indexzero committed Apr 3, 2011
Showing with 21 additions and 14 deletions.
  1. +21 −14 lib/jitsu.js
View
35 lib/jitsu.js
@@ -74,23 +74,29 @@ jitsu.start = function (command, callback) {
//
jitsu.exec = function (command, callback) {
if (!command) {
- return winston.error('No command supplied');
- }
- else if (!started) {
- jitsu.setup();
+ winston.error('No command supplied');
+ return jitsu.showError(command, {}, true, true);
}
- winston.info('Executing command ' + jitsu.commands.parse(command).splice(0, 2).join(' ').magenta);
- jitsu.commands.run(command, function (err, shallow) {
+ function execCommand (err) {
if (err) {
- return jitsu.showError(command, err, shallow);
+ return callback(err);
}
- //
- // TODO (indexzero): Something here
- //
- callback();
- });
+ winston.info('Executing command ' + jitsu.commands.parse(command).splice(0, 2).join(' ').magenta);
+ jitsu.commands.run(command, function (err, shallow) {
+ if (err) {
+ return jitsu.showError(command, err, shallow);
+ }
+
+ //
+ // TODO (indexzero): Something here
+ //
+ callback();
+ });
+ }
+
+ return !started ? jitsu.setup(execCommand) : execCommand();
};
//
@@ -108,6 +114,7 @@ jitsu.setup = function (callback) {
jitsu.apps = new jitsu.api.Apps(jitsu.config.settings);
jitsu.snapshots = new jitsu.api.Snapshots(jitsu.config.settings);
started = true;
+ callback();
};
//
@@ -152,8 +159,8 @@ jitsu.setupUser = function (callback) {
});
};
-jitsu.showError = function (command, err, shallow) {
- if (err.statusCode !== '403') {
+jitsu.showError = function (command, err, shallow, skip) {
+ if (err.statusCode !== '403' && !skip) {
winston.error('Error running command ' + command.magenta);
if (err.message) {

0 comments on commit f5121b9

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