andrewrjones/grunt-ssh — pull request #18 by andysprout (2013-05-27 23:46:49+00:00)
Title: Adding support for multiple comands

I wanted to perform quite a few commands one after the other so decided to extend the code to support an array of commands. I also added a "ignoreErrors" option to control if the code should stop if one of the commands fails.

Most of the changes are to add another util function: `validateStringArrayAndProcess` that processes a string or string array and returns a string array. A also created unit tests for this and the other util functions. There appeared to be a bug that 0 was not considered a valid number by `validateNumber` but this function wasn't being used anywhere in the plugin.

In sshexec I created a new function `execCommand` that gets called firstly when the connection is ready, then recurses through the list of commands until there is an error, or they are all executed.

When the command exits (see below) I am could not find any documentation about what values the `code` could be, but it seemed that 0 meant success and any other value meant failure.

```javascript
stream.on('exit', function (code, signal) {
grunt.verbose.writeln('Stream :: exit :: code: ' + code + ', signal: ' + signal);
if(!options.ignoreErrors && code !== 0) {
grunt.fail.warn('Error executing task ' + command);
c.end();
} else {
execCommand();
}
});
```