collect stdout only if flag is set

This commit is contained in:
oleg 2014-12-14 23:00:48 +03:00
parent a47f9e2cdf
commit 06f33fa3ff
2 changed files with 3 additions and 3 deletions

View File

@ -20,7 +20,7 @@ inherits(Command, ParentCommand);
*/
Command.prototype.run = function(params, callback) {
var self = this,
stdout = '';
stdout = self.isCollect ? '' : null;
if (!params.cmd) return callback(new Error('`cmd` is not set'));
if (!params.args) return callback(new Error('`args` is not set'));
callback = utils.once(callback);
@ -29,8 +29,7 @@ Command.prototype.run = function(params, callback) {
var cmd = spawn(params.cmd, params.args, params.options);
cmd.stdout.on('data', function(data) {
if (self.isEmit) self.emit('stdout', data);
// TODO: join stdout only if flag is set
stdout += data;
if (self.isCollect) stdout += data;
});
cmd.stderr.on('data', function(data) {
callback(new Error('Spawned command outputs to stderr: ' + data));

View File

@ -9,6 +9,7 @@ function Scm(params) {
if (!this.repository && !this.cwd) throw new Error(
'`repository` or `cwd` must be set'
);
this.isCollect = true;
}
exports.Scm = Scm;