Skip to content
This repository
Browse code

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

  • Loading branch information...
commit f5121b9c6e3728b0832494aa9c0a865ada709e6f 1 parent e971a29
Charlie Robbins indexzero authored

Showing 1 changed file with 21 additions and 14 deletions. Show diff stats Hide diff stats

  1. +21 14 lib/jitsu.js
35 lib/jitsu.js
@@ -74,23 +74,29 @@ jitsu.start = function (command, callback) {
74 74 //
75 75 jitsu.exec = function (command, callback) {
76 76 if (!command) {
77   - return winston.error('No command supplied');
78   - }
79   - else if (!started) {
80   - jitsu.setup();
  77 + winston.error('No command supplied');
  78 + return jitsu.showError(command, {}, true, true);
81 79 }
82 80
83   - winston.info('Executing command ' + jitsu.commands.parse(command).splice(0, 2).join(' ').magenta);
84   - jitsu.commands.run(command, function (err, shallow) {
  81 + function execCommand (err) {
85 82 if (err) {
86   - return jitsu.showError(command, err, shallow);
  83 + return callback(err);
87 84 }
88 85
89   - //
90   - // TODO (indexzero): Something here
91   - //
92   - callback();
93   - });
  86 + winston.info('Executing command ' + jitsu.commands.parse(command).splice(0, 2).join(' ').magenta);
  87 + jitsu.commands.run(command, function (err, shallow) {
  88 + if (err) {
  89 + return jitsu.showError(command, err, shallow);
  90 + }
  91 +
  92 + //
  93 + // TODO (indexzero): Something here
  94 + //
  95 + callback();
  96 + });
  97 + }
  98 +
  99 + return !started ? jitsu.setup(execCommand) : execCommand();
94 100 };
95 101
96 102 //
@@ -108,6 +114,7 @@ jitsu.setup = function (callback) {
108 114 jitsu.apps = new jitsu.api.Apps(jitsu.config.settings);
109 115 jitsu.snapshots = new jitsu.api.Snapshots(jitsu.config.settings);
110 116 started = true;
  117 + callback();
111 118 };
112 119
113 120 //
@@ -152,8 +159,8 @@ jitsu.setupUser = function (callback) {
152 159 });
153 160 };
154 161
155   -jitsu.showError = function (command, err, shallow) {
156   - if (err.statusCode !== '403') {
  162 +jitsu.showError = function (command, err, shallow, skip) {
  163 + if (err.statusCode !== '403' && !skip) {
157 164 winston.error('Error running command ' + command.magenta);
158 165
159 166 if (err.message) {

0 comments on commit f5121b9

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