Skip to content

Commit

Permalink
[minor] Small refactor to make jitsu.setup() async.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Apr 3, 2011
1 parent e971a29 commit f5121b9
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/jitsu.js
Expand Up @@ -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();
};

//
Expand All @@ -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();
};

//
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f5121b9

Please sign in to comment.