diff --git a/README.md b/README.md index 694caa4..870fcaf 100644 --- a/README.md +++ b/README.md @@ -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`: diff --git a/lib/transport/commands.js b/lib/transport/commands.js index 2492875..4d26b1e 100644 --- a/lib/transport/commands.js +++ b/lib/transport/commands.js @@ -14,7 +14,6 @@ var common = [ 'hostname', 'kill', 'ln', - 'whoami', 'ls', 'mkdir', 'mv', diff --git a/lib/transport/index.js b/lib/transport/index.js index f16ad1c..e23513c 100644 --- a/lib/transport/index.js +++ b/lib/transport/index.js @@ -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`: * diff --git a/lib/transport/shell.js b/lib/transport/shell.js index fc5156f..d0ec9f3 100644 --- a/lib/transport/shell.js +++ b/lib/transport/shell.js @@ -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; diff --git a/lib/transport/ssh.js b/lib/transport/ssh.js index e07f166..822bc3e 100644 --- a/lib/transport/ssh.js +++ b/lib/transport/ssh.js @@ -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' }); } @@ -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') { diff --git a/package.json b/package.json index d8ad96b..025b57d 100644 --- a/package.json +++ b/package.json @@ -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 ", "keywords": [ "deploy",