Skip to content

Commit

Permalink
Merge pull request #8 from nickbabcock/inquire
Browse files Browse the repository at this point in the history
Add ability to inquire for password
  • Loading branch information
lepture committed Dec 28, 2013
2 parents f5fc327 + 444b01e commit fb74ea7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"dependencies": {
"async": "~0.2.6",
"scp2": "~0.1.4"
"scp2": "~0.1.4",
"inquirer": "~0.3.5"
},
"keywords": [
"gruntplugin"
Expand Down
35 changes: 27 additions & 8 deletions tasks/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
var path = require('path');
var async = require('async');
var Client = require('scp2').Client;
var inquirer = require('inquirer');

module.exports = function(grunt) {

Expand All @@ -21,6 +22,7 @@ module.exports = function(grunt) {
var done = this.async();
var filename, destfile;
var client = new Client(options);
var files = this.files;

client.on('connect', function() {
grunt.log.writeln('ssh connect ' + options.host);
Expand Down Expand Up @@ -56,14 +58,16 @@ module.exports = function(grunt) {
return false;
});

async.eachSeries(this.files, function(fileObj, cb) {
upload(fileObj, cb);
}, function(err) {
if (err) {
grunt.log.error('Error ' + err);
}
client.close();
});
function execUploads() {
async.eachSeries(files, function(fileObj, cb) {
upload(fileObj, cb);
}, function(err) {
if (err) {
grunt.log.error('Error ' + err);
}
client.close();
});
}

function upload(fileObj, cb) {
async.eachSeries(fileObj.src, function(filepath, cb) {
Expand All @@ -79,5 +83,20 @@ module.exports = function(grunt) {
cb(err);
});
}

if (options.password === true) {
inquirer.prompt([{
name: 'password',
message: 'password: ',
type: 'password'
}], function(answers) {
options.password = answers.password;
client.defaults(options);
execUploads();
});
}
else {
execUploads();
}
});
};

0 comments on commit fb74ea7

Please sign in to comment.