dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

BUG: vorpal.exec never fires callback with piped commands when using promises #33

Closed scotthovestadt closed 8 years ago

scotthovestadt commented 8 years ago

Looks like it affects promises only. The first command resolves, subsequent piped commands promise doesn't seem to be seen as resolved.

scotthovestadt commented 8 years ago

This issue is this block in command-instance.js

var res = fn.call(self.downstream, self.downstream.args, function () {
  self.session.completeCommand();
});

It's assuming that the command will return a callback instead of a promise. In other places, both types are accounted for. The fix is pretty simple:

var onComplete = function () {
  self.session.completeCommand();
};
var res = fn.call(self.downstream, self.downstream.args, onComplete);
if (res && res.then) {
  res.then(onComplete, onComplete);
}
dthree commented 8 years ago

Good find. Would you mind throwing in a PR for that?

scotthovestadt commented 8 years ago

Done. If you wouldn't mind doing a release after you've verified, I would appreciate it.

dthree commented 8 years ago

Thanks! :+1:

Patch v1.3.27 published for you :)