Skip to content

Commit

Permalink
t2 run: hook up process.stdin to remote.stdin
Browse files Browse the repository at this point in the history
Unblocks use of readline, etc.

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 13, 2016
1 parent f2f7752 commit cb710fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
28 changes: 16 additions & 12 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,24 @@ exportables.run = function(tessel, opts) {
}

return prom.then(() => {
tessel.connection.exec(commands[opts.lang.meta.extname].execute(Tessel.REMOTE_RUN_PATH, opts.resolvedEntryPoint), {
pty: true
}, (error, remoteProcess) => {
if (error) {
return reject(error);
}
tessel.connection.exec(
commands[opts.lang.meta.extname].execute(Tessel.REMOTE_RUN_PATH, opts.resolvedEntryPoint), {
pty: true
}, (error, remoteProcess) => {
if (error) {
return reject(error);
}

// When the stream closes, return from the function
remoteProcess.once('close', resolve);
// When the stream closes, return from the function
remoteProcess.once('close', resolve);

// Pipe data and errors
remoteProcess.stdout.pipe(process.stdout);
remoteProcess.stderr.pipe(process.stderr);
});
// Pipe input TO the remote process.
process.stdin.pipe(remoteProcess.stdin);

// Pipe output FROM the remote process.
remoteProcess.stdout.pipe(process.stdout);
remoteProcess.stderr.pipe(process.stderr);
});
});
});
};
Expand Down
20 changes: 19 additions & 1 deletion test/unit/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,26 @@ exports['deploy.run'] = {
test.deepEqual(this.exec.lastCall.args[0], ['rust_executable']);
test.done();
});
}
},

runStdInOut: function(test) {
test.expect(1);

this.exec = sandbox.stub(this.tessel.connection, 'exec', (command, options, callback) => {
callback(null, this.tessel._rps);
this.tessel._rps.emit('close');
});

this.stdinPipe = sandbox.stub(process.stdin, 'pipe');

deploy.run(this.tessel, {
resolvedEntryPoint: 'foo',
lang: deployment.js,
}).then(() => {
test.equal(this.stdinPipe.callCount, 1);
test.done();
});
},
};

exports['deploy.createShellScript'] = {
Expand Down

0 comments on commit cb710fe

Please sign in to comment.