Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to inquire for password #8

Merged
merged 1 commit into from
Dec 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});
};