Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

replace the homegrown prompt method with the prompt npm package #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 27 additions & 12 deletions bin/scp2
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

var fs = require('fs');
var path = require('path');
var prompt = require("prompt");
var client = require('../');

prompt.message = "";

main(process.argv.slice());

function main(argv) {
Expand Down Expand Up @@ -76,10 +79,20 @@ function main(argv) {

client.on('error', function(err) {
if (err.code === 'ECONNREFUSED') {
prompt(' password: ', function(val) {
prompt.start();
prompt.get({
properties: {
password: {
hidden: true
}
}
}, function(err, values) {
if(err) {
process.exit(0);
}
client.close();
delete client.__ssh;
defaults.password = val;
defaults.password = values.password;
scp(src, dest, defaults);
});
} else {
Expand All @@ -92,8 +105,18 @@ function main(argv) {
defaults.privateKey = fs.readFileSync(identify);
scp(src, dest, defaults);
} else if (!password) {
prompt(' password: ', function(val) {
defaults.password = val;
prompt.start();
prompt.get({
properties: {
password: {
hidden: true
}
}
}, function(err, values) {
if(err) {
process.exit(0);
}
defaults.password = values.password;
scp(src, dest, defaults);
});
} else {
Expand Down Expand Up @@ -163,14 +186,6 @@ function printLog(quiet) {
}
}

function prompt(str, fn) {
process.stdout.write(str);
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(val) {
fn(val.trim());
}).resume();
}

function scp(src, dest, defaults) {
console.log();
client.defaults(defaults);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"async": "~0.9.0",
"glob": "~7.0.3",
"lodash": "~4.11.1",
"prompt": "^1.0.0",
"ssh2": "^0.6.0"
},
"repository": {
Expand Down