Update 'add' command

This commit is contained in:
Mattias Erming 2014-09-15 14:31:25 -07:00
parent 78d36d6750
commit c3552319cd

View File

@ -6,9 +6,9 @@ var mkdirp = require("mkdirp");
var Helper = require("../helper"); var Helper = require("../helper");
program program
.command("add <name>") .command("add <name> [<password>]")
.description("Add a new user") .description("Add a new user")
.action(function(name) { .action(function(name, password) {
var path = Helper.resolveHomePath("users"); var path = Helper.resolveHomePath("users");
try { try {
mkdirp.sync(path); mkdirp.sync(path);
@ -38,14 +38,20 @@ program
console.log(""); console.log("");
return; return;
} }
if (password) {
add(manager, name, password);
} else {
require("read")({ require("read")({
prompt: "Password: ", prompt: "Password: ",
silent: true silent: true
}, function(err, password) { }, function(err, password) {
console.log(""); if (!err) add(manager, name, password);
if (err) { });
return;
} }
});
function add(manager, name, password) {
console.log("");
var hash = bcrypt.hashSync(password, 8); var hash = bcrypt.hashSync(password, 8);
manager.addUser( manager.addUser(
name, name,
@ -53,5 +59,4 @@ program
); );
console.log("Added '" + name + "'."); console.log("Added '" + name + "'.");
console.log(""); console.log("");
}); }
});