Skip to content

Commit

Permalink
Transport#exec() now supports advanced options. Buffer size for Shell…
Browse files Browse the repository at this point in the history
…Transport#exec increased.
  • Loading branch information
pstadler committed Aug 28, 2014
1 parent 9663bce commit 25d6ff1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ transport.ls('-al foo', {silent: true, failsafe: true});
To apply these options to multiple commands check out the docs of
`transport.silent()` and `transport.failsafe()`.

#### Advanced options
Flightplan uses `child_process#exec()` for executing local commands and
`mscdex/ssh2#exec()` for remote commands. Options passed with `exec` will
be forwarded to either of these.

```javascript
// increase maxBuffer for child_process#exec()
local.ls('-al', {exec: {maxBuffer: 2000*1024}});

// enable pty for mscdex/ssh2#exec()
remote.ls('-al', {exec: {pty: true}});
```

#### Return value
Each command returns an object containing `code`, `stdout` and`stderr`:

Expand Down
1 change: 0 additions & 1 deletion lib/transport/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var common = [
'hostname',
'kill',
'ln',
'whoami',
'ls',
'mkdir',
'mv',
Expand Down
13 changes: 13 additions & 0 deletions lib/transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ Transport.prototype = {
* To apply these options to multiple commands check out the docs of
* `transport.silent()` and `transport.failsafe()`.
*
* #### Advanced options
* Flightplan uses `child_process#exec()` for executing local commands and
* `mscdex/ssh2#exec()` for remote commands. Options passed with `exec` will
* be forwarded to either of these.
*
* ```javascript
* // increase maxBuffer for child_process#exec()
* local.ls('-al', {exec: {maxBuffer: 2000*1024}});
*
* // enable pty for mscdex/ssh2#exec()
* remote.ls('-al', {exec: {pty: true}});
* ```
*
* #### Return value
* Each command returns an object containing `code`, `stdout` and`stderr`:
*
Expand Down
6 changes: 5 additions & 1 deletion lib/transport/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ ShellTransport.prototype.__exec = function(cmd, args, options) {
stdout: null,
stderr: null
};
var execOptions = { maxBuffer: 1000*1024 };
execOptions = util._extend(execOptions, options.exec);

cmd = (cmd !== 'sudo') ? this._execWith + cmd : cmd;
cmd = cmd + (args ? ' ' + args : '');
this.logger.command(cmd);
proc = exec(cmd, options.execOptions || {});

proc = exec(cmd, execOptions);

proc.stdout.on('data', function(data) {
ret.stdout = (ret.stdout || '') + data;
Expand Down
8 changes: 4 additions & 4 deletions lib/transport/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function SSHTransport(flight, target) {
});

var options = util._extend({}, this.target); // clone
delete options.exec;
if(options.privateKey) {
options.privateKey = fs.readFileSync(options.privateKey, { encoding: 'utf8' });
}
Expand All @@ -36,13 +35,14 @@ SSHTransport.prototype.__exec = function(cmd, args, options) {
stdout: null,
stderr: null
};
var execOptions = {};
execOptions = util._extend(execOptions, options.exec);

cmd = (cmd !== 'sudo') ? this._execWith + cmd : cmd;
cmd = cmd + (args ? ' ' + args : '');

this.logger.command(cmd);
var execOpts = options.exec || this.target.exec || {};

this.connection.exec(cmd, execOpts, function(err, stream) {
this.connection.exec(cmd, execOptions, function(err, stream) {

stream.on('data', function(data, extended) {
if(extended === 'stderr') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flightplan",
"description": "Library for streamlining application deployment or systems administration tasks",
"version": "0.4.2",
"version": "0.4.3",
"author": "Patrick Stadler <patrick.stadler@gmail.com>",
"keywords": [
"deploy",
Expand Down

0 comments on commit 25d6ff1

Please sign in to comment.